crn-jax
Chemical reaction networks in JAX: a lightweight, GPU-optimized Gillespie / SSA simulation library.
☝️ Wall-time to simulate 1,000,000 independent stochastic trajectories — each a full Gillespie run of the reaction network from t=0 to t=20, sampled at 200 time points (CPU vs RTX 5090 GPU).
☝️ 24 stochastic trajectories of the repressilator gene circuit, sampled in parallel from a one-line call.
Key features
- 🎯 Exact Gillespie simulations: an exact implementation of the Gillespie (SSA) algorithm.
- 🚀 GPU-optimized: run 1M+ independent trajectories on a single GPU with no Python overhead, powered by JAX.
- 🎛️ Closed-loop simulations: propensity functions take an optional
inputargument that can vary per-interval and per-replicate, so each ofNparallel trajectories can follow its own time-dependent input schedule (useful for closed-loop experiment simulations, RL-style rollouts, …). - 🎨 Pre-built suite of common reaction networks: a library of canonical examples already implemented with realistic default (tunable) parameters (useful for benchmarking, prototyping, and getting started).
- 🧩 Customizable: implementing a new chemical reaction network is easy.
Install
crn-jax depends on jax / jaxlib only.
pip install crn-jax
# with NVIDIA GPU support:
pip install crn-jax "jax[cuda12]"
# with plotting helpers:
pip install "crn-jax[examples]"
# for local development (uses Poetry):
git clone https://github.com/robinhenry/crn-jax && cd crn-jax
poetry install # main deps + dev tools
poetry install --with gpu # add jax[cuda12] on an NVIDIA host
Quickstart
To simulate 32 stochastic trajectories of the repressilator in parallel and plot them:
import jax, jax.numpy as jnp
from crn_jax import models
from crn_jax.plotting import plot_species_trajectories
# Initial counts: (n_replicates, n_species). You always supply x0 yourself.
# We deliberately don't sample initial conditions for users because the sensible
# initial distribution is often problem-specific.
key, k_x0 = jax.random.split(jax.random.PRNGKey(0))
x0 = jax.random.uniform(
k_x0, (32, len(models.repressilator.SPECIES)), minval=0.0, maxval=50.0,
)
ds = models.sample_trajectories(models.repressilator, key, x0, n_steps=3000, dt=0.1)
plot_species_trajectories(ds, title="Repressilator") # see the plot at the top of this file
The returned Dataset has the following fields:
ds.species: a tuple of species names, e.g.("A", "B", "C").ds.xs: a 3D array with shape(n_replicates, n_steps, n_species)that contains the full trajectories.ds.X_t,ds.dX: two 2D arrays with shape(n_replicates * n_steps, n_species)that contain the timestamps and deltas of each reactions (useful to use as a training dataset for downstream ML).
Swapping models can be done by replacing models.repressilator with models.toggle_switch, models.incoherent_ffl, etc.
For a complete walkthrough of how to implement your own models, see Examples below.
Pre-built models
crn_jax.models provides a library of canonical reaction networks inspired by the literature, each exposing the same interface.
Currently, these are mostly gene reaction networks (GRNs), but this may evolve over time.
| model | species | reactions | shape |
|---|---|---|---|
birth_death |
X | 2 | minimal one-species baseline |
single_gene |
R, P | 4 | constitutive transcription-translation |
negative_autoregulation |
X | 2 | Hill-repressed self-feedback |
positive_autoregulation |
X | 2 | Hill self-activation (Params.bistable() for the bistable regime) |
linear_cascade |
A, B | 4 | A → B activation cascade |
toggle_switch |
A, B | 4 | mutual repression |
incoherent_ffl |
A, B, C | 6 | adaptive / pulse-generating FFL |
repressilator |
A, B, C | 6 | synthetic oscillator |
cca_optogenetic |
R, P | 4 | light-driven gene expression (CcaS/CcaR) — input-driven |
Override the defaults by passing your own Params values:
ds = models.sample_trajectories(
models.positive_autoregulation, key, x0,
params=models.positive_autoregulation.Params(n=3), # default is n=2
n_steps=3000, dt=0.1,
)
Examples
The examples/ folder walks through the main features end-to-end:
1_library_examples.ipynb: sample and plot from every pre-built model. Start here.2_per-replicate_control.ipynb: closed-loop simulations where each replicate gets its own time-varying controller and setpoint.3_implement_your_own.ipynb: define a custom reaction network from scratch, and optionally use the low-levelsimulate_interval/simulate_untilprimitives for finer-grained control (RL-style rollouts, non-uniform time grids).
See Also
- GillesPy2: C++ optimized Gillespie simulations on CPU.
- jax-smfsb: JAX implementations of algorithms from the Stochastic Modelling for Systems Biology book.
- myriad-jax: RL-style decision making fully in JAX, powered by
crn-jaxat its core.
Metadata
Release files for crn-jax 0.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| crn_jax-0.3.1.tar.gz | 28.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| crn_jax-0.3.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 63.6 kB
Release files / crn_jax-0.3.1.tar.gz
| Download URL | crn_jax-0.3.1.tar.gz |
|---|---|
| Size | 28.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
47ab71cb73a063f8d00da1d35b50d8f3d32a778761c91e9dbf45f3e8f9299bbd
|
|
BLAKE2b-256 checksum How to use checksums |
32c2566c3c28fc9add96ddf8b170e81aefd96dd4a2fd7707dec4a95e3a79ce0f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 25, 2026.
Transparency logRelease files / crn_jax-0.3.1-py3-none-any.whl
| Download URL | crn_jax-0.3.1-py3-none-any.whl |
|---|---|
| Size | 35.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0a246a8a0615670e4bb33f609b142b5d62caeec64e544dc94baec4f664b264e4
|
|
BLAKE2b-256 checksum How to use checksums |
a3ada05f7dbcb0c9e1686665b59948577857c556b710376d61acd9579edd2983
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 25, 2026.
Transparency log