The main purpose of this library is to provide a high-level, fairly flexible implementation of stochastic simulations of kinetic models (also commonly referred to as Gillespie simulations from the author of the most used solvers).
The design is heavily inspired by the Diffrax library for solution of differential equations and heavily relies on the infrastructure provided by Equinox. All of this is built on top of JAX, if you are new to this world you might want to take a quick look at some basic JAX Tutorials.
Basic usage of the main stochastix API for running forward simulations should require only a minimal knowledge of JAX.
Main features:
- Automatic GPU/TPU acceleration, JIT compilation, and vectorization via JAX
- Exact, approximate, and pathwise differentiable stochastic solvers (
DirectMethod,TauLeaping,DifferentiableDirect,DGA, etc.) - Seamless integration with the JAX ecosystem (Equinox, Diffrax, Optax, etc.)
- Automatic conversion between CME (jump process), CLE (stochastic differential equation), and ODE (deterministic differential equation) models for Diffrax integration
- Built-in kinetics (MassAction, Hill, Michaelis–Menten) and support for learnable neural network propensities
- Controllers for time-based interventions during simulations
- Likelihood computation via
log_probfor exact trajectories and helpers for REINFORCE-style training - Analysis utilities: differentiable autocorrelation, cross-correlation, histograms, and mutual information
Installation
GPU support
stochastix (as all other JAX-based libraries) relies on JAX for hardware acceleration support. To run on GPU or other accelerators, you need to install the appropriate JAX version. If JAX is not already present, the standard stochastix installation will automatically install the CPU version.
Please refer to the JAX installation guide for the latest guidelines.
pip
To install the package and core dependencies:
pip install stochastix
or directly from the repository:
pip install git+https://github.com/fmottes/stochastix.git
Note: in order to run the Jupyter notebooks, you need to install the optional dependencies:
pip install stochastix[notebooks]
uv
You can add the package to your project dependencies with:
uv add stochastix
For all other uv installation options, see the uv docs.
Quick Example
A basic simulation of a chain reaction with Gillespie's direct method:
import jax
import jax.numpy as jnp
import stochastix as stx
from stochastix.kinetics import MassAction
# simple reaction chain with mass action rates
network = stx.ReactionNetwork(
[
stx.Reaction('0 -> X', MassAction(k=0.01)),
stx.Reaction('X -> Y', MassAction(k=0.002)),
]
)
x0 = jnp.array([0, 0]) # initial conditions [X, Y]
sim_key = jax.random.PRNGKey(0) # key for jax random number generator
# solve with direct method from t0=0 to t1=100
sim_results = stx.stochsimsolve(sim_key, network, x0, T=100.0)
Diving deeper
- Documentation: Full documentation with API reference
- Basic Usage: Quick examples of core library functionalities
- User Guide: Detailed explanations of library features
- Example notebooks: Jupyter notebooks with worked examples
Citation
If you use this software, please cite the paper:
Gradient-based optimization of exact stochastic kinetic models Francesco Mottes, Qian-Ze Zhu, Michael P. Brenner arXiv:2601.14183 (2026)
You can use the "Cite this repository" button in the top right corner of the repository page to get the citation in various formats.
Metadata
Release files for stochastix 0.3.1
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 |
|---|---|---|---|---|
| stochastix-0.3.1.tar.gz | 365.5 kB | With provenance | Details for stochastix-0.3.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| stochastix-0.3.1-py3-none-any.whl | Python 3 | none | any | Details for stochastix-0.3.1-py3-none-any.whl |
Total release size: 467.5 kB
Release files / stochastix-0.3.1.tar.gz
| Download URL | stochastix-0.3.1.tar.gz |
|---|---|
| Size | 365.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
414ee7203967bc38aae10c2b9962fc9c0023361a040367925e857ba52fe3a45e
|
|
BLAKE2b-256 checksum How to use checksums |
aa63de641e530362092680798f56d7a6cb3c882dd75ef7fb5503383d30895887
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 3, 2026.
Transparency logRelease files / stochastix-0.3.1-py3-none-any.whl
| Download URL | stochastix-0.3.1-py3-none-any.whl |
|---|---|
| Size | 101.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
46b8ad89aeb27bce02e380464cafe12c7ad7fd59ca85b09ba729a8103f532406
|
|
BLAKE2b-256 checksum How to use checksums |
c8ed876aceb5607a03050e8b5bd80ed835e2d1ca7ade4cd40819c336e539d900
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 3, 2026.
Transparency logSecurity for stochastix 0.3.1
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
Both files in this release have been uploaded with provenance metadata.
Attestation for stochastix-0.3.1.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 Nov 3, 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.