This is experimental and has not been thoroughly tested. Use with caution.
If there is an error during an event, this function will rewind the simulation to a state
numEvents prior to the event that led to the error. The developer may then modify the
source code of the module that caused the break and resume the simulation.
This is experimental and has not been thoroughly tested. Use with caution.
This is the simInit/.inputObjects analogue of restartSpades(). If a module's
.inputObjects errors during simInit() and options('spades.recoveryMode') was
set to TRUE or a numeric (the default, 1), the interrupted simList is saved to
savedSimEnv()$.sim with a list .recoverableObjs recording the state of each
module's input objects at the start of its .inputObjects. restartSimInit() rewinds
the simList to the start of the interrupted .inputObjects (i.e., numEvents prior),
re-parses the (presumably fixed) module source, then resumes simInit by running the
remaining modules' .inputObjects and completing the initialization.
restartSpades(
sim = NULL,
module = NULL,
numEvents = 1L,
restart = TRUE,
verbose = getOption("reproducible.verbose", 1L),
...
)
saveState(filename, ...)
restartSimInit(
sim = NULL,
module = NULL,
numEvents = 1L,
restart = TRUE,
verbose = getOption("reproducible.verbose", 1L),
...
)
restartOrSimInitAndSpades(ll, file, reset = getOption("spades.resetRestart"))A simList or a filename that will load a simList, e.g., from
saveState or saveSimList. If not supplied (the default),
this will take the sim from
savedSimEnv()$.sim, i.e., the one that was interrupted
A character string naming the module whose .inputObjects caused the
error and whose source code was fixed. This module will be re-parsed into the
simList. If NULL (default), it is taken from the most recent recovery snapshot.
Numeric. Default 1L (rewind only the interrupted module's
.inputObjects). Use Inf to rewind all recoverable .inputObjects.
Logical. If TRUE, then the call to spades will be made, i.e.,
restarting the simulation. If FALSE, then it will return a new simList
with the module code parsed into the simList
Logical or Numeric, follows reproducible.verbose value by default.
Passed to spades, e.g., debug, .plotInitialTime. If the
interrupted spades() call used an events filter (to run only certain
events), the same filter is reused automatically on restart; pass a new
events argument here to override it.
The filename to save the sim state.
saveState is a wrapper around restartSpades and saveSimList. You can
pass arguments to the ... that will be passed to saveSimList, such as
modules, inputs, outputs.
A list of elements that would be passed to simInit, such as modules.
An optional file that has a saved simList, e.g., from saveSimList
or saveState.
Logical. If TRUE, then it will force simInitAndSpades to be called
even if there is saved sim available.
A simList as if spades had been called on a simList.
A simList as if simInit() had completed (when restart = TRUE), or the
rewound simList with the fixed module re-parsed (when restart = FALSE).
A simList, that has been "executed" until end(sim), if it does not
hit an error.
If options('spades.recoveryMode') is set to TRUE or a numeric (default 1), then
there will be a list in the simList called .recoverableObjs.
These record the elements of simList that have changed over a number of events equal
to the number chosen for options('spades.recoveryMode').
The restartSpades function then uses this list to rewind numEvents backwards from the
first event in events(sim) (likely the one that caused the error).
The random number seed will be reset to the state it was at the start of the earliest event recovered, thereby returning to the exact stochastic simulation trajectory.
The random number seed is reset to its state at the start of the earliest recovered
.inputObjects, so that any stochastic defaults are reproduced exactly.
The simList will be in the state it was numEvents prior to the event
that led to the error (although some objects, e.g., on disk, may have already been modified).
# \donttest{
# options("spades.recoveryMode" = 1) # now the default
s <- simInit()
#> Setting:
#> options(
#> reproducible.cachePath = '/tmp/RtmpmM1qrr/myProject/cache'
#> spades.inputPath = '/tmp/RtmpmM1qrr/myProject/inputs'
#> spades.outputPath = '/tmp/RtmpmM1qrr/myProject/outputs'
#> spades.modulePath = '/tmp/RtmpmM1qrr/myProject/modules'
#> spades.scratchPath = '/tmp/RtmpmM1qrr/SpaDES/scratch'
#> )
#> Aug29 22:30:37 simInit Using setDTthreads(1). To change: 'options(spades.DTthreads = X)'.
#> Elapsed time for simInit: 0.03120518 secs
s <- spades(s) # if this is interrupted or fails
#> Aug29 22:30:37 simInit Using setDTthreads(1). To change: 'options(spades.DTthreads = X)'.
#> Aug29 22:30:37 chckpn:init total elpsd: 0.032 secs | 0 checkpoint init 0
#> Aug29 22:30:37 save :init total elpsd: 0.034 secs | 0 save init 0
#> Aug29 22:30:37 prgrss:init total elpsd: 0.036 secs | 0 progress init 0
#> Aug29 22:30:37 load :init total elpsd: 0.038 secs | 0 load init 0
#> simList saved in
#> SpaDES.core:::savedSimEnv()$.sim
#> It will be deleted at next spades() call.
## the following line will not work if the previous line didn't fail:
## don't need to specify `sim` if previous line fails;
## will take from savedSimEnv()$.sim automatically
s <- restartSpades(s)
#> This is experimental and should be used with caution.
#> There no saved state prior to any changes that happened in . Would you like to proceed from the last state of the simList anyway? i.e., any changes that had already happened inside the module: before the fail will be kept...
#> Would you like to restart anyway? (y or n)
#> Aug29 22:30:37 simInit Using setDTthreads(1). To change: 'options(spades.DTthreads = X)'.
#> simList saved in
#> SpaDES.core:::savedSimEnv()$.sim
#> It will be deleted at next spades() call.
# }