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, store_git_hash=False)
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.
|
[] |
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 |
store_git_hash |
bool |
Runs 'git rev-parse HEAD' on current folder and stores it to configurations files. Defaults to False. |
False |
Source code in comorbuss/lab/simulation.py
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
|
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. |
Source code in comorbuss/lab/simulation.py
374 375 376 377 378 379 380 381 382 383 |
|
get_iteration_parameters(self)
¶
Outputs the iteration parameters as a list of dicts.
Returns:
Type | Description |
---|---|
dict |
Iteration parameters as list of dicts. |
Source code in comorbuss/lab/simulation.py
385 386 387 388 389 390 391 392 393 394 395 |
|
print_iteration_parameters(self)
¶
Prints the iteration parameters as a list of dicts.
Source code in comorbuss/lab/simulation.py
397 398 399 |
|
simulate(self, node=0, number_of_nodes=1, node_type='seeds')
¶
Runs the simulations
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node |
int |
[description]. Defaults to 0. |
0 |
number_of_nodes |
int |
Divides the simulation in multiples nodes. Defaults to 1. |
1 |
node_type |
str |
Specify where to divide nodes, |
'seeds' |
Source code in comorbuss/lab/simulation.py
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 |
|
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. |
Source code in comorbuss/lab/simulation_analysis.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
|
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. |
Source code in comorbuss/lab/simulation_analysis.py
104 105 106 107 108 109 110 111 112 113 |
|
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. |
Source code in comorbuss/lab/simulation_analysis.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
|
from_folder(folder, strings_to_ignore=[])
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. |
Source code in comorbuss/lab/simulation_analysis.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
|
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. |
Source code in comorbuss/lab/simulation_analysis.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
|