HenrikBengtsson / doFuture

:rocket: R package: doFuture - Use Foreach to Parallelize via Future Framework
https://doFuture.futureverse.org
84 stars 6 forks source link

Option 'doFuture.rng.onMisuse' to disable RNG checks only for doFuture #59

Closed HenrikBengtsson closed 3 years ago

HenrikBengtsson commented 3 years ago

Since there are cases where we get false RNG warnings when using downstream packages, e.g.

doFuture::registerDoFuture()
BiocParallel::register(BiocParallel::DoparParam())
y <- BiocParallel::bplapply(1:2, rnorm)
Warning message:
UNRELIABLE VALUE: One of the foreach() iterations ('doFuture-1') unexpectedly generated random numbers ...

Until we can figure out a non-hacky way for doFuture to be BiocParallel-aware, the workaround is to disable this check by setting:

options(future.rng.onMisuse = "ignore")

However, this will disable these checks throughout the future ecosystem, which is not good.

A slightly better solution would be to disable such warnings only for the doFuture adaptor. We could simply introduce support for:

options(doFuture.rng.onMisuse = "ignore")

where the default is:

onMisuse <- getOption("doFuture.rng.onMisuse", getOption("future.rng.onMisuse"))

and have that temporarily override whatever option 'future.rng.onMisuse' declares, e.g.

oopts <- options(future.rng.onMisuse = onMisuse)
on.exit(options(oopts), add = TRUE)