Skip to main content

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

Project description

stochastix

Differentiable, hardware accelerated stochastic kinetic models in JAX.

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

See CITATION.cff. For BibTeX format, click on the “Cite this repository” button in the top right corner of the repository page.

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.1.0.tar.gz (242.6 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.1.0-py3-none-any.whl (92.9 kB view details)

Uploaded Python 3

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

Hashes for stochastix-0.1.0.tar.gz
Algorithm Hash digest
SHA256 487814fc0ed14cf5e3ffdbcf17c0ebb088287e14feca4f74e859bc5fa04aca86
MD5 3064f40fd2c42674b54f1448c00d3272
BLAKE2b-256 03db5bef0be393dd98c7f365bec600061d91c6de4d7d643f68104a81cdbf92ff

See more details on using hashes here.

Provenance

The following attestation bundles were made for stochastix-0.1.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.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

Hashes for stochastix-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ac315476799f52d7a83776f164d3676771d12e38e57c7481ccb282ff6db34ecc
MD5 81d1addf40aa9704e98457fa71f5dbc1
BLAKE2b-256 1e5f4db6505b791a9c685c7491c2cc56432c265948f451d3aa61ecf562ce6b55

See more details on using hashes here.

Provenance

The following attestation bundles were made for stochastix-0.1.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