Differentiable, hardware accelerated (stochastic) kinetic models in JAX.
Project description
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
See CITATION.cff. For BibTeX format, click on the “Cite this repository” button in the top right corner of the repository page.
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 stochastix-0.1.0.tar.gz.
File metadata
- Download URL: stochastix-0.1.0.tar.gz
- Upload date:
- Size: 242.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
487814fc0ed14cf5e3ffdbcf17c0ebb088287e14feca4f74e859bc5fa04aca86
|
|
| MD5 |
3064f40fd2c42674b54f1448c00d3272
|
|
| BLAKE2b-256 |
03db5bef0be393dd98c7f365bec600061d91c6de4d7d643f68104a81cdbf92ff
|
Provenance
The following attestation bundles were made for stochastix-0.1.0.tar.gz:
Publisher:
publish.yml on fmottes/stochastix
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
stochastix-0.1.0.tar.gz -
Subject digest:
487814fc0ed14cf5e3ffdbcf17c0ebb088287e14feca4f74e859bc5fa04aca86 - Sigstore transparency entry: 836083948
- Sigstore integration time:
-
Permalink:
fmottes/stochastix@9a0cf509e88d7faf39b2b486350ca36251bea85a -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/fmottes
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9a0cf509e88d7faf39b2b486350ca36251bea85a -
Trigger Event:
release
-
Statement type:
File details
Details for the file stochastix-0.1.0-py3-none-any.whl.
File metadata
- Download URL: stochastix-0.1.0-py3-none-any.whl
- Upload date:
- Size: 92.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ac315476799f52d7a83776f164d3676771d12e38e57c7481ccb282ff6db34ecc
|
|
| MD5 |
81d1addf40aa9704e98457fa71f5dbc1
|
|
| BLAKE2b-256 |
1e5f4db6505b791a9c685c7491c2cc56432c265948f451d3aa61ecf562ce6b55
|
Provenance
The following attestation bundles were made for stochastix-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on fmottes/stochastix
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
stochastix-0.1.0-py3-none-any.whl -
Subject digest:
ac315476799f52d7a83776f164d3676771d12e38e57c7481ccb282ff6db34ecc - Sigstore transparency entry: 836083952
- Sigstore integration time:
-
Permalink:
fmottes/stochastix@9a0cf509e88d7faf39b2b486350ca36251bea85a -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/fmottes
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9a0cf509e88d7faf39b2b486350ca36251bea85a -
Trigger Event:
release
-
Statement type: