dqrng icon indicating copy to clipboard operation
dqrng copied to clipboard

Simplify reproducible parallel random streams in R

Open rstub opened this issue 6 years ago • 1 comments

The parallel vignette shows how one can get reproducible parallel RNG streams in principle. However, this is not very convenient. It would be nice to have an analogue function for clusterSetRNGStream, e.g.:

dqclusterSetRNGStream <- function(cl = NULL, iseed =  NULL) {
    if (is.null(cl))
        cl <- parallel::getDefaultCluster()
    if (is.null(iseed))
        iseed <- dqrng::generateSeedVectors(1L)[[1L]]
    invisible(parallel::clusterApply(cl,
                                     seq_along(cl),
                                     function(seed, stream) {
                                         dqrng::dqset.seed(seed, stream)},
                                     seed = iseed))
}
  • This is just one way to achieve reproducibility, see https://pat-s.me/reproducibility-when-going-parallel/ by @pat-s for more details.
  • It would be nice to not use R's RNG here via dqrng::generateSeedVectors. Instead, the random seed could be taken from dqrng's RNG.
  • It would make sense to offer the possibility to set the RNG kind as well.

rstub avatar Dec 17 '19 14:12 rstub

  • Maybe something like https://github.com/renozao/doRNG/blob/master/R/doRNG.R
  • Ideal would be an integration into future, but that might be more complex for now, c.f. https://github.com/HenrikBengtsson/future/discussions/726

rstub avatar Aug 05 '24 08:08 rstub