Skip to contents

Runs multiple independent MCMC chains using a strict slice-only sampling strategy (onlySlice semantics), in parallel, on either a PSOCK or FORK backend. All stochastic nodes are updated exclusively with slice samplers, with no use of random-walk, block, conjugate, or gradient-based samplers.

Usage

run_only_slice_parallel(
  build_fn,
  niter,
  nburnin = floor(0.25 * niter),
  thin = 1L,
  monitors = NULL,
  nchains = 1L,
  seed = 1L,
  n_cores = nchains,
  extra_export = character(0),
  parallel_backend = c("PSOCK", "FORK", "AUTO"),
  worker_log = TRUE,
  useConjugacy = FALSE
)

Arguments

build_fn

Function building per-chain model objects (see Builder contract).

niter

Integer; total number of MCMC iterations.

nburnin

Integer; number of burn-in iterations.

thin

Integer; thinning interval.

monitors

Optional character vector of monitored nodes.

nchains

Integer; number of chains to run.

seed

Integer; base seed (chain k uses seed + k - 1).

n_cores

Integer; number of parallel workers (default = nchains).

extra_export

Optional character vector of additional objects to export to workers.

parallel_backend

Character; parallel backend to use ("PSOCK", "FORK", or "AUTO").

worker_log

Logical; whether to emit minimal per-worker diagnostic logs.

useConjugacy

Logical; passed for API consistency but ignored (slice-only).

Value

A list with components:

  • samples : posterior samples (combined across chains when possible)

  • runtime_s : wall-clock runtime (seconds) for the parallel runMCMC() phase

  • conf : NULL in parallel mode; per-chain configurations are attached as attribute conf_by_chain

Details

This function is primarily intended as a robust convergence-oriented baseline for complex or non-differentiable models (e.g. models involving truncated distributions, constrained parameters, or piecewise likelihoods), for which default sampler configurations or HMC/NUTS are inappropriate.

Implementation notes:

  • Each worker builds and configures its own model and MCMC independently.

  • All existing samplers are removed and replaced by slice samplers on all stochastic nodes.

  • Parallel execution can rely on a PSOCK cluster (portable) or a FORK backend (Unix-alike systems only).

  • The reported runtime measures the wall-clock time spent in runMCMC(), excluding model construction and compilation.

Builder contract:

  • build_fn() must work either as build_fn() or build_fn(chain_id = <int>, export_global = <logical>).

  • It must return a list containing at least:

    • model : an uncompiled nimbleModel

    • cmodel : the compiled model (compileNimble(model))

    • conf : an MCMC configuration object