Skip to content

TIGRE as a CT backend, chosen library-wide and recorded in the geometry - #397

Open
AnderBiguri wants to merge 2 commits into
mainfrom
tigre-backend
Open

AnderBiguri wants to merge 2 commits into
mainfrom
tigre-backend

Conversation

@AnderBiguri

@AnderBiguri AnderBiguri commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

First step of TIGRE as LION's CT backend (design: the project note lion-tigre-backend-design.md). TIGRE 3.3.0 keeps PyTorch CUDA tensors on their GPU, so this is now possible; the tigre extra installs 3.3.1 (faster, same API).

What it does

  • CTProjectionOp(backend="tigre"): projection (tigre.Ax, Siddon), backprojection (tigre.Atb, "matched", so it is the adjoint), autograd() (two small torch.autograd.Functions, batched), in LION's layout: images (1, H, W), sinograms (1, angles, detectors), the same as tomosipo. CUDA tensors stay on their GPU; CPU tensors go through NumPy. The TIGRE code is in LION/operators/ct/_tigre.py.
  • FDK/FBP with TIGRE: torch weighting and TIGRE's Ram-Lak filter (ported from tigre.utilities.filtering), then TIGRE's backprojection (FDK weights for fan beam), on the GPU, and differentiable with differentiable=True. It is tigre.algorithms.fdk/fbp without Parker weights: LION's tomosipo FDK has none either.
  • The library-wide choice: LION.operators.ct.set_ct_backend("tigre"); tomosipo stays the default until the comparison below.
  • Recorded, as agreed:
    • OperatorParameters.backend (generic) and Geometry.backend: "default" unless set, replaced by the backend used when the operator is made or the geometry saved (the initial_reconstruction = "default" pattern). Every record that has the geometry (models, solvers, reconstructors, experiments, data records) says which backend was used, and loading makes the operator with it again, whatever the current setting.
    • Operator.backend: which library computes an operator (None for torch-only ones).
  • Needs tomosipo, for now: sirt and tv_min raise a clear NotImplementedError with another backend (require_ct_backend). The 2DeteCT loader still uses ts_algorithms itself. Porting them is the next PR.
  • DeepFusionBP asks its single-angle operators for autograd() instead of calling tomosipo's to_autograd itself. For tomosipo it is the same call, and it now works with TIGRE.
  • import_tigre (LION/utils/tigre_import.py); a tigre extra in pyproject.toml (TIGRE isn't on PyPI); tigre in the environment record's packages; a tigre pytest marker; README, CHANGELOG, contributor guide.

What changes for existing results

Nothing is computed differently: tomosipo is still the default. Saved geometries now have "backend": "tomosipo". CTProjectionOp's backend argument now defaults to None (the geometry's), and its shapes come from the geometry rather than tomosipo (they are the same).

Not verified yet: conventions and numbers (needs holly)

TIGRE can't be built here (no CUDA), so the LION-side code was tested with a stand-in TIGRE (a matrix): layout, adjointness, batching, autograd, FDK, records. The angle and detector conventions that make TIGRE's sinogram equal tomosipo's are my reading of the two libraries: TIGRE angle = LION angle − π/2, detector not flipped (ANGLE_SIGN, ANGLE_OFFSET, FLIP_U in _tigre.py). The script finds the right ones.

On holly:

cd ~/AItomotools
git fetch origin tigre-backend && git checkout tigre-backend
mamba activate <your LION env>
pip install "tigre @ git+https://github.com/CERN/TIGRE.git@v3.3.1"
python -m pytest -q pytests/test_ct_backends.py      # 2 tests need TIGRE and tomosipo with CUDA
python scripts/tigre_vs_tomosipo.py --out ~/tigre_vs_tomosipo

The script (internal: to remove before merging) prints:

  1. Conventions: the error of each of 16 sign/offset/flip choices, for fan and parallel beam, and the best. If it isn't the one in _tigre.py, I'll change it.
  2. Agreement on LION's geometries (default fan, sparse view, limited angle, parallel): projection, backprojection and its scale, FDK against tomosipo's, both FDKs against the phantom, LION's TIGRE FDK against tigre.algorithms.fdk/fbp, and each backend's adjointness. It also saves fdk.png.
  3. Speed and memory: projection, backprojection, FDK and one LPD training step, at batch sizes 1, 4 and 16 (--batch-sizes). torch's peak memory doesn't include TIGRE's own CUDA allocations, so it also reports the change in free GPU memory.

Please send me the output and results.json.

Open (for after the numbers)

  • Making TIGRE the default (its own PR), then porting SIRT, TV-min and the 2DeteCT loader.
  • Parallel beam could project a whole batch in one TIGRE call (as z-slices) instead of one sample at a time, if the speed numbers say it's worth it.
  • Siddon (TIGRE's default) vs "interpolated" projection, and Parker weights for short scans in FDK.

Generated by Claude Code

CTProjectionOp(backend="tigre"): projection, matched backprojection,
autograd and FDK/FBP (TIGRE's, in torch) with TIGRE 3.3.0, on the tensors'
GPU. set_ct_backend() chooses the backend library-wide (tomosipo by
default); a geometry's backend ("default" unless set) is replaced by the
one used when the operator is made or the geometry saved, so records say
which backend made a result and loading uses it again. Operator.backend
says which library computes an operator.

SIRT and TV-min need tomosipo (require_ct_backend). DeepFusionBP asks its
single-angle operators for autograd() instead of calling tomosipo.

scripts/tigre_vs_tomosipo.py (to remove before merging) finds TIGRE's
angle/detector convention against tomosipo and compares agreement, speed
and memory.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L6n1VL9muzzcts6DAv9Vzm
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L6n1VL9muzzcts6DAv9Vzm

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants