mlr-org / paradox

ParamHelpers Next Generation
https://paradox.mlr-org.com
GNU Lesser General Public License v3.0
28 stars 7 forks source link

clone fails if .$values are objects imported via reticulate #276

Closed pfistfl closed 4 years ago

pfistfl commented 4 years ago
library(paradox)
library(keras)
ParamSet$new(list(ParamUty$new("a")))    
ps = ParamSet$new(list(ParamUty$new("a")))
ps$values = list(a = optimizer_adam())
ps$clone(deep = TRUE)

Error in py_get_attr_impl(x, name, silent) : AttributeError: 'Adam' object has no attribute '.__enclos_env__'

Error most likely comes from Line 449 in https://github.com/mlr-org/paradox/blob/master/R/ParamSet.R

This currently breaks mlr3keras :)

pfistfl commented 4 years ago

The problem is, that reticulate overloads the $ operator and therefore the access errors (and does not point to NULL).

jakob-r commented 4 years ago

Do we really want to to solve this in paradox? I think the go to solution is just construct the objects in the objective or in the trafo. My preferred solution would be to make the param a character and then just call get(a, mode = "function")() to construct the object. You are more flexible if you write expressions, though.

pfistfl commented 4 years ago

One problem here would be that then all extra args would also need to become parameters i.e. optimizer_adam() has 8 args, which would then really blow up the param space.

jakob-r commented 4 years ago

What about

ps$values = list(a = quote(optimizer_adam(foo = 1, bar = 2)))
pfistfl commented 4 years ago

Solved via #277