Contributing to TIGRE#
Thanks for helping improve TIGRE! Bug reports, fixes, new algorithms, demos and documentation are all welcome. This guide explains how to get set up and what we look for in a pull request.
By participating you agree to follow our Code of Conduct.
Asking questions and reporting bugs#
Questions about using TIGRE (geometry setup, which algorithm to use, loading your scanner data): please open a Discussion rather than an issue. Check the FAQ first.
Bugs: open an issue using the bug template. Include a minimal script that reproduces the problem, and your OS, GPU, CUDA version and MATLAB/Python version (
tigre.show_versions()in Python ortigreVersionin MATLAB prints most of them). Most TIGRE bugs depend on these.Feature ideas: open an issue with the feature template so we can discuss the design before you write a lot of code.
Setting up a development environment#
You need an NVIDIA GPU, the CUDA toolkit and a C++ compiler (MSVC on Windows, gcc on Linux). See the full installation guides for Python and MATLAB.
Python#
git clone https://github.com/<your-username>/TIGRE.git
cd TIGRE
python -m venv .venv # or a conda environment
source .venv/bin/activate # .venv\Scripts\activate on Windows
pip install --group dev . # builds the CUDA extensions and installs dev tools
Re-run pip install . after changing any CUDA (Common/CUDA) or Cython
(Python/tigre/utilities/cuda_interface) code, since those need recompiling.
By default the CUDA code is compiled for every GPU architecture your nvcc
supports, which takes a while. While developing, compile only for your own GPU
with TIGRE_CUDA_ARCH, several times faster (the build then runs only on that
GPU, so don’t distribute it):
TIGRE_CUDA_ARCH=native pip install . # the GPUs in this machine (nvcc 11.6+)
TIGRE_CUDA_ARCH=89 pip install . # or by compute capability, e.g. 89 for RTX 40xx; 75,89 for two
On Windows: set TIGRE_CUDA_ARCH=native before pip install ..
MATLAB#
Run MATLAB/Compile.m once to build the MEX files, then InitTIGRE at the start of
each session to add TIGRE to the path.
setenv('TIGRE_CUDA_ARCH','native') before Compile does the same as for Python.
Running the tests#
pytest
Tests live in Python/tests/. Tests that need a GPU are marked with
@pytest.mark.gpu (or pytestmark = pytest.mark.gpu for a whole file) and are
skipped automatically on machines without one, which is how they run on GitHub
Actions. Please run the suite on a GPU machine before submitting changes to
projectors, kernels or algorithms.
A plain pytest runs the core suite (a few minutes with a GPU). Tests for rare
edge cases and stress tests, such as running with almost no free GPU memory,
thousands of repeated calls or images that must be split, are marked
extended and are not run by default:
pytest -m extended # only the extended tests
pytest -m "extended or not extended" # everything
Run the extended tests too when you change CUDA code, memory handling or how
the image is split between GPUs. Mark a new test extended if it guards a rare
case and takes long or needs a particular amount of free GPU memory.
MATLAB tests are in MATLAB/Tests/.
GitHub’s runners have no GPU, so the GPU and MATLAB tests are run by hand on a
maintainer’s machine, before merging changes to CUDA code or algorithms and
before a release. On Windows, tools/run_gpu_tests.ps1 -Ref <PR number> checks
the pull request out in a separate folder, builds it, runs both test suites and
writes a summary to paste into the pull request.
Making a change#
Fork the repository and create a branch from
masterwith a descriptive name (fix/fdk-offset-weights,feature/new-loader).Keep each pull request focused on one thing. Small PRs get reviewed faster.
Add tests for new behaviour, and for bug fixes that could plausibly come back or that affect results. Keep them few and small (up to 64^3 volumes, a few seconds each), and extend an existing test before adding a new file. Pure-Python logic should be testable without a GPU; mock
Ax/Atbif needed (seePython/tests/test_krylov_restart_and_norms.pyfor an example).Update the demos and documentation if you change user-facing behaviour.
Add a line to
changelog.mdunder the next release. Do not rename, remove or change the meaning of anything public (includinggeofields and their conventions) without first deprecating it, as described in the compatibility policy.Open the pull request and fill in the template.
Code style#
Python is formatted with black (line length 100) and checked with flake8. Run
black .before committing.Use numpy-style docstrings for public functions, and describe every parameter.
MATLAB code should follow the style of the surrounding files, with a help block at the top of each function.
MATLAB and Python parity#
TIGRE aims to offer the same features in both languages. If you add a feature or algorithm to one, either port it to the other in the same PR or open an issue so someone else can. Keep argument names and defaults the same across both.
Adding an algorithm#
Python: add it to the matching family module in
Python/tigre/algorithms/(for examplekrylov_subspace_algorithms.py,pocs_algorithms.py), deriving fromIterativeReconAlgwhere possible, and export it inPython/tigre/algorithms/__init__.py.MATLAB: add the function to
MATLAB/Algorithms/.Add or extend a demo showing how to use it.
If it implements a published method, add the reference to
TIGRE.bib(bothPython/tigre/utilities/TIGRE.bibandMATLAB/Utilities/TIGRE.bib) and cite it in the docstring.
Changing CUDA kernels#
The kernels in Common/CUDA are shared by both languages, so changes affect
MATLAB and Python. Please mention in the PR which GPU(s) and CUDA version(s) you
tested on, and include timings if the change is meant to improve performance.
Recognition#
We use all-contributors to thank everyone who contributes, including code, documentation, bug reports and user testing. Ask in your PR to be added.
License#
By contributing to TIGRE, you agree that your contributions will be licensed under its BSD 3-Clause license.