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

csv_contents$metadata$save_warmup is "true" (character), not TRUE (logical) #957

Open
dholstius opened this issue Apr 25, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@dholstius
Copy link

dholstius commented Apr 25, 2024

Summary

Update: This error does not occur with cmdstan v2.33.1.

Running cmdstan v2.34.1 (23 January 2024) and cmdstanr v0.7.1. Reprex follows.

Attempting to fit a trivial model:

library(brms)
dat <- data.frame(y = rnorm(1000))
mod <- brm(y ~ 1, data = dat, backend = "cmdstanr")

... fails with:

Error in !is.null(csv_contents$metadata$save_warmup) && csv_contents$metadata$save_warmup: invalid 'y' type in 'x && y'

Debugging with options(error = recover), it seems that csv_contents$metadata$save_warmup is "true" (character), not TRUE (logical), when we reach lines 1437-1438 of fit.R.

Reprex

library(brms)
#> Loading required package: Rcpp
#> Loading 'brms' package (version 2.21.0). Useful instructions
#> can be found by typing help('brms'). A more detailed introduction
#> to the package is available through vignette('brms_overview').
#> 
#> Attaching package: 'brms'
#> The following object is masked from 'package:stats':
#> 
#>     ar
dat <- data.frame(y = rnorm(1000))
mod <- brm(y ~ 1, data = dat, backend = "cmdstanr")
#> Start sampling
#> Running MCMC with 4 sequential chains...
#> 
#> Chain 1 Iteration:    1 / 2000 [  0%]  (Warmup) 
#> Chain 1 Iteration:  100 / 2000 [  5%]  (Warmup) 
#> Chain 1 Iteration:  200 / 2000 [ 10%]  (Warmup) 
#> Chain 1 Iteration:  300 / 2000 [ 15%]  (Warmup) 
#> Chain 1 Iteration:  400 / 2000 [ 20%]  (Warmup) 
#> Chain 1 Iteration:  500 / 2000 [ 25%]  (Warmup) 
#> Chain 1 Iteration:  600 / 2000 [ 30%]  (Warmup) 
#> Chain 1 Iteration:  700 / 2000 [ 35%]  (Warmup) 
#> Chain 1 Iteration:  800 / 2000 [ 40%]  (Warmup) 
#> Chain 1 Iteration:  900 / 2000 [ 45%]  (Warmup) 
#> Chain 1 Iteration: 1000 / 2000 [ 50%]  (Warmup) 
#> Chain 1 Iteration: 1001 / 2000 [ 50%]  (Sampling) 
#> Chain 1 Iteration: 1100 / 2000 [ 55%]  (Sampling) 
#> Chain 1 Iteration: 1200 / 2000 [ 60%]  (Sampling) 
#> Chain 1 Iteration: 1300 / 2000 [ 65%]  (Sampling) 
#> Chain 1 Iteration: 1400 / 2000 [ 70%]  (Sampling) 
#> Chain 1 Iteration: 1500 / 2000 [ 75%]  (Sampling) 
#> Chain 1 Iteration: 1600 / 2000 [ 80%]  (Sampling) 
#> Chain 1 Iteration: 1700 / 2000 [ 85%]  (Sampling) 
#> Chain 1 Iteration: 1800 / 2000 [ 90%]  (Sampling) 
#> Chain 1 Iteration: 1900 / 2000 [ 95%]  (Sampling) 
#> Chain 1 Iteration: 2000 / 2000 [100%]  (Sampling) 
#> Chain 1 finished in 0.1 seconds.
#> Chain 2 Iteration:    1 / 2000 [  0%]  (Warmup) 
#> Chain 2 Iteration:  100 / 2000 [  5%]  (Warmup) 
#> Chain 2 Iteration:  200 / 2000 [ 10%]  (Warmup) 
#> Chain 2 Iteration:  300 / 2000 [ 15%]  (Warmup) 
#> Chain 2 Iteration:  400 / 2000 [ 20%]  (Warmup) 
#> Chain 2 Iteration:  500 / 2000 [ 25%]  (Warmup) 
#> Chain 2 Iteration:  600 / 2000 [ 30%]  (Warmup) 
#> Chain 2 Iteration:  700 / 2000 [ 35%]  (Warmup) 
#> Chain 2 Iteration:  800 / 2000 [ 40%]  (Warmup) 
#> Chain 2 Iteration:  900 / 2000 [ 45%]  (Warmup) 
#> Chain 2 Iteration: 1000 / 2000 [ 50%]  (Warmup) 
#> Chain 2 Iteration: 1001 / 2000 [ 50%]  (Sampling) 
#> Chain 2 Iteration: 1100 / 2000 [ 55%]  (Sampling) 
#> Chain 2 Iteration: 1200 / 2000 [ 60%]  (Sampling) 
#> Chain 2 Iteration: 1300 / 2000 [ 65%]  (Sampling) 
#> Chain 2 Iteration: 1400 / 2000 [ 70%]  (Sampling) 
#> Chain 2 Iteration: 1500 / 2000 [ 75%]  (Sampling) 
#> Chain 2 Iteration: 1600 / 2000 [ 80%]  (Sampling) 
#> Chain 2 Iteration: 1700 / 2000 [ 85%]  (Sampling) 
#> Chain 2 Iteration: 1800 / 2000 [ 90%]  (Sampling) 
#> Chain 2 Iteration: 1900 / 2000 [ 95%]  (Sampling) 
#> Chain 2 Iteration: 2000 / 2000 [100%]  (Sampling) 
#> Chain 2 finished in 0.1 seconds.
#> Chain 3 Iteration:    1 / 2000 [  0%]  (Warmup) 
#> Chain 3 Iteration:  100 / 2000 [  5%]  (Warmup) 
#> Chain 3 Iteration:  200 / 2000 [ 10%]  (Warmup) 
#> Chain 3 Iteration:  300 / 2000 [ 15%]  (Warmup) 
#> Chain 3 Iteration:  400 / 2000 [ 20%]  (Warmup) 
#> Chain 3 Iteration:  500 / 2000 [ 25%]  (Warmup) 
#> Chain 3 Iteration:  600 / 2000 [ 30%]  (Warmup) 
#> Chain 3 Iteration:  700 / 2000 [ 35%]  (Warmup) 
#> Chain 3 Iteration:  800 / 2000 [ 40%]  (Warmup) 
#> Chain 3 Iteration:  900 / 2000 [ 45%]  (Warmup) 
#> Chain 3 Iteration: 1000 / 2000 [ 50%]  (Warmup) 
#> Chain 3 Iteration: 1001 / 2000 [ 50%]  (Sampling) 
#> Chain 3 Iteration: 1100 / 2000 [ 55%]  (Sampling) 
#> Chain 3 Iteration: 1200 / 2000 [ 60%]  (Sampling) 
#> Chain 3 Iteration: 1300 / 2000 [ 65%]  (Sampling) 
#> Chain 3 Iteration: 1400 / 2000 [ 70%]  (Sampling) 
#> Chain 3 Iteration: 1500 / 2000 [ 75%]  (Sampling) 
#> Chain 3 Iteration: 1600 / 2000 [ 80%]  (Sampling) 
#> Chain 3 Iteration: 1700 / 2000 [ 85%]  (Sampling) 
#> Chain 3 Iteration: 1800 / 2000 [ 90%]  (Sampling) 
#> Chain 3 Iteration: 1900 / 2000 [ 95%]  (Sampling) 
#> Chain 3 Iteration: 2000 / 2000 [100%]  (Sampling) 
#> Chain 3 finished in 0.1 seconds.
#> Chain 4 Iteration:    1 / 2000 [  0%]  (Warmup) 
#> Chain 4 Iteration:  100 / 2000 [  5%]  (Warmup) 
#> Chain 4 Iteration:  200 / 2000 [ 10%]  (Warmup) 
#> Chain 4 Iteration:  300 / 2000 [ 15%]  (Warmup) 
#> Chain 4 Iteration:  400 / 2000 [ 20%]  (Warmup) 
#> Chain 4 Iteration:  500 / 2000 [ 25%]  (Warmup) 
#> Chain 4 Iteration:  600 / 2000 [ 30%]  (Warmup) 
#> Chain 4 Iteration:  700 / 2000 [ 35%]  (Warmup) 
#> Chain 4 Iteration:  800 / 2000 [ 40%]  (Warmup) 
#> Chain 4 Iteration:  900 / 2000 [ 45%]  (Warmup) 
#> Chain 4 Iteration: 1000 / 2000 [ 50%]  (Warmup) 
#> Chain 4 Iteration: 1001 / 2000 [ 50%]  (Sampling) 
#> Chain 4 Iteration: 1100 / 2000 [ 55%]  (Sampling) 
#> Chain 4 Iteration: 1200 / 2000 [ 60%]  (Sampling) 
#> Chain 4 Iteration: 1300 / 2000 [ 65%]  (Sampling) 
#> Chain 4 Iteration: 1400 / 2000 [ 70%]  (Sampling) 
#> Chain 4 Iteration: 1500 / 2000 [ 75%]  (Sampling) 
#> Chain 4 Iteration: 1600 / 2000 [ 80%]  (Sampling) 
#> Chain 4 Iteration: 1700 / 2000 [ 85%]  (Sampling) 
#> Chain 4 Iteration: 1800 / 2000 [ 90%]  (Sampling) 
#> Chain 4 Iteration: 1900 / 2000 [ 95%]  (Sampling) 
#> Chain 4 Iteration: 2000 / 2000 [100%]  (Sampling) 
#> Chain 4 finished in 0.1 seconds.
#> 
#> All 4 chains finished successfully.
#> Mean chain execution time: 0.1 seconds.
#> Total execution time: 1.0 seconds.
#> Error in !is.null(csv_contents$metadata$save_warmup) && csv_contents$metadata$save_warmup: invalid 'y' type in 'x && y'

Created on 2024-04-24 with reprex v2.0.2

Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.2.0 (2022-04-22)
#>  os       macOS 14.4.1
#>  system   aarch64, darwin20
#>  ui       X11
#>  language (EN)
#>  collate  en_US.UTF-8
#>  ctype    en_US.UTF-8
#>  tz       America/Los_Angeles
#>  date     2024-04-24
#>  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 [1] CRAN (R 4.2.0)
#>  backports        1.4.1    2021-12-13 [1] CRAN (R 4.2.0)
#>  bayesplot        1.11.1   2024-02-15 [1] CRAN (R 4.2.3)
#>  bridgesampling   1.1-2    2021-04-16 [1] CRAN (R 4.2.0)
#>  brms           * 2.21.0   2024-03-20 [1] CRAN (R 4.2.0)
#>  Brobdingnag      1.2-9    2022-10-19 [1] CRAN (R 4.2.0)
#>  checkmate        2.3.1    2023-12-04 [1] CRAN (R 4.2.3)
#>  cli              3.6.2    2023-12-11 [1] CRAN (R 4.2.3)
#>  cmdstanr         0.7.1    2024-04-24 [1] Github (stan-dev/cmdstanr@2bec769)
#>  coda             0.19-4.1 2024-01-31 [1] CRAN (R 4.2.3)
#>  codetools        0.2-18   2020-11-04 [1] CRAN (R 4.2.0)
#>  colorspace       2.1-0    2023-01-23 [1] CRAN (R 4.2.0)
#>  curl             5.2.1    2024-03-01 [1] CRAN (R 4.2.3)
#>  data.table       1.15.4   2024-03-30 [1] CRAN (R 4.2.3)
#>  digest           0.6.34   2024-01-11 [1] CRAN (R 4.2.3)
#>  distributional   0.4.0    2024-02-07 [1] CRAN (R 4.2.3)
#>  dplyr            1.1.4    2023-11-17 [1] CRAN (R 4.2.3)
#>  emmeans          1.8.9    2023-10-17 [1] CRAN (R 4.2.0)
#>  estimability     1.4.1    2022-08-05 [1] CRAN (R 4.2.0)
#>  evaluate         0.23     2023-11-01 [1] CRAN (R 4.2.0)
#>  fansi            1.0.6    2023-12-08 [1] CRAN (R 4.2.3)
#>  fastmap          1.1.1    2023-02-24 [1] CRAN (R 4.2.0)
#>  fs               1.6.3    2023-07-20 [1] CRAN (R 4.2.0)
#>  generics         0.1.3    2022-07-05 [1] CRAN (R 4.2.0)
#>  ggplot2          3.5.0    2024-02-23 [1] CRAN (R 4.2.3)
#>  glue             1.7.0    2024-01-09 [1] CRAN (R 4.2.3)
#>  gridExtra        2.3      2017-09-09 [1] CRAN (R 4.2.0)
#>  gtable           0.3.4    2023-08-21 [1] CRAN (R 4.2.0)
#>  htmltools        0.5.7    2023-11-03 [1] CRAN (R 4.2.0)
#>  inline           0.3.19   2021-05-31 [1] CRAN (R 4.2.0)
#>  jsonlite         1.8.8    2023-12-04 [1] CRAN (R 4.2.3)
#>  knitr            1.45     2023-10-30 [1] CRAN (R 4.2.0)
#>  lattice          0.20-45  2021-09-22 [1] CRAN (R 4.2.0)
#>  lifecycle        1.0.4    2023-11-07 [1] CRAN (R 4.2.0)
#>  loo              2.7.0    2024-02-24 [1] CRAN (R 4.2.3)
#>  magrittr         2.0.3    2022-03-30 [1] CRAN (R 4.2.0)
#>  Matrix           1.6-5    2024-01-11 [1] CRAN (R 4.2.3)
#>  matrixStats      1.3.0    2024-04-11 [1] CRAN (R 4.2.3)
#>  munsell          0.5.0    2018-06-12 [1] CRAN (R 4.2.0)
#>  mvtnorm          1.2-3    2023-08-25 [1] CRAN (R 4.2.0)
#>  nlme             3.1-157  2022-03-25 [1] CRAN (R 4.2.0)
#>  pillar           1.9.0    2023-03-22 [1] CRAN (R 4.2.0)
#>  pkgbuild         1.4.3    2023-12-10 [1] CRAN (R 4.2.3)
#>  pkgconfig        2.0.3    2019-09-22 [1] CRAN (R 4.2.0)
#>  posterior        1.5.0    2023-10-31 [1] CRAN (R 4.2.0)
#>  processx         3.8.4    2024-03-16 [1] CRAN (R 4.2.3)
#>  ps               1.7.6    2024-01-18 [1] CRAN (R 4.2.3)
#>  purrr            1.0.2    2023-08-10 [1] CRAN (R 4.2.0)
#>  QuickJSR         1.1.3    2024-01-31 [1] CRAN (R 4.2.3)
#>  R.cache          0.16.0   2022-07-21 [1] CRAN (R 4.2.0)
#>  R.methodsS3      1.8.2    2022-06-13 [1] CRAN (R 4.2.0)
#>  R.oo             1.25.0   2022-06-12 [1] CRAN (R 4.2.0)
#>  R.utils          2.12.0   2022-06-28 [1] CRAN (R 4.2.0)
#>  R6               2.5.1    2021-08-19 [1] CRAN (R 4.2.0)
#>  Rcpp           * 1.0.12   2024-01-09 [1] CRAN (R 4.2.0)
#>  RcppParallel     5.1.7    2023-02-27 [1] CRAN (R 4.2.0)
#>  reprex           2.0.2    2022-08-17 [1] CRAN (R 4.2.0)
#>  rlang            1.1.3    2024-01-10 [1] CRAN (R 4.2.3)
#>  rmarkdown        2.25     2023-09-18 [1] CRAN (R 4.2.0)
#>  rstan            2.32.6   2024-03-05 [1] CRAN (R 4.2.3)
#>  rstantools       2.4.0    2024-01-31 [1] CRAN (R 4.2.3)
#>  rstudioapi       0.15.0   2023-07-07 [1] CRAN (R 4.2.0)
#>  scales           1.3.0    2023-11-28 [1] CRAN (R 4.2.3)
#>  sessioninfo      1.2.2    2021-12-06 [1] CRAN (R 4.2.0)
#>  StanHeaders      2.32.6   2024-03-01 [1] CRAN (R 4.2.3)
#>  stringi          1.8.3    2023-12-11 [1] CRAN (R 4.2.3)
#>  stringr          1.5.1    2023-11-14 [1] CRAN (R 4.2.3)
#>  styler           1.7.0    2022-03-13 [1] CRAN (R 4.2.0)
#>  tensorA          0.36.2.1 2023-12-13 [1] CRAN (R 4.2.3)
#>  tibble           3.2.1    2023-03-20 [1] CRAN (R 4.2.0)
#>  tidyselect       1.2.1    2024-03-11 [1] CRAN (R 4.2.3)
#>  utf8             1.2.4    2023-10-22 [1] CRAN (R 4.2.0)
#>  V8               4.4.2    2024-02-15 [1] CRAN (R 4.2.3)
#>  vctrs            0.6.5    2023-12-01 [1] CRAN (R 4.2.3)
#>  withr            3.0.0    2024-01-16 [1] CRAN (R 4.2.3)
#>  xfun             0.41     2023-11-01 [1] CRAN (R 4.2.0)
#>  xtable           1.8-4    2019-04-21 [1] CRAN (R 4.2.0)
#>  yaml             2.3.8    2023-12-11 [1] CRAN (R 4.2.3)
#> 
#>  [1] /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library
#> 
#> ──────────────────────────────────────────────────────────────────────────────
@dholstius dholstius added the bug Something isn't working label Apr 25, 2024
@thomasgstewart
Copy link

Got the same error fitting the example in the startup guide. Like the previous commenter, I was able to verify that csv_contents$metadata$save_warmup is a character string and not a logical.

@andrjohns
Copy link
Collaborator

Got the same error fitting the example in the startup guide. Like the previous commenter, I was able to verify that csv_contents$metadata$save_warmup is a character string and not a logical.

Do you get the same error if you install cmdstanr from github?

remotes::install_github("stan-dev/cmdstanr")

I can't replicate the error locally

@BjarkeHautop
Copy link

BjarkeHautop commented Jul 17, 2024

I get the same error @andrjohns. Have attached all the code I ran from re-downloading and re-building to fitting.

install.packages("rstan") # version 2.32.6

remotes::install_github("stan-dev/cmdstanr")
library(cmdstanr)
rebuild_cmdstan()

cmdstan_version() # 2.35.0

file <- file.path(cmdstan_path(), "examples", "bernoulli", "bernoulli.stan")
mod <- cmdstan_model(file)

data_list <- list(N = 10, y = c(0,1,0,0,0,0,0,0,0,1))

fit <- mod$sample(
  data = data_list,
  seed = 123,
  chains = 4,
  parallel_chains = 4,
  refresh = 500 
)

stanfit <- rstan::read_stan_csv(fit$output_files())
# Error in if (max(save_warmup) == 0L) { : 
#  missing value where TRUE/FALSE needed
# In addition: Warning messages:
# 1: In parse_stancsv_comments(comments) : NAs introduced by coercion
# 2: In parse_stancsv_comments(comments) : NAs introduced by coercion
# 3: In parse_stancsv_comments(comments) : NAs introduced by coercion
# 4: In parse_stancsv_comments(comments) : NAs introduced by coercion

Session info

R version 4.4.1 (2024-06-14 ucrt)
Platform: x86_64-w64-mingw32/x64
Running under: Windows 11 x64 (build 22631)

Matrix products: default

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] cmdstanr_0.8.1.9000 rstan_2.32.6        StanHeaders_2.32.10

loaded via a namespace (and not attached):
 [1] tensorA_0.36.2.1     utf8_1.2.4           generics_0.1.3       magrittr_2.0.3      
 [5] grid_4.4.1           jsonlite_1.8.8       processx_3.8.4       pkgbuild_1.4.4      
 [9] backports_1.5.0      ps_1.7.7             gridExtra_2.3        fansi_1.0.6         
[13] QuickJSR_1.3.0       scales_1.3.0         codetools_0.2-20     abind_1.4-5         
[17] cli_3.6.3            rlang_1.1.4          munsell_0.5.1        withr_3.0.0         
[21] tools_4.4.1          inline_0.3.19        parallel_4.4.1       checkmate_2.3.1     
[25] dplyr_1.1.4          colorspace_2.1-0     ggplot2_3.5.1        curl_5.2.1          
[29] vctrs_0.6.5          posterior_1.6.0      R6_2.5.1             matrixStats_1.3.0   
[33] stats4_4.4.1         lifecycle_1.0.4      V8_4.4.2             pkgconfig_2.0.3     
[37] RcppParallel_5.1.8   pillar_1.9.0         gtable_0.3.5         loo_2.8.0           
[41] glue_1.7.0           data.table_1.15.4    Rcpp_1.0.12          xfun_0.45           
[45] tibble_3.2.1         tidyselect_1.2.1     rstudioapi_0.16.0    knitr_1.48          
[49] compiler_4.4.1       distributional_0.4.0

@andrjohns
Copy link
Collaborator

That's an issue with rstan's csv parsing, not cmdstanr

@jgabry
Copy link
Member

jgabry commented Jul 18, 2024

I'm guessing it's related to this issue stan-dev/rstan#1131. There's an open PR to fix it that I'm reviewing at the moment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants