Integrates a compiled ODE model over several independent parameter sets
(experimental conditions, or the subjects of a mixed-effects fit) inside a
single .Call, using OpenMP where the toolchain provides it.
Usage
solveODEBatch(
model,
conditions,
times = NULL,
parms = NULL,
tangent = NULL,
hessian = NULL,
fixed = NULL,
forcings = NULL,
abstol = 1e-06,
reltol = 1e-06,
maxattempts = 50L,
maxsteps = 1000000L,
hini = 0,
roottol = 1e-06,
maxroot = 1L,
cores = NULL,
traceFile = NULL,
onFailure = c("stop", "warn", "silent"),
cotangent = NULL,
curvature = NULL,
keepStore = FALSE,
store = NULL,
sensErrCon = TRUE,
adjoint = NULL,
maxOrder = NULL,
stald = FALSE
)Arguments
- model
- conditions
A named or unnamed list of per-condition argument lists. Recognized names are
times,parms,tangent,hessian,cotangent,curvature,fixed,forcings,abstol,reltol,maxattempts,maxsteps,hini,roottol,maxroot,keepStore,store,sensErrCon,adjoint,maxOrderandstald; each overrides the batch-wide argument of the same name.- times, parms
Batch-wide
timesandparmsas insolveODE(), for the conditions that do not give their own. DefaultNULL.- tangent
Optional numeric matrix, the tangent of the inputs; shapes in Details. Default
NULL: the identity on the active sensitivities.- hessian
Optional numeric array, the second derivative of the inputs; shapes in Details. Needs a model with
attr(model, "deriv2"). DefaultNULL: the inputs are affine in \(\theta\).- fixed
Optional character vector, sensitivity names held fixed in this call, a subset of
attr(model, "dimNames")$sens. UnlikefixedofcppODE()it changes without recompiling. Not with a full or partialtangent. DefaultNULL.- forcings
Named list of forcing data, one element per name in
attr(model, "forcings"): adata.framewith columnstimeandvalue, or a two-column matrix.cppODE()andcvode()take the forcing names, this argument the data. A forcing is the monotone cubic Hermite interpolant (PCHIP) of the data points and constant beyond the first and the last point, seeforcingValues(). DefaultNULL.- abstol
Absolute error tolerance. Default
1e-6.- reltol
Relative error tolerance. Default
1e-6.- maxattempts
Maximum number of consecutive step attempts without progress in time before the solve stops with
return_code = -4. Default50.- maxsteps
Maximum total number of integration steps. Default
1e6.- hini
Initial step size;
0(default) triggers automatic estimation.- roottol
Tolerance for locating root events. Default
1e-6. Underrootfunc = "equilibrate"the solve stops once every \(|\dot x_i| \le \mathrm{roottol}\, |x_i| + \mathrm{abstol}\); on acppODE()model the test covers the sensitivities as well.- maxroot
Maximum number of triggers per root event. Default
1.- cores
Number of threads, at most the processors; one for a single condition.
NULL(default) takes the first ofgetOption("cppDE.cores"),getOption("Ncpus")andparallel::detectCores(logical = FALSE)that is set.1forces the serial loop.- traceFile
Optional. Either one path per condition, or a single path used as a template, in which case the condition's name (or index) is inserted before the extension. Needs a model built with
stepTrace = TRUE. DefaultNULL.- onFailure
Applied once after all conditions have run.
"stop"(default) runs every condition, then raises one error naming the failed ones;"warn"and"silent"as insolveODE().- cotangent
The cotangent of the outputs,
[n_t, n_x]or[n_t, n_x, n_seed]. Required by a model compiled withderivMode = "reverse"or"forward-reverse"unlesskeepStore = TRUE; an error on any other model.result$cotangentis then \(\sum_{t,i} w_{t,i}\, \partial x_i(t) / \partial \theta\), one column per seed. DefaultNULL.- curvature
Optional,
"forward-reverse"only: the derivative ofcotangentalong the tangent,[n_t, n_x, n_seed, n_s]. For a cotangent that is the gradient of a functional of the outputs, this is that functional's Hessian applied to the output tangent. DefaultNULL: the cotangent is constant in \(\theta\).- keepStore
Logical, default
FALSE. Return the checkpoints of a reverse solve as$store, for a later solve to reuse throughstore. Thecotangentmay then be omitted, and the solve returns the values alone. Only on acppODE()model compiled withderivMode = "reverse".- store
The
$storeof an earlier solve of the same model at the sametimesandparms. The solve then integrates nothing and runs the backward sweep alone. A store from a different point is an error. A store may be reused any number of times. DefaultNULL.- sensErrCon
Logical. Include the sensitivities, under
derivMode = "forward-reverse"the tangents, in the error test and the first step. DefaultTRUE.FALSEtakes the steps and corrector iterations of a value run, up to rounding: cheaper and less accurate, the sensitivities are the derivative of the computed solution, as the reverse mode of"adams"returns; that of"bdf"solves the corrector equations instead. Under"forward-reverse"the step grid does not depend on the directions of the tangent. Needs a model with sensitivities, has no effect underderivMode = "reverse"; acvode()model takesTRUEonly.- adjoint
Optional
adjointControl()object for a model compiled withderivMode = "reverse". DefaultNULL, the same asadjointControl().- maxOrder
Optional upper bound on the order of a multistep method, 1 to 5 for
"bdf"and 1 to 12 for"adams". DefaultNULL, the method's own maximum. An error on"rb4"and"tsit5".- stald
Logical, default
FALSE. Stability limit detection for method"bdf": the order drops when the step size leaves the stability region of the current order. See Stepping and error control.
Value
A list of solveODE() results, one per condition, named after
conditions, with attribute threads, the thread count used.
Details
Results are bit-identical to the serial path. The batch falls back to a
serial loop in a forked child, inside an OpenMP region, or without OpenMP;
see batchAvailable(). A model without a batch entry point is solved by
solveODE() per condition.
See also
solveODE(); prepareBatch() and solveBatch() for repeated
solves of the same conditions; batchAvailable().
Batches of conditions in the
Guide.
Examples
# \donttest{
if (codegenAvailable()) {
## One model, several conditions, solved on threads in one call. A condition's
## list overrides the batch-wide arguments.
f <- cppODE(c(x = "-k*x"), deriv = FALSE)
conditions <- list(slow = list(parms = c(x = 1, k = 0.1)),
fast = list(parms = c(x = 1, k = 1)))
res <- solveODEBatch(f, conditions, times = 0:5)
sapply(res, function(r) r$variable[, "x"])
}
#> using C++ compiler: g++ [-O2 -DNDEBUG -w -fPIC -fopenmp]
#> slow fast
#> [1,] 1.0000000 1.000000000
#> [2,] 0.9048319 0.367875096
#> [3,] 0.8187232 0.135329689
#> [4,] 0.7408129 0.049785983
#> [5,] 0.6703154 0.018315541
#> [6,] 0.6065275 0.006738326
# }