diff --git a/NEWS.md b/NEWS.md index afbfde19..a3f11003 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,13 @@ ## Changes in SimDesign 2.25 +- Fixed a bug where list-based (L'Ecuyer-CMRG) seeds were not applied on the + serial (non-parallel) execution path, causing `runArraySimulation(..., iseed)` + and `runSimulation(seed = )` to be non-reproducible when + `parallel = FALSE`. The internal `set_seed()` helper was assigning + `.Random.seed` to its local frame rather than `.GlobalEnv`, so the RNG state + was silently discarded. The parallel path was unaffected + - `SimErrors()` and `SimWarnings()` functions added to better track and extract error/warning information. Makes it easier to track down specific seed states to replicate any of the recorded messages diff --git a/R/util.R b/R/util.R index d5a3d307..88670309 100644 --- a/R/util.R +++ b/R/util.R @@ -678,7 +678,7 @@ pickReps <- function(replications, iter){ } set_seed <- function(seed){ - if(is.list(seed)) .Random.seed <- seed[[1L]] + if(is.list(seed)) .GlobalEnv$.Random.seed <- seed[[1L]] else set.seed(seed) invisible(NULL) } diff --git a/tests/tests/test-03-array.R b/tests/tests/test-03-array.R index 50befea0..46b0e126 100644 --- a/tests/tests/test-03-array.R +++ b/tests/tests/test-03-array.R @@ -70,6 +70,22 @@ test_that('array', { SimClean('mysim-1.rds') + # serial iseed must be byte-for-byte reproducible (L'Ecuyer-CMRG seed + # applied via set_seed(); see GitHub bug re: .GlobalEnv assignment) + res_s1 <- runArraySimulation(design=Design, replications=20, + generate=Generate, analyse=Analyse, + summarise=Summarise, arrayID=1L, + iseed=iseed, filename='serialseed', + parallel=FALSE, verbose=FALSE) + res_s2 <- runArraySimulation(design=Design, replications=20, + generate=Generate, analyse=Analyse, + summarise=Summarise, arrayID=1L, + iseed=iseed, filename='serialseed', + parallel=FALSE, verbose=FALSE) + expect_identical(SimExtract(res_s1, what='results'), + SimExtract(res_s2, what='results')) + SimClean('serialseed-1.rds') + ######################## # Same submission job as above, however split the replications over multiple # evaluations and combine when complete