diff --git a/R/correlation.R b/R/correlation.R
index ee3305cc..df5f88f5 100644
--- a/R/correlation.R
+++ b/R/correlation.R
@@ -117,6 +117,7 @@ CorrelationParameters <- R6::R6Class(
private$.mvnorm
},
+ #' @description Save the correlation state.
save_state = function() {
# mvnorm is sampled at random lazily on its first use. We need to save it
# in order to restore the same value when resuming the simulation,
@@ -126,6 +127,11 @@ CorrelationParameters <- R6::R6Class(
list(mvnorm=private$.mvnorm)
},
+ #' @description Restore the correlation state.
+ #' Only the randomly drawn weights are restored. The object needs to be
+ #' initialized with the same rhos.
+ #' @param state a previously saved correlation state, as returned by the
+ #' save_state method.
restore_state = function(state) {
private$.mvnorm <- state$mvnorm
}
diff --git a/man/CorrelationParameters.Rd b/man/CorrelationParameters.Rd
index c2e6ada7..480d663d 100644
--- a/man/CorrelationParameters.Rd
+++ b/man/CorrelationParameters.Rd
@@ -19,6 +19,8 @@ Describes an event in the simulation
\item \href{#method-CorrelationParameters-inter_intervention_rho}{\code{CorrelationParameters$inter_intervention_rho()}}
\item \href{#method-CorrelationParameters-sigma}{\code{CorrelationParameters$sigma()}}
\item \href{#method-CorrelationParameters-mvnorm}{\code{CorrelationParameters$mvnorm()}}
+\item \href{#method-CorrelationParameters-save_state}{\code{CorrelationParameters$save_state()}}
+\item \href{#method-CorrelationParameters-restore_state}{\code{CorrelationParameters$restore_state()}}
\item \href{#method-CorrelationParameters-clone}{\code{CorrelationParameters$clone()}}
}
}
@@ -101,6 +103,36 @@ multivariate norm draws for these parameters
\if{html}{\out{
}}\preformatted{CorrelationParameters$mvnorm()}\if{html}{\out{
}}
}
+}
+\if{html}{\out{
}}
+\if{html}{\out{}}
+\if{latex}{\out{\hypertarget{method-CorrelationParameters-save_state}{}}}
+\subsection{Method \code{save_state()}}{
+Save the correlation state.
+\subsection{Usage}{
+\if{html}{\out{}}\preformatted{CorrelationParameters$save_state()}\if{html}{\out{
}}
+}
+
+}
+\if{html}{\out{
}}
+\if{html}{\out{}}
+\if{latex}{\out{\hypertarget{method-CorrelationParameters-restore_state}{}}}
+\subsection{Method \code{restore_state()}}{
+Restore the correlation state.
+Only the randomly drawn weights are restored. The object needs to be
+initialized with the same rhos.
+\subsection{Usage}{
+\if{html}{\out{}}\preformatted{CorrelationParameters$restore_state(state)}\if{html}{\out{
}}
+}
+
+\subsection{Arguments}{
+\if{html}{\out{}}
+\describe{
+\item{\code{state}}{a previously saved correlation state, as returned by the
+save_state method.}
+}
+\if{html}{\out{
}}
+}
}
\if{html}{\out{
}}
\if{html}{\out{}}
diff --git a/man/run_resumable_simulation.Rd b/man/run_resumable_simulation.Rd
new file mode 100644
index 00000000..8991fd1c
--- /dev/null
+++ b/man/run_resumable_simulation.Rd
@@ -0,0 +1,34 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/model.R
+\name{run_resumable_simulation}
+\alias{run_resumable_simulation}
+\title{Run the simulation in a resumable way}
+\usage{
+run_resumable_simulation(
+ timesteps,
+ parameters = NULL,
+ correlations = NULL,
+ initial_state = NULL,
+ restore_random_state = FALSE
+)
+}
+\arguments{
+\item{timesteps}{the timestep at which to stop the simulation}
+
+\item{parameters}{a named list of parameters to use}
+
+\item{correlations}{correlation parameters}
+
+\item{initial_state}{the state from which the simulation is resumed}
+
+\item{restore_random_state}{if TRUE, restore the random number generator's state from the checkpoint.}
+}
+\value{
+a list with two entries, one for the dataframe of results and one for the final
+simulation state.
+}
+\description{
+this function accepts an initial simulation state as an argument, and returns the
+final state after running all of its timesteps. This allows one run to be resumed, possibly
+having changed some of the parameters.
+}