SimulationHandler {epizootic}R Documentation

R6 class representing a simulation handler.

Description

R6::R6Class class to represent a handler for running multiple model simulations and saving results. This simulation manager bears some resemblance to the poems::SimulationManager in poems, but differs in that it can handle multiple dispersal generators, uses a different engine for parallelization, handles errors differently, and has a different default data format (.qs).

Super classes

poems::GenericClass -> poems::GenericManager -> SimulationHandler

Public fields

attached

A list of dynamically attached attributes (name-value pairs).

Active bindings

sample_data

A data frame of sampled parameters for each simulation/result.

model_template

A poems::SimulationModel (or inherited class) object with parameters common to all simulations.

nested_model

A poems::SimulationModel (or inherited class) object with empty sample parameters and a nested model template common to all simulations.

generators

A list of generators (poems::Generator or inherited class) objects for generating simulation model values.

model_simulator

A poems::ModelSimulator (or inherited class) object for running the simulations.

parallel_cores

Number of cores for running the simulations in parallel.

results_dir

Results directory path.

results_ext

Result file extension (default is .RData).

results_filename_attributes

A vector of: prefix (optional); attribute names (from the sample data frame); postfix (optional); utilized to construct results filenames.

error_messages

A vector of error messages encountered when setting model attributes.

warning_messages

A vector of warning messages encountered when setting model attributes.

Methods

Public methods

Inherited methods

Method new()

Initialization method sets any included attributes (sample_data, model_template, generators, model_simulator, parallel_cores, results_dir, results_filename_attributes) and attaches other attributes individually listed.

Usage
SimulationHandler$new(model_template = NULL, ...)
Arguments
model_template

A SimulationModel (or inherited class) object with parameters common to all simulations.

...

Parameters listed individually.


Method log_simulation()

Summarizes the simulation log and writes it to a text file.

This method takes a nested list of simulation log entries generated by the run method and summarizes the log. It determines which simulations were successful, collects any warnings, and writes the summary to a text file in the results directory.

Usage
SimulationHandler$log_simulation(simulation_log)
Arguments
simulation_log

A nested list of simulation log entries.

Returns

A list containing the summary, indices of failed simulations, indices of simulations with warnings, and the full log.


Method set_model_sample()

Sets the model sample attributes via the sample data frame and the generators.

This method sets the sample attributes of a SimulationModel object based on the specified sample index. It uses the sample data frame and the generators to determine the attribute values.

Usage
SimulationHandler$set_model_sample(model, sample_index)
Arguments
model

poems::SimulationModel (or inherited class) object (clone) to receive sample attributes.

sample_index

Index of sample from data frame.


Method run()

Runs the multiple population simulations, stores the results, and creates a simulation log.

This method runs multiple population simulations using the specified model template and sample data. It stores the simulation results in the specified results directory and creates a simulation log. The simulation log contains information about the success or failure of each simulation run.

Usage
SimulationHandler$run(results_dir = NULL)
Arguments
results_dir

Results directory path where the simulation results will be stored. If not provided, the results directory must be set within the manager class object.

Returns

A list representing the simulation log. Each element of the list corresponds to a simulation run and contains information about the success or failure of the run, any error messages, and the path to the saved results file (if applicable).


Method clone()

The objects of this class are cloneable with this method.

Usage
SimulationHandler$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.


[Package epizootic version 1.0.0 Index]