Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correlated random numbers in nested loops #74

Open
lbau7 opened this issue Apr 26, 2023 · 1 comment
Open

Correlated random numbers in nested loops #74

lbau7 opened this issue Apr 26, 2023 · 1 comment

Comments

@lbau7
Copy link

lbau7 commented Apr 26, 2023

I saw this bug on future.apply's GitHub page [HB edit: futureverse/future.apply#108] and checked whether the same issue exists with dofuture-loops, since this is something that I used in an R-package that I'm currently developing. Is this the same bug or am I doing something wrong?

Describe the bug
When random numbers are generated in a nested loop using the %dofuture% adapter many random numbers appear several times

Reproduce example
library(doFuture)
plan(multisession, workers = 4)
foreach::foreach(i = 1:4,.combine = 'cbind') %dofuture% {
b <- foreach::foreach(j = 1:4) %dofuture% {
runif(1)
} %seed% TRUE
b
} %seed% TRUE

Expected behavior
Random numbers should be unique.

Session information
R version 4.2.1 (2022-06-23 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19045)

Matrix products: default

locale:
[1] LC_COLLATE=German_Germany.utf8 LC_CTYPE=German_Germany.utf8 LC_MONETARY=German_Germany.utf8
[4] LC_NUMERIC=C LC_TIME=German_Germany.utf8

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] doFuture_1.0.0 future_1.32.0 foreach_1.5.2

loaded via a namespace (and not attached):
[1] compiler_4.2.1 parallelly_1.35.0 parallel_4.2.1 tools_4.2.1 future.apply_1.10.0
[6] listenv_0.9.0 codetools_0.2-18 iterators_1.0.14 digest_0.6.31 globals_0.16.2

@HenrikBengtsson
Copy link
Owner

checked whether the same issue exists with dofuture-loops, ...

Yes, this is exactly the same problem. You'd find it with furrr too. You're not doing anything wrong. It's a fundamental, important problem that needs some seriously deep focus to be solved properly. When solved for future.apply, it'll be solved elsewhere too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants