-
Notifications
You must be signed in to change notification settings - Fork 85
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
R options: options() are not passed down to futures - should they? (document either way) #134
Comments
Some ideas: Ignoring any "automatic" passing down of options, this could be done by adding an argument f <- future(..., options = c("digits", "repos")) That construct provides the developer control over options. For the end user to control options, there would need to be a similar argument that can be specified when setting the plan(batchtools_sge, workers = 100L, options = c("digits", "repos")) Options specified via |
So, |
Good point, I agree that options(future.globals.maxSize = 1.0 * 1024^3) |
Moving the discussion of |
FYI/@rubenarslan, in the next release (develop branch right now), we're also passing down:
|
FYI, future 1.9.0, which passes down several more |
I don't see any difference, did I do something wrong ?
Matrix products: default locale: attached base packages: other attached packages: loaded via a namespace (and not attached):
[[1]] |
Nah, please read the above comments again. future 1.9.0 only pass down some specific |
Ok, I have read the comment but I just understand it now. |
Here's an example: library(future)
plan(multisession) # Use background R sessions
## My personal option
options(test = 5)
## Use only 3 digits
options(digits = 3L)
## Options that I want to pass down to the futures/workers
fopts <- options()[c("digits", "test")]
str(fopts)
# List of 2
# $ digits: int 3
# $ test : num 5
# Create a future using those "frozen" 'fopts' options
> f <- future({
+ ## Set 'fopts' options (here fopts is a global variable)
+ options(fopts)
+ ## Show that those options are set
+ cat(sprintf("test = %s\n", getOption("test")))
+ print(pi)
+ 2 * getOption("test")
+ })
> v <- value(f) ## requires future 1.9.0 to see output
test = 5
[1] 3.14
> v
[1] 10
Are you asking how to do the same with |
Are you asking how to do the same with future.apply::future_lapply()? Thanks |
The same way, via global > library(future.apply)
> plan(multiprocess)
> options(test = 5)
> options(digits = 3L)
> fopts <- options()[c("digits", "test")]
> y <- future_lapply(1:3, FUN = function(x) {
+ ## Set 'fopts' options (here fopts is a global variable)
+ options(fopts)
+ ## Show that those options are set
+ cat(sprintf("test = %s\n", getOption("test")))
+ print(pi)
+ getOption("test") * x
+ })
test = 5
[1] 3.14
test = 5
[1] 3.14
test = 5
[1] 3.14
> unlist(y)
[1] 5 10 15
> |
Thanks a lot. library("future.apply") I also have another one but I can't (yet) reproduce it on small code. |
Please create a separate issue if you're changing topics |
Hello! Just stumbled upon this when my code started behaving strangely and realized after a few hours of debugging that the "memory_saving_mode" option had defaulted to TRUE because future wasn't passing options on. Maybe could be suitable with a warning about this? I'm using future version 1.11.1.1 through Drake, calling |
Hello Adam,
I have used a workaround. I am reloading each worker independently. More
CPU/bandwith, less work :)
Best
Le mer. 30 oct. 2019 à 12:23, Adam Altmejd <[email protected]> a
écrit :
… Hello! Just stumbled upon this when my code started behaving strangely and
realized after a few hours of debugging that all the "memory_saving_mode"
options had defaulted to TRUE because future wasn't passing options on.
Maybe could be suitable with a warning about this?
I'm using future version 1.11.1.1 through Drake
<https://github.com/ropensci/drake>, calling
future:plan(future::multiprocess). What is the recommended way to pass
options to workers?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#134>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEGAXTUMAV3NL23YANAD45TQRFVDXANCNFSM4DD7FPPA>
.
|
So, I'm objecting that a warning could be useful but it's unfortunately not feasible. How would future know what options to warn about and not? Feel free to clarify how you want it to work.
I highly recommend that you update - you are way behind and you're missing out on bug fixes and features. Is there a reason why you're not updating?
You can do it via a global variable, e.g. my_opts <- options(c("memory_saving_mode", "digits"))
f <- future({
options(my_opts)
...
})
v <- value(f) |
Tack :). You are probably right. But also package options could create problems if they are changed from their defaults. Same for base R options that are changed. One possibility is to issue a warning when the package is loaded, but that might be too extreme. I guess the best would be to pass options on to works by default and then allowing the user to shut that down in the function call. As I was saying I'm calling future via drake so am not explicitly creating any "future" objects. Only setting plan(multiprocess) and then run |
Maybe the problem of environment variables could be added to this thread. |
Identifying automagically which options and environment variables should be passed down to workers is hard, indeed. I would like to add a further idea as well - not a silver bullet, but sometimes useful:
This is of course a rude approximation, can result in both false positives and false negatives. |
This is because things set in options() don't get passed on to workers 🤷♂️ futureverse/future#134
Probably silly question for @HenrikBengtsson: why not just pass all the options down at worker creation? it should not be much of overhead isn't it? |
side note (not related to previous comment's question): I wonder if a useful comparison is to Bash options and sub-shells. For example, in bash if you run |
You broke Rule No 1; there are no silly questions - just silly answers.
For a few different reasons, but one issue is "discussed" in futureverse/parallelly#70. Until then, you can use argument > cl <- parallelly::makeClusterPSOCK(2, rscript_startup = quote(options(hello = "world")))
> str(parallel::clusterEvalQ(cl, getOption("hello")))
List of 2
$ : chr "world"
$ : chr "world" Or similarly, > library(future)
> plan(multisession, workers = 2, rscript_startup = quote(options(hello = "world")))
> f <- future(getOption("hello"))
> value(f)
[1] "world" A more important design reason is: If your code depends on A safer design is probably better to pass down R options via the |
I'm adding this as a reminder to myself to document this (next release), but also to consider more automated solutions (a future release):
R's global
options()
are not passed down to futures. This has to be done manually right now, e.g.This works, but it would be nice to have an automated version of this as well (cf. globals and packages) to better capture the state of the calling R process. Doing this might be a bit tricky since some options are read only / shouldn't be changed and others are specific the local machine, which may not work on a remote machine. Maybe it's possible to use static-code inspection to identify what options are used (similar to how globals are identified).
The text was updated successfully, but these errors were encountered: