Constrained tau-leap-like stochastic simulator for SBML models
Project description
stochmod
Constrained tau-leap-like stochastic simulator for SBML models, adapted from SPARCED-style simulation.
stochmod ingests SBML in Python, generates per-model C propensity code, compiles it into a cached shared library, and runs simulation through a pybind11 core with sparse CSC stoichiometry.
Install
pip install stochmod
For development from a clone:
pip install -e ".[dev]"
Requirements
- Python 3.10+
- A C compiler (
gcc,clang, or MSVCcl) for first-time model builds (per-model codegen at runtime) - CMake 3.18+ only when building the Python extension from source (binary wheels from PyPI already include it)
Quickstart
from stochmod import StochasticModule
mod = StochasticModule("model.xml")
traj = mod.run(start=0.0, stop=10.0, step=0.1) # shape: (n_steps, n_species)
print(mod.species_names)
print(mod.parameter_ids)
print(mod.initial_state)
print(mod.parameter_values)
mod.update("k1", 0.5)
mod.set_state([100.0, 0.0])
mod.set_parameters([0.1, 1.0])
Trajectory columns follow mod.species_names index order. Row 0 is the initial state.
Cache
Compiled model libraries are stored under:
$HOME/.cache/stochmod/<hash>/(default)- or a custom cache root via
StochasticModule(sbml_path, cache_dir="/path/to/cache/root")
Each cache entry contains sparse stoichiometry arrays, generated C sources, and libmodel.so / libmodel.dll / libmodel.dylib.
SBML support (v1)
- SBML Level 3 Version 2 kinetic models
- Species, parameters, compartments, reactions with MathML kinetic laws
- Species amounts used as-is from SBML (
initialAmountorinitialConcentration * compartment size)
Not supported in v1: events, assignment/rate rules, algebraic constraints.
API
| Method / property | Description |
|---|---|
StochasticModule(sbml_path, cache_dir=None, verbose=None) |
Parse SBML, build/load cached model |
run(start, stop, step) |
Simulate; returns [n_steps, n_species] NumPy array |
update(key, val) |
Update species, parameter, or compartment by SBML id |
set_state(vector) |
Replace all species amounts |
set_parameters(vector) |
Replace all parameter values |
species_names |
Species ids in column order |
parameter_ids |
Global parameter ids |
initial_state |
Current species amount vector |
parameter_values |
Current parameter vector |
Tests
pytest
Publishing
See PUBLISHING.md for PyPI release steps (wheels CI + Trusted Publishing).
License
MIT — see LICENSE.txt.
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 stochmod-0.1.0.tar.gz.
File metadata
- Download URL: stochmod-0.1.0.tar.gz
- Upload date:
- Size: 1.3 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a199f7489060d59af4045d9a8012a67e6dc962f94d547289371b78c75b7e477b
|
|
| MD5 |
d5b5d5c370154057148b699069c26832
|
|
| BLAKE2b-256 |
25192e201ff6fe1d40a29fabad61ee2ed273e8c72a28c628e6dd0d9a19479eb4
|
File details
Details for the file stochmod-0.1.0-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: stochmod-0.1.0-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 121.3 kB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
46277ffbdbb07396e5ca53c7754a499f94fdc41c06ed61fb6148d99aed5fcb4f
|
|
| MD5 |
55ea08830eeef09cf4068c83b7325424
|
|
| BLAKE2b-256 |
18be1ed52779b3ee1e738f81d0d27265960f23dccc4e43818ed50df997e63c9b
|