greta-dev / greta

simple and scalable statistical modelling in R
https://greta-stats.org
Other
518 stars 63 forks source link

`mcmc` failed in R 4.3.3 #618

Closed yangchino1 closed 4 months ago

yangchino1 commented 4 months ago

Hi, mcmc() failed simply after upgrading R to the lastest version, even if the conda environment and the greta package was also reinstalled. This occurred in both the TF1 and TF2 branches, on all the three platforms. E.g., TF1 branch on Windows 11,

library(greta)
#> 
#> Attaching package: 'greta'
#> The following objects are masked from 'package:stats':
#> 
#>     binomial, cov2cor, poisson
#> The following objects are masked from 'package:base':
#> 
#>     %*%, apply, backsolve, beta, chol2inv, colMeans, colSums, diag,
#>     eigen, forwardsolve, gamma, identity, rowMeans, rowSums, sweep,
#>     tapply
greta_sitrep()
#> ℹ checking if python available
#> ✔ python (version 3.7) available
#> 
#> ℹ checking if TensorFlow available
#> ✔ TensorFlow (version 1.14.0) available
#> 
#> ℹ checking if TensorFlow Probability available
#> ✔ TensorFlow Probability (version 0.7.0) available
#> 
#> ℹ checking if greta conda environment available
#> ✔ greta conda environment available
#> 
#> ℹ Initialising python and checking dependencies, this may take a moment.
#> ✔ Initialising python and checking dependencies ... done!
#> 
#> ℹ greta is ready to use!
example(mcmc,run.dontrun=T)
#> 
#> mcmc> # define a simple Bayesian model
#> mcmc> x <- rnorm(10)
#> 
#> mcmc> mu <- normal(0, 5)
#> 
#> mcmc> sigma <- lognormal(1, 0.1)
#> 
#> mcmc> distribution(x) <- normal(mu, sigma)
#> 
#> mcmc> m <- model(mu, sigma)
#> 
#> mcmc> # carry out mcmc on the model
#> mcmc> draws <- mcmc(m, n_samples = 100)
#> running 4 chains simultaneously on up to 16 cores
#> Error in eval(call("force", as.symbol(paste0("..", x)))): argument "..2" is missing, with no default
sessionInfo('greta')
#> R version 4.3.3 (2024-02-29 ucrt)
#> Platform: x86_64-w64-mingw32/x64 (64-bit)
#> Running under: Windows 11 x64 (build 22631)
#> 
#> Matrix products: default
#> 
#> 
#> locale:
#> [1] LC_COLLATE=Chinese (Simplified)_China.utf8 
#> [2] LC_CTYPE=Chinese (Simplified)_China.utf8   
#> [3] LC_MONETARY=Chinese (Simplified)_China.utf8
#> [4] LC_NUMERIC=C                               
#> [5] LC_TIME=Chinese (Simplified)_China.utf8    
#> 
#> time zone: Asia/Shanghai
#> tzcode source: internal
#> 
#> attached base packages:
#> character(0)
#> 
#> other attached packages:
#> [1] greta_0.4.4
#> 
#> loaded via a namespace (and not attached):
#>  [1] Matrix_1.6-5      jsonlite_1.8.8    compiler_4.3.3    crayon_1.5.2     
#>  [5] stats_4.3.3       reprex_2.1.0      Rcpp_1.0.12       tensorflow_2.15.0
#>  [9] parallel_4.3.3    callr_3.7.5       tfruns_1.5.2      globals_0.16.2   
#> [13] progress_1.2.3    png_0.1-8         yaml_2.3.8        fastmap_1.1.1    
#> [17] reticulate_1.35.0 lattice_0.22-5    base_4.3.3        coda_0.19-4.1    
#> [21] R6_2.5.1          knitr_1.45        datasets_4.3.3    methods_4.3.3    
#> [25] future_1.33.1     rlang_1.1.3       xfun_0.42         fs_1.6.3         
#> [29] utils_4.3.3       cli_3.6.2         magrittr_2.0.3    withr_3.0.0      
#> [33] ps_1.7.6          digest_0.6.34     grid_4.3.3        processx_3.8.3   
#> [37] rappdirs_0.3.3    base64enc_0.1-3   graphics_4.3.3    hms_1.1.3        
#> [41] lifecycle_1.0.4   prettyunits_1.2.0 vctrs_0.6.5       evaluate_0.23    
#> [45] glue_1.7.0        whisker_0.4.1     listenv_0.9.1     codetools_0.2-19 
#> [49] abind_1.4-5       parallelly_1.37.1 rmarkdown_2.26    grDevices_4.3.3  
#> [53] tools_4.3.3       pkgconfig_2.0.3   htmltools_0.5.7

TF2 branch on Ubuntu 22.04:

library(greta)
#> 
#> Attaching package: 'greta'
#> The following objects are masked from 'package:stats':
#> 
#>     binomial, cov2cor, poisson
#> The following objects are masked from 'package:base':
#> 
#>     %*%, apply, backsolve, beta, chol2inv, colMeans, colSums, diag,
#>     eigen, forwardsolve, gamma, identity, rowMeans, rowSums, sweep,
#>     tapply
greta_sitrep()
#> ℹ checking if python available
#> ✔ python (v3.11) available
#> 
#> ℹ checking if TensorFlow available
#> ✔ TensorFlow (v2.14.0) available
#> 
#> ℹ checking if TensorFlow Probability available
#> ✔ TensorFlow Probability (v0.22.1) available
#> 
#> ℹ checking if greta conda environment available
#> ✔ greta conda environment available
#> 
#> ℹ Initialising python and checking dependencies, this may take a moment.
#> ✔ Initialising python and checking dependencies ... done!
#> 
#> ℹ greta is ready to use!
example(mcmc,run.dontrun=T)
#> 
#> mcmc> # define a simple Bayesian model
#> mcmc> x <- rnorm(10)
#> 
#> mcmc> mu <- normal(0, 5)
#> 
#> mcmc> sigma <- lognormal(1, 0.1)
#> 
#> mcmc> distribution(x) <- normal(mu, sigma)
#> 
#> mcmc> m <- model(mu, sigma)
#> 
#> mcmc> # carry out mcmc on the model
#> mcmc> draws <- mcmc(m, n_samples = 100)
#> running 4 chains simultaneously on up to 16 CPU cores
#> Error in eval(call("force", as.symbol(paste0("..", x)))): argument "..2" is missing, with no default
sessionInfo('greta')
#> R version 4.3.3 (2024-02-29)
#> Platform: x86_64-pc-linux-gnu (64-bit)
#> Running under: Ubuntu 22.04.4 LTS
#> 
#> Matrix products: default
#> BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
#> LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so;  LAPACK version 3.10.0
#> 
#> locale:
#>  [1] LC_CTYPE=C.UTF-8       LC_NUMERIC=C           LC_TIME=C.UTF-8       
#>  [4] LC_COLLATE=C.UTF-8     LC_MONETARY=C.UTF-8    LC_MESSAGES=C.UTF-8   
#>  [7] LC_PAPER=C.UTF-8       LC_NAME=C              LC_ADDRESS=C          
#> [10] LC_TELEPHONE=C         LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C   
#> 
#> time zone: Asia/Shanghai
#> tzcode source: system (glibc)
#> 
#> attached base packages:
#> character(0)
#> 
#> other attached packages:
#> [1] greta_0.4.4.9000
#> 
#> loaded via a namespace (and not attached):
#>  [1] Matrix_1.6-5      jsonlite_1.8.8    compiler_4.3.3    crayon_1.5.2     
#>  [5] stats_4.3.3       reprex_2.1.0      Rcpp_1.0.12       tensorflow_2.15.0
#>  [9] parallel_4.3.3    callr_3.7.3       tfruns_1.5.2      globals_0.16.2   
#> [13] progress_1.2.3    png_0.1-7         yaml_2.3.8        fastmap_1.1.1    
#> [17] reticulate_1.35.0 lattice_0.22-5    base_4.3.3        coda_0.19-4      
#> [21] R6_2.5.1          knitr_1.45        backports_1.4.1   datasets_4.3.3   
#> [25] methods_4.3.3     future_1.33.1     rlang_1.1.3       xfun_0.41        
#> [29] fs_1.6.3          utils_4.3.3       cli_3.6.2         magrittr_2.0.3   
#> [33] withr_3.0.0       ps_1.7.6          digest_0.6.34     grid_4.3.3       
#> [37] processx_3.8.3    rappdirs_0.3.3    base64enc_0.1-3   graphics_4.3.3   
#> [41] hms_1.1.3         lifecycle_1.0.4   prettyunits_1.2.0 vctrs_0.6.5      
#> [45] tfautograph_0.3.2 evaluate_0.23     glue_1.7.0        whisker_0.4      
#> [49] listenv_0.9.1     codetools_0.2-19  abind_1.4-5       parallelly_1.36.0
#> [53] rmarkdown_2.25    grDevices_4.3.3   tools_4.3.3       pkgconfig_2.0.3  
#> [57] htmltools_0.5.7

TF2 branch on Mac M1 has the same result.

njtierney commented 4 months ago

I confirm that I get the same error:

library(greta)
#> 
#> Attaching package: 'greta'
#> The following objects are masked from 'package:stats':
#> 
#>     binomial, cov2cor, poisson
#> The following objects are masked from 'package:base':
#> 
#>     %*%, apply, backsolve, beta, chol2inv, colMeans, colSums, diag,
#>     eigen, forwardsolve, gamma, identity, rowMeans, rowSums, sweep,
#>     tapply
m <- model(normal(0,1))
#> ℹ Initialising python and checking dependencies, this may take a moment.
#> ✔ Initialising python and checking dependencies ... done!
#> 
draws <- mcmc(m, n_samples = 10, warmup = 10)
#> running 4 chains simultaneously on up to 8 CPU cores
#> Error in eval(call("force", as.symbol(paste0("..", x)))): argument "..2" is missing, with no default

Created on 2024-03-10 with reprex v2.1.0

Session info ``` r sessioninfo::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.3.3 (2024-02-29) #> os macOS Sonoma 14.3.1 #> system aarch64, darwin20 #> ui X11 #> language (EN) #> collate en_US.UTF-8 #> ctype en_US.UTF-8 #> tz Australia/Hobart #> date 2024-03-10 #> pandoc 3.1.1 @ /Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools/ (via rmarkdown) #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date (UTC) lib source #> abind 1.4-5 2016-07-21 [2] CRAN (R 4.3.0) #> backports 1.4.1 2021-12-13 [1] CRAN (R 4.3.0) #> base64enc 0.1-3 2015-07-28 [1] CRAN (R 4.3.0) #> callr 3.7.5 2024-02-19 [1] CRAN (R 4.3.1) #> cli 3.6.2 2023-12-11 [1] CRAN (R 4.3.1) #> coda 0.19-4.1 2024-01-31 [2] CRAN (R 4.3.1) #> codetools 0.2-19 2023-02-01 [2] CRAN (R 4.3.3) #> crayon 1.5.2 2022-09-29 [1] CRAN (R 4.3.0) #> digest 0.6.34 2024-01-11 [1] CRAN (R 4.3.1) #> evaluate 0.23 2023-11-01 [1] CRAN (R 4.3.1) #> fastmap 1.1.1 2023-02-24 [1] CRAN (R 4.3.0) #> fs 1.6.3 2023-07-20 [1] CRAN (R 4.3.0) #> future 1.33.1 2023-12-22 [2] CRAN (R 4.3.1) #> globals 0.16.2 2022-11-21 [2] CRAN (R 4.3.0) #> glue 1.7.0 2024-01-09 [1] CRAN (R 4.3.1) #> greta * 0.4.4.9000 2024-02-06 [2] Github (njtierney/greta@db4154e) #> hms 1.1.3 2023-03-21 [1] CRAN (R 4.3.0) #> htmltools 0.5.7 2023-11-03 [1] CRAN (R 4.3.1) #> jsonlite 1.8.8 2023-12-04 [1] CRAN (R 4.3.1) #> knitr 1.45 2023-10-30 [1] CRAN (R 4.3.1) #> lattice 0.22-5 2023-10-24 [1] CRAN (R 4.3.1) #> lifecycle 1.0.4 2023-11-07 [1] CRAN (R 4.3.1) #> listenv 0.9.1 2024-01-29 [2] CRAN (R 4.3.1) #> magrittr 2.0.3 2022-03-30 [1] CRAN (R 4.3.0) #> Matrix 1.6-5 2024-01-11 [1] CRAN (R 4.3.1) #> parallelly 1.37.0 2024-02-14 [1] CRAN (R 4.3.1) #> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.3.0) #> png 0.1-8 2022-11-29 [2] CRAN (R 4.3.0) #> prettyunits 1.2.0 2023-09-24 [1] CRAN (R 4.3.1) #> processx 3.8.3 2023-12-10 [1] CRAN (R 4.3.1) #> progress 1.2.3 2023-12-06 [1] CRAN (R 4.3.1) #> ps 1.7.6 2024-01-18 [1] CRAN (R 4.3.1) #> purrr 1.0.2 2023-08-10 [1] CRAN (R 4.3.0) #> R.cache 0.16.0 2022-07-21 [2] CRAN (R 4.3.0) #> R.methodsS3 1.8.2 2022-06-13 [2] CRAN (R 4.3.0) #> R.oo 1.26.0 2024-01-24 [2] CRAN (R 4.3.1) #> R.utils 2.12.3 2023-11-18 [2] CRAN (R 4.3.1) #> R6 2.5.1 2021-08-19 [1] CRAN (R 4.3.0) #> Rcpp 1.0.12 2024-01-09 [1] CRAN (R 4.3.1) #> reprex 2.1.0 2024-01-11 [2] CRAN (R 4.3.1) #> reticulate 1.35.0 2024-01-31 [2] CRAN (R 4.3.1) #> rlang 1.1.3 2024-01-10 [1] CRAN (R 4.3.1) #> rmarkdown 2.25 2023-09-18 [1] CRAN (R 4.3.1) #> rstudioapi 0.15.0 2023-07-07 [1] CRAN (R 4.3.0) #> sessioninfo 1.2.2 2021-12-06 [2] CRAN (R 4.3.0) #> styler 1.10.2 2023-08-29 [2] CRAN (R 4.3.0) #> tensorflow 2.15.0 2024-01-31 [2] CRAN (R 4.3.1) #> tfautograph 0.3.2 2021-09-17 [2] CRAN (R 4.3.0) #> tfruns 1.5.2 2024-01-26 [2] CRAN (R 4.3.1) #> vctrs 0.6.5 2023-12-01 [1] CRAN (R 4.3.1) #> whisker 0.4.1 2022-12-05 [2] CRAN (R 4.3.0) #> withr 3.0.0 2024-01-16 [1] CRAN (R 4.3.1) #> xfun 0.42 2024-02-08 [1] CRAN (R 4.3.1) #> yaml 2.3.8 2023-12-11 [1] CRAN (R 4.3.1) #> #> [1] /Users/nick/Library/R/arm64/4.3/library #> [2] /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library #> #> ─ Python configuration ─────────────────────────────────────────────────────── #> python: /Users/nick/Library/r-miniconda-arm64/envs/greta-env-tf2/bin/python #> libpython: /Users/nick/Library/r-miniconda-arm64/envs/greta-env-tf2/lib/libpython3.9.dylib #> pythonhome: /Users/nick/Library/r-miniconda-arm64/envs/greta-env-tf2:/Users/nick/Library/r-miniconda-arm64/envs/greta-env-tf2 #> version: 3.9.18 | packaged by conda-forge | (main, Dec 23 2023, 16:35:41) [Clang 16.0.6 ] #> numpy: /Users/nick/Library/r-miniconda-arm64/envs/greta-env-tf2/lib/python3.9/site-packages/numpy #> numpy_version: 1.26.4 #> tensorflow: /Users/nick/Library/r-miniconda-arm64/envs/greta-env-tf2/lib/python3.9/site-packages/tensorflow #> #> NOTE: Python version was forced by use_python() function #> #> ────────────────────────────────────────────────────────────────────────────── ```

This is referenced in https://github.com/tidyverse/glue/issues/320 - it is because R 4.3.3 now errors when there are trailing commas. Previously glue had let you get away with this.

Searching for references to glue I've found an example of a single trailing comma:

https://github.com/greta-dev/greta/blob/master/R/progress_bar.R#L31

Annoyingly, and thankfully so far, that seems to be the main cause of the error.

I'll push some changes this week and update greta on CRAN so we can resolve this error.

Thanks for taking the time to make this issue :)

njtierney commented 4 months ago

tf2 branch now works, and so should github master branch:

library(greta)
#> 
#> Attaching package: 'greta'
#> The following objects are masked from 'package:stats':
#> 
#>     binomial, cov2cor, poisson
#> The following objects are masked from 'package:base':
#> 
#>     %*%, apply, backsolve, beta, chol2inv, colMeans, colSums, diag,
#>     eigen, forwardsolve, gamma, identity, rowMeans, rowSums, sweep,
#>     tapply
m <- model(normal(0,1))
#> ℹ Initialising python and checking dependencies, this may take a moment.
#> ✔ Initialising python and checking dependencies ... done!
#> 
draws <- mcmc(m, n_samples = 10, warmup = 10)
#> running 4 chains simultaneously on up to 8 CPU cores
#> 
#>     warmup                                             0/10 | eta:  ?s              warmup ========================================== 10/10 | eta:  0s          
#>   sampling                                             0/10 | eta:  ?s            sampling ========================================== 10/10 | eta:  0s

Created on 2024-03-10 with reprex v2.1.0

Session info ``` r sessioninfo::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.3.3 (2024-02-29) #> os macOS Sonoma 14.3.1 #> system aarch64, darwin20 #> ui X11 #> language (EN) #> collate en_US.UTF-8 #> ctype en_US.UTF-8 #> tz Australia/Hobart #> date 2024-03-10 #> pandoc 3.1.1 @ /Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools/ (via rmarkdown) #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date (UTC) lib source #> abind 1.4-5 2016-07-21 [2] CRAN (R 4.3.0) #> backports 1.4.1 2021-12-13 [1] CRAN (R 4.3.0) #> base64enc 0.1-3 2015-07-28 [1] CRAN (R 4.3.0) #> callr 3.7.5 2024-02-19 [1] CRAN (R 4.3.1) #> cli 3.6.2 2023-12-11 [1] CRAN (R 4.3.1) #> coda 0.19-4.1 2024-01-31 [2] CRAN (R 4.3.1) #> codetools 0.2-19 2023-02-01 [2] CRAN (R 4.3.3) #> crayon 1.5.2 2022-09-29 [1] CRAN (R 4.3.0) #> digest 0.6.34 2024-01-11 [1] CRAN (R 4.3.1) #> evaluate 0.23 2023-11-01 [1] CRAN (R 4.3.1) #> fastmap 1.1.1 2023-02-24 [1] CRAN (R 4.3.0) #> fs 1.6.3 2023-07-20 [1] CRAN (R 4.3.0) #> future 1.33.1 2023-12-22 [2] CRAN (R 4.3.1) #> globals 0.16.2 2022-11-21 [2] CRAN (R 4.3.0) #> glue 1.7.0 2024-01-09 [1] CRAN (R 4.3.1) #> greta * 0.4.4.9000 2024-03-10 [1] local #> hms 1.1.3 2023-03-21 [1] CRAN (R 4.3.0) #> htmltools 0.5.7 2023-11-03 [1] CRAN (R 4.3.1) #> jsonlite 1.8.8 2023-12-04 [1] CRAN (R 4.3.1) #> knitr 1.45 2023-10-30 [1] CRAN (R 4.3.1) #> lattice 0.22-5 2023-10-24 [1] CRAN (R 4.3.1) #> lifecycle 1.0.4 2023-11-07 [1] CRAN (R 4.3.1) #> listenv 0.9.1 2024-01-29 [2] CRAN (R 4.3.1) #> magrittr 2.0.3 2022-03-30 [1] CRAN (R 4.3.0) #> Matrix 1.6-5 2024-01-11 [1] CRAN (R 4.3.1) #> parallelly 1.37.0 2024-02-14 [1] CRAN (R 4.3.1) #> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.3.0) #> png 0.1-8 2022-11-29 [2] CRAN (R 4.3.0) #> prettyunits 1.2.0 2023-09-24 [1] CRAN (R 4.3.1) #> processx 3.8.3 2023-12-10 [1] CRAN (R 4.3.1) #> progress 1.2.3 2023-12-06 [1] CRAN (R 4.3.1) #> ps 1.7.6 2024-01-18 [1] CRAN (R 4.3.1) #> purrr 1.0.2 2023-08-10 [1] CRAN (R 4.3.0) #> R.cache 0.16.0 2022-07-21 [2] CRAN (R 4.3.0) #> R.methodsS3 1.8.2 2022-06-13 [2] CRAN (R 4.3.0) #> R.oo 1.26.0 2024-01-24 [2] CRAN (R 4.3.1) #> R.utils 2.12.3 2023-11-18 [2] CRAN (R 4.3.1) #> R6 2.5.1 2021-08-19 [1] CRAN (R 4.3.0) #> Rcpp 1.0.12 2024-01-09 [1] CRAN (R 4.3.1) #> reprex 2.1.0 2024-01-11 [2] CRAN (R 4.3.1) #> reticulate 1.35.0 2024-01-31 [2] CRAN (R 4.3.1) #> rlang 1.1.3 2024-01-10 [1] CRAN (R 4.3.1) #> rmarkdown 2.25 2023-09-18 [1] CRAN (R 4.3.1) #> rstudioapi 0.15.0 2023-07-07 [1] CRAN (R 4.3.0) #> sessioninfo 1.2.2 2021-12-06 [2] CRAN (R 4.3.0) #> styler 1.10.2 2023-08-29 [2] CRAN (R 4.3.0) #> tensorflow 2.15.0 2024-01-31 [2] CRAN (R 4.3.1) #> tfautograph 0.3.2 2021-09-17 [2] CRAN (R 4.3.0) #> tfruns 1.5.2 2024-01-26 [2] CRAN (R 4.3.1) #> vctrs 0.6.5 2023-12-01 [1] CRAN (R 4.3.1) #> whisker 0.4.1 2022-12-05 [2] CRAN (R 4.3.0) #> withr 3.0.0 2024-01-16 [1] CRAN (R 4.3.1) #> xfun 0.42 2024-02-08 [1] CRAN (R 4.3.1) #> yaml 2.3.8 2023-12-11 [1] CRAN (R 4.3.1) #> #> [1] /Users/nick/Library/R/arm64/4.3/library #> [2] /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library #> #> ─ Python configuration ─────────────────────────────────────────────────────── #> python: /Users/nick/Library/r-miniconda-arm64/envs/greta-env-tf2/bin/python #> libpython: /Users/nick/Library/r-miniconda-arm64/envs/greta-env-tf2/lib/libpython3.9.dylib #> pythonhome: /Users/nick/Library/r-miniconda-arm64/envs/greta-env-tf2:/Users/nick/Library/r-miniconda-arm64/envs/greta-env-tf2 #> version: 3.9.18 | packaged by conda-forge | (main, Dec 23 2023, 16:35:41) [Clang 16.0.6 ] #> numpy: /Users/nick/Library/r-miniconda-arm64/envs/greta-env-tf2/lib/python3.9/site-packages/numpy #> numpy_version: 1.26.4 #> tensorflow: /Users/nick/Library/r-miniconda-arm64/envs/greta-env-tf2/lib/python3.9/site-packages/tensorflow #> #> NOTE: Python version was forced by use_python() function #> #> ────────────────────────────────────────────────────────────────────────────── ```