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.3.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.3-cp310-abi3-win_amd64.whl (1.1 MB view details)

Uploaded CPython 3.10+Windows x86-64

batss-1.0.3-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.3-cp310-abi3-musllinux_1_2_aarch64.whl (1.4 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

batss-1.0.3-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.3-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.3-cp310-abi3-macosx_11_0_arm64.whl (1.2 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

batss-1.0.3-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.3.tar.gz.

File metadata

  • Download URL: batss-1.0.3.tar.gz
  • Upload date:
  • Size: 10.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.14.1

File hashes

Hashes for batss-1.0.3.tar.gz
Algorithm Hash digest
SHA256 aa9fee27e3b7885595fa509aa891da00da1c60be70147d1f531ef4d641d1e918
MD5 b17f2825c05895f0652c07bd6d099b8b
BLAKE2b-256 e37a464e2e1ab8f569f1c12007209340c3d5a7afd003c123ee826a0dcde304b7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: batss-1.0.3-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: maturin/1.14.1

File hashes

Hashes for batss-1.0.3-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 8c46fe37a6656ab1034ca57d959e9c176f173e3719c8e810e0f5938c03ea93f7
MD5 1e1da4597fb55b0b2f2eb60f5dfddc20
BLAKE2b-256 cab73040a1e8a3529472869c2b213f30c4865bc71c4a96bb2fce0fce287fc030

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for batss-1.0.3-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 eb55f063677942150a7895008bf3a114ed9c10ce632d1bc64e025abc751031b0
MD5 3a11da51ba7e0b5abbf27f39506610d4
BLAKE2b-256 b20ca9092ed36e4ece6f20c8fd1ab1ffaa4db0029e615217e08ee72bfeee0501

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for batss-1.0.3-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 32980ed9ceb179a0b45fe757a1f0cb69e62a35baa97a9226306ffc6c5f15ba87
MD5 b93e5eb900e659ebba58e2daa12a2fd5
BLAKE2b-256 0c3af64706e33b70eb8e88e853da641e67d50a488b86002a9dd1e1e1c6f1e4e0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for batss-1.0.3-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3efdfd8429572bedbef6aece06652827f652bc596dead764fdc304d6d745157b
MD5 a996d4b3d4cbf77943f25f4a4745aefa
BLAKE2b-256 74f5e4ce18ad5c87ccbbb304f3a96b4695295293c55fcbb0c7cb09e114a45097

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for batss-1.0.3-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 d01b530b87714cef1fac9e3a8715ff44a589276e7f352c4f37e4d7e9019d72f0
MD5 0facb2a8f79fe88aa7ec7b1a962859b4
BLAKE2b-256 812e513b40acbce14b501561c901613ac77c3f77473936e22ccd5ef01db9d276

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for batss-1.0.3-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 52e6428efe014b9b23893ec19fa76298af6f6c7f3c8ef745f1ed215a49471a4d
MD5 d2d25b22c64aaf22b493c28adf9ae254
BLAKE2b-256 635332937eb0fda730b6abac779b87b1d048802189528542017e79419ebb0cad

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for batss-1.0.3-cp310-abi3-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 badd8364ef147465d32493f923ddc9bd90671c84f580ee1ac845b450e2be6675
MD5 0dc464559e8be6fe50405ec260ec0268
BLAKE2b-256 5542c7ba9c258555356a709563631b3642e024c37f50bd09e13f94b465a73746

See more details on using hashes here.

Release history Release notifications | RSS feed

1.0.4

8 files

This release

1.0.3 This release

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