Skip to contents

For each DISTINCT row of fit_grid (deduped by model_spec_hash()), compiles a prefit via brms::brm(chains = 0) against generator-supplied template data. Returns a named list of prefit objects keyed by spec hash.

Usage

build_model_bank(
  fitter,
  fit_grid,
  data_generator,
  data_spec_template,
  result_path = NULL
)

Arguments

fitter

A BrmsFitter S7 object.

fit_grid

A data.frame of model fitting specifications. Each row's formula, family, prior, stanvars columns (list-columns) define a model spec.

data_generator

The simulation data generator function.

data_spec_template

A named list (one row of data_grid as a list) used to generate template data.

result_path

NULL or character path. When non-NULL, options(cmdstanr_write_stan_file_dir) is set to file.path(result_path, "stan_binaries") so compiled binaries persist and are shared across controller and local daemons.

Value

A named list of brmsfit prefit objects keyed by model_spec_hash(), or NULL when precompile is FALSE.

Details

When fitter@precompile is FALSE, returns NULL immediately (the fitter falls back to a fresh brms::brm() per task).

A compile failure is fatal: it raises a bayesim_internal_error() since the simulation cannot proceed without a compilable model.

A model spec without an explicit prior is likewise fatal (a bayesim_config_error(), raised before any compilation work for that spec) unless the fitter opts in via allow_default_priors = TRUE: brms data-derived default priors from the template dataset would otherwise stay embedded in the compiled model reused for every task. When opted in, a one-time notice is emitted instead.