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
25def run(params):
26 handle = handle_module.init_simulation(OUTFOLDER,SIMULATION_NAME,CMA_PATH,params)
27 # cma with 500 compartment, simulation with 4 species liquid only
28 liquid_concentration_0 = np.zeros((500,4))
29 handle_module.set_initial_concentrations(handle,liquid_concentration_0)
30 handle_module.register_model_name(handle, "model_name")
31 # Apply the simulation settings
32 rc = handle_module.apply(handle, False)
33
34 # Check if the simulation settings were applied successfully
35 if not rc[0]:
36 print(rc[1])
37 return -1
38
39 # Execute the simulation
40 rc = handle_module.exec(handle)
41
42if __name__ == "__main__":
43 # Create the simulation parameters
44 params = handle_module.make_params(
45 biomass_initial_concentration=0,
46 final_time=250,
47 delta_time=0.5,
48 number_particle=0,
49 number_exported_result=5,
50 )
51
52 run(params)