Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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

What is included

PartWhat it does
Model inputthe builder crn.Model; JSON model files; strict SBML and BioNetGen subsets (chapter 11)
Exact methodsStatic Direct with five selectors, next reaction, the tree method for species that appear and disappear
Approximate methodstau leaping, binomial splitting, hybrid for continuous variables
Distributionsfinite state projection with separate error terms
Resultspandas and xarray; mean, variance, standard error, quantiles; trackers, event logs and callbacks; reports in markdown or JSON
Reproducibilityone random stream per replicate, results independent of the thread count, model and request named by SHA-256
InterfacesPython, the crn-craft command line, Rust; R through reticulate
Analysisconservation 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.