futureverse / future.apply

:rocket: R package: future.apply - Apply Function to Elements in Parallel using Futures
https://future.apply.futureverse.org
211 stars 16 forks source link

future.seed error with future_apply #55

Closed eweisbrod closed 4 years ago

eweisbrod commented 4 years ago

This example for future_apply from the documentation does not work for multiprocess. It only works for plan(sequential). For multiprocess it gives the error:

Error in ...future.FUN(...future.X_jj, ...) : 
  unused argument (future.seed = 48879)

## ---------------------------------------------------------
## Parallel Random Number Generation
## ---------------------------------------------------------
# }
# NOT RUN {
## Regardless of the future plan, the number of workers, and
## where they are, the random numbers produced are identical

X <- matrix(c(1:4, 1, 6:8), nrow = 2L)

plan(multiprocess)
Y1 <- future_apply(X, MARGIN = 1L, FUN = sample, future.seed = 0xBEEF)
print(Y1)

plan(sequential)
Y2 <- future_apply(X, MARGIN = 1L, FUN = sample, future.seed = 0xBEEF)
print(Y2)
HenrikBengtsson commented 4 years ago

Wow, thanks, I can reproduce. It's actually plan(multisession) that you end up using since you're on Windows. This also happens with backends such as plan(future.callr::callr) and plan(future.batchtools::batchtools_local). Right now I'm really surprised because it's not a problem for all backends (like plan(multicore)) but I'm even more surprised that this has gone undetected this long and that I somehow managed to not add a solid package test for future_apply(..., future.seed).

PS. I've edited your comment by wrapping your code snipped in a fenced Markdown block. Have a look at https://help.github.com/en/github/writing-on-github/creating-and-highlighting-code-blocks#fenced-code-blocks - it's super easy and super convenient

HenrikBengtsson commented 4 years ago

For the record, this is a problem for several other future.* arguments to future_apply(), e.g.

> library(future.apply)
> plan(multisession)
> y <- future_apply(matrix(1:4, nrow=2), MARGIN=1, FUN=rnorm, future.stdout=FALSE)
Error in ...future.FUN(...future.X_jj, ...) : 
  unused argument (future.stdout = FALSE)

I know why this happens and the fix should be simple.

HenrikBengtsson commented 4 years ago

Thanks again for reporting. This has been fixed in the 'develop' branch and will be part on the next release.

HenrikBengtsson commented 4 years ago

future 1.6.0 where this is fixed is now on CRAN. Thxs again for reporting.

eweisbrod commented 4 years ago

my pleasure, thanks for letting me know.

On Wed, Jul 1, 2020 at 12:02 PM Henrik Bengtsson notifications@github.com wrote:

future 1.6.0 where this is fixed is now on CRAN. Thxs again for reporting.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/HenrikBengtsson/future.apply/issues/55#issuecomment-652506962, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADBGGLBFJJKW5WZJ4I3WV4LRZNM2JANCNFSM4MXFKKQA .