tidymodels / parsnip

A tidy unified interface to models
https://parsnip.tidymodels.org
Other
597 stars 89 forks source link

Error in rlang::env_get(get_model_env(), paste0(cls, "_modes")) : argument "default" is missing, with no default #399

Closed mdancho84 closed 3 years ago

mdancho84 commented 3 years ago

I have a user of a developmental package modeltime.gluonts that has an error, which they posted here (business-science/modeltime.gluonts#9). I can trace the issue back to parsnip. In new_model_spec it uses rlang::env_get(). Any help figuring this one out will be much appreciated. Note that I have not been able to reproduce the issue.

#> Error in rlang::env_get(get_model_env(), paste0(cls, "_modes")): argument "default" is missing, with no default

Full Issue

Hey @mdancho84 -- I'm getting a failure for main modeltime.gluonts example. Reprex with error message and sessionInfo() below.

I can't find the precise location of the error but looks like an argument is missing to rlang::env_get... somewhere. Unclear if this is an issue with modeltime.gluonts specifically or in a dependency, but posting here first as this is where I found it.

library(modeltime.gluonts)
#> Loading required package: modeltime
library(tidymodels)
#> ── Attaching packages ────────────────────────────────────── tidymodels 0.1.2 ──
#> ✓ broom     0.7.2      ✓ recipes   0.1.15
#> ✓ dials     0.0.9      ✓ rsample   0.0.8 
#> ✓ dplyr     1.0.2      ✓ tibble    3.0.4 
#> ✓ ggplot2   3.3.2      ✓ tidyr     1.1.2 
#> ✓ infer     0.5.3      ✓ tune      0.1.2 
#> ✓ modeldata 0.1.0      ✓ workflows 0.2.1 
#> ✓ parsnip   0.1.4      ✓ yardstick 0.0.7 
#> ✓ purrr     0.3.4
#> ── Conflicts ───────────────────────────────────────── tidymodels_conflicts() ──
#> x purrr::discard() masks scales::discard()
#> x dplyr::filter()  masks stats::filter()
#> x dplyr::lag()     masks stats::lag()
#> x recipes::step()  masks stats::step()
library(tidyverse)

# Fit a GluonTS DeepAR Model
model_fit_deepar <- deep_ar(
    id                    = "id",
    freq                  = "M",
    prediction_length     = 24,
    lookback_length       = 36,
    epochs                = 10, 
    num_batches_per_epoch = 50,
    learn_rate            = 0.001,
    num_layers            = 2,
    dropout               = 0.10
) %>%
    set_engine("gluonts_deepar") %>%
    fit(value ~ ., training(m750_splits))
#> Error in rlang::env_get(get_model_env(), paste0(cls, "_modes")): argument "default" is missing, with no default

Created on 2020-12-08 by the reprex package (v0.3.0)

Session info ``` r devtools::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 3.6.0 (2019-04-26) #> os Debian GNU/Linux 9 (stretch) #> system x86_64, linux-gnu #> ui X11 #> language (EN) #> collate en_US.UTF-8 #> ctype en_US.UTF-8 #> tz Etc/UTC #> date 2020-12-08 #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date lib #> assertthat 0.2.1 2019-03-21 [1] #> backports 1.2.0 2020-11-02 [1] #> broom * 0.7.2 2020-10-20 [1] #> callr 3.5.1 2020-10-13 [1] #> cellranger 1.1.0 2016-07-27 [1] #> class 7.3-15 2019-01-01 [2] #> cli 2.2.0 2020-11-20 [1] #> codetools 0.2-16 2018-12-24 [2] #> colorspace 2.0-0 2020-11-11 [1] #> crayon 1.3.4 2017-09-16 [1] #> DBI 1.1.0 2019-12-15 [1] #> dbplyr 2.0.0 2020-11-03 [1] #> desc 1.2.0 2018-05-01 [1] #> devtools 2.3.2 2020-09-18 [1] #> dials * 0.0.9 2020-09-16 [1] #> DiceDesign 1.8-1 2019-07-31 [1] #> digest 0.6.27 2020-10-24 [1] #> dplyr * 1.0.2 2020-08-18 [1] #> ellipsis 0.3.1 2020-05-15 [1] #> evaluate 0.14 2019-05-28 [1] #> fansi 0.4.1 2020-01-08 [1] #> forcats * 0.5.0 2020-03-01 [1] #> foreach 1.5.1 2020-10-15 [1] #> fs 1.5.0 2020-07-31 [1] #> furrr 0.2.1 2020-10-21 [1] #> future 1.20.1 2020-11-03 [1] #> generics 0.1.0 2020-10-31 [1] #> ggplot2 * 3.3.2 2020-06-19 [1] #> globals 0.14.0 2020-11-22 [1] #> glue 1.4.2 2020-08-27 [1] #> gower 0.2.2 2020-06-23 [1] #> GPfit 1.0-8 2019-02-08 [1] #> gtable 0.3.0 2019-03-25 [1] #> haven 2.3.1 2020-06-01 [1] #> highr 0.8 2019-03-20 [1] #> hms 0.5.3 2020-01-08 [1] #> htmltools 0.5.0 2020-06-16 [1] #> httr 1.4.2 2020-07-20 [1] #> infer * 0.5.3 2020-07-14 [1] #> ipred 0.9-9 2019-04-28 [1] #> iterators 1.0.13 2020-10-15 [1] #> jsonlite 1.7.1 2020-09-07 [1] #> knitr 1.30 2020-09-22 [1] #> lattice 0.20-38 2018-11-04 [2] #> lava 1.6.8.1 2020-11-04 [1] #> lhs 1.1.1 2020-10-05 [1] #> lifecycle 0.2.0 2020-03-06 [1] #> listenv 0.8.0 2019-12-05 [1] #> lubridate 1.7.9.2 2020-11-13 [1] #> magrittr 2.0.1 2020-11-17 [1] #> MASS 7.3-51.4 2019-03-31 [2] #> Matrix 1.2-17 2019-03-22 [2] #> memoise 1.1.0 2017-04-21 [1] #> modeldata * 0.1.0 2020-10-22 [1] #> modelr 0.1.8 2020-05-19 [1] #> modeltime * 0.4.0.9000 2020-12-03 [1] #> modeltime.gluonts * 0.1.0.9000 2020-12-08 [1] #> munsell 0.5.0 2018-06-12 [1] #> nnet 7.3-12 2016-02-02 [2] #> parallelly 1.21.0 2020-10-27 [1] #> parsnip * 0.1.4 2020-10-27 [1] #> pillar 1.4.7 2020-11-20 [1] #> pkgbuild 1.1.0 2020-07-13 [1] #> pkgconfig 2.0.3 2019-09-22 [1] #> pkgload 1.1.0 2020-05-29 [1] #> plyr 1.8.6 2020-03-03 [1] #> prettyunits 1.1.1 2020-01-24 [1] #> pROC 1.16.2 2020-03-19 [1] #> processx 3.4.5 2020-11-30 [1] #> prodlim 2019.11.13 2019-11-17 [1] #> ps 1.5.0 2020-12-05 [1] #> purrr * 0.3.4 2020-04-17 [1] #> R6 2.5.0 2020-10-28 [1] #> Rcpp 1.0.5 2020-07-06 [1] #> RcppParallel 5.0.2 2020-06-24 [1] #> readr * 1.4.0 2020-10-05 [1] #> readxl 1.3.1 2019-03-13 [1] #> recipes * 0.1.15 2020-11-11 [1] #> remotes 2.2.0 2020-07-21 [1] #> reprex 0.3.0 2019-05-16 [1] #> reticulate 1.18 2020-10-25 [1] #> rlang 0.4.9 2020-11-26 [1] #> rmarkdown 2.5 2020-10-21 [1] #> rpart 4.1-15 2019-04-12 [2] #> rprojroot 2.0.2 2020-11-15 [1] #> rsample * 0.0.8 2020-09-23 [1] #> rstudioapi 0.13 2020-11-12 [1] #> rvest 0.3.6 2020-07-25 [1] #> scales * 1.1.1 2020-05-11 [1] #> sessioninfo 1.1.1 2018-11-05 [1] #> StanHeaders 2.21.0-6 2020-08-16 [1] #> stringi 1.5.3 2020-09-09 [1] #> stringr * 1.4.0 2019-02-10 [1] #> survival 2.44-1.1 2019-04-01 [2] #> testthat 3.0.0 2020-10-31 [1] #> tibble * 3.0.4 2020-10-12 [1] #> tidymodels * 0.1.2 2020-11-22 [1] #> tidyr * 1.1.2 2020-08-27 [1] #> tidyselect 1.1.0 2020-05-11 [1] #> tidyverse * 1.3.0 2019-11-21 [1] #> timeDate 3043.102 2018-02-21 [1] #> tune * 0.1.2 2020-11-17 [1] #> usethis 1.6.3 2020-09-17 [1] #> vctrs 0.3.5 2020-11-17 [1] #> withr 2.3.0 2020-09-22 [1] #> workflows * 0.2.1 2020-10-08 [1] #> xfun 0.19 2020-10-30 [1] #> xml2 1.3.2 2020-04-23 [1] #> yaml 2.2.1 2020-02-01 [1] #> yardstick * 0.0.7 2020-07-13 [1] #> source #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> Github (business-science/modeltime@f126665) #> Github (business-science/modeltime.gluonts@2c95409) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> #> [1] /usr/local/lib/R/site-library #> [2] /usr/local/lib/R/library ```
juliasilge commented 3 years ago

I can reproduce this problem; I think something is not quite correct with how you are registering your model in your package:

library(parsnip)
library(modeltime.gluonts)
#> Loading required package: modeltime

show_model_info("deep_ar")
#> Error: Model `deep_ar` has not been registered.

modeltime.gluonts:::make_deep_ar()
show_model_info("deep_ar")
#> Information for `deep_ar`
#>  modes: unknown, regression 
#> 
#>  engines: 
#>    regression: gluonts_deepar
#> 
#>  arguments: 
#>    gluonts_deepar: 
#>       id                      --> id
#>       freq                    --> freq
#>       prediction_length       --> prediction_length
#>       lookback_length         --> context_length
#>       epochs                  --> epochs
#>       batch_size              --> batch_size
#>       num_batches_per_epoch   --> num_batches_per_epoch
#>       learn_rate              --> learning_rate
#>       learn_rate_decay_factor --> learning_rate_decay_factor
#>       learn_rate_min          --> minimum_learning_rate
#>       patience                --> patience
#>       clip_gradient           --> clip_gradient
#>       penalty                 --> weight_decay
#>       cell_type               --> cell_type
#>       num_layers              --> num_layers
#>       num_cells               --> num_cells
#>       dropout                 --> dropout_rate
#>       scale                   --> scale_by_id
#> 
#>  fit modules:
#>            engine       mode
#>    gluonts_deepar regression
#> 
#>  prediction modules:
#>          mode         engine methods
#>    regression gluonts_deepar numeric

Created on 2020-12-08 by the reprex package (v0.3.0.9001)

Looks like make_deep_ar() is not getting executed on package load.

mdancho84 commented 3 years ago

Ah OK. He must not have installed GluonTS using modeltime.gluonts::install_gluonts(). The models are only registered if the reticulate environment is activated.

juliasilge commented 3 years ago

I also used modeltime.gluonts::install_gluonts() FWIW and that looked like it succeeded, but I still see these results.

mdancho84 commented 3 years ago

Ok this is interesting- I'll need to dig in. Thanks for your help so far.

juliasilge commented 3 years ago

You are so welcome! 🙌 Sounds like this is not a parsnip issue so we'll close.

mdancho84 commented 3 years ago

FYI - We've found a solution. The source of the issue is reticulate not finding the correct r-gluonts python environment. The solution is to override the default reticulate as discussed in the solution.

github-actions[bot] commented 3 years ago

This issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.