Repository navigation
Python proton CT plugin: tigre.plugins.pct.pCTCubicSpline - #986
Merged
Merged
Conversation
- Cython binding (Python/tigre/plugins/pct/_pct.pyx) of the shared CUDA code;
built only with TIGRE_PLUGINS=pct (or all); TIGRE_PCT_PIXEL and
TIGRE_PCT_INTERCEPTS set the intercept vector lengths like Compile('pCT',...).
Importing it without the build raises an ImportError saying how to build it.
- pCTCubicSpline(posIn, posOut, dirIn, dirOut, Wepl, eIn, geo): same name and
arguments as MATLAB; geo detector fields in (y, x) like other Python TIGRE
geometry; result indexed [y, x].
- MATLAB pCTCubicSpline.m: same function, converts inputs to single and takes
N-by-2 positions; the demo and test use it.
- Header: host entry points visible to the C++ compiler, device code only for
nvcc.
- Demo Python/demos/pRad_demo.py, test Python/tests/test_pct_plugin.py (same
case as the MATLAB test), docs with Python and MATLAB tabs, changelog.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L6n1VHyq4uNorM3CAiBUPo
pytest 9's importorskip skips only ModuleNotFoundError; the plugin raises a plain ImportError with build instructions, so collection failed in CI. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L6n1VHyq4uNorM3CAiBUPo
AnderBiguri
marked this pull request as ready for review
November 28, 2026 17:53
mexPrintf in the Python build called PRINT_HERE(""), which printed the
location of that line in TIGRE_common.cpp, not of the caller, before every
message. Also removes the build's zero-length format string warning.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L6n1VHyq4uNorM3CAiBUPo
- A CUDA error used to leave every buffer of the call allocated (and the host histograms); now released with tigre::ReleaseOnError, so Python can catch the error and carry on. - Cone beam never freed dSourceDist: a small GPU leak on every call. - Detector pixel indices used int(), which truncates towards zero, so protons up to one pixel below the first pixel were counted in it; now floorf. - Buffer sizes in size_t (2*N*4 bytes overflowed int above 268M protons). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L6n1VHyq4uNorM3CAiBUPo
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L6n1VHyq4uNorM3CAiBUPo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The Python version of the proton CT plugin from #985, so proton radiographies work in both languages with the same function. Stacked on #985 (base
plugins/pct-matlab); retarget tomasteronce #985 is merged.tigre.plugins.pct.pCTCubicSpline(posIn, posOut, dirIn, dirOut, Wepl, eIn, geo): Cython binding of the shared CUDA code inCommon/CUDA/plugins/pCT. Positions and directions as(2, N)(row 0 x, row 1 y) or a2Nvector;geo.dDetector/sDetectorin(y, x)like other Python geometry; result indexed[y, x], NaN where no proton crossed. Any numeric input type.TIGRE_PLUGINS=pct pip install .(orall).TIGRE_PCT_PIXEL=0.5/TIGRE_PCT_INTERCEPTS=10,220,100set the intercept vector lengths, asCompile('pCT','-pct_pixel',…)does;tigre.plugins.pct.INTERCEPTSreports them. Importingtigre.plugins.pctwithout the build raises anImportErrorsaying how to build it. Non-CUDA backends skip the plugin with a message.pCTCubicSpline.m: the same function in MATLAB (converts to single, takes N-by-2), used bypRad_demo.mand the MATLAB test.pCTCubicSpline_mexis unchanged..cppincludes it); device declarations and thepi/epsmacros only under__CUDACC__.Python/demos/pRad_demo.py(needs a source checkout for the data file); docs page with Python/MATLAB tabs; the demo is listed but not run when the site is built.MANIFEST.in/pyproject.toml: plugin sources in the sdist;.gitignorefor the generated.cpp.mexPrintfinCommon/CUDA/TIGRE_common.cppno longer prefixes every C++/CUDA message withCommon/CUDA/TIGRE_common.cpp (9):(the location of its ownPRINT_HERE(""), never the caller). This also removes the Python build's zero-length format string warning. Checked in the sandbox: build has no warnings, messages print without the prefix..cufiles): a CUDA error no longer leaves the call's GPU buffers and host histograms allocated (tigre::ReleaseOnError, as in core); cone beam no longer leaksdSourceDiston every call; detector pixel indices usefloorfinstead ofint()truncation, so protons up to one pixel below the first pixel are no longer counted in it; buffer sizes insize_t.CompilePCT.mremoved (deprecated in Proton CT becomes a MATLAB plugin (Compile pCT), with input and launch fixes #985); useCompile pCT.Tests
Python/tests/test_pct_plugin.py: the same case asMATLAB/Tests/test_pCT_plugin.m(100 straight protons, 4×4, each pixel its mean WEPL10+ix+4*iy), which also pins the orientation of the result. Markedgpu, skipped when the plugin is not built. One test.What was and was not tested
Written by an AI agent (Claude).
TIGRE_PLUGINS=pct TIGRE_PCT_PIXEL=0.5 python setup.py build_extbuilds and links_pct(intercepts 5/110/100); the module imports; the input checks raise the expectedValueErrors; without a GPU the CUDA error comes back as aRuntimeErrorinstead of crashing. The test is skipped without the build. Docs build withsphinx-build -W.TIGRE_PLUGINS=pct TIGRE_CUDA_ARCH=native pip install .: builds;pytest Python/tests/test_pct_plugin.pypasses;pRad_demo.pyruns.pRad_demo(now throughpCTCubicSpline.m) on this branch.CompilePCTremoval came after the checks above: compiled with nvcc 13.5 in the sandbox (no warnings), and re-run by Ander on the GPU (Windows) at 517d282:test_pct_plugin.pyandtest_pCT_plugin.mpass, Python and MATLABpRad_demoagree.🤖 Generated with Claude Code
https://claude.ai/code/session_01L6n1VHyq4uNorM3CAiBUPo