Skip to content

Simplify reproducible parallel random streams in R #38

@rstub

Description

@rstub

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions