Skip to main content

batss Python package

The batss package (batched stochastic simulator) is used for simulating stochastic chemical reaction networks (CRNs). The package and further example notebooks can be found on Github.

If you find batss useful in a scientific project, please cite its associated paper:

Exactly simulating stochastic chemical reaction networks in sub-constant time per reaction.
Joshua Petrack and David Doty. preprint
[ paper | BibTeX ]

The core of the simulator is inspired by a batching algorithm for population protocols (chemical reaction networks with exactly two reactants and two products per reaction) that gives significant asymptotic gains for protocols with relatively small reachable state sets. It adapts this for general CRNs. The package is designed to be run in a Python notebook, to concisely describe complex protocols, efficiently simulate their dynamics, and provide helpful visualization of the simulation.

Table of contents

Installation

The package can be installed with pip via

pip install batss

First example CRN

We will show how to simulate the Lotka-Volterra oscillator,

$$\begin{aligned} R &\to 2R,\ R + F &\to 2F,\ F &\to \emptyset, \end{aligned}$$

with all rate constants 1.

Within python, begin by importing batss. To specify your species, use the species function:

import batss
r,f = batss.species('R F')

batss overloads operators to allow reactions to be specified in a way visually similar to the way they are typically notated. In this case,

rxns = [
    (r+f >> 2*f),
    (r >> 2*r),
    (f >> None),
]

Each line creates a reaction by specifying the reactants and products. Rate constants default to 1; they can be specified inline, e.g. the first reaction's rate constant could be set to 0.5 by replacing the first reaction line with

(r+f >> 2*f).k(0.5),

Next, specify initial molecular counts and create a Simulation object. The Simulation class is the most important object in the module, responsible for parsing the reactions, performing the simulation, and giving data about the simulation.

inits = {r: 10 ** 7, f: 10 ** 7}
sim = batss.Simulation(inits, rxns)

Now, we can run the simulation.

end_time = 10.0
checkpoint_time = end_time / 1000
sim.run(end_time, checkpoint_time)

This will cause the Simulation to simulate the CRN until continuous time 10.0, recording the state at 1000 uniformly spaced sample times. This shouldn't take more than 10 seconds to execute (at time of writing, it took about 5 seconds on a Macbook Air). We can plot these using matplotlib:

from matplotlib import pyplot as plt
f, ax = plt.subplots()

ax.plot(sim.history['R'], label = 'R')
ax.plot(sim.history['F'], label = 'F')
plt.legend()
plt.show()

This produces this graph:

Plot of Lotka-Volterra oscillator

More examples

See examples.

Download files

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

Source Distribution

batss-1.0.4.tar.gz (10.2 MB view details)

Uploaded Source

Built Distributions

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

batss-1.0.4-cp310-abi3-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.10+Windows x86-64

batss-1.0.4-cp310-abi3-musllinux_1_2_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ x86-64

batss-1.0.4-cp310-abi3-musllinux_1_2_aarch64.whl (1.4 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

batss-1.0.4-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ x86-64

batss-1.0.4-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.3 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

batss-1.0.4-cp310-abi3-macosx_11_0_arm64.whl (1.2 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

batss-1.0.4-cp310-abi3-macosx_10_13_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.10+macOS 10.13+ x86-64

File details

Details for the file batss-1.0.4.tar.gz.

File metadata

  • Download URL: batss-1.0.4.tar.gz
  • Upload date:
  • Size: 10.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for batss-1.0.4.tar.gz
Algorithm Hash digest
SHA256 e749c52bdec1cb10a6f685e10caa6b795e49fad6fb0ded20ddbd3329ce10edf2
MD5 accc781bf023cfb3d053a773c8255461
BLAKE2b-256 1ec5c9b6c3bd538c39947bb540945cfe7fedc7ef3fb4397441e3cd49d88468bf

See more details on using hashes here.

File details

Details for the file batss-1.0.4-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: batss-1.0.4-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 1.1 MB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for batss-1.0.4-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 f217de979c76e3633fe9cde302afe1e13ec05c6875eea036e313c02133337608
MD5 2f5a058c7a68dd469f925d9e41cec96c
BLAKE2b-256 4663d5743befd7636c5d32c67ed533d94a643ebe2710683275b17903dea5ba3a

See more details on using hashes here.

File details

Details for the file batss-1.0.4-cp310-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for batss-1.0.4-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 bffb9ccd5ccd769dc4d6a176d7e4d9ab0edcacd249e561e85f7dc2f7f2049684
MD5 2cf6cff049edcfe2198317dba87130b5
BLAKE2b-256 094abe0d02f27f0019230a8559a86646659b9c8237f726155ef37a9cfa336459

See more details on using hashes here.

File details

Details for the file batss-1.0.4-cp310-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for batss-1.0.4-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 8c0d5c96f49589d3f9c37f5a06a5e6dde328c3700b4fcea6eb95f21a777573b2
MD5 8ef1ba11d9654893cb0fbb2b8d6e4ba4
BLAKE2b-256 38369a6330d0a522d7a90ebc97b575eef69ac18fb7ac0b34102ac98456af2e43

See more details on using hashes here.

File details

Details for the file batss-1.0.4-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for batss-1.0.4-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1bff63a599a99c699f5a2d1bd53fa04f1b573cf1b7952df16d61dcfd77b36274
MD5 24f6f50bb9032b2d114a85350dcb8a2f
BLAKE2b-256 f32f39b968586335135345401abcd6916c8a16f3245667a49ef04b4a630af312

See more details on using hashes here.

File details

Details for the file batss-1.0.4-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for batss-1.0.4-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 f37923e621ce36650b0897cdba2dd4aa8107ddca9187864500cf480f028e753d
MD5 71d52fdb57bbb198b019dbcf26bea965
BLAKE2b-256 1d6f142ee3241d4660ef00dbd8851c70758267cac964b2613c07ae1ba0c065bd

See more details on using hashes here.

File details

Details for the file batss-1.0.4-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for batss-1.0.4-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 91a4c40eb84ebbf2793321e250550e7b5bce7e5b48a8e9675385b25bf63dbecc
MD5 a298d3bca20098d49761abd53649ba73
BLAKE2b-256 7ee762d3011986c03af5e17b95758cece77da1ee082c30882752c7432da43f68

See more details on using hashes here.

File details

Details for the file batss-1.0.4-cp310-abi3-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for batss-1.0.4-cp310-abi3-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 ebe98bc6f8330f378a1c1a433bcfd28484193e06c6b47fd9b04f4cfedd9e8ab8
MD5 1c00ca1e2033f5db88206e70cf0877ab
BLAKE2b-256 4ecc0d91492f86bcf65e03b7d992be0651b82b39e80bed5ad059e9f5a3120d6f

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.0.4 This release

8 files

1.0.3

8 files

1.0.2

83 files

1.0.1

83 files

1.0.0

83 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page