From 2a089a58baa2692c71820027c3b52583ebfc2eba Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 18:06:49 +0000 Subject: [PATCH 1/2] Docs: plugins page, proton CT in the API reference, pCT papers in TIGRE.bib - docs/user-guide/plugins.md: what plugins are, building them (TIGRE_PLUGINS, Compile / all), where they live, and how to add one (build, test skip pattern, docs). - User guide index: a Plugins section with plugins and proton-ct. - API reference: Python and MATLAB plugin pages (pCTCubicSpline); the compiled _pct module is mocked for autodoc. - proton-ct.md: links to the plugins page, the API and the paper; parallel beam is the checked mode. - TIGRE.bib (both): Kaser et al. 2023 and Collins-Fekete et al. 2016. - AGENTS.md: where plugins live. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01L6n1VHyq4uNorM3CAiBUPo --- AGENTS.md | 5 ++ MATLAB/Utilities/TIGRE.bib | 36 ++++++++++ Python/tigre/utilities/TIGRE.bib | 36 ++++++++++ changelog.md | 2 + docs/_ext/tigre_matlab_api.py | 1 + docs/api/matlab/index.md | 1 + docs/api/matlab/plugins.md | 15 ++++ docs/api/python/index.md | 1 + docs/api/python/plugins.md | 20 ++++++ docs/conf.py | 1 + docs/user-guide/index.md | 14 ++++ docs/user-guide/plugins.md | 115 +++++++++++++++++++++++++++++++ docs/user-guide/proton-ct.md | 12 +++- 13 files changed, 257 insertions(+), 2 deletions(-) create mode 100644 docs/api/matlab/plugins.md create mode 100644 docs/api/python/plugins.md create mode 100644 docs/user-guide/plugins.md diff --git a/AGENTS.md b/AGENTS.md index 5ea94f4d..8bf181a5 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -17,6 +17,11 @@ MATLAB and Python on top of shared CUDA code. `Python/demos/`. - `MATLAB/`: the MATLAB toolbox (`Algorithms/`, `Utilities/`, `Demos/`, `Tests/`). `Compile.m` builds the MEX files. +- Plugins (optional parts, outside the core): `Python/tigre/plugins//`, + `MATLAB/Plugins//`, CUDA in `Common/CUDA/plugins//`. Compiled + plugins are not built by default (`TIGRE_PLUGINS=|all`, + `Compile ` / `Compile all`). How to add one: + https://cern.github.io/TIGRE/user-guide/plugins.html - `docs/`: the website (Sphinx, MyST Markdown), https://cern.github.io/TIGRE/. - `changelog.md`, `CITATION.cff`, `pyproject.toml`: release notes, citation and version. diff --git a/MATLAB/Utilities/TIGRE.bib b/MATLAB/Utilities/TIGRE.bib index 565d719e..26895b80 100644 --- a/MATLAB/Utilities/TIGRE.bib +++ b/MATLAB/Utilities/TIGRE.bib @@ -435,4 +435,40 @@ @article{https://doi.org/10.1002/mp.17002 url = {https://aapm.onlinelibrary.wiley.com/doi/abs/10.1002/mp.17002}, eprint = {https://aapm.onlinelibrary.wiley.com/doi/pdf/10.1002/mp.17002}, +pCTCubicSpline + +S. Kaser, T. Bergauer, A. Biguri, W. Birkfellner, S. Hatamikia, A. Hirtl, C. Irmler, B. Kirchmayer and F. Ulrich-Pur. +Extension of the open-source TIGRE toolbox for proton imaging. +Zeitschrift fur Medizinische Physik, 33(4):552-566, 2023. +DOI: 10.1016/j.zemedi.2022.08.005 + +@article{pCT_TIGRE, + author={Kaser, Stefanie and Bergauer, Thomas and Biguri, Ander and Birkfellner, Wolfgang and Hatamikia, Sepideh and Hirtl, Albert and Irmler, Christian and Kirchmayer, Benjamin and Ulrich-Pur, Felix}, + title={Extension of the open-source {TIGRE} toolbox for proton imaging}, + journal={Zeitschrift f{\"u}r Medizinische Physik}, + volume={33}, + number={4}, + pages={552--566}, + year={2023}, + doi={10.1016/j.zemedi.2022.08.005} +} + +pCTCubicSpline_method + +C.-A. Collins-Fekete, S. Brousmiche, S. K. N. Portillo, L. Beaulieu and J. Seco. +A maximum likelihood method for high resolution proton radiography/proton CT. +Physics in Medicine and Biology, 61(23):8232, 2016. +DOI: 10.1088/0031-9155/61/23/8232 + +@article{pCT_cubic_spline, + author={Collins-Fekete, Charles-Antoine and Brousmiche, S{\'e}bastien and Portillo, Stephen K. N. and Beaulieu, Luc and Seco, Joao}, + title={A maximum likelihood method for high resolution proton radiography/proton {CT}}, + journal={Physics in Medicine and Biology}, + volume={61}, + number={23}, + pages={8232}, + year={2016}, + doi={10.1088/0031-9155/61/23/8232} +} + End of Bib (leave this here) \ No newline at end of file diff --git a/Python/tigre/utilities/TIGRE.bib b/Python/tigre/utilities/TIGRE.bib index c587c48e..0201fa3b 100644 --- a/Python/tigre/utilities/TIGRE.bib +++ b/Python/tigre/utilities/TIGRE.bib @@ -394,4 +394,40 @@ @article{sun2010fasks publisher={IOP Publishing} } +pCTCubicSpline + +S. Kaser, T. Bergauer, A. Biguri, W. Birkfellner, S. Hatamikia, A. Hirtl, C. Irmler, B. Kirchmayer and F. Ulrich-Pur. +Extension of the open-source TIGRE toolbox for proton imaging. +Zeitschrift fur Medizinische Physik, 33(4):552-566, 2023. +DOI: 10.1016/j.zemedi.2022.08.005 + +@article{pCT_TIGRE, + author={Kaser, Stefanie and Bergauer, Thomas and Biguri, Ander and Birkfellner, Wolfgang and Hatamikia, Sepideh and Hirtl, Albert and Irmler, Christian and Kirchmayer, Benjamin and Ulrich-Pur, Felix}, + title={Extension of the open-source {TIGRE} toolbox for proton imaging}, + journal={Zeitschrift f{\"u}r Medizinische Physik}, + volume={33}, + number={4}, + pages={552--566}, + year={2023}, + doi={10.1016/j.zemedi.2022.08.005} +} + +pCTCubicSpline_method + +C.-A. Collins-Fekete, S. Brousmiche, S. K. N. Portillo, L. Beaulieu and J. Seco. +A maximum likelihood method for high resolution proton radiography/proton CT. +Physics in Medicine and Biology, 61(23):8232, 2016. +DOI: 10.1088/0031-9155/61/23/8232 + +@article{pCT_cubic_spline, + author={Collins-Fekete, Charles-Antoine and Brousmiche, S{\'e}bastien and Portillo, Stephen K. N. and Beaulieu, Luc and Seco, Joao}, + title={A maximum likelihood method for high resolution proton radiography/proton {CT}}, + journal={Physics in Medicine and Biology}, + volume={61}, + number={23}, + pages={8232}, + year={2016}, + doi={10.1088/0031-9155/61/23/8232} +} + End of Bib (leave this here) diff --git a/changelog.md b/changelog.md index 8c8ced4f..441fb2c7 100644 --- a/changelog.md +++ b/changelog.md @@ -39,6 +39,8 @@ thank you. them directly, e.g. `from _minTV import minTV`, now needs `from tigre.utilities.cuda_interface._minTV import minTV`. ### Added +- Docs: a Plugins section in the user guide (what plugins are, how to build them, how to add one) and the proton CT + plugin in the Python and MATLAB API reference. Its papers are in `TIGRE.bib` (`citeme('pCTCubicSpline')` in MATLAB). - Python proton CT: `tigre.plugins.pct.pCTCubicSpline`, the optimised proton radiographies MATLAB already had. Not built by default: install with `TIGRE_PLUGINS=pct pip install .` (or `TIGRE_PLUGINS=all`); intercept vector lengths with `TIGRE_PCT_PIXEL` / `TIGRE_PCT_INTERCEPTS`. Demo: `Python/demos/pRad_demo.py`. diff --git a/docs/_ext/tigre_matlab_api.py b/docs/_ext/tigre_matlab_api.py index 0318d8a2..6f0e41cb 100644 --- a/docs/_ext/tigre_matlab_api.py +++ b/docs/_ext/tigre_matlab_api.py @@ -60,6 +60,7 @@ "Utilities/IO/DXChange/DXChangeDataLoader.m", "Utilities/IO/Dicom/dicomDataLoader.m", ], + "plugins": ["Plugins/pCT/pCTCubicSpline.m"], } # Families for a group's page, in order, as on the Python API page and in the diff --git a/docs/api/matlab/index.md b/docs/api/matlab/index.md index f7fd925b..2bf6461d 100644 --- a/docs/api/matlab/index.md +++ b/docs/api/matlab/index.md @@ -20,4 +20,5 @@ Geometry Algorithms Utilities Scanner data loaders +Plugins ``` diff --git a/docs/api/matlab/plugins.md b/docs/api/matlab/plugins.md new file mode 100644 index 00000000..4c82edfd --- /dev/null +++ b/docs/api/matlab/plugins.md @@ -0,0 +1,15 @@ +--- +og:description: "MATLAB reference for TIGRE's plugins: the proton CT plugin's optimised proton radiographies." +myst: + html_meta: + description: "MATLAB reference for TIGRE's plugins: the proton CT plugin's optimised proton radiographies." +--- + +# MATLAB plugins + +Optional parts of TIGRE in `MATLAB/Plugins`; compiled plugins must be built +first (see {doc}`/user-guide/plugins`). Proton CT: `Compile pCT`, see +{doc}`/user-guide/proton-ct`. + +```{include} ../../_generated/matlab/plugins.md +``` diff --git a/docs/api/python/index.md b/docs/api/python/index.md index f244e98a..a603df47 100644 --- a/docs/api/python/index.md +++ b/docs/api/python/index.md @@ -25,4 +25,5 @@ Algorithms Utilities Scanner data loaders Plotting +Plugins ``` diff --git a/docs/api/python/plugins.md b/docs/api/python/plugins.md new file mode 100644 index 00000000..41888f3e --- /dev/null +++ b/docs/api/python/plugins.md @@ -0,0 +1,20 @@ +--- +og:description: "Python reference for TIGRE's plugins: the proton CT plugin's optimised proton radiographies." +myst: + html_meta: + description: "Python reference for TIGRE's plugins: the proton CT plugin's optimised proton radiographies." +--- + +# Python plugins + +Optional parts of TIGRE; compiled plugins must be built first (see +{doc}`/user-guide/plugins`). + +```{eval-rst} +Proton CT +--------- + +Built with ``TIGRE_PLUGINS=pct``. See :doc:`/user-guide/proton-ct`. + +.. autofunction:: tigre.plugins.pct.pCTCubicSpline +``` diff --git a/docs/conf.py b/docs/conf.py index a958142b..ac5992cd 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -52,6 +52,7 @@ def _version_from_cff(): autodoc_mock_imports = [ *("tigre.utilities.cuda_interface." + m for m in ( "_Ax", "_Atb", "_AwminTV", "_minTV", "_minPICCS", "_tv_proximal", "_gpuUtils", "_RandomNumberGenerator")), + "tigre.plugins.pct._pct", "h5py", "tqdm", "torch", ] autodoc_typehints = "none" diff --git a/docs/user-guide/index.md b/docs/user-guide/index.md index e679a2a5..6ffc8dc3 100644 --- a/docs/user-guide/index.md +++ b/docs/user-guide/index.md @@ -122,6 +122,13 @@ from loading to the final image. [](performance-tuning.md) : Source-level changes for a little more speed. +## Plugins + +Optional parts of TIGRE, outside the core toolbox. + +[](plugins.md) +: What plugins are, how to build them, and how to add one. + [](proton-ct.md) : The proton CT plugin: optimised proton radiographies. @@ -154,6 +161,13 @@ real-data-tutorial interoperability troubleshooting performance-tuning +``` + +```{toctree} +:hidden: +:caption: Plugins + +plugins proton-ct ``` diff --git a/docs/user-guide/plugins.md b/docs/user-guide/plugins.md new file mode 100644 index 00000000..002c34ef --- /dev/null +++ b/docs/user-guide/plugins.md @@ -0,0 +1,115 @@ +--- +og:description: "TIGRE plugins: optional parts of TIGRE outside the core toolbox, how to build them in Python and MATLAB, and how to add a new one." +myst: + html_meta: + description: "TIGRE plugins: optional parts of TIGRE outside the core toolbox, how to build them in Python and MATLAB, and how to add a new one." +--- + +# Plugins + +Plugins are optional parts of TIGRE that live outside the core toolbox. They +are for methods that only some users need, such as a different imaging +modality, so that core TIGRE stays small and quick to build. A plugin works in +both Python and MATLAB, with the same function names, like the rest of TIGRE. + +| Plugin | What it does | Compiled | Page | +|---|---|---|---| +| `pct` (Python), `pCT` (MATLAB) | Optimised proton radiographies from single-proton data | Yes (CUDA, NVIDIA GPUs) | [](proton-ct.md) | + +## Building plugins + +Plugins with compiled code are **not built by default**: building TIGRE as +usual gives core TIGRE only. Ask for the plugins you want when you build. +Plugins written only in Python or MATLAB need no build and are always there. + +::::{tab-set} +:sync-group: lang + +:::{tab-item} Python +:sync: python +Set `TIGRE_PLUGINS` to a comma-separated list of plugins, or `all`, when +installing TIGRE from its source folder: + +```bash +TIGRE_PLUGINS=pct pip install . +TIGRE_PLUGINS=all pip install . +``` + +In Windows cmd, set the variable first: + +```bat +set TIGRE_PLUGINS=pct +pip install . +``` + +Plugins are imported from `tigre.plugins`, for example +`from tigre.plugins.pct import pCTCubicSpline`. Importing a plugin that was +not built raises an `ImportError` that says how to build it. The release +wheels do not include compiled plugins: build TIGRE from source to use them. +::: + +:::{tab-item} MATLAB +:sync: matlab +From TIGRE's `MATLAB` folder: + +```matlab +Compile % core TIGRE only, as always +Compile pCT % only the proton CT plugin (compile core TIGRE first) +Compile all % core TIGRE and every plugin +``` + +`InitTIGRE` puts every plugin folder (`MATLAB/Plugins/`) on the path, +with its demos and, once compiled, its MEX files. +::: +:::: + +A plugin can have its own build options; see its page. + +## Where plugins live + +| | Python | MATLAB | Shared CUDA code | +|---|---|---|---| +| Code | `Python/tigre/plugins//` | `MATLAB/Plugins//` | `Common/CUDA/plugins//` | +| Demos | `Python/demos/` | `MATLAB/Plugins//Demos/` | | +| Tests | `Python/tests/test__plugin.py` | `MATLAB/Tests/test__plugin.m` | | + +Data a plugin's demos need stays in the source folder (for proton CT, +`MATLAB/Plugins/pCT/data/`) and is not installed. + +## Adding a plugin + +For contributors. A plugin follows the same rules as the rest of TIGRE (see +[`AGENTS.md`](https://github.com/CERN/TIGRE/blob/master/AGENTS.md) and +[`contributing.md`](https://github.com/CERN/TIGRE/blob/master/contributing.md)): +the same function names and arguments in Python and MATLAB, a line in +`changelog.md`, and few, small tests. + +1. **Code.** Put it in the folders above. Shared CUDA code goes in + `Common/CUDA/plugins//` and includes `../../TIGRE_common.hpp` (not + `mex.h`), so both languages can build it. If the C++ wrapper includes a + header with device code, keep the `__device__` and `__global__` + declarations under `#ifdef __CUDACC__`. +2. **MATLAB build** (compiled plugins). In `MATLAB/Compile.m`, add the name to + `all_plugins` and a `case` that calls a local `compile_` function. + Write the MEX files to `MATLAB/Plugins//Mex_files/`, where + `InitTIGRE` finds them. +3. **Python build** (compiled plugins). In `setup.py`, add the name to + `PLUGINS` and an `Extension` named `tigre.plugins.._` in the + loop that builds `plugin_exts`. In the package's `__init__.py`, import the + compiled module inside `try`/`except ImportError` and re-raise an + `ImportError` that says how to build it. Add the generated `.cpp` to + `.gitignore` (already covered for `Python/tigre/plugins/*/*.cpp`) and the + `.pyx` to `[tool.setuptools.package-data]` in `pyproject.toml`. +4. **Tests.** One small test per language. A compiled plugin's Python test + must skip when the plugin is not built: import it in `try`/`except + ImportError` and call `pytest.skip(..., allow_module_level=True)`. + `pytest.importorskip` is not enough, because from pytest 9 it only skips + a missing module, not the plugin's own `ImportError`. Mark tests that need + a GPU with `pytest.mark.gpu`. +5. **Docs.** A user-guide page for the plugin, linked from the table at the + top of this page and from the user guide's index; its functions in the + API reference (add the compiled module to `autodoc_mock_imports` in + `docs/conf.py`); and its demos in `docs/_ext/tigre_demos.py`, where a + MATLAB demo in a plugin folder is given relative to `MATLAB/` (for example + `Plugins/pCT/Demos/pRad_demo.m`). Add a Python demo that needs a compiled + plugin to `NOT_RUN`. diff --git a/docs/user-guide/proton-ct.md b/docs/user-guide/proton-ct.md index a9b4f623..b634e0e0 100644 --- a/docs/user-guide/proton-ct.md +++ b/docs/user-guide/proton-ct.md @@ -19,8 +19,16 @@ The radiographies can then be reconstructed with TIGRE's usual algorithms to give a full proton CT image, or used on their own. The plugin lives in `Python/tigre/plugins/pct` and `MATLAB/Plugins/pCT`, with -its CUDA code in `Common/CUDA/plugins/pCT`. It is not compiled with the rest of -TIGRE. +its CUDA code in `Common/CUDA/plugins/pCT`. Like other compiled +[plugins](plugins.md), it is not compiled with the rest of TIGRE. The method +and its validation are described in +[Kaser et al. (2023)](https://doi.org/10.1016/j.zemedi.2022.08.005); cite it +if you use the plugin. The function reference is in the API pages +([Python](../api/python/plugins.md), [MATLAB](../api/matlab/plugins.md)). + +The radiographies are computed for parallel-beam protons (`geo.mode = +'parallel'`), as in the demo and the paper. A `'cone'` mode exists in the code +but has not been checked since the plugin moved out of core TIGRE. ## Building the plugin From 72bcd6d4dabb8751c5ccbd03ba3ecd2129e54668 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 18:08:47 +0000 Subject: [PATCH 2/2] Release workflow: build and import the plugins Plugins are not built on pull requests (building takes long), so the release workflow builds TIGRE with TIGRE_PLUGINS=all and imports each compiled plugin. It does not block attaching the wheels. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01L6n1VHyq4uNorM3CAiBUPo --- .github/workflows/release.yml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8e47a41d..0b53ab22 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -82,6 +82,31 @@ jobs: name: cibw-sdist path: dist/*.tar.gz + # Plugins (Python/tigre/plugins, MATLAB/Plugins) are not in the wheels and + # not built on pull requests, because building takes long. This checks at + # each release that every compiled plugin still builds and imports. It does + # not block the release: a broken plugin shows here as a failed job. + plugins: + name: Build and import the plugins + needs: check_version + runs-on: ubuntu-latest + container: nvidia/cuda:12.8.1-devel-ubuntu24.04 + env: + TIGRE_PLUGINS: all + # No GPU here, so compile for one architecture only (much faster). + TIGRE_CUDA_ARCH: "75" + steps: + - uses: actions/checkout@v7 + - uses: astral-sh/setup-uv@v10.3.3 + with: + version: 0.13.10 + - name: Build and install TIGRE with every plugin + run: | + uv venv --python 3.14 + uv pip install --python .venv/bin/python . + - name: Import the plugins + run: .venv/bin/python -c "import tigre.plugins.pct as pct; print('proton CT plugin built, intercepts', pct.INTERCEPTS)" + # TIGRE is not published to PyPI: the `tigre` name there belongs to an # unrelated project. Wheels and the sdist are attached to the GitHub Release. github_release: