Skip to main content

Differentiable, hardware accelerated (stochastic) kinetic models in JAX.

Project description

stochastix

Differentiable, hardware accelerated stochastic kinetic models in JAX.

InstallationQuick ExampleDocumentationCitation

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_prob for 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

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.

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

stochastix-0.2.0.tar.gz (252.5 kB view details)

Uploaded Source

Built Distribution

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

stochastix-0.2.0-py3-none-any.whl (96.6 kB view details)

Uploaded Python 3

File details

Details for the file stochastix-0.2.0.tar.gz.

File metadata

  • Download URL: stochastix-0.2.0.tar.gz
  • Upload date:
  • Size: 252.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for stochastix-0.2.0.tar.gz
Algorithm Hash digest
SHA256 7e8f9f519151d49600168b5c00bca08e8e648b2e5b49556afc7496a2cbcb1159
MD5 1016563b68ce719415639fab07633949
BLAKE2b-256 585ad8d4c193fe261ab0e8cedd979651f5ca0a7601f790f3c83dc29678ada6e8

See more details on using hashes here.

Provenance

The following attestation bundles were made for stochastix-0.2.0.tar.gz:

Publisher: publish.yml on fmottes/stochastix

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file stochastix-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: stochastix-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 96.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for stochastix-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6d91414f3d33bd4e9a75c7908dd362108849232086ab6ad0c99aff283d666b82
MD5 10242bd7cdaf14e7044b8299503f40a9
BLAKE2b-256 770ab9e7f41474f5104d7efd9d7f58be6fca3c8974e435eccd4aadb42ecdda4a

See more details on using hashes here.

Provenance

The following attestation bundles were made for stochastix-0.2.0-py3-none-any.whl:

Publisher: publish.yml on fmottes/stochastix

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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