Skip to content
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

liesel model definition fails since recently #4

Closed
stefgehrig opened this issue May 6, 2024 · 2 comments · Fixed by #5
Closed

liesel model definition fails since recently #4

stefgehrig opened this issue May 6, 2024 · 2 comments · Fixed by #5

Comments

@stefgehrig
Copy link

stefgehrig commented May 6, 2024

After a while and some updating on my local Windows machine (of R, Python, their libraries, including liesel), the rliesel::liesel() function is not called successfully in two scripts where it used to work fine previously. I don't know yet whether this a weird local issue in my environment / a coding error, or indeed some general incompatability of software versions. I'd be interested in whether you can reproduce the problem.

This is the code that fails since recently:

  1. R chunk to simulate some data
library(tidyverse)
library(rliesel)
library(reticulate)
library(mgcv)

# simulate data
set.seed(123)
df <- tibble(
  center = sample(c("1", "2", "3", "4", "5"), size = 1e3, replace = TRUE),
  E_center = 2.25 + 0.05 * as.numeric(center),
  SD_center = as.numeric(center) / 20,
  bmi = rlnorm(1e3, log(25), 1/5) ,
  y = rlnorm(1e3, 0.15 * bmi - 0.00225 * bmi^2 + E_center, SD_center)
) %>% mutate(center = factor(center))
  1. R chunk to set up the model that fails:
model <- liesel(
  response = df$y,
  distribution = "LogNormal",
  predictors = list(
    loc = predictor( ~ s(bmi, bs = "ps", k = 10) + s(center, bs = "re"), inverse_link = "Identity"),
    scale = predictor( ~ s(center, bs = "re"), inverse_link = "Exp") 
  ),
  data = df
)

This is my config:

  • R:

R version 4.4.0 (2024-04-24 ucrt)
Platform: x86_64-w64-mingw32/x64
Running under: Windows 11 x64 (build 22631)
other attached packages:
[1] mgcv_1.9-1 nlme_3.1-164 reticulate_1.36.1 rliesel_0.0.1 lubridate_1.9.3 forcats_1.0.0 stringr_1.5.1 dplyr_1.1.4 purrr_1.0.2 readr_2.1.5 tidyr_1.3.1 tibble_3.2.1 ggplot2_3.5.1
[14] tidyverse_2.0.0
loaded via a namespace (and not attached):
[1] utf8_1.2.4 generics_0.1.3 xml2_1.3.6 stringi_1.8.3 lattice_0.22-6 hms_1.1.3 digest_0.6.35 magrittr_2.0.3 evaluate_0.23 grid_4.4.0 timechange_0.3.0 fastmap_1.1.1 jsonlite_1.8.8
[14] Matrix_1.7-0 fansi_1.0.6 viridisLite_0.4.2 scales_1.3.0 cli_3.6.2 rlang_1.1.3 munsell_0.5.1 splines_4.4.0 withr_3.0.0 tools_4.4.0 tzdb_0.4.0 colorspace_2.1-0 kableExtra_1.4.0
[27] png_0.1-8 vctrs_0.6.5 R6_2.5.1 lifecycle_1.0.4 pkgconfig_2.0.3 pillar_1.9.0 gtable_0.3.5 Rcpp_1.0.12 glue_1.7.0 systemfonts_1.0.6 xfun_0.43 tidyselect_1.2.1 rstudioapi_0.16.0
[40] knitr_1.46 htmltools_0.5.8.1 rmarkdown_2.26 svglite_2.1.3 compiler_4.4.0

  • Python:

jax 0.4.26
liesel 0.2.9
pandas 2.2.2
plotnine 0.13.5
tensorflow_probability 0.24.0
Python 3.12.3 (tags/v3.12.3:f6650f9, Apr 9 2024, 14:05:25) [MSC v.1938 64 bit (AMD64)]
Windows-11-10.0.22631-SP0

The messages, warnings and error I get from the last chunk are:

Installed Liesel version 0.2.9 is compatible, continuing to set up model
liesel.model.nodes - WARNING - Calc(name="") was not updated during initialization, because the following exception occured: RuntimeError('Error while updating Calc(name="").'). See debug log for the full traceback.
liesel.model.nodes - WARNING - Calc(name="") was not updated during initialization, because the following exception occured: RuntimeError('Error while updating Calc(name="").'). See debug log for the full traceback.
liesel.model.nodes - WARNING - Calc(name="_model_log_lik") was not updated during initialization, because the following exception occured: RuntimeError('Error while updating Calc(name="_model_log_lik").'). See debug log for the full traceback.
liesel.model.nodes - WARNING - Calc(name="_model_log_prior") was not updated during initialization, because the following exception occured: RuntimeError('Error while updating Calc(name="_model_log_prior").'). See debug log for the full traceback.
liesel.model.nodes - WARNING - Calc(name="_model_log_prob") was not updated during initialization, because the following exception occured: RuntimeError('Error while updating Calc(name="_model_log_prob").'). See debug log for the full traceback.
Error in py_call_impl(callable, call_args$unnamed, call_args$named) :
RuntimeError: Error while updating Calc(name="scale_value").

And the traceback is:

── Python Exception Message ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Traceback (most recent call last):
File "C:\Users\stefa\AppData\Local\Programs\Python\Python312\Lib\site-packages\liesel\model\nodes.py", line 705, in update
self._value = self.function(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\stefa\AppData\Local\Programs\Python\Python312\Lib\site-packages\liesel\model\legacy.py", line 102, in fn
return bijector().forward(x) if not inverse else bijector().inverse(x)
^^^^^^^^^^
TypeError: 'NoneType' object is not callable
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\stefa\AppData\Local\Programs\Python\Python312\Lib\site-packages\liesel\model\model.py", line 454, in build_model
model = Model(nodes_and_vars, grow=False, copy=copy)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\stefa\AppData\Local\Programs\Python\Python312\Lib\site-packages\liesel\model\model.py", line 1032, in init
node.update()
File "C:\Users\stefa\AppData\Local\Programs\Python\Python312\Lib\site-packages\liesel\model\nodes.py", line 707, in update
raise RuntimeError(f"Error while updating {self}.") from e
RuntimeError: Error while updating Calc(name="scale_value").
── R Traceback ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── 1. └─rliesel::liesel(...) 2. └─mb$build_model() 3. └─reticulate:::py_call_impl(callable, call_args$unnamed, call_args$named)

@hriebl
Copy link
Contributor

hriebl commented Jun 27, 2024

Thank you for your bug report, @stefgehrig, and sorry for the delay! The problem was caused by a reticulate update and should now be fixed. Could you confirm that things are working again for you with the latest commit from main?

@stefgehrig
Copy link
Author

Thanks @hriebl and @jobrachem !! The issues is succesfully fixed also on my end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants