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.

Metadata

Release files for batss 1.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for batss 1.0.4
File Size Uploaded
batss-1.0.4.tar.gz 10.2 MB Details

Built distributions (wheels)

Table of built distributions (wheels) for batss 1.0.4
File
batss-1.0.4-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details
batss-1.0.4-cp310-abi3-musllinux_1_2_x86_64.whl CPython 3.10 abi3 Linux musl 1.2+ x86-64 Details
batss-1.0.4-cp310-abi3-musllinux_1_2_aarch64.whl CPython 3.10 abi3 Linux musl 1.2+ ARM64 Details
batss-1.0.4-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 abi3 Linux glibc 2.17+ x86-64 Details
batss-1.0.4-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.10 abi3 Linux glibc 2.17+ ARM64 Details
batss-1.0.4-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details
batss-1.0.4-cp310-abi3-macosx_10_13_x86_64.whl CPython 3.10 abi3 macOS 10.13+ x86-64 Details

Total release size: 19.2 MB

Release files / batss-1.0.4.tar.gz

Download URL batss-1.0.4.tar.gz
Size 10.2 MB
Tags Source
SHA-256 checksum
How to use checksums
e749c52bdec1cb10a6f685e10caa6b795e49fad6fb0ded20ddbd3329ce10edf2
BLAKE2b-256 checksum
How to use checksums
1ec5c9b6c3bd538c39947bb540945cfe7fedc7ef3fb4397441e3cd49d88468bf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Release files / batss-1.0.4-cp310-abi3-win_amd64.whl

Download URL batss-1.0.4-cp310-abi3-win_amd64.whl
Size 1.1 MB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
f217de979c76e3633fe9cde302afe1e13ec05c6875eea036e313c02133337608
BLAKE2b-256 checksum
How to use checksums
4663d5743befd7636c5d32c67ed533d94a643ebe2710683275b17903dea5ba3a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Release files / batss-1.0.4-cp310-abi3-musllinux_1_2_x86_64.whl

Download URL batss-1.0.4-cp310-abi3-musllinux_1_2_x86_64.whl
Size 1.5 MB
Tags CPython 3.10 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
bffb9ccd5ccd769dc4d6a176d7e4d9ab0edcacd249e561e85f7dc2f7f2049684
BLAKE2b-256 checksum
How to use checksums
094abe0d02f27f0019230a8559a86646659b9c8237f726155ef37a9cfa336459
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Release files / batss-1.0.4-cp310-abi3-musllinux_1_2_aarch64.whl

Download URL batss-1.0.4-cp310-abi3-musllinux_1_2_aarch64.whl
Size 1.4 MB
Tags CPython 3.10 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
8c0d5c96f49589d3f9c37f5a06a5e6dde328c3700b4fcea6eb95f21a777573b2
BLAKE2b-256 checksum
How to use checksums
38369a6330d0a522d7a90ebc97b575eef69ac18fb7ac0b34102ac98456af2e43
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Release files / batss-1.0.4-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL batss-1.0.4-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.3 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
1bff63a599a99c699f5a2d1bd53fa04f1b573cf1b7952df16d61dcfd77b36274
BLAKE2b-256 checksum
How to use checksums
f32f39b968586335135345401abcd6916c8a16f3245667a49ef04b4a630af312
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Release files / batss-1.0.4-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL batss-1.0.4-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 1.3 MB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
f37923e621ce36650b0897cdba2dd4aa8107ddca9187864500cf480f028e753d
BLAKE2b-256 checksum
How to use checksums
1d6f142ee3241d4660ef00dbd8851c70758267cac964b2613c07ae1ba0c065bd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Release files / batss-1.0.4-cp310-abi3-macosx_11_0_arm64.whl

Download URL batss-1.0.4-cp310-abi3-macosx_11_0_arm64.whl
Size 1.2 MB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
91a4c40eb84ebbf2793321e250550e7b5bce7e5b48a8e9675385b25bf63dbecc
BLAKE2b-256 checksum
How to use checksums
7ee762d3011986c03af5e17b95758cece77da1ee082c30882752c7432da43f68
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Release files / batss-1.0.4-cp310-abi3-macosx_10_13_x86_64.whl

Download URL batss-1.0.4-cp310-abi3-macosx_10_13_x86_64.whl
Size 1.2 MB
Tags CPython 3.10 abi3 macOS 10.13+ x86-64
SHA-256 checksum
How to use checksums
ebe98bc6f8330f378a1c1a433bcfd28484193e06c6b47fd9b04f4cfedd9e8ab8
BLAKE2b-256 checksum
How to use checksums
4ecc0d91492f86bcf65e03b7d992be0651b82b39e80bed5ad059e9f5a3120d6f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Release history Release notifications | RSS feed

This release

1.0.4 This release

8 release files

1.0.3

8 release files

1.0.2

83 release files

1.0.1

83 release files

1.0.0

83 release 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