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. Results are pandas DataFrames (pandas is installed with the package): per-replicate records and rule counts, statistics by report time, kept paths by (replicate, time), trackers and event logs. Result.to_xarray() returns the paths as an xarray Dataset with pip install "crn-craft[xarray]". 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["X"].unstack("time").head(3))
           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, ODEs between events that rates read (for example an ATP pool), which method="hybrid" simulates at declared tolerances.

New in 0.4.0, opt-in, with a Rust toolchain (1.85 or newer): loop = rules.compile_loop(model) compiles a model's Static Direct event loop 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.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 crn-craft 0.4.0
File Size Uploaded Provenance Actions
crn_craft-0.4.0.tar.gz 476.9 kB Without provenance Details for crn_craft-0.4.0.tar.gz

Built distributions (wheels)

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

Total release size: 8.1 MB

Release files / crn_craft-0.4.0.tar.gz

Download URL crn_craft-0.4.0.tar.gz
Size 476.9 kB
Tags Source
SHA-256 checksum
How to use checksums
75c1539d7947c5cee5d6e7935a7808d332b24a9574e0ea985e42b8385146982d
BLAKE2b-256 checksum
How to use checksums
8907413d5d887b0b92e094948777014c17b83f31b66ee49cc50a1ea6b350c28e
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.4.0-cp310-abi3-win_amd64.whl

Download URL crn_craft-0.4.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
cf5cba8930dcdb2f8d9873c01bcd98d4b0f542e3780e1c99cbbbd155c2ebe129
BLAKE2b-256 checksum
How to use checksums
2e85f0717a7e846c6cef45c57f6e9e80ed3d9910a2ae3d9645e4918b1e1704b3
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.4.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL crn_craft-0.4.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 2.0 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
b96f23fcbc751580a007dc8a09bc9a7f9a7c63ba06ef63d49a874cd0f4682658
BLAKE2b-256 checksum
How to use checksums
41f9c106de0e389a99a271499193b57befd3b0d8269139284a4cd47431166a9f
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.4.0-cp310-abi3-macosx_11_0_arm64.whl

Download URL crn_craft-0.4.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
1bbb151aae6bf9f9b9eb7b9196df9e478b3e65264fed1a2a8c644c9d693bbff8
BLAKE2b-256 checksum
How to use checksums
e0222994455597f7fcf4a74ea38703907ce9865e5be022008cead8e0319d6497
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.4.0-cp310-abi3-macosx_10_12_x86_64.whl

Download URL crn_craft-0.4.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
3a92fe3b0a203acde1a488b55d41dd56cf36c4778a29f2c3baeca33f6f70fc97
BLAKE2b-256 checksum
How to use checksums
f0cbe62e7f97632639d3c4b0f713eb5664b716ea126fb71583c9ee95787d6d40
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.4.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