Run a baseline NIMBLE MCMC configuration in parallel (timing = runMCMC only)
Source:R/runners.R
run_baseline_config_parallel.RdRuns multiple MCMC chains on a PSOCK cluster using a baseline NIMBLE
configuration. The reported runtime follows the historic semantics used in
samOptiPro: runtime_s measures only the wall-clock time spent inside
nimble::runMCMC() across all chains, excluding model building, MCMC setup,
and compilation.
Usage
run_baseline_config_parallel(
build_fn,
niter,
nburnin,
thin,
monitors = NULL,
nchains = 3L,
seed = 1L,
n_cores = nchains,
extra_export = character(0),
samplesAsCodaMCMC = FALSE,
export_global = FALSE,
opts = NULL
)Arguments
- build_fn
Function that builds per-chain model objects (see Builder contract).
- niter
Integer, total MCMC iterations.
- nburnin
Integer, burn-in iterations.
- thin
Integer, thinning interval.
- monitors
Optional character vector of additional monitors to add.
- nchains
Integer, number of chains to run.
- seed
Integer, base seed; chain
kusesseed + k - 1.- n_cores
Integer, number of PSOCK workers (defaults to
nchains).- extra_export
Character vector of additional objects to export to workers.
- samplesAsCodaMCMC
Logical; if TRUE,
runMCMC()returns coda objects.- export_global
Logical; if TRUE export full
.GlobalEnv(use with care).- opts
Optional samOptiPro options object (reserved for future use).
Value
A list with:
samples: list of samples (one element per chain; type depends onsamplesAsCodaMCMC)runtime_s: global wall time (seconds) for the parallelrunMCMC()phase onlyruntime_by_chain: per-chain wall time (seconds) forrunMCMC()only
Details
Implementation notes:
Each worker calls
build_fn()to build (and possibly compile) the model and MCMC configuration outside the timed section.Each worker then builds + compiles the MCMC and runs
nimble::runMCMC(); only therunMCMC()call is timed per chain.The master records a global wall-clock time around the parallel
runMCMC()phase (start just beforeparLapply(), stop after all chains return).
Builder contract:
build_fn()must work as eitherbuild_fn()orbuild_fn(chain_id = <int>, export_global = <logical>).It must return a list containing at least:
model: an uncompilednimbleModel(recommended; used for diagnostics)cmodel: the compiled model (compileNimble(model))conf: an MCMC configuration (e.g. fromnimble::configureMCMC()) Optionally it may includemonitors.