10000 BUG: Correlated RNG with nested future.apply calls · Issue #108 · futureverse/future.apply · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
BUG: Correlated RNG with nested future.apply calls #108
Open
@HenrikBengtsson

Description

@HenrikBengtsson

Issue

library(future.apply)
y <- do.call(rbind, future_lapply(1:3, future.seed = TRUE, FUN = function(i) { 
  do.call(rbind, future_lapply(1:3, future.seed = TRUE, FUN = function(j) {
    data.frame(i = i, j = j, random = runif(n = 1L)) })) 
  })
)
print(y)

gives

  i j    random
1 1 1 0.8146860
2 1 2 0.4950540
3 1 3 0.9308272
4 2 1 0.4950540
5 2 2 0.9308272
6 2 3 0.2019456
7 3 1 0.9308272
8 3 2 0.2019456
9 3 3 0.6057787

Note how some of the random numbers are duplicated, e.g.

> y$random
[1] 0.8146860 0.4950540 0.9308272 0.4950540 0.9308272 0.2019456 0.9308272
[8] 0.2019456 0.6057787
> unique(y$random)
[1] 0.8146860 0.4950540 0.9308272 0.2019456 0.6057787

Troubleshooting

It could be that we've been here before; this seems familiar. I don't have time to investigate in full right now, but it's not that the RNG state of the parent isn't forwarded;

> seed0 <- .Random.seed
> y <- future_lapply(1:3, FUN = function(i) runif(n = 1L), future.seed = TRUE)
> seed <- .Random.seed
> identical(seed, seed0)
[1] FALSE

but it could be that it's only forwarded a single step, whereas it needs to be forward length(X) steps.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0