Develop pySRX¶
To change pySRX itself or run its tests, work inside the pySRX repository. To use pySRX in a project, see Getting started instead.
Work inside the pySRX repository¶
git clone git@github.com:Oxford-Zeiss-Centre-of-Excellence/pySRX.git
cd pySRX
pixi install # the default environment, pySRX itself is editable
pixi run test # the test suite, CPU
pixi run lint # ruff
Every command then runs as pixi run <command>, or start a shell inside the
environment with pixi shell. There are three environments:
| Environment | Use | PyTorch |
|---|---|---|
default |
development, tests, CI | CPU (pytorch-cpu) |
cuda |
reconstructions on a GPU | CUDA 12 (pytorch-gpu, CuPy) |
docs |
this guide | CPU, plus MkDocs Material and mkdocstrings |
Tests that need a CUDA device are marked gpu, and tests that need real data
on a mounted share are marked data. CI leaves both out:
pixi run -e cuda test # everything, on a GPU
pixi run test -m "not gpu and not data" # what CI runs
A fix made from inside a project's dependency/pySRX submodule is a pySRX
commit: commit and push it in pySRX, then commit the new submodule pointer in
the project.
GPU acceleration¶
pySRX runs its heavy work in PyTorch on CUDA and a few metrics in CuPy; everything also runs on the CPU, which is what CI tests. The list of GPU functions and the GPU tutorial describe them for users. New code follows the same rules:
- One device choice. A function that creates tensors from nothing takes
device=; anything that receives an operator, a PSF or a tensor uses that object's device. Never call.cuda()or hard-code"cuda"inside a function body. - CPU always works. Every function runs with
device="cpu", and its tests run on the CPU in CI. Tests that need a GPU (speed, memory) are markedgpu. - CUDA-only calls are guarded.
torch.cuda.synchronize, the memory counters andempty_cacheare called only whendevice.type == "cuda". - NumPy in, NumPy out. Public functions accept NumPy arrays and return NumPy arrays on the host (result dataclasses hold NumPy); tensors stay inside.
- Report time and memory. Solvers and fits return
secondsandpeak_vram_gb, measured after asynchronize. - Memory through chunks, not through luck. Large volumes are processed in
chunks with a documented knob (
z_chunk,plane_chunk); a default must fit an 8 GB card on the test crop. - Precision. float32 for volumes and images; float64 only where it matters (phases, frequencies, metric sums), and stated in the docstring.
- CuPy only through
pysrx.gpu. Usegpu.xp,gpu.ndi,gpu.to_gpuandgpu.to_cpu, so the NumPy and SciPy fallback is automatic; free the cache withgpu.clear()after large arrays. - Add it to the list. A new GPU function gets a row in GPU acceleration.
Edit this guide¶
The guide is in docs/ (Markdown) and mkdocs.yml; the API reference is
generated from the docstrings. Start the live preview, which reloads on every
save:
pixi run -e docs docs-serve # http://127.0.0.1:8766/
pixi run -e docs site runs what CI runs: the strict build and the leak check,
into site/. Every pull request runs the same build; merging to main
publishes it to https://pysrx.pages.dev/. Translations follow
docs/TRANSLATING.md.