Skip to main content

Python+JAX code relating to the textbook, Stochastic modelling for systems biology, third edition

Project description

JAX-SMfSB (jsmfsb)

DOI Code style: black

SMfSB code in Python+JAX

Python code relating to the book Stochastic Modelling for Systems Biology, third edition.

There is a regular Python+Numpy package on PyPI, smfsb, which has complete coverage of the book. If you are new to the book and/or this codebase, that might be a simpler place to start.

This package covers all of the core simulation and inference algorithms from the book, including the parsing of SBML and SBML-shorthand models. These core algorithms will run very fast, using JAX. Computationally intensive algorithms will typically run between 50 and 150 times faster than they would using the regular smfsb package, even without a GPU (but YMMV). You must install JAX (which is system dependent), before attempting to install this package. See the JAX documentation for details, but for a CPU-only installation, it should be as simple as pip install jax.

Once you have JAX installed and working correctly, you can install this package with:

pip install jsmfsb

To upgrade already installed package:

pip install --upgrade jsmfsb

Note that a number of breaking syntax changes (more pythonic names) were introduced in version 1.1.0. If you upgrade to a version >= 1.1.0 from a version prior to 1.1.0 you will have to update syntax to the new style.

Note that version 1.1.3 fixes a bug in sim_time_series (see the release notes for details). Users are encouraged to update to the latest release ASAP.

You can test that your installation is working by entering the following at a python prompt:

import jax
import jsmfsb

If these both return silently, you are probably good to go.

Documentation

Note that the book, and its associated github repo is the main source of documentation for this library. The code in the book is in R, but the code in this library is supposed to mirror the R code, but in Python.

For an introduction to this library, see the jax-smfsb tutorial.

Converting from the smfsb python package

The API for this package is very similar to that of the smfsb package. The main difference is that non-deterministic (random) functions have an extra argument (typically the first argument) that corresponds to a JAX random number key. See the relevant section of the JAX documentation for further information regarding random numbers in JAX code.

Further information

For further information, see the demo directory and the API documentation. Within the demos directory, see shbuild.py for an example of how to specify a (SEIR epidemic) model using SBML-shorthand and sbml-params.py for an example of how to modify the parameters of a model parsed from SBML (or SBML-shorthand). Also see step_cle_2df.py for a 2-d reaction-diffusion simulation. For parameter inference (from time course data), see abc-cal.py for ABC inference, abc_smc.py for ABC-SMC inference and pmmh.py for particle marginal Metropolis-Hastings MCMC-based inference. There are many other demos besides these.

You can view this package on GitHub or PyPI.

Citing

If you use this software in your research, please cite the paper:

Wilkinson, D. J. (2025). jax-smfsb: A Python library for stochastic systems biology modelling and inference. Journal of Open Source Software, 10(106), 7491.

Contributing

If you have problems with this software, please start an Issue or a Discussion. Pull requests containing bug fixes are welcome.

Copyright (C) 2024-2025 Darren J Wilkinson

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jsmfsb-1.1.6.tar.gz (3.3 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jsmfsb-1.1.6-py3-none-any.whl (23.2 kB view details)

Uploaded Python 3

File details

Details for the file jsmfsb-1.1.6.tar.gz.

File metadata

  • Download URL: jsmfsb-1.1.6.tar.gz
  • Upload date:
  • Size: 3.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.3

File hashes

Hashes for jsmfsb-1.1.6.tar.gz
Algorithm Hash digest
SHA256 a964f09bfe7180535dd945b2d424f251a2b5c494fb5eb7491f5f236680d07537
MD5 881690f4618a6a18a7d7fd5c72f9a977
BLAKE2b-256 6c88a9475a763301f03af1f7a11df9ebe3830dbb87261f8728200eb20b707638

See more details on using hashes here.

File details

Details for the file jsmfsb-1.1.6-py3-none-any.whl.

File metadata

  • Download URL: jsmfsb-1.1.6-py3-none-any.whl
  • Upload date:
  • Size: 23.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.3

File hashes

Hashes for jsmfsb-1.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 f5212ab99a98f09ff927bfac84c81e8811d970623330499b47b628b5c9adef85
MD5 12b6e27ddf2ff91a8748b1d9b48fcab2
BLAKE2b-256 e836974da5dd77fab1d4cb853bee05c449c8d9a4e362cb492e982417bd6d036d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page