BioCMAMC-ST
simple_simulation.py

This example demonstrates how to perfom a simple simulation using the python API

import handle_module>
outfolder = "./out/"
simulation_name = "my_simulation_name"
cma_path = "/path/to/the/cma/" #don´t forget last /
def run(params):
handle =
handle_module.init_simulation(outfolder,simulation_name,cma_path,params) #
cma with 500 compartment, simulation with 4 species liquid only
liquid_concentration_0 = np.zeros((500,4))
handle_module.set_initial_concentrations(handle,liquid_concentration_0)
handle_module.register_model_name(handle, "model_name")
# Apply the simulation settings
rc = handle_module.apply(handle, False)
# Check if the simulation settings were applied successfully
if not rc[0]:
print(rc[1])
return -1
# Execute the simulation
rc = handle_module.exec(handle);
1"""
2Minimal working program to use BioMC API V0.5.
3
4This program demonstrates a basic example of how to perform a simulation using BioMC from a Python program.
5It focuses on:
6- Creating a handle for shared execution (No MPI)
7- Performing basic simulation settings and running it
8- Loading and running a basic simulation
9
10Note that the linked library is the shared one, this will not work linking the distributed one.
11
12Usage:
13 Run this script to perform a simulation using BioMC API V0.5.
14"""
15
16# Import the handle module
17import handle_module
18import numpy as np
19
20# define the constants
21OUTFOLDER = "./out/"
22SIMULATION_NAME = "my_simulation_name"
23CMA_PATH = "/path/to/the/cma/" # don´t forget last /
24
25
26def run(params):
27 handle = handle_module.init_simulation(OUTFOLDER, SIMULATION_NAME, CMA_PATH, params)
28 # cma with 500 compartment, simulation with 4 species liquid only
29 liquid_concentration_0 = np.zeros((500, 4))
30 handle_module.set_initial_concentrations(handle, liquid_concentration_0)
31 handle_module.register_model_name(handle, "model_name")
32 # Apply the simulation settings
33 rc = handle_module.apply(handle, False)
34
35 # Check if the simulation settings were applied successfully
36 if not rc[0]:
37 print(rc[1])
38 return -1
39
40 # Execute the simulation
41 rc = handle_module.exec(handle)
42
43
44if __name__ == "__main__":
45 # Create the simulation parameters
46 params = handle_module.make_params(
47 biomass_initial_concentration=0,
48 final_time=250,
49 delta_time=0.5,
50 number_particle=0,
51 number_exported_result=5,
52 )
53
54 run(params)