Skip to main content

pyRadMC

PyPI version CI codecov Documentation Python License: Apache 2.0 Ruff Checked with mypy

Fast photon Monte Carlo dose engine for radiotherapy treatment planning.

Status: pre-1.0 research software. The physics, both backends and the influence-matrix pipeline are complete and test-pinned, but the software is young, and the validation it has passed is stated precisely on the validation status page rather than claimed broadly. Do not use it for anything clinical, now or later, without independent validation.

The primary product is a beamlet-resolved dose influence matrix (Dij) for photon IMRT/VMAT planning: sparse CSC columns with a per-entry statistical uncertainty, computed on CPU and CUDA from a single physics source by tagging every history's whole secondary family with its beamlet of origin. Scheduling — grouping, chunking, batch merging, which GPU gets which column — cannot change the matrix by one bit (test-pinned). Measured end to end on a laptop RTX 4070 at planning statistics: ~1.1e7 histories/s, i.e. a 100-beamlet 6 MeV field at 2–3 % per-beamlet sigma in single-digit seconds.

One physics source compiled three ways, and the throughput gap

The same 6 MeV beam computed with the reference interpreter and with the Warp compilation of the identical physics source on CPU and CUDA (examples/warp_backend_demo.py). The depth-dose curves agree within their error bands; the bars show why the backend exists.

One Dij column, the fluence-sum identity, and a wedge plan recombined from the matrix

The point of the whole exercise (examples/dij_demo.py): one beamlet's dose column with the truncated tail visible (left); the open field recombined from the columns at unit weights against an independently simulated open field (middle — columns partition the field exactly); and a wedge plan as Dij @ weights, no re-simulation (right), which is the loop a treatment-plan optimizer runs thousands of times.

Install

pip install pyRadMC              # reference backend; NumPy and SciPy only
pip install "pyRadMC[warp]"      # production backend, CPU and CUDA
pip install "pyRadMC[ct]"        # CT image reading (SimpleITK)

Until the first tagged release reaches PyPI, install from a clone instead: pip install -e ".[warp]".

Backend Role Devices
ref correctness oracle; never optimized CPU (NumPy)
warp production CPU, CUDA

Warp needs no CUDA toolkit to install and runs on the CPU without a GPU; CUDA is used when a device is present. The two backends are validated against each other statistically — CPU and GPU results are never bit-identical, but each is bit-reproducible on its own device for a given seed.

Quick start

from pyradmc import AnalyticCrossSections, HostRNG, PencilBeamSource, ReferenceEngine, VoxelGrid

grid = VoxelGrid.uniform_water(shape=(16, 16, 16), spacing=(1.0, 1.0, 1.0))
xs = AnalyticCrossSections(geometry_densities=grid.max_density_by_material())
source = PencilBeamSource(energy=6.0, position=(8.0, 8.0, -1.0), direction=(0.0, 0.0, 1.0))

result = ReferenceEngine(grid=grid, cross_sections=xs, rng=HostRNG()).run(
    source, n_histories=80_000, n_batches=10, seed=20260726
)
result.dose          # MeV/g per emitted history, on the scoring grid
result.dose_sigma    # batched 1-sigma
result.provenance    # version, seed, cutoffs, backend, device, cross-sections

Swap in WarpEngine(grid=..., cross_sections=..., device="cuda:0") for the production backend — the run signatures are identical. Everything importable from the top-level pyradmc namespace is public API.

From here, the documentation carries the rest: getting started (GPU runs, the influence matrix, pencil-beam kernels, a tour of the examples/), validation status — read it before trusting a number — and cross-section data (the engine ships no libraries; the tabulated backend compiles from the IAEA EPICS evaluations, digest-verified).

Contributing

Read AGENTS.md before contributing — it is the governing document, written for human and agentic contributors alike; CONTRIBUTING.md is the short version of the mechanics. Work lands on develop through squash-merged pull requests; main carries releases only.

License

Apache-2.0. See LICENSE.

Release files for pyRadMC 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyRadMC 0.2.0
File Size Uploaded
pyradmc-0.2.0.tar.gz 1.7 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyRadMC 0.2.0
File Interpreter ABI Platform
pyradmc-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 2.0 MB

Release files / pyradmc-0.2.0.tar.gz

Download URL pyradmc-0.2.0.tar.gz
Size 1.7 MB
Tags Source
SHA-256 checksum
How to use checksums
b1872406533ca966a6114f620ab274bac5e8ccfa8791774398fcf2fe0cc3ce37
BLAKE2b-256 checksum
How to use checksums
2047ce1665a13faaf8592e94bf77479c363121f44bd1e7e9cd8be6dcb203e81a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 5, 2026.

Transparency log

Release files / pyradmc-0.2.0-py3-none-any.whl

Download URL pyradmc-0.2.0-py3-none-any.whl
Size 293.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
59a384f04a6448ee12bd84b988c4ecc5a4566b20f3f464719ce9afb5cc916ca7
BLAKE2b-256 checksum
How to use checksums
b58963b0b243238f134706a75ac71b802a5edd324805b7a6f08bee4f23f0da1e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 5, 2026.

Transparency log

Release history Release notifications | RSS feed

0.2.1

2 release files

This release

0.2.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page