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.3.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.3.0
File Size Uploaded
openbnct-0.3.0.tar.gz 1.1 MB Details

Built distributions (wheels)

Table of built distributions (wheels) for openbnct 0.3.0
File
openbnct-0.3.0-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details
openbnct-0.3.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.3.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.10 abi3 Linux glibc 2.17+ ARM64 Details
openbnct-0.3.0-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details
openbnct-0.3.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.3.0.tar.gz

Download URL openbnct-0.3.0.tar.gz
Size 1.1 MB
Tags Source
SHA-256 checksum
How to use checksums
e70902dc87c24745b1ade5863cbef4f4c265acf299a34b1e2a6f523d281e705e
BLAKE2b-256 checksum
How to use checksums
7408611b7c91ff91e01698bb73e321902a4297c82833ad62bc27cd1271db4036
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 1, 2026.

Transparency log

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

Download URL openbnct-0.3.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
c22aada2b52fea6c311f4fe9c7ec554b5c65dfce5490f4523e92c80d3dcee7de
BLAKE2b-256 checksum
How to use checksums
1dc35c91d91751ee9a9e96d6db0d53ebfc08142e33c35e67b5ad2e9448f74a13
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 1, 2026.

Transparency log

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

Download URL openbnct-0.3.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
f86211ae10fce4727c047173b2cef9597cf49d5e397fcda4c36327f98cf4b0a9
BLAKE2b-256 checksum
How to use checksums
f43e2ac4b517fd9351abafc6e24754de3014be3cbae453d41eea9b798249dbde
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 1, 2026.

Transparency log

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

Download URL openbnct-0.3.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
6864489aaa80a643a33aa22a4e1d5a94ec404b2973c6318dbf19dfa3418f180f
BLAKE2b-256 checksum
How to use checksums
eb738d8653dd78f4c9eeac10c77f77659ca32e6c63e27cb4a4fd50b69544f528
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 1, 2026.

Transparency log

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

Download URL openbnct-0.3.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
9913a61304a8cea210b191b3f96d12a4e5d3a7b21c3292e14121c44a8966d242
BLAKE2b-256 checksum
How to use checksums
5172d7d22d50614c44e04f2b316dd754d00a0937c16126be033299a6c4c2cd61
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 1, 2026.

Transparency log

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

Download URL openbnct-0.3.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
1bdd83171737fcbd484a408968b211ed5048f21e2177553669da7e6c0b03de60
BLAKE2b-256 checksum
How to use checksums
07ffb7e16f69404adbfb5aa719d9f730dbd7e68f3fe7da9512ee87b86188681f
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 1, 2026.

Transparency log

Release history Release notifications | RSS feed

0.4.0

6 release files

This release

0.3.0 This release

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