In [1]:
# jLM CME Imports
from jLM.CME import CMESimulation
from jLM.units import *
from jLM.LMLogger import *
from jLM.CMEPostProcessing import *
In [2]:
# Custom Post-processing Imports
import matplotlib.pyplot as plt
import numpy as np
import os
import scipy
import scipy.optimize
import logging
In [3]:
outputFile = "bimol-pp.lm"
In [4]:
# Set up logging for jLM CME
setLMLoggerLevel(logging.INFO)
In [5]:
# Create our CME simulation object
sim = CMESimulation()
In [6]:
# Define our chemical species
species = ['A', 'B', 'C']
sim.defineSpecies(species)
In [7]:
# Add reactions to the simulation
sim.addReaction(reactant = ('A', 'B'), product = 'C', rate = 1.78e-4)
sim.addReaction(reactant = 'C', product = ('A', 'B'), rate = 3.51e-1)
In [8]:
# Set our initial species counts
sim.addParticles(species = 'A', count = 1000)
sim.addParticles(species = 'B', count = 1000)
sim.addParticles(species = 'C', count = 0)
In [9]:
# Define simulation parameters: run for 10 seconds, saving data every ms
sim.setWriteInterval(ms(1))
sim.setSimulationTime(10)
os.system("rm -rf %s"%(outputFile))
sim.save(outputFile)
In [10]:
# Plot a graph file with the reaction network
plotCMEReactionNetwork(sim, "BimolGraph.gml")
In [11]:
# Run some replicates using the Gillespie solver
numberReplicates = 50
sim.run(filename = outputFile, method = "lm::cme::GillespieDSolver", replicates = numberReplicates)
0%| | 0/50 [00:00<?, ?it/s]
2025-09-02 15:31:09) Info: Using 32 processor(s) and 1 CUDA device(s) per process. 2025-09-02 15:31:09) Info: Assigning 1.00 processor(s) and 1.00 CUDA device(s) per replicate. 2025-09-02 15:31:09) Info: Data output thread running. 2025-09-02 15:31:09) Info: Seeding xorwow rng with top word 1 and bottom word 888526969 2025-09-02 15:31:09) Info: Data output thread finished. 2025-09-02 15:31:09) Info: Simulation file closed.
2%|2 | 1/50 [00:00<00:14, 3.30it/s]
2025-09-02 15:31:09) Info: Using 32 processor(s) and 1 CUDA device(s) per process. 2025-09-02 15:31:09) Info: Assigning 1.00 processor(s) and 1.00 CUDA device(s) per replicate. 2025-09-02 15:31:09) Info: Data output thread running. 2025-09-02 15:31:09) Info: Seeding xorwow rng with top word 2 and bottom word 954841271 2025-09-02 15:31:09) Info: Data output thread finished. 2025-09-02 15:31:09) Info: Simulation file closed. 2025-09-02 15:31:10) Info: Using 32 processor(s) and 1 CUDA device(s) per process. 2025-09-02 15:31:10) Info: Assigning 1.00 processor(s) and 1.00 CUDA device(s) per replicate. 2025-09-02 15:31:10) Info: Data output thread running. 2025-09-02 15:31:10) Info: Seeding xorwow rng with top word 3 and bottom word 12822803 2025-09-02 15:31:10) Info: Data output thread finished. 2025-09-02 15:31:10) Info: Simulation file closed.
6%|6 | 3/50 [00:00<00:05, 8.19it/s]
2025-09-02 15:31:10) Info: Using 32 processor(s) and 1 CUDA device(s) per process. 2025-09-02 15:31:10) Info: Assigning 1.00 processor(s) and 1.00 CUDA device(s) per replicate. 2025-09-02 15:31:10) Info: Data output thread running. 2025-09-02 15:31:10) Info: Seeding xorwow rng with top word 4 and bottom word 71641405 2025-09-02 15:31:10) Info: Data output thread finished. 2025-09-02 15:31:10) Info: Simulation file closed. 2025-09-02 15:31:10) Info: Using 32 processor(s) and 1 CUDA device(s) per process. 2025-09-02 15:31:10) Info: Assigning 1.00 processor(s) and 1.00 CUDA device(s) per replicate. 2025-09-02 15:31:10) Info: Data output thread running. 2025-09-02 15:31:10) Info: Seeding xorwow rng with top word 5 and bottom word 131027528 2025-09-02 15:31:10) Info: Data output thread finished. 2025-09-02 15:31:10) Info: Simulation file closed.
10%|# | 5/50 [00:00<00:04, 11.16it/s]
2025-09-02 15:31:10) Info: Using 32 processor(s) and 1 CUDA device(s) per process. 2025-09-02 15:31:10) Info: Assigning 1.00 processor(s) and 1.00 CUDA device(s) per replicate. 2025-09-02 15:31:10) Info: Data output thread running. 2025-09-02 15:31:10) Info: Seeding xorwow rng with top word 6 and bottom word 189696320 2025-09-02 15:31:10) Info: Data output thread finished. 2025-09-02 15:31:10) Info: Simulation file closed. 2025-09-02 15:31:10) Info: Using 32 processor(s) and 1 CUDA device(s) per process. 2025-09-02 15:31:10) Info: Assigning 1.00 processor(s) and 1.00 CUDA device(s) per replicate. 2025-09-02 15:31:10) Info: Data output thread running. 2025-09-02 15:31:10) Info: Seeding xorwow rng with top word 7 and bottom word 248044742 2025-09-02 15:31:10) Info: Data output thread finished. 2025-09-02 15:31:10) Info: Simulation file closed.
14%|#4 | 7/50 [00:00<00:03, 13.10it/s]
2025-09-02 15:31:10) Info: Using 32 processor(s) and 1 CUDA device(s) per process. 2025-09-02 15:31:10) Info: Assigning 1.00 processor(s) and 1.00 CUDA device(s) per replicate. 2025-09-02 15:31:10) Info: Data output thread running. 2025-09-02 15:31:10) Info: Seeding xorwow rng with top word 8 and bottom word 306107985 2025-09-02 15:31:10) Info: Data output thread finished. 2025-09-02 15:31:10) Info: Simulation file closed. 2025-09-02 15:31:10) Info: Using 32 processor(s) and 1 CUDA device(s) per process. 2025-09-02 15:31:10) Info: Assigning 1.00 processor(s) and 1.00 CUDA device(s) per replicate. 2025-09-02 15:31:10) Info: Data output thread running. 2025-09-02 15:31:10) Info: Seeding xorwow rng with top word 9 and bottom word 362924627 2025-09-02 15:31:10) Info: Data output thread finished. 2025-09-02 15:31:10) Info: Simulation file closed.
18%|#8 | 9/50 [00:00<00:02, 14.45it/s]
2025-09-02 15:31:10) Info: Using 32 processor(s) and 1 CUDA device(s) per process. 2025-09-02 15:31:10) Info: Assigning 1.00 processor(s) and 1.00 CUDA device(s) per replicate. 2025-09-02 15:31:10) Info: Data output thread running. 2025-09-02 15:31:10) Info: Seeding xorwow rng with top word 10 and bottom word 420893949 2025-09-02 15:31:10) Info: Data output thread finished. 2025-09-02 15:31:10) Info: Simulation file closed. 2025-09-02 15:31:10) Info: Using 32 processor(s) and 1 CUDA device(s) per process. 2025-09-02 15:31:10) Info: Assigning 1.00 processor(s) and 1.00 CUDA device(s) per replicate. 2025-09-02 15:31:10) Info: Data output thread running. 2025-09-02 15:31:10) Info: Seeding xorwow rng with top word 11 and bottom word 478469111 2025-09-02 15:31:10) Info: Data output thread finished. 2025-09-02 15:31:10) Info: Simulation file closed.
22%|##2 | 11/50 [00:00<00:02, 15.35it/s]
2025-09-02 15:31:10) Info: Using 32 processor(s) and 1 CUDA device(s) per process. 2025-09-02 15:31:10) Info: Assigning 1.00 processor(s) and 1.00 CUDA device(s) per replicate. 2025-09-02 15:31:10) Info: Data output thread running. 2025-09-02 15:31:10) Info: Seeding xorwow rng with top word 12 and bottom word 536036423 2025-09-02 15:31:10) Info: Data output thread finished. 2025-09-02 15:31:10) Info: Simulation file closed. 2025-09-02 15:31:10) Info: Using 32 processor(s) and 1 CUDA device(s) per process. 2025-09-02 15:31:10) Info: Assigning 1.00 processor(s) and 1.00 CUDA device(s) per replicate. 2025-09-02 15:31:10) Info: Data output thread running. 2025-09-02 15:31:10) Info: Seeding xorwow rng with top word 13 and bottom word 593652525 2025-09-02 15:31:10) Info: Data output thread finished. 2025-09-02 15:31:10) Info: Simulation file closed.
26%|##6 | 13/50 [00:01<00:02, 15.92it/s]
2025-09-02 15:31:10) Info: Using 32 processor(s) and 1 CUDA device(s) per process. 2025-09-02 15:31:10) Info: Assigning 1.00 processor(s) and 1.00 CUDA device(s) per replicate. 2025-09-02 15:31:10) Info: Data output thread running. 2025-09-02 15:31:10) Info: Seeding xorwow rng with top word 14 and bottom word 653026178 2025-09-02 15:31:10) Info: Data output thread finished. 2025-09-02 15:31:10) Info: Simulation file closed. 2025-09-02 15:31:10) Info: Using 32 processor(s) and 1 CUDA device(s) per process. 2025-09-02 15:31:10) Info: Assigning 1.00 processor(s) and 1.00 CUDA device(s) per replicate. 2025-09-02 15:31:10) Info: Data output thread running. 2025-09-02 15:31:10) Info: Seeding xorwow rng with top word 15 and bottom word 711155720 2025-09-02 15:31:10) Info: Data output thread finished. 2025-09-02 15:31:10) Info: Simulation file closed.
30%|### | 15/50 [00:01<00:02, 16.25it/s]
2025-09-02 15:31:10) Info: Using 32 processor(s) and 1 CUDA device(s) per process. 2025-09-02 15:31:10) Info: Assigning 1.00 processor(s) and 1.00 CUDA device(s) per replicate. 2025-09-02 15:31:10) Info: Data output thread running. 2025-09-02 15:31:10) Info: Seeding xorwow rng with top word 16 and bottom word 770705382 2025-09-02 15:31:10) Info: Data output thread finished. 2025-09-02 15:31:10) Info: Simulation file closed. 2025-09-02 15:31:10) Info: Using 32 processor(s) and 1 CUDA device(s) per process. 2025-09-02 15:31:10) Info: Assigning 1.00 processor(s) and 1.00 CUDA device(s) per replicate. 2025-09-02 15:31:10) Info: Data output thread running. 2025-09-02 15:31:10) Info: Seeding xorwow rng with top word 17 and bottom word 827670435 2025-09-02 15:31:10) Info: Data output thread finished. 2025-09-02 15:31:10) Info: Simulation file closed.
34%|###4 | 17/50 [00:01<00:01, 16.55it/s]
2025-09-02 15:31:10) Info: Using 32 processor(s) and 1 CUDA device(s) per process. 2025-09-02 15:31:10) Info: Assigning 1.00 processor(s) and 1.00 CUDA device(s) per replicate. 2025-09-02 15:31:10) Info: Data output thread running. 2025-09-02 15:31:10) Info: Seeding xorwow rng with top word 18 and bottom word 886197047 2025-09-02 15:31:10) Info: Data output thread finished. 2025-09-02 15:31:10) Info: Simulation file closed. 2025-09-02 15:31:10) Info: Using 32 processor(s) and 1 CUDA device(s) per process. 2025-09-02 15:31:10) Info: Assigning 1.00 processor(s) and 1.00 CUDA device(s) per replicate. 2025-09-02 15:31:10) Info: Data output thread running. 2025-09-02 15:31:10) Info: Seeding xorwow rng with top word 19 and bottom word 943419089 2025-09-02 15:31:10) Info: Data output thread finished. 2025-09-02 15:31:10) Info: Simulation file closed.
38%|###8 | 19/50 [00:01<00:01, 16.77it/s]
2025-09-02 15:31:10) Info: Using 32 processor(s) and 1 CUDA device(s) per process. 2025-09-02 15:31:10) Info: Assigning 1.00 processor(s) and 1.00 CUDA device(s) per replicate. 2025-09-02 15:31:11) Info: Data output thread running. 2025-09-02 15:31:11) Info: Seeding xorwow rng with top word 20 and bottom word 1772361 2025-09-02 15:31:11) Info: Data output thread finished. 2025-09-02 15:31:11) Info: Simulation file closed. 2025-09-02 15:31:11) Info: Using 32 processor(s) and 1 CUDA device(s) per process. 2025-09-02 15:31:11) Info: Assigning 1.00 processor(s) and 1.00 CUDA device(s) per replicate. 2025-09-02 15:31:11) Info: Data output thread running. 2025-09-02 15:31:11) Info: Seeding xorwow rng with top word 21 and bottom word 60239243 2025-09-02 15:31:11) Info: Data output thread finished. 2025-09-02 15:31:11) Info: Simulation file closed.
42%|####2 | 21/50 [00:01<00:01, 16.87it/s]
2025-09-02 15:31:11) Info: Using 32 processor(s) and 1 CUDA device(s) per process. 2025-09-02 15:31:11) Info: Assigning 1.00 processor(s) and 1.00 CUDA device(s) per replicate. 2025-09-02 15:31:11) Info: Data output thread running. 2025-09-02 15:31:11) Info: Seeding xorwow rng with top word 22 and bottom word 118583316 2025-09-02 15:31:11) Info: Data output thread finished. 2025-09-02 15:31:11) Info: Simulation file closed. 2025-09-02 15:31:11) Info: Using 32 processor(s) and 1 CUDA device(s) per process. 2025-09-02 15:31:11) Info: Assigning 1.00 processor(s) and 1.00 CUDA device(s) per replicate. 2025-09-02 15:31:11) Info: Data output thread running. 2025-09-02 15:31:11) Info: Seeding xorwow rng with top word 23 and bottom word 175631678 2025-09-02 15:31:11) Info: Data output thread finished. 2025-09-02 15:31:11) Info: Simulation file closed.
46%|####6 | 23/50 [00:01<00:01, 17.00it/s]
2025-09-02 15:31:11) Info: Using 32 processor(s) and 1 CUDA device(s) per process. 2025-09-02 15:31:11) Info: Assigning 1.00 processor(s) and 1.00 CUDA device(s) per replicate. 2025-09-02 15:31:11) Info: Data output thread running. 2025-09-02 15:31:11) Info: Seeding xorwow rng with top word 24 and bottom word 234135220 2025-09-02 15:31:11) Info: Data output thread finished. 2025-09-02 15:31:11) Info: Simulation file closed. 2025-09-02 15:31:11) Info: Using 32 processor(s) and 1 CUDA device(s) per process. 2025-09-02 15:31:11) Info: Assigning 1.00 processor(s) and 1.00 CUDA device(s) per replicate. 2025-09-02 15:31:11) Info: Data output thread running. 2025-09-02 15:31:11) Info: Seeding xorwow rng with top word 25 and bottom word 292019252 2025-09-02 15:31:11) Info: Data output thread finished. 2025-09-02 15:31:11) Info: Simulation file closed.
50%|##### | 25/50 [00:01<00:01, 17.06it/s]
2025-09-02 15:31:11) Info: Using 32 processor(s) and 1 CUDA device(s) per process. 2025-09-02 15:31:11) Info: Assigning 1.00 processor(s) and 1.00 CUDA device(s) per replicate. 2025-09-02 15:31:11) Info: Data output thread running. 2025-09-02 15:31:11) Info: Seeding xorwow rng with top word 26 and bottom word 350082294 2025-09-02 15:31:11) Info: Data output thread finished. 2025-09-02 15:31:11) Info: Simulation file closed. 2025-09-02 15:31:11) Info: Using 32 processor(s) and 1 CUDA device(s) per process. 2025-09-02 15:31:11) Info: Assigning 1.00 processor(s) and 1.00 CUDA device(s) per replicate. 2025-09-02 15:31:11) Info: Data output thread running. 2025-09-02 15:31:11) Info: Seeding xorwow rng with top word 27 and bottom word 407049146 2025-09-02 15:31:11) Info: Data output thread finished. 2025-09-02 15:31:11) Info: Simulation file closed.
54%|#####4 | 27/50 [00:01<00:01, 17.16it/s]
2025-09-02 15:31:11) Info: Using 32 processor(s) and 1 CUDA device(s) per process. 2025-09-02 15:31:11) Info: Assigning 1.00 processor(s) and 1.00 CUDA device(s) per replicate. 2025-09-02 15:31:11) Info: Data output thread running. 2025-09-02 15:31:11) Info: Seeding xorwow rng with top word 28 and bottom word 465159888 2025-09-02 15:31:11) Info: Data output thread finished. 2025-09-02 15:31:11) Info: Simulation file closed. 2025-09-02 15:31:11) Info: Using 32 processor(s) and 1 CUDA device(s) per process. 2025-09-02 15:31:11) Info: Assigning 1.00 processor(s) and 1.00 CUDA device(s) per replicate. 2025-09-02 15:31:11) Info: Data output thread running. 2025-09-02 15:31:11) Info: Seeding xorwow rng with top word 29 and bottom word 521318881 2025-09-02 15:31:11) Info: Data output thread finished. 2025-09-02 15:31:11) Info: Simulation file closed.
58%|#####8 | 29/50 [00:01<00:01, 17.31it/s]
2025-09-02 15:31:11) Info: Using 32 processor(s) and 1 CUDA device(s) per process. 2025-09-02 15:31:11) Info: Assigning 1.00 processor(s) and 1.00 CUDA device(s) per replicate. 2025-09-02 15:31:11) Info: Data output thread running. 2025-09-02 15:31:11) Info: Seeding xorwow rng with top word 30 and bottom word 578684993 2025-09-02 15:31:11) Info: Data output thread finished. 2025-09-02 15:31:11) Info: Simulation file closed. 2025-09-02 15:31:11) Info: Using 32 processor(s) and 1 CUDA device(s) per process. 2025-09-02 15:31:11) Info: Assigning 1.00 processor(s) and 1.00 CUDA device(s) per replicate. 2025-09-02 15:31:11) Info: Data output thread running. 2025-09-02 15:31:11) Info: Seeding xorwow rng with top word 31 and bottom word 634648275 2025-09-02 15:31:11) Info: Data output thread finished. 2025-09-02 15:31:11) Info: Simulation file closed.
62%|######2 | 31/50 [00:02<00:01, 17.39it/s]
2025-09-02 15:31:11) Info: Using 32 processor(s) and 1 CUDA device(s) per process. 2025-09-02 15:31:11) Info: Assigning 1.00 processor(s) and 1.00 CUDA device(s) per replicate. 2025-09-02 15:31:11) Info: Data output thread running. 2025-09-02 15:31:11) Info: Seeding xorwow rng with top word 32 and bottom word 692424537 2025-09-02 15:31:11) Info: Data output thread finished. 2025-09-02 15:31:11) Info: Simulation file closed. 2025-09-02 15:31:11) Info: Using 32 processor(s) and 1 CUDA device(s) per process. 2025-09-02 15:31:11) Info: Assigning 1.00 processor(s) and 1.00 CUDA device(s) per replicate. 2025-09-02 15:31:11) Info: Data output thread running. 2025-09-02 15:31:11) Info: Seeding xorwow rng with top word 33 and bottom word 750182029 2025-09-02 15:31:11) Info: Data output thread finished. 2025-09-02 15:31:11) Info: Simulation file closed.
66%|######6 | 33/50 [00:02<00:00, 17.35it/s]
2025-09-02 15:31:11) Info: Using 32 processor(s) and 1 CUDA device(s) per process. 2025-09-02 15:31:11) Info: Assigning 1.00 processor(s) and 1.00 CUDA device(s) per replicate. 2025-09-02 15:31:11) Info: Data output thread running. 2025-09-02 15:31:11) Info: Seeding xorwow rng with top word 34 and bottom word 808304501 2025-09-02 15:31:11) Info: Data output thread finished. 2025-09-02 15:31:11) Info: Simulation file closed. 2025-09-02 15:31:11) Info: Using 32 processor(s) and 1 CUDA device(s) per process. 2025-09-02 15:31:11) Info: Assigning 1.00 processor(s) and 1.00 CUDA device(s) per replicate. 2025-09-02 15:31:11) Info: Data output thread running. 2025-09-02 15:31:11) Info: Seeding xorwow rng with top word 35 and bottom word 865602364 2025-09-02 15:31:11) Info: Data output thread finished. 2025-09-02 15:31:11) Info: Simulation file closed.
70%|####### | 35/50 [00:02<00:00, 17.37it/s]
2025-09-02 15:31:11) Info: Using 32 processor(s) and 1 CUDA device(s) per process. 2025-09-02 15:31:11) Info: Assigning 1.00 processor(s) and 1.00 CUDA device(s) per replicate. 2025-09-02 15:31:11) Info: Data output thread running. 2025-09-02 15:31:11) Info: Seeding xorwow rng with top word 36 and bottom word 923166186 2025-09-02 15:31:11) Info: Data output thread finished. 2025-09-02 15:31:11) Info: Simulation file closed. 2025-09-02 15:31:11) Info: Using 32 processor(s) and 1 CUDA device(s) per process. 2025-09-02 15:31:11) Info: Assigning 1.00 processor(s) and 1.00 CUDA device(s) per replicate. 2025-09-02 15:31:11) Info: Data output thread running. 2025-09-02 15:31:12) Info: Seeding xorwow rng with top word 37 and bottom word 980298508 2025-09-02 15:31:12) Info: Data output thread finished. 2025-09-02 15:31:12) Info: Simulation file closed.
74%|#######4 | 37/50 [00:02<00:00, 17.36it/s]
2025-09-02 15:31:12) Info: Using 32 processor(s) and 1 CUDA device(s) per process. 2025-09-02 15:31:12) Info: Assigning 1.00 processor(s) and 1.00 CUDA device(s) per replicate. 2025-09-02 15:31:12) Info: Data output thread running. 2025-09-02 15:31:12) Info: Seeding xorwow rng with top word 38 and bottom word 38407121 2025-09-02 15:31:12) Info: Data output thread finished. 2025-09-02 15:31:12) Info: Simulation file closed. 2025-09-02 15:31:12) Info: Using 32 processor(s) and 1 CUDA device(s) per process. 2025-09-02 15:31:12) Info: Assigning 1.00 processor(s) and 1.00 CUDA device(s) per replicate. 2025-09-02 15:31:12) Info: Data output thread running. 2025-09-02 15:31:12) Info: Seeding xorwow rng with top word 39 and bottom word 96605633 2025-09-02 15:31:12) Info: Data output thread finished. 2025-09-02 15:31:12) Info: Simulation file closed.
78%|#######8 | 39/50 [00:02<00:00, 17.32it/s]
2025-09-02 15:31:12) Info: Using 32 processor(s) and 1 CUDA device(s) per process. 2025-09-02 15:31:12) Info: Assigning 1.00 processor(s) and 1.00 CUDA device(s) per replicate. 2025-09-02 15:31:12) Info: Data output thread running. 2025-09-02 15:31:12) Info: Seeding xorwow rng with top word 40 and bottom word 154654725 2025-09-02 15:31:12) Info: Data output thread finished. 2025-09-02 15:31:12) Info: Simulation file closed. 2025-09-02 15:31:12) Info: Using 32 processor(s) and 1 CUDA device(s) per process. 2025-09-02 15:31:12) Info: Assigning 1.00 processor(s) and 1.00 CUDA device(s) per replicate. 2025-09-02 15:31:12) Info: Data output thread running. 2025-09-02 15:31:12) Info: Seeding xorwow rng with top word 41 and bottom word 212419397 2025-09-02 15:31:12) Info: Data output thread finished. 2025-09-02 15:31:12) Info: Simulation file closed.
82%|########2 | 41/50 [00:02<00:00, 17.28it/s]
2025-09-02 15:31:12) Info: Using 32 processor(s) and 1 CUDA device(s) per process. 2025-09-02 15:31:12) Info: Assigning 1.00 processor(s) and 1.00 CUDA device(s) per replicate. 2025-09-02 15:31:12) Info: Data output thread running. 2025-09-02 15:31:12) Info: Seeding xorwow rng with top word 42 and bottom word 271007119 2025-09-02 15:31:12) Info: Data output thread finished. 2025-09-02 15:31:12) Info: Simulation file closed. 2025-09-02 15:31:12) Info: Using 32 processor(s) and 1 CUDA device(s) per process. 2025-09-02 15:31:12) Info: Assigning 1.00 processor(s) and 1.00 CUDA device(s) per replicate. 2025-09-02 15:31:12) Info: Data output thread running. 2025-09-02 15:31:12) Info: Seeding xorwow rng with top word 43 and bottom word 328822861 2025-09-02 15:31:12) Info: Data output thread finished. 2025-09-02 15:31:12) Info: Simulation file closed.
86%|########6 | 43/50 [00:02<00:00, 17.29it/s]
2025-09-02 15:31:12) Info: Using 32 processor(s) and 1 CUDA device(s) per process. 2025-09-02 15:31:12) Info: Assigning 1.00 processor(s) and 1.00 CUDA device(s) per replicate. 2025-09-02 15:31:12) Info: Data output thread running. 2025-09-02 15:31:12) Info: Seeding xorwow rng with top word 44 and bottom word 386587813 2025-09-02 15:31:12) Info: Data output thread finished. 2025-09-02 15:31:12) Info: Simulation file closed. 2025-09-02 15:31:12) Info: Using 32 processor(s) and 1 CUDA device(s) per process. 2025-09-02 15:31:12) Info: Assigning 1.00 processor(s) and 1.00 CUDA device(s) per replicate. 2025-09-02 15:31:12) Info: Data output thread running. 2025-09-02 15:31:12) Info: Seeding xorwow rng with top word 45 and bottom word 443387195 2025-09-02 15:31:12) Info: Data output thread finished. 2025-09-02 15:31:12) Info: Simulation file closed.
90%|######### | 45/50 [00:02<00:00, 17.29it/s]
2025-09-02 15:31:12) Info: Using 32 processor(s) and 1 CUDA device(s) per process. 2025-09-02 15:31:12) Info: Assigning 1.00 processor(s) and 1.00 CUDA device(s) per replicate. 2025-09-02 15:31:12) Info: Data output thread running. 2025-09-02 15:31:12) Info: Seeding xorwow rng with top word 46 and bottom word 502147798 2025-09-02 15:31:12) Info: Data output thread finished. 2025-09-02 15:31:12) Info: Simulation file closed. 2025-09-02 15:31:12) Info: Using 32 processor(s) and 1 CUDA device(s) per process. 2025-09-02 15:31:12) Info: Assigning 1.00 processor(s) and 1.00 CUDA device(s) per replicate. 2025-09-02 15:31:12) Info: Data output thread running. 2025-09-02 15:31:12) Info: Seeding xorwow rng with top word 47 and bottom word 559800630 2025-09-02 15:31:12) Info: Data output thread finished. 2025-09-02 15:31:12) Info: Simulation file closed.
94%|#########3| 47/50 [00:02<00:00, 17.32it/s]
2025-09-02 15:31:12) Info: Using 32 processor(s) and 1 CUDA device(s) per process. 2025-09-02 15:31:12) Info: Assigning 1.00 processor(s) and 1.00 CUDA device(s) per replicate. 2025-09-02 15:31:12) Info: Data output thread running. 2025-09-02 15:31:12) Info: Seeding xorwow rng with top word 48 and bottom word 617477152 2025-09-02 15:31:12) Info: Data output thread finished. 2025-09-02 15:31:12) Info: Simulation file closed. 2025-09-02 15:31:12) Info: Using 32 processor(s) and 1 CUDA device(s) per process. 2025-09-02 15:31:12) Info: Assigning 1.00 processor(s) and 1.00 CUDA device(s) per replicate. 2025-09-02 15:31:12) Info: Data output thread running. 2025-09-02 15:31:12) Info: Seeding xorwow rng with top word 49 and bottom word 674985314 2025-09-02 15:31:12) Info: Data output thread finished. 2025-09-02 15:31:12) Info: Simulation file closed.
98%|#########8| 49/50 [00:03<00:00, 17.28it/s]
2025-09-02 15:31:12) Info: Using 32 processor(s) and 1 CUDA device(s) per process. 2025-09-02 15:31:12) Info: Assigning 1.00 processor(s) and 1.00 CUDA device(s) per replicate. 2025-09-02 15:31:12) Info: Data output thread running. 2025-09-02 15:31:12) Info: Seeding xorwow rng with top word 50 and bottom word 733669937 2025-09-02 15:31:12) Info: Data output thread finished. 2025-09-02 15:31:12) Info: Simulation file closed.
100%|##########| 50/50 [00:03<00:00, 15.92it/s]
In [12]:
# Post-Processing commands #
# The following command will compute and plot the average and variance over
# all replicates for the species specified in the list passed as the second argument.
# It will create an image as named by the final argument.
plotAvgVarFromFile(outputFile, ['A','B','C'], 'BimolSpeciesTrace.png')
<Figure size 640x480 with 0 Axes>
In [13]:
##########################
# Custom Post Processing #
##########################
# Custom post-processing generally begins by getting a handle
# to the file. This is accomplished by passing the filename
# to the function "openLMFile" which is supplied by "PostProcessing".
# This function does some error checking to make sure the file is
# generated by LM.
fileHandle = openLMFile(outputFile) # Clean way to open a file for post-processing
In [14]:
# Most often you will need a list of the timesteps. The following
# function will extract the timesteps from the first replicate (rep 1)
# and return it as a list.
timesteps = getTimesteps(fileHandle)
In [15]:
# The following commands demonstrate how to extract the species
# trace for the specified molecular species and replicate number
# These traces will be the same length as the timesteps array.
# Only one species can be extracted from a single replicate
# for each call to the function.
speciesTraceA = getSpecieTrace(fileHandle, 'A', 1)
speciesTraceC = getSpecieTrace(fileHandle, 'C', 1)
for i in range(1,numberReplicates):
stA = getSpecieTrace(fileHandle, 'A', i)
stC = getSpecieTrace(fileHandle, 'C', i)
# The bad way to do it
for j in range(len(stA)):
speciesTraceA[j] += stA[j]
speciesTraceC[j] += stC[j]
In [16]:
# Get averages
# This is just Python...
for i in range(0, len(speciesTraceA)):
speciesTraceA[i] /= numberReplicates
speciesTraceC[i] /= numberReplicates
afinal = speciesTraceA[len(speciesTraceA) - 1]
In [17]:
# Fit some curves
# Fitting some curves using SciPy Curvefit
def f_A(x, a, k1):
return a*np.exp(-k1*x)+afinal
def f_C(x, a, k1):
return a*(1.0-np.exp(-k1*x))
In [18]:
popA, popconvA = scipy.optimize.curve_fit(f_A, timesteps, speciesTraceA)
popC, popconvC = scipy.optimize.curve_fit(f_C, timesteps, speciesTraceC)
fitA=[0]*len(timesteps)
fitC=[0]*len(timesteps)
for i in range(len(timesteps)):
fitA[i] = f_A(timesteps[i], popA[0], popA[1])
fitC[i] = f_C(timesteps[i], popC[0], popC[1])
/tmp/ipykernel_3533694/487922998.py:4: RuntimeWarning: overflow encountered in exp return a*np.exp(-k1*x)+afinal /tmp/ipykernel_3533694/487922998.py:4: RuntimeWarning: overflow encountered in multiply return a*np.exp(-k1*x)+afinal /tmp/ipykernel_3533694/487922998.py:7: RuntimeWarning: overflow encountered in exp return a*(1.0-np.exp(-k1*x)) /tmp/ipykernel_3533694/487922998.py:7: RuntimeWarning: overflow encountered in multiply return a*(1.0-np.exp(-k1*x))
In [19]:
# Plot traces
# Some custom plotting
plt.clf()
plt.plot(timesteps, speciesTraceA, label='Avg. A')
plt.plot(timesteps, speciesTraceC, label='Avg. C')
plt.plot(timesteps, fitA, label='k1=%f'%(popA[1]))
plt.plot(timesteps, fitC, label='k2=%f'%(popC[1]))
plt.legend()
plt.xlabel('Time (s)')
plt.ylabel('Species Count')
plt.savefig('BimolSpeciesFit.png')
In [20]:
# Close the LM File
# It is very important that if you open an LM file with
# the function "openLMFile" that it be closed at the
# end of your post-processing with "closeLMFile".
# The function takes the filehandle that is returned
# by "openLMFile" as an argument. Also, not that
# once this function is called, any function that
# takes the filehandle as an argument will fail to work
# as the handle is now stale. This is a common mistake
# and if you get crashing, check that you haven't prematurely
# closed the file. This function is usually called
# last.
closeLMFile(fileHandle) # Clean up after ourselves