lmbio guide: reaction networks, solvers and limits

This guide explains how lmbio thinks about a model and what its numbers mean. For commands see the skill page; for signatures see the reference.

Overview

lmbio describes biology as a reaction network: compartments hold species, reactions move substance between species at a rate given by an expression, and parameters name the constants. The same network can be integrated deterministically, solved for a steady state, sampled stochastically or differentiated with respect to a parameter. The repository ships 18 examples in three groups (gene circuits and noise; enzymes, metabolism and chemistry; medicine, epidemics and populations), and every example checks its own numbers against a known answer before it draws anything.

Architecture

Workflow

  1. Build the model: bio.model or bio.load_sbml, then compartment, species, param, reaction, mass_action, rule and rate_rule.
  2. Optionally set tolerances with tol and call validate.
  3. Compute: simulate for a time course, steady_state, ssa for one stochastic trajectory, or sensitivity.
  4. Check: compare result values with bio.assert_close and bio.assert_true; a wrong result stops the run.
  5. Export: save_csv for other hosts, save_sbml for the model.
  6. Draw: a second block for lmplot or lmdraw reads the CSV, as in the repository examples.

Domain model

Rates and concentrations

Kinetic laws are reaction extents, substance per time. A concentration species receives stoichiometry times rate divided by compartment volume. Compartments have a fixed, positive size. mass_action writes the law for you: for 2 A -> D with constant k it is k*V*A^2 for ODEs and the propensity k*A*(A-1) for SSA.

Rules

An assignment rule defines a quantity by an expression and is evaluated in dependency order; cycles and unknown names are errors. A rate rule gives a quantity its own differential equation.

Results

Every solver returns a Result: a matrix whose columns are time, the species in creation order and the parameters in identifier order. Simulation does not change the initial values stored in the model, so a model can be run many times with set between runs for a scan.

Restarts instead of events

There are no events. A dose or medium change is modelled by set_state with the previous result, a set that applies the jump, a further simulate, and append to join the pieces; a jump at the joint keeps both rows. The pk_dosing example compares 400 mg twice daily with 800 mg once daily this way and uses integral for exposure.

Numerics and accuracy

Limits

Building from source

scripts/sync-deps.sh
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build --parallel 4
./test.sh

This requires CMake 3.24+, C++17, git, Python 3, and lmscript for the tests. test.sh runs the native regression tests, every example with its known-answer assertions, a byte-identical rerun check and schema, dependency pin and error code checks.

Where to go next