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}},
}
Metadata
Release files for bcrnnoise 3.0.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| bcrnnoise-3.0.6.tar.gz | 14.1 kB | With provenance | Details for bcrnnoise-3.0.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| bcrnnoise-3.0.6-py3-none-any.whl | Python 3 | none | any | Details for bcrnnoise-3.0.6-py3-none-any.whl |
Total release size: 27.1 kB
Release files / bcrnnoise-3.0.6.tar.gz
| Download URL | bcrnnoise-3.0.6.tar.gz |
|---|---|
| Size | 14.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
475eb49a0cf9d563436bd076f98aa22904180ce456023d2f72bea63fbabd59ea
|
|
BLAKE2b-256 checksum How to use checksums |
01b6fd7a63b7cb97157876105ffe4f20afa8839562e3a49fe4187105b99da5bb
|
| 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 4, 2026.
Transparency logRelease files / bcrnnoise-3.0.6-py3-none-any.whl
| Download URL | bcrnnoise-3.0.6-py3-none-any.whl |
|---|---|
| Size | 13.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
64d3e34c4522fc3b28b9999790702f6fc77502849d6b1d120c6f034d54aa8156
|
|
BLAKE2b-256 checksum How to use checksums |
620a4b56d98bc979cdc254bcfa4a62fef9f418c1b0ed59fe3dd871c4c4336893
|
| 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 4, 2026.
Transparency logSecurity for bcrnnoise 3.0.6
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.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for bcrnnoise-3.0.6.tar.gz
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 4, 2026.
Transparency logA 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.