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.

Both backends reuse deterministic Goudsmit-Saunderson tables from ~/.cache/pyradmc/gs-grid. The reference sampler loads existing nodes and grows the stored window on demand, so fresh processes reuse previous table builds.

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.1

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.1
File Size Uploaded
pyradmc-0.2.1.tar.gz 1.7 MB Details

Built distribution (wheel)

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

Total release size: 2.0 MB

Release files / pyradmc-0.2.1.tar.gz

Download URL pyradmc-0.2.1.tar.gz
Size 1.7 MB
Tags Source
SHA-256 checksum
How to use checksums
e18c12c95a1d1eb2e1011f37fd17f4326851dfa37e32d02ab27669a434508b94
BLAKE2b-256 checksum
How to use checksums
e6af98a28d813421ee31fb670ff7287f20dca0f90e099ef8ed2425ff187f712d
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 6, 2026.

Transparency log

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

Download URL pyradmc-0.2.1-py3-none-any.whl
Size 294.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c92af30ba6ef6f3fd402af88ffef4113e3c9b43d3bf4b50e2efe0e088a2106ac
BLAKE2b-256 checksum
How to use checksums
35a04a72194e8327f71262067974ed5574feaafacd9e68821b3f7fb22bec18a0
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 6, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

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