
Audit parallel RNG invariance across core counts
Source:R/audit-parallel-rng.R
check_parallel_rng.RdVerifies that a stochastic pipeline produces identical results when executed
sequentially (cores = 1) versus in parallel (cores = 2, etc.). Supports
either a custom runner(cores, seed) function to audit your own parallel
code directly, or a task function fun evaluated via
statci_parallel_apply().
Arguments
- runner
Optional function of signature
function(cores, seed)that executes the stochastic computation usingcoresworkers and masterseed. If provided,check_parallel_rng()tests whetherrunneryields identical outputs across all values ofcores.- fun
Optional task function
function(i, ...)evaluated overXviastatci_parallel_apply()whenrunnerisNULL.- X
Sequence or list of inputs for
fun(defaults toseq_len(8L)).- cores
Integer vector of core counts to compare (default
c(1L, 2L)). Must contain at least two distinct values.- seed
Integer seed passed to each run.
- tolerance
Numeric comparison tolerance (
0checks bit-for-bit exactness viaidentical()).- ...
Additional arguments forwarded to
fun.
Value
An S3 object of class "statci_parallel_rng" with status
("pass" or "fail"), comparisons tibble, identical_all,
max_abs_diff, cores_tested, and seed.
Examples
# Passes: deterministic L'Ecuyer stream per task
ok <- check_parallel_rng(
runner = function(cores, seed) {
unlist(statci_parallel_apply(1:6, function(i) mean(rnorm(20)), cores = cores, seed = seed))
},
cores = c(1L, 2L),
seed = 123L
)
ok$status
#> [1] "pass"