R/sim_survey.R
    sim_survey_parallel.RdA wrapper around sim_survey() that enables a much larger number of survey
simulations to be performed using parallel processing. Unlike test_surveys(),
this function retains full survey details and is suitable for evaluating
alternate stratified analysis approaches for generating survey indices.
sim_survey_parallel(
  sim,
  n_sims = 1,
  n_loops = 100,
  cores = 1,
  quiet = FALSE,
  ...
)A simulation object returned by sim_distribution().
Number of surveys to simulate per loop. Large values may increase memory usage significantly.
Number of times to call sim_survey().
Total number of simulations = n_sims × n_loops.
Using a smaller n_sims and larger n_loops reduces memory demand but may increase runtime.
Number of processor cores to use in parallel. More cores typically reduce total time.
Logical. If FALSE, prints messages estimating run time.
Arguments passed on to sim_survey
qA closure (e.g., sim_logistic()) for simulating catchability at age.
Returned values must range between 0 and 1.
trawl_dimTrawl width and distance (same units as the grid).
resample_cellsLogical. If TRUE, allows grid cells to be resampled.
May introduce bias, as depletion is applied at the cell level.
binom_errorLogical. Should binomial error be imposed?
If FALSE, stratified estimates at older ages may be biased due to rounding zeros.
min_setsMinimum number of sets per stratum.
set_denSet density (sets per grid unit squared).
Warning: May error if set_den is high and resample_cells = FALSE, because allocated sets may exceed available cells.
lengths_capMaximum number of lengths measured per set.
ages_capCap on the number of ages to sample, depending on age_sampling type:
If "stratified": maximum per length bin (via age_length_group) and per age_space_group (e.g., "division", "strat").
If "random": maximum number of fish aged per set.
age_samplingType of age sampling strategy: "stratified" (default) or "random".
age_length_groupWidth of length bins for stratified age sampling. Ignored if age_sampling = "random".
age_space_groupSpatial scale for stratified age sampling.
Options: "division" (default), "strat", or "set". Ignored if age_sampling = "random".
custom_setsA data.table of set locations (same structure as returned by sim_sets()).
If NULL, set locations are generated automatically.
lightLogical. If TRUE, drops some objects from output to reduce memory footprint.
A list of the same structure as returned by sim_survey(), containing the
results of all simulations.
This function runs sim_survey() with light = TRUE to reduce object size
and minimize RAM usage.
# \donttest{
# Run 25 total simulations (5 per loop × 5 loops) over the same population
sim <- sim_abundance(ages = 1:20, years = 1:5) |>
  sim_distribution(grid = make_grid(res = c(10, 10))) |>
  sim_survey_parallel(
    n_sims = 5, n_loops = 5, cores = 1,
    q = sim_logistic(k = 2, x0 = 3),
    quiet = FALSE
  )
#> One run of sim_survey took ~ 1 secs to run. It may take up to 5 secs to run all simulations.
# }