Skip to main content

Python bindings

pip install openbnct installs the published scientific package. For the current workflow, start with the Python handbook chapter. The package uses PyO3 and maturin to wrap the authoritative Rust crates; it does not implement a second dose, geometry, evidence, or QA engine (ADR 0015).

The mixed-package shape is:

bindings/python/
  Cargo.toml                 PyO3 extension crate (outside the workspace)
  pyproject.toml             maturin build and package metadata
  src/lib.rs                 narrow Rust-to-Python boundary
  python/openbnct/
    __init__.py              ergonomic public API
    _openbnct.pyi            checked extension types
    py.typed                 typing marker
  tests/                     cross-language parity suite

The API covers case generation, verification, and gated loading for NF-BNCT-001; geometry, ROI, and CT inspection; case.json manifest reading and artifact re-verification; validated material, source, component profile, response-generation method, and response-set contract readers with canonical to_json serialization; the response-set folding_ready review gate; statepoint collection; DVH and dose-volume metrics; biological-model application and TCP/NTCP/UTCP endpoint evaluation; exposure-plan table import/export and weighted accumulation; and external component-dose import (import_component_dose, import_mcnp_meshtal, import_phits) plus MCNP deck export (export_mcnp_deck); and external-dose/BED combined analysis (import_external_dose, bed_from_external_dose, combine_biological_doses); source positioning (aim_source, rotate_source, PositionReport); and cross-code dose comparison (compare_dose_bundles, DoseComparison); and gamma-index evaluation (evaluate_gamma, GammaEvaluation); and biological-model sensitivity sweeps (sweep_biological_model, SensitivitySweep); and validated readers for the deterministic-transport and evidence artifact family — multigroup data/flux/covariance, dose-uncertainty budgets, sensitivity specs and screening reports, resolved weight windows, measurement records and comparison reports, beam descriptions and beam-quality reports, accelerator sources, beam-shaping assemblies and sweeps, lineal-energy spectra and tally specs, metamorphic and analytic oracle evaluations, boron microdistribution models and corrections, RTPLAN summaries (load_rtplan_summary, summarize_rtplan), and component-NIfTI export manifests. Every load runs the same Rust validate() as the CLI, every rejection raises OpenBnctError (NctForgeError remains as an alias for the very same class), and adapter provenance binds the generated interchange document's SHA-256 exactly as the CLI does. Monte Carlo transport actions stay unavailable until the Rust capability and evidence gates pass; backends() reports those flags honestly.

NumPy arrays and axis order

numpy is a package dependency. Every voxel field (DoseVolume, ExternalDoseBundle, BedBundle, CombinedDoseBundle, BoronUnitDose, BoronField, Structure masks via VerifiedCase.structure_mask_array) has an as_array() accessor (and uncertainty_array() where a one-sigma exists) returning a C-order np.ndarray of shape (nz, ny, nx), so array[k, j, i] is column i, row j, slice k. This is the repo's flat voxel order (i + nx*j + nx*ny*k, x fastest) reshaped without any transposition, so as_array().ravel() equals the list-returning values, which stay for backward compatibility. Multigroup flux adds a leading group axis, (groups, nz, ny, nx), with groups in energy_boundaries_ev order (descending energy). Geometry rides along as geometry, array_shape, spacing_mm, origin_mm and direction (Geometry.shape, spacing, origin and direction keep x, y, z order; Geometry.array_shape is the NumPy shape). A MultigroupFlux loaded from JSON carries no grid; bind one with flux.with_geometry(geometry). DVH curves offer dose_edges_array() and friends.

Solving from Python

import numpy as np, openbnct

solution = openbnct.sn_solve("case.json", "multigroup-data.json", order=4)
flux = solution.flux.as_array()                       # (groups, nz, ny, nx)
dose = solution.dose.physical_total.as_array()        # (nz, ny, nx)
print(dose[: dose.shape[0] // 2].mean())

sn_solve(case, data, assignment=None, *, order=4, max_outer=32, convergence=1e-6, allow_unconverged=False, anderson=3, p1=None, anisotropy=0, dose=True, boron_unit=False) (p1=None selects P1 whenever every scattering material carries P1 moments, as the CLI does) calls the same Rust library functions as openbnct sn solve (solve_multigroup, fold_multigroup_dose, fold_boron_unit_dose) and releases the GIL while solving; it adds no transport logic in Python (ADR 0015). case is a path or a TransportCase (load_transport_case), data a path or MultigroupData. It returns an SnSolution with .flux, .dose (a PhysicalDoseBundle, needs data that declares a component profile) and .boron_unit_dose (a BoronUnitDose, needs a collapsed boron_unit_response_gy_cm2_per_ug_g), which boron_dose accepts directly. An unconverged solve raises OpenBnctError unless allow_unconverged=True, which returns the provisional field with converged == False and a RuntimeWarning. examples/python/workflow.py runs the whole chain on the tiny nf-bnct-003 fixture (well under a second); --layered-head also solves the layered head phantom, which takes minutes in a debug-built wheel.

Local development:

python3 -m venv .venv
.venv/bin/pip install 'maturin>=1.7,<2'
.venv/bin/maturin develop
.venv/bin/python -m unittest discover -s tests -p 'test_*.py'

maturin develop builds the extension in place; maturin build produces a wheel under target/wheels. The extension targets the CPython stable ABI (abi3-py310), so one wheel per platform covers every supported interpreter (cp310-abi3-*). CI builds the wheel, installs it into a clean virtual environment, and runs the parity suite there; the same build + clean-venv parity run has been verified locally on CPython 3.14. Platform wheels are published on PyPI. Packaged releases can lag this source tree; build current source to use later API additions. ADR 0015 and ADR 0027 retain the original distribution and API decisions.

Metadata

Release files for openbnct 0.4.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 openbnct 0.4.0
File Size Uploaded
openbnct-0.4.0.tar.gz 1.1 MB Details

Built distributions (wheels)

Table of built distributions (wheels) for openbnct 0.4.0
File
openbnct-0.4.0-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details
openbnct-0.4.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 abi3 Linux glibc 2.17+ x86-64 Details
openbnct-0.4.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.10 abi3 Linux glibc 2.17+ ARM64 Details
openbnct-0.4.0-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details
openbnct-0.4.0-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details

Total release size: 31.0 MB

Release files / openbnct-0.4.0.tar.gz

Download URL openbnct-0.4.0.tar.gz
Size 1.1 MB
Tags Source
SHA-256 checksum
How to use checksums
152866ef2500aff889f664cc2c4d3b3054d528df0eaf8f35b749e3a1740ca01a
BLAKE2b-256 checksum
How to use checksums
3a2a87c3ec17fcf0b8bb5af20149eb1c0bd512c812f4c51fae4a668c53bc0703
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 Oct 2, 2026.

Transparency log

Release files / openbnct-0.4.0-cp310-abi3-win_amd64.whl

Download URL openbnct-0.4.0-cp310-abi3-win_amd64.whl
Size 6.0 MB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
679fc9773a41848300686c10592e41d08eec602c7cc8e8f9ca51864094cb0b40
BLAKE2b-256 checksum
How to use checksums
228e167b699750115f3e1df1bbfcb841fb05d1e7c9797651e4ef5048e21597f5
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 Oct 2, 2026.

Transparency log

Release files / openbnct-0.4.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL openbnct-0.4.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 6.1 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
a6b536989ec1ecf785255768581acf9e443c7487c904ce60070119017fdc3ea5
BLAKE2b-256 checksum
How to use checksums
3a19931008e00df40fd126306da30a96ee83ca6040619dee532301b5909a7875
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 Oct 2, 2026.

Transparency log

Release files / openbnct-0.4.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL openbnct-0.4.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 5.9 MB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
6b3586bc3737434faf36d1380d8f3aaa95d676e0ec7666bfad50e154dd098ab2
BLAKE2b-256 checksum
How to use checksums
8acdbaf99861b03e4d5d8a138f88a4b2a2cb1dca186ffd94b169fd3b8ff22607
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 Oct 2, 2026.

Transparency log

Release files / openbnct-0.4.0-cp310-abi3-macosx_11_0_arm64.whl

Download URL openbnct-0.4.0-cp310-abi3-macosx_11_0_arm64.whl
Size 5.8 MB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
0d93b376523c89d9e730cd92941b6ee2f37d5be46f8a1db518174065163649fd
BLAKE2b-256 checksum
How to use checksums
a7f87364f308b9908dae0fbd3fdfbcf300b65e957cd64212aa72a895712c9b2d
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 Oct 2, 2026.

Transparency log

Release files / openbnct-0.4.0-cp310-abi3-macosx_10_12_x86_64.whl

Download URL openbnct-0.4.0-cp310-abi3-macosx_10_12_x86_64.whl
Size 6.1 MB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
28dc2790fec7a8ee0a5b81ffa089057a0642345057706131f68f086d53c7b694
BLAKE2b-256 checksum
How to use checksums
814fe97add1cdc5692038b95c6b0914c1e60c5dfebc1f6c56aff2acba72e6ec1
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 Oct 2, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.4.0 This release

6 release files

0.3.0

6 release files

0.2.2

6 release files

0.2.0

6 release files

0.1.1

6 release files

0.1.0

6 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