Skip to contents

This inner function is called by netsim_scenarios and step_tmpl_netsim_scenarios. It runs the simulations of batch batch_num with netsim_path_wrapper, one netsim call per simulation, merges them and saves them as "sim____<batch_num>.rds" in output_dir. The simulations of batch b are numbered (b - 1) * n_cores + 1 to b * n_cores over all the batches of a scenario. With a restart pool of size N, simulation k starts from pool element (k - 1) %% N + 1, the same for every scenario. The simulations are run with the future::tweak() plan in control$future.use.plan, or with future::plan("multisession", workers = n_cores) if there is none. The step templates set it to multicore before calling this function.

Usage

netsim_run_one_scenario(
  scenario,
  batch_num,
  path_to_x,
  param,
  init,
  control,
  libraries,
  output_dir,
  n_batch,
  n_rep,
  n_cores
)

Arguments

scenario

A single "EpiModel scenario" to be used in the simulation

batch_num

The batch number, calculated from the number of replications and CPUs required.

path_to_x

Path to a fitted network model or a restart point saved with saveRDS (See the x argument to the EpiModel::netsim function), or to a restart pool directory (see make_restart_pool).

param

Model parameters, as an object of class param.net. Includes transmission probability (inf.prob), act rate (act.rate), recovery rate (rec.rate), and demographic rates for models with vital dynamics. Custom parameters for extended models may also be passed through param.net.

init

Initial conditions, as an object of class init.net. Specifies the initial number of infected nodes (i.num) and, for SIR models, recovered nodes (r.num). For two-group models, the corresponding .g2 parameters are also required.

control

Control settings, as an object of class control.net. Key settings include type (disease model: "SI", "SIR", or "SIS"), nsteps (number of time steps), nsims (number of simulations), tergmLite (lightweight mode for performance), and resimulate.network (required for models with vital dynamics). For extended models, custom module functions are also passed here.

libraries

A character vector containing the name of the libraries required for the model to run. (e.g. EpiModelHIV or EpiModelCOVID)

output_dir

The folder where the simulation files are to be stored.

n_batch

The number of batches to be run ceiling(n_rep / n_cores).

n_rep

The number of replication to be run for each scenario.

n_cores

The number of CPUs on which the simulations will be run.

Checkpointing

This function takes care of editing .checkpoint.dir to create unique sub directories for each scenario, batch and simulation: "<.checkpoint.dir>/sim____<batch_num>/sim_". The EpiModel::control.net way of setting up checkpoints can be used transparently. Unless .checkpoint.keep is TRUE, the batch directory is removed once the batch file is saved.