CRN-craft
CRN-craft simulates chemical reaction networks stochastically, from Python, with a native engine.
pip install crn-craft
This example builds a model, runs 1,000 trajectories and prints their means:
import crn_craft as crn
model = crn.Model("immigration_death")
model.add_species("A", 0)
model.add_reaction(4.0, [], ["A"], name="birth") # molecules arrive at rate 4
model.add_reaction(0.2, ["A"], [], name="death") # each one decays at rate 0.2
run = crn.ensemble(model, end=10.0, report_times=[0.0, 5.0, 10.0],
replicates=1000, seed=1, threads=2, method="static_direct")
result = run.simulate()
print(result.statistics["mean"]) # exact: 20 * (1 - exp(-0.2 t)) = 0, 12.64, 17.29
A
time
0.0 0.000
5.0 12.623
10.0 17.305
The 1,000 trajectories ran on two threads in one call, and the same seed gives the same numbers on any number of threads.
Why CRN-craft
- Many trajectories in one call. An ensemble runs on native threads, and the same seed gives the same result on any number of threads (chapter 3).
- Compiled models from Python.
crn.compile_loop(model)compiles a model’s event loop, and the results stay byte-identical. On 12 November 2026 the compiled mtDNA model ran 2.1 times as fast as the interpreted one (chapter 5). - Exact methods and exact distributions. Static Direct with five selectors, next reaction and finite state projection; approximate methods are labeled as approximate (chapter 7).
- More than reaction networks. Continuous variables (chapter 9) and species with attributes, such as clones, sizes and lineages (chapter 12).
- Runs that can be checked. Strict input checks, explicit budgets, and sealed archives with a verifier (chapter 10).
Coming from GillesPy2 or rebop? See how CRN-craft compares.
Where to start
- New here: read chapters 1 to 4 in order.
- A question: the task index links fifty tasks to their answers.
- Tutorials: the tutorials page lists all of them in two groups. Simulation tutorials rebuild published stochastic models and compare the simulations with the papers. Optimization tutorials put an fcmaes optimizer around a simulation to fit, select, design or search.
- mtDNA models: the case study, the re-creation of a published study, the comparison of three mechanisms from two 2014 studies, and the inference of takeover times from cell snapshots from a 2026 study.
- Code of an earlier release: Migrating from earlier releases.
What is included
| Part | What it does |
|---|---|
| Model input | the builder crn.Model; JSON model files; strict SBML and BioNetGen subsets (chapter 11) |
| Exact methods | Static Direct with five selectors, next reaction, the tree method for species that appear and disappear |
| Approximate methods | tau leaping, binomial splitting, hybrid for continuous variables |
| Distributions | finite state projection with separate error terms |
| Results | pandas and xarray; mean, variance, standard error, quantiles; trackers, event logs and callbacks; reports in markdown or JSON |
| Reproducibility | one random stream per replicate, results independent of the thread count, model and request named by SHA-256 |
| Interfaces | Python, the crn-craft command line, Rust; R through reticulate |
| Analysis | conservation laws and structure, GillesPy2 export; ODE right-hand sides and Jacobians in Rust |
The rest of the site
- Reference: the model language, methods, the Python API, contracts, results, archives and diagnostics.
- Developer: the architecture, the Rust API, extending and checking the project.
- Evidence: the technical report, measurements and comparisons.
- History: plans, decisions and campaign logs.
Release 0.7.0 merged two earlier engines into one; the changelog says what changed and how to migrate. CRN-craft is one of 18 related repositories; the repository overview shows how they connect.