Skip to content

Simulation

The Simulation class handles multiple simulations with multiple seeds and/or multiple combinations of parameters.

Seealso

Usage examples can be found in the jupyter-examples folder in the repository:

__init__(self, experiment_name, seeds, fixed_parameters={}, iteration_parameters=[], recording_data=[], recording_data_srvc=[], nproc=1, pre_simulate=None, post_simulate=None, out=None, append_data=False, product_iter_method=None, wipe_on_run=None) special

Instances and initialize a Simulation object.

Parameters:

Name Type Description Default
experiment_name str

Name of the experiment, will me used to name files and folders.

required
fixed_parameters dict

Fixed parameters.

{}
iteration_parameters dict or list

Parameters to iterate during simulation.

  • If list of dicts: Will run a simulation for each dict, replacing the parameters in each dict.
  • If dict of list: Will run a simulation for each multiplicative combination of the parameters.
[]
recording_data list

List with all data to be recorded after the simulation.

[]
recording_data_srvc list

List with all service data to be recorded after the simulation.

[]
pre_simulate function

A function to be run between community initialization and simulation, it must accept a community object as parameter.

None
post_simulate function

A function to be run after simulation of the community, it must accept a community object as parameter.

None
seeds list

List of seeds.

required
nproc int

Number of concurrent threads. Defaults to 1.

1
append_data bool

Append data to existing files, will not simulate existing seeds. Defaults to False.

False
out str

Output directory.

None

get_hdf5_files(self)

Generates a dict of the hdf5 files for the set simulations with the sim_id/name as the keys.

Returns:

Type Description
dict

Paths to the HDF5 files.

get_iteration_parameters(self)

Outputs the iteration parameters as a list of dicts.

Returns:

Type Description
dict

Iteration parameters as list of dicts.

print_iteration_parameters(self)

Prints the iteration parameters as a list of dicts.

simulate(self)

Runs the simulations.

SimulationAnalysis

Interface to make plots of multiple hdf5 files generated with Simulation.

All plot methods of the Analysis class are available in the SimulationAnalysis class.

Important

When calling an Analysis method from a SimulationAnalysis object every instance of "$id" in a str parameter will be replaced with the identifier of that hdf5, this can be useful to use with parameters like filename or title.

Example:

from comorbuss import SimulationAnalysis

analysis = SimulationAnalysis.from_folder("/data/folder")
analysis.plot_SEIR(filename="$id.pdf")
analysis.close()

empty_from_files(filenames) classmethod

Instances an empty SimulationAnalysis object from a list/array/tuples of hdf5 filenames

Parameters:

Name Type Description Default
filenames

A list/numpy.array/tuple array of filenames

required

Returns:

Type Description
SimulationAnalysis

SimulationAnalysis object.

from_exp_parameters(*args, **kwargs) classmethod

Instance an SimulationAnalysis object from experiment parameters. Accepts same parameters as the Simulation class.

Returns:

Type Description
SimulationAnalysis

SimulationAnalysis object.

from_files(filenames) classmethod

Instances a SimulationAnalysis object from a list/array/tuples of hdf5 filenames

Parameters:

Name Type Description Default
filenames

A list/numpy.array/tuple array of filenames

required

Returns:

Type Description
SimulationAnalysis

SimulationAnalysis object.

from_folder(folder) classmethod

Instance an SimulationAnalysis object from all hdf5 files in a folder.

Parameters:

Name Type Description Default
folder str

Path to the folder where the hdf5 files are stored.

required

Returns:

Type Description
SimulationAnalysis

SimulationAnalysis object.

from_sim(sim) classmethod

Instance an SimulationAnalysis object from a Simulation object.

Parameters:

Name Type Description Default
sim Simulation

Simulation object to load data.

required

Returns:

Type Description
SimulationAnalysis

SimulationAnalysis object.