HenrikBengtsson / future

:rocket: R package: future: Unified Parallel and Distributed Processing in R for Everyone
https://future.futureverse.org
951 stars 83 forks source link

Globals specified as a named list not exported with map-reduce APIs for certain backends #515

Closed HenrikBengtsson closed 3 years ago

HenrikBengtsson commented 3 years ago

Issue

library(future.apply)
plan(sequential)
y <- future_lapply(1, FUN = function(x) a * x, future.globals = list(a = 42))
## Error in ...future.FUN(...future.X_jj, ...) : object 'a' not found

and

library(furrr)
plan(sequential)
y <- future_map(1, function(x) a * x, .options = furrr_options(globals = list(a = 42)))
## Error in ...furrr_fn(...) : object 'a' not found

The above works with other types of backends, e.g. plan(cluster, workers = 1L).

Troubleshooting

It works with plain futures:

f <- future(a, globals = list(a = 42))
value(f)
## [1] 42

Since it affects both future.apply and furrr, my best guess is that this needs to be fixed in the future package.

> sessionInfo()
R version 4.1.0 Patched (2021-05-18 r80320)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.5 LTS

Matrix products: default
BLAS:   /home/hb/software/R-devel/R-4-1-branch/lib/R/lib/libRblas.so
LAPACK: /home/hb/software/R-devel/R-4-1-branch/lib/R/lib/libRlapack.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
[1] future.apply_1.7.0 future_1.21.0     

loaded via a namespace (and not attached):
[1] compiler_4.1.0         parallelly_1.26.0-9001 tools_4.1.0           
[4] parallel_4.1.0         listenv_0.8.0          codetools_0.2-18      
[7] digest_0.6.27          globals_0.14.0
HenrikBengtsson commented 3 years ago

I think a reproducible example based on plain sequential futures is:

library(future)
plan(sequential)
f <- future(fcn(), globals = list(a=42, fcn=function() a))
value(f)
## Error in fcn() : object 'a' not found

The same works with, say, plan(cluster, workers = 1).

HenrikBengtsson commented 3 years ago

This fails also with plan(multicore). ... hmm, starting to get a deja vu feeling about this one.

HenrikBengtsson commented 3 years ago

hmm, starting to get a deja vu feeling about this one.

Indeed, this is the same problem as in https://github.com/HenrikBengtsson/future.apply/issues/10 from May 2018.