Skip to main content

CRN-craft

CRN-craft: chemical reaction networks in native Rust with stochastic simulation

Reproducible simulation and analysis of well-mixed chemical reaction networks, with a native Rust core. Models, requests and results are versioned JSON documents with strict input checks, explicit budgets and replayable seeds.

pip install crn-craft

Wheels for CPython 3.10 and newer (stable ABI) on Linux x86_64, Windows x64 and macOS (x86_64 and arm64); other platforms build from the source distribution with a Rust toolchain.

Example

Immigration–death (birth rate 4, death rate 0.2, starting from zero) has a Poisson law with mean 20 (1 - exp(-0.2 t)): 12.64 at t = 5 and 17.29 at t = 10.

import crn_craft as crn

model = crn.load_example("immigration-death")
request = crn.ssa_spec(
    model, end=10.0, save_times=[0.0, 5.0, 10.0], replicates=1000, seed=1
)
result = crn.simulate_ssa(model, request)
print(result["sampler"])
print(result["statistics"]["mean"], result["statistics"]["mean_standard_error"])
xoshiro256pp-u53/direct_cr/inverse/fast-1
[[0.0], [12.618], [17.22500000000001]] [[0.0], [0.10959967193421745], [0.13107843665743252]]

Both means lie within one standard error of the exact values. The same seed gives the same result on every run and for every thread count.

What is included

  • Exact stochastic simulation: direct, cached_direct, direct_cr, sorting_direct and rssa_cr, with inverse or Ziggurat waiting times. fast (the default) emulates JumpProcesses.jl; fast=False selects the checked policy, which rejects lost increments and channels below the 53-bit selection resolution.
  • Prepared simulations and reusable parameter templates for optimization loops (crn.prepare_ssa, crn.prepare_parameters).
  • Sparse finite state projection (crn.fsp), explicitly approximate Poisson leaping (crn.tau), network analysis and conservation checks.
  • Strict SBML and BioNetGen import subsets (crn-craft-import) and the crn-craft command for archives, verification and export.
  • pip install "crn-craft[fit]" adds the pinned SciPy, fcmaes-rust and SQP-craft versions used by the fitting examples.

The rules engine for dynamic, attributed species is in the wheel as crn_craft.rules: prepared parallel ensembles, trackers, event logs and callbacks, and the mtDNA methods; see the mtDNA user manual. rules.Model builds models from Python calls, in the style of rebop: a numeric rate is a mass-action constant, a string the reaction's whole propensity. add_species and add_parameter take one name and value or a mapping such as {"S": 999, "I": 1}. Results are pandas DataFrames: per-replicate records and rule counts, statistics by report time and trackers. Kept paths and event logs are xarray DataArrays: result.paths has the dimensions (time, variable, replicate), and event_columns() (replicate, entry, variable). pandas and xarray are installed with the package. paths_frame() and event_frame() return the DataFrames of release 0.4.0, and to_xarray() the paths as a Dataset. The same immigration–death model:

from crn_craft import rules

model = rules.Model("immigration_death")
model.add_parameter("k_in", 4.0).add_species("X")
model.add_reaction("k_in", [], ["X"], name="immigration")  # string: whole propensity
model.add_reaction(0.2, ["X"], [], name="death")  # number: mass action, 0.2 X
result = rules.ensemble(
    model,
    end=10.0,
    report_times=[0.0, 5.0, 10.0],
    replicates=1000,
    seed=1,
    threads=2,
    method="static_direct",
    keep_paths="all",
).simulate()
print(result.statistics["mean"])
print(result.rule_events.sum().to_dict())
print(result.paths.sel(variable="X").T.to_pandas().head(3))  # cells x times
           X
time
0.0    0.000
5.0   12.623
10.0  17.305
{'immigration': 39800, 'death': 22495}
time       0.0   5.0   10.0
replicate
0           0.0  14.0  19.0
1           0.0  19.0  20.0
2           0.0  17.0  17.0

The means lie within one standard error of the exact 12.64 and 17.29. method="static_direct" draws Ziggurat waiting times and integrates count trackers sparsely (rules-run/0.6). method={"kind": "static_direct", "waiting_time": "inverse", "sparse_trackers": False} gives the numbers of release 0.3.0, which printed 12.550 and 17.351 here. Models may also declare continuous variables (Model.add_ode), ODEs between events that rates read (for example an ATP pool), which method="hybrid" simulates at declared tolerances.

Opt-in since 0.4.0, with a Rust toolchain (1.85 or newer): loop = rules.compile_loop(model) compiles a model's Static Direct event loop, string rates included since 0.5.0, into a cached native program, and rules.ensemble(..., method="static_direct", compiled=loop) runs it with results byte-identical to the interpreter's, about 2.2× faster on the three-class mtDNA model. The first build takes a minute or more; see the user manual for requirements and limitations. Release 0.3.0 changed the rules results from NumPy arrays to DataFrames; the changelog lists what to migrate. Its command-line tools (rules-check, rules) are in the native CLI (cargo install crn-craft-cli --locked, crates crn-craft and crn-craft-rules), which installs a crn-craft command of the same name as the wheel's. The optional diffsol BDF integrator with forward sensitivities and the job worker for optimization-jobs build from the repository and are not part of the wheel.

Documentation

A successful numerical run is not biological validation. MIT licensed; see THIRD_PARTY_NOTICES.md for the Ziggurat tables adapted from Julia.

Metadata

Release files for crn-craft 0.5.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 crn-craft 0.5.0
File Size Uploaded Provenance Actions
crn_craft-0.5.0.tar.gz 500.3 kB Without provenance Details for crn_craft-0.5.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for crn-craft 0.5.0
File Actions
crn_craft-0.5.0-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details for crn_craft-0.5.0-cp310-abi3-win_amd64.whl
crn_craft-0.5.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 abi3 Linux glibc 2.17+ x86-64 Details for crn_craft-0.5.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
crn_craft-0.5.0-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details for crn_craft-0.5.0-cp310-abi3-macosx_11_0_arm64.whl
crn_craft-0.5.0-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details for crn_craft-0.5.0-cp310-abi3-macosx_10_12_x86_64.whl

Total release size: 8.2 MB

Release files / crn_craft-0.5.0.tar.gz

Download URL crn_craft-0.5.0.tar.gz
Size 500.3 kB
Tags Source
SHA-256 checksum
How to use checksums
7f975a1a8dde5bdee8c58643bc66d2f8f8eea8592bd076790c6451d8a18325b3
BLAKE2b-256 checksum
How to use checksums
993cfea943e9e3ff830d7d4e99c33111ff2e3c2b4c1bb91ac0c5af99c2bca528
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / crn_craft-0.5.0-cp310-abi3-win_amd64.whl

Download URL crn_craft-0.5.0-cp310-abi3-win_amd64.whl
Size 1.8 MB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
61bb96ea17e9fda5434e072b8e982ec62e62ac919634a5068a2ea757d3f26ae2
BLAKE2b-256 checksum
How to use checksums
972d7a7cad50728814e09437598980aa67a6a447cb4cb7aabfa2b5b48629d5a0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / crn_craft-0.5.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL crn_craft-0.5.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 2.1 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
49003cd7d652026c3d27fce3dea4aa0cc46ac1221ebfde331d1c11e66bd762ed
BLAKE2b-256 checksum
How to use checksums
b5573002b8f53689e2b9ea73c5f10b03ad73e0445082220e8ccc7efce482a271
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / crn_craft-0.5.0-cp310-abi3-macosx_11_0_arm64.whl

Download URL crn_craft-0.5.0-cp310-abi3-macosx_11_0_arm64.whl
Size 1.9 MB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
1fb481d2c78f876170b36bbe6495856d23875a1b3d2890cf81a0dc4082eb4c6f
BLAKE2b-256 checksum
How to use checksums
8be3fa1704264d39e2447b115b8796152947c0b572237b60c22fa1b7a17e3d0c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / crn_craft-0.5.0-cp310-abi3-macosx_10_12_x86_64.whl

Download URL crn_craft-0.5.0-cp310-abi3-macosx_10_12_x86_64.whl
Size 1.9 MB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
f9e3a33cba04e1a71edf987aa86661a4f60614e65fb64613813333b4abfa4e05
BLAKE2b-256 checksum
How to use checksums
2addcf0680de407ff36b1f6337b7747c0e58a96d01ee14c8f5848dafc39d6873
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for crn-craft 0.5.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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