rebop is a fast stochastic simulator for well-mixed chemical reaction networks.
Two goals of this project are efficiency and convenience. The following macro defines a reaction network naturally:
rust
define_system! {
r_tx r_tl r_dim r_decay_mrna r_decay_prot;
Dimers { gene, mRNA, protein, dimer }
transcription : gene => gene, mRNA @ r_tx
translation : mRNA => mRNA, protein @ r_tl
dimerization : protein, protein => dimer @ r_dim
decay_mRNA : mRNA => @ r_decay_mrna
decay_protein : protein => @ r_decay_prot
}
To simulate the system: instantiate a new problem, set the initial values, the parameters, and launch the simulation.
rust
let mut problem = Dimers::with_parameters(25., 1000., 0.001, 0.1, 1.);
problem.gene = 1;
problem.advance_until(1.);
println!("{}: dimer = {}", problem.t, problem.dimer);
Or for the classic SIR example:
``` rust definesystem! { rinf rheal; SIR { S, I, R } infection: S, I => I, I @ rinf healing : I => R @ r_heal }
fn main() { let mut problem = SIR::new(); problem.rinf = 0.1 / 1000.; problem.rheal = 0.01; problem.S = 999; problem.I = 1; println!("time,S,I,R"); for t in 0..250 { problem.advance_until(t as f64); println!("{},{},{},{}", problem.t, problem.S, problem.I, problem.R); } } ```
which can produce an output such as
On typical example networks, rebop outperformed all other software.
Disclaimer: Most of this software contains much more features than rebop (e.g. spatial models, custom reaction rates, etc.). Some of these features might require them to make compromises on speed. Moreover, some can be conveniently used through wrappers (for example when the simulation code is written in C++ but the model is expressible in Python). These wrappers can also add a significant overhead.
To benchmark these programs in the fairest possible conditions, we
considered for everyone a typical situation where the model was just
modified and we want to simulate it N
times. So the (re-)compilation
time is included in this benchmark.
Example for the Vilar oscillator (Mechanisms of noise-resistance in
genetic oscillators, Vilar et al., PNAS 2002). Here, we simulate this
model from t=0
to t=200
, saving the state at time intervals of 1
.
rebop
is the fastest, both per simulation, and with compilation time
included. rebopy
measures the performance of the function-based API
through the Python bindings.
Python bindings are available to expose the functional API to Python. Example for the SIR model:
``` python import rebop
sir = rebop.Gillespie() sir.addreaction(0.1 / 1000, ['S', 'I'], ['I', 'I']) sir.addreaction(0.01, ['I'], ['R']) print(sir) times, sol = sir.run({'S': 9999, 'I': 1}, tmax=250, nb_steps=250) ```
To run this Python file, you must first compile rebop with cargo build
--release
and copy or link the library next to the script: ln -s
target/release/librebop.so rebop.so
.