A 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,
  ...
)

Arguments

sim

A simulation object returned by sim_distribution().

n_sims

Number of surveys to simulate per loop. Large values may increase memory usage significantly.

n_loops

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.

cores

Number of processor cores to use in parallel. More cores typically reduce total time.

quiet

Logical. If FALSE, prints messages estimating run time.

...

Arguments passed on to sim_survey

q

A closure (e.g., sim_logistic()) for simulating catchability at age. Returned values must range between 0 and 1.

trawl_dim

Trawl width and distance (same units as the grid).

resample_cells

Logical. If TRUE, allows grid cells to be resampled. May introduce bias, as depletion is applied at the cell level.

binom_error

Logical. Should binomial error be imposed? If FALSE, stratified estimates at older ages may be biased due to rounding zeros.

min_sets

Minimum number of sets per stratum.

set_den

Set 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_cap

Maximum number of lengths measured per set.

ages_cap

Cap 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_sampling

Type of age sampling strategy: "stratified" (default) or "random".

age_length_group

Width of length bins for stratified age sampling. Ignored if age_sampling = "random".

age_space_group

Spatial scale for stratified age sampling. Options: "division" (default), "strat", or "set". Ignored if age_sampling = "random".

custom_sets

A data.table of set locations (same structure as returned by sim_sets()). If NULL, set locations are generated automatically.

light

Logical. If TRUE, drops some objects from output to reduce memory footprint.

Value

A list of the same structure as returned by sim_survey(), containing the results of all simulations.

Details

This function runs sim_survey() with light = TRUE to reduce object size and minimize RAM usage.

Examples

# \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.
# }