multi_run#
- class multi_run(sim, n_runs=4, reseed=None, noise=0.0, noisepar=None, iterpars=None, combine=False, keep_people=None, run_args=None, sim_args=None, par_args=None, do_run=True, parallel=True, n_cpus=None, verbose=None, retry='warn', **kwargs)[source]#
For running multiple runs in parallel. If the first argument is a list of sims, exactly these will be run and most other arguments will be ignored.
- Parameters:
sim (Sim) – the sim instance to be run, or a list of sims.
n_runs (int) – the number of parallel runs
reseed (bool) – whether or not to generate a fresh seed for each run (default: true for single, false for list of sims)
noise (float) – the amount of noise to add to each run
noisepar (str) – the name of the parameter to add noise to
iterpars (dict) – any other parameters to iterate over the runs; see sc.parallelize() for syntax
combine (bool) – whether or not to combine all results into one sim, rather than return multiple sim objects
keep_people (bool) – whether to keep the people after the sim run (default false)
run_args (dict) – arguments passed to sim.run()
sim_args (dict) – extra parameters to pass to the sim
par_args (dict) – arguments passed to sc.parallelize()
do_run (bool) – whether to actually run the sim (if not, just initialize it)
parallel (bool) – whether to run in parallel using multiprocessing (else, just run in a loop)
n_cpus (int) – the number of CPUs to run on (if blank, set automatically; otherwise, passed to par_args)
verbose (int) – detail to print
retry (str) – what to do if default parallelizer fails: choices are ‘warn’ (default), ‘die’ (raise exception), or ‘silent’ (keep going)
kwargs (dict) – also passed to the sim
- Returns:
If combine is True, a single sim object with the combined results from each sim. Otherwise, a list of sim objects (default).
Example:
import covasim as cv sim = cv.Sim() sims = cv.multi_run(sim, n_runs=6, noise=0.2)