futureverse / futureverse/future
Discussion: Forcing parallel reproducibility via the default RNG kind?
- Dominant language
- R
- Stars
- 1k
- Forks
- 92
- PR merge metrics
- No merged PRs in 30d
Description
(This issue should serve as a public place for the discussion @HenrikBengtsson and I had via mail recently)
I wonder if it makes sense to support reproducible parallel streams via the default RNG kind "Mersenne-Twister" within a package to help users who are not aware that this RNG kind does not provide reproducible streams in parallel.
(I am talking about the standard parallel backends in R and not specifically about the way one can do this via the {future} package.)
# Multicore backend
```r
old.seed = .Random.seed
seed = sample(1:100000, 1)
# we need to reset the seed first in case the user supplied a seed,
# otherwise "L'Ecuyer-CMRG" won't be used
rm(.Random.seed, envir = globalenv())
set.seed(seed, "L'Ecuyer-CMRG")
```
If the user uses `set.seed()` and goes parallel via the `multicore` backend, the code above will ensure parallel RNG streams.
If you want to see in action, https://github.com/mlr-org/parallelMap/pull/80 has some tests to ensure the correct functioning.
# Socket backend
Here, one can do
```r
clusterSetRNGStream(cl, iseed = sample(1:100000, 1))
```
to support the default RNG kind in parallel scenarios.
# General
Whenever doing this, I wonder if one should at least tell the user that this was done behind the scenes to make them aware of whats happening (including eventual decreases in speed).
Contributor guide
Assessment
This issue has not been assessed yet.