Stochastic simulation of biochemical reaction networks with noise
Project description
bcrnnoise
A Python library for simulating Bio-Chemical Reaction Networks (BCRNs) with noise. Supports deterministic ODE integration, exact Markov chain simulation via Gillespie's algorithm, and stochastic SDE simulation via Euler-Maruyama — including a vectorised batch mode for efficient multi-trajectory sampling.
Available on PyPI:
pip install bcrnnoise
Overview
Models are defined by subclassing BCRN and implementing two things:
stoichiometry— numpy array of shape(n_reactions, n_species)giving net stoichiometric changes per reactionreaction_rates(state)— returns per-reaction propensities aslist[Quantity]
All quantities carry physical units via pint, so dimensional errors are caught at runtime rather than buried in wrong results.
Simulation modes
| Method | Type | Description |
|---|---|---|
simulate_ode() |
deterministic | Integrates the mean-field ODE via scipy.solve_ivp |
simulate_markov_chain(seed) |
stochastic | Exact sample path via Gillespie's algorithm |
simulate_sde(noise_fun, seed) |
stochastic | Euler-Maruyama with custom additive noise |
simulate_sde_batch(noise_fun, n, seed) |
stochastic | Vectorised Euler-Maruyama for n trajectories simultaneously |
All methods return a Timeseries (or BatchTimeseries for the batch variant) with a shared time axis and unit-carrying states.
Quick start
from collections.abc import Sequence
import numpy as np
from pint import Quantity, UnitRegistry
from bcrnnoise import BCRN, plot_timeseries
u = UnitRegistry()
class TranscriptionSystem(BCRN):
"""0 -> mRNA [alpha], mRNA -> 0 [delta]"""
def __init__(self, alpha, delta, **kwargs):
super().__init__(**kwargs)
self._alpha, self._delta = alpha, delta
@property
def stoichiometry(self) -> np.ndarray:
return np.array([[1], [-1]])
def reaction_rates(self, state: Sequence[Quantity]) -> list[Quantity]:
return [self._alpha, self._delta * state[0]]
sys = TranscriptionSystem(
alpha=1.0 / u.minute / u.femtoliter,
delta=0.1 / u.minute,
init_state=[0.0 / u.femtoliter],
volume=1.0 * u.femtoliter,
time_horizon=200.0 * u.minute,
dt=0.1 * u.minute,
)
# Deterministic
ode_ts = sys.simulate_ode()
# Exact stochastic
mc_ts = sys.simulate_markov_chain(seed=0)
# SDE with Gaussian noise
sigma = 5.0 / u.femtoliter / u.minute**0.5
def gaussian_noise(rng, t, state):
return [sigma * np.sqrt(sys.dt) * rng.normal()]
sde_ts = sys.simulate_sde(noise_fun=gaussian_noise, seed=0)
plot_timeseries([ode_ts, mc_ts, sde_ts], labels=["ODE", "Markov chain", "SDE"])
Batch SDE simulation
For multi-trajectory studies, simulate_sde_batch runs n trajectories in a single vectorised loop — roughly n× faster than calling simulate_sde repeatedly:
def gaussian_batch_noise(rng, t, states):
n = states[0].magnitude.shape[0]
return [sigma * np.sqrt(sys.dt) * rng.normal(size=n)]
batch = sys.simulate_sde_batch(noise_fun=gaussian_batch_noise, n=500, seed=0)
# Access individual trajectory
ts_42 = batch.trajectory(42)
# Unpack all at once (single pass, more efficient than looping trajectory())
all_ts = batch.to_timeseries_list()
The noise function receives and returns list[Quantity] where each Quantity wraps a (n,) numpy array. Any reaction_rates implementation that uses only numpy-compatible arithmetic works in batch mode without modification.
Examples
examples/example_vanilla.py— minimal one-species model with ODE, Markov chain, Gaussian and Pareto SDEexamples/example_rna.py— multi-species transcription models including two-state promoter and geometric noiseexamples/example_batch.py— batch SDE simulation with ensemble mean vs ODE comparison
Citation
@misc{bcrnnoise:github,
author = {Arman Ferdowsi and Mattias F{\"u}gger and Thomas Nowak},
title = {bcrnnoise: simulate Bio-Chemical Reaction Networks with noise},
year = {2025},
howpublished = {\url{https://github.com/BioDisCo/bcrnnoise}},
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bcrnnoise-3.0.6.tar.gz.
File metadata
- Download URL: bcrnnoise-3.0.6.tar.gz
- Upload date:
- Size: 14.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
475eb49a0cf9d563436bd076f98aa22904180ce456023d2f72bea63fbabd59ea
|
|
| MD5 |
8f10a252b03e5ec8e00132ccce7356e6
|
|
| BLAKE2b-256 |
01b6fd7a63b7cb97157876105ffe4f20afa8839562e3a49fe4187105b99da5bb
|
Provenance
The following attestation bundles were made for bcrnnoise-3.0.6.tar.gz:
Publisher:
publish.yaml on BioDisCo/bcrnnoise
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bcrnnoise-3.0.6.tar.gz -
Subject digest:
475eb49a0cf9d563436bd076f98aa22904180ce456023d2f72bea63fbabd59ea - Sigstore transparency entry: 1437186874
- Sigstore integration time:
-
Permalink:
BioDisCo/bcrnnoise@438e6ec18a482058ee528e287e1ee9aef36419ee -
Branch / Tag:
refs/tags/v3.0.6 - Owner: https://github.com/BioDisCo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@438e6ec18a482058ee528e287e1ee9aef36419ee -
Trigger Event:
push
-
Statement type:
File details
Details for the file bcrnnoise-3.0.6-py3-none-any.whl.
File metadata
- Download URL: bcrnnoise-3.0.6-py3-none-any.whl
- Upload date:
- Size: 13.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
64d3e34c4522fc3b28b9999790702f6fc77502849d6b1d120c6f034d54aa8156
|
|
| MD5 |
14fcbf5f0a01fe4be9f6c42cea15982e
|
|
| BLAKE2b-256 |
620a4b56d98bc979cdc254bcfa4a62fef9f418c1b0ed59fe3dd871c4c4336893
|
Provenance
The following attestation bundles were made for bcrnnoise-3.0.6-py3-none-any.whl:
Publisher:
publish.yaml on BioDisCo/bcrnnoise
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bcrnnoise-3.0.6-py3-none-any.whl -
Subject digest:
64d3e34c4522fc3b28b9999790702f6fc77502849d6b1d120c6f034d54aa8156 - Sigstore transparency entry: 1437186877
- Sigstore integration time:
-
Permalink:
BioDisCo/bcrnnoise@438e6ec18a482058ee528e287e1ee9aef36419ee -
Branch / Tag:
refs/tags/v3.0.6 - Owner: https://github.com/BioDisCo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@438e6ec18a482058ee528e287e1ee9aef36419ee -
Trigger Event:
push
-
Statement type: