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 with the replicate first: result.paths has the dimensions (replicate, time, variable), 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").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. Model.set_stop("I == 0") sets a stop condition: a replicate keeps its state from the first time it holds and is recorded as stopped. 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.6.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.6.0
File Size Uploaded Provenance Actions
crn_craft-0.6.0.tar.gz 500.8 kB Without provenance Details for crn_craft-0.6.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for crn-craft 0.6.0
File Actions
crn_craft-0.6.0-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details for crn_craft-0.6.0-cp310-abi3-win_amd64.whl
crn_craft-0.6.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.6.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
crn_craft-0.6.0-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details for crn_craft-0.6.0-cp310-abi3-macosx_11_0_arm64.whl
crn_craft-0.6.0-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details for crn_craft-0.6.0-cp310-abi3-macosx_10_12_x86_64.whl

Total release size: 8.2 MB

Release files / crn_craft-0.6.0.tar.gz

Download URL crn_craft-0.6.0.tar.gz
Size 500.8 kB
Tags Source
SHA-256 checksum
How to use checksums
8feed052e5a147a78fec61aac55384c7e2374e2b443872a5c7ff93d145eb587d
BLAKE2b-256 checksum
How to use checksums
45c3c2f1cebbf997ef1bc3d925ae485023a7a5b447bd15e378f90dfb41a7795a
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.6.0-cp310-abi3-win_amd64.whl

Download URL crn_craft-0.6.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
6a907c539ba9dae08191a38123dd7b2815964f76872e48b6b5df7a458bece234
BLAKE2b-256 checksum
How to use checksums
29b7a0a4a4ca345404c8d08dc4117af817917f3cf5e0cab7dfaca16e09742cd5
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.6.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL crn_craft-0.6.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
20dc93a9858ba16eaae957529562c9a9d1e619824edfe017b8a18c4b14c2e833
BLAKE2b-256 checksum
How to use checksums
e2b07b0cc53c4e5c5ded9c2c56108f92eda39acb614f7db515aeaa2a5bdcb65d
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.6.0-cp310-abi3-macosx_11_0_arm64.whl

Download URL crn_craft-0.6.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
b7032b3fd6581ccdbf416d2e5120fca3db99a729e1119344653f27f04be2f56b
BLAKE2b-256 checksum
How to use checksums
b21391dfa82afe71fc73b79daf4f5f5a363344e507ed0eb7ca131c6be5527a9d
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.6.0-cp310-abi3-macosx_10_12_x86_64.whl

Download URL crn_craft-0.6.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
ba0d13a99dc029c4589788ce9c211d41b7c1920a3c9817642286166ce7d0d0da
BLAKE2b-256 checksum
How to use checksums
4ba3514dca38d741c4743046a0ef2dbe7a6836a00f09f52293bd33d81d3c0b6d
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.6.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