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

cmdstanr backend with save_warmup = TRUE: shinystan error #1257

Closed
fweber144 opened this issue Oct 31, 2021 · 4 comments
Closed

cmdstanr backend with save_warmup = TRUE: shinystan error #1257

fweber144 opened this issue Oct 31, 2021 · 4 comments
Labels
Milestone

Comments

@fweber144
Copy link
Contributor

fweber144 commented Oct 31, 2021

After fitting a model with the cmdstanr backend and save_warmup = TRUE, launching the shinystan app raises an error. I'm not sure if this is really related to brms, but that was my first guess.

Reprex:

data(bacteria, package = "MASS")
bfit <- brms::brm(
  formula = y ~ 1 + week * trt + (1 | ID),
  data = bacteria,
  family = brms::bernoulli(),
  chains = 2,
  iter = 500,
  backend = "cmdstanr",
  save_warmup = TRUE,
  seed = 1234
)
library(shinystan)
launch_shinystan(bfit)

with the last line throwing the error

Error in .validate_sampler_params(sampler_params, n_chain = ncol(X), n_iter = nrow(X),  : 
  Each matrix in 'sampler_params' must have number of rows equal to number of iterations in 'X'.

Session info:

> sessioninfo::session_info()
─ Session info ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 setting  value                       
 version  R version 4.1.1 (2021-08-10)
 os       Ubuntu 20.04.3 LTS          
 system   x86_64, linux-gnu           
 ui       RStudio                     
 language (EN)                        
 collate  en_US.UTF-8                 
 ctype    en_US.UTF-8                 
 tz       Europe/Berlin               
 date     2021-10-31                  

─ Packages ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 package        * version    date       lib source        
 abind            1.4-5      2016-07-21 [1] CRAN (R 4.0.4)
 assertthat       0.2.1      2019-03-21 [1] CRAN (R 4.0.4)
 backports        1.3.0      2021-10-27 [1] CRAN (R 4.1.1)
 base64enc        0.1-3      2015-07-28 [1] CRAN (R 4.0.4)
 bayesplot        1.8.1      2021-06-14 [1] CRAN (R 4.1.0)
 boot             1.3-28     2021-05-03 [4] CRAN (R 4.0.5)
 bridgesampling   1.1-2      2021-04-16 [1] CRAN (R 4.0.5)
 brms             2.16.1     2021-08-23 [1] CRAN (R 4.1.1)
 Brobdingnag      1.2-6      2018-08-13 [1] CRAN (R 4.0.4)
 callr            3.7.0      2021-04-20 [1] CRAN (R 4.0.5)
 checkmate        2.0.0      2020-02-06 [1] CRAN (R 4.0.4)
 cli              3.1.0      2021-10-27 [1] CRAN (R 4.1.1)
 cmdstanr         0.4.0      2021-04-16 [1] local         
 coda             0.19-4     2020-09-30 [1] CRAN (R 4.0.4)
 codetools        0.2-18     2020-11-04 [4] CRAN (R 4.0.3)
 colorspace       2.0-2      2021-06-24 [1] CRAN (R 4.1.0)
 colourpicker     1.1.1      2021-10-04 [1] CRAN (R 4.1.1)
 crayon           1.4.1      2021-02-08 [1] CRAN (R 4.0.4)
 crosstalk        1.1.1      2021-01-12 [1] CRAN (R 4.0.4)
 curl             4.3.2      2021-06-23 [1] CRAN (R 4.1.0)
 data.table       1.14.2     2021-09-27 [1] CRAN (R 4.1.1)
 DBI              1.1.1      2021-01-15 [1] CRAN (R 4.0.4)
 digest           0.6.28     2021-09-23 [1] CRAN (R 4.1.1)
 distributional   0.2.2      2021-02-02 [1] CRAN (R 4.0.4)
 dplyr            1.0.7      2021-06-18 [1] CRAN (R 4.1.0)
 DT               0.19       2021-09-02 [1] CRAN (R 4.1.1)
 dygraphs         1.1.1.6    2018-07-11 [1] CRAN (R 4.0.4)
 ellipsis         0.3.2      2021-04-29 [1] CRAN (R 4.0.5)
 emmeans          1.7.0      2021-09-29 [1] CRAN (R 4.1.1)
 estimability     1.3        2018-02-11 [1] CRAN (R 4.0.4)
 fansi            0.5.0      2021-05-25 [1] CRAN (R 4.1.0)
 farver           2.1.0      2021-02-28 [1] CRAN (R 4.0.4)
 fastmap          1.1.0      2021-01-25 [1] CRAN (R 4.0.4)
 gamm4            0.2-6      2020-04-03 [1] CRAN (R 4.0.4)
 generics         0.1.1      2021-10-25 [1] CRAN (R 4.1.1)
 ggplot2          3.3.5      2021-06-25 [1] CRAN (R 4.1.0)
 ggridges         0.5.3      2021-01-08 [1] CRAN (R 4.0.4)
 glue             1.4.2      2020-08-27 [1] CRAN (R 4.0.4)
 gridExtra        2.3        2017-09-09 [1] CRAN (R 4.0.4)
 gtable           0.3.0      2019-03-25 [1] CRAN (R 4.0.4)
 gtools           3.9.2      2021-06-06 [1] CRAN (R 4.1.0)
 htmltools        0.5.2      2021-08-25 [1] CRAN (R 4.1.1)
 htmlwidgets      1.5.4      2021-09-08 [1] CRAN (R 4.1.1)
 httpuv           1.6.3      2021-09-09 [1] CRAN (R 4.1.1)
 igraph           1.2.7      2021-10-15 [1] CRAN (R 4.1.1)
 inline           0.3.19     2021-05-31 [1] CRAN (R 4.1.0)
 jsonlite         1.7.2      2020-12-09 [1] CRAN (R 4.0.4)
 knitr            1.36       2021-09-29 [1] CRAN (R 4.1.1)
 later            1.3.0      2021-08-18 [1] CRAN (R 4.1.1)
 lattice          0.20-45    2021-09-22 [4] CRAN (R 4.1.1)
 lifecycle        1.0.1      2021-09-24 [1] CRAN (R 4.1.1)
 lme4             1.1-27.1   2021-06-22 [1] CRAN (R 4.1.0)
 loo              2.4.1      2020-12-09 [1] CRAN (R 4.1.1)
 magrittr         2.0.1      2020-11-17 [1] CRAN (R 4.0.4)
 markdown         1.1        2019-08-07 [1] CRAN (R 4.0.4)
 MASS             7.3-54     2021-05-03 [4] CRAN (R 4.0.5)
 Matrix           1.3-4      2021-06-01 [4] CRAN (R 4.1.0)
 matrixStats      0.61.0     2021-09-17 [1] CRAN (R 4.1.1)
 mgcv             1.8-38     2021-10-06 [4] CRAN (R 4.1.1)
 mime             0.12       2021-09-28 [1] CRAN (R 4.1.1)
 miniUI           0.1.1.1    2018-05-18 [1] CRAN (R 4.0.4)
 minqa            1.2.4      2014-10-09 [1] CRAN (R 4.0.4)
 multcomp         1.4-17     2021-04-29 [1] CRAN (R 4.1.0)
 munsell          0.5.0      2018-06-12 [1] CRAN (R 4.0.4)
 mvtnorm          1.1-3      2021-10-08 [1] CRAN (R 4.1.1)
 nlme             3.1-152    2021-02-04 [4] CRAN (R 4.0.3)
 nloptr           1.2.2.2    2020-07-02 [1] CRAN (R 4.0.4)
 pillar           1.6.4      2021-10-18 [1] CRAN (R 4.1.1)
 pkgbuild         1.2.0      2020-12-15 [1] CRAN (R 4.0.4)
 pkgconfig        2.0.3      2019-09-22 [1] CRAN (R 4.0.4)
 plyr             1.8.6      2020-03-03 [1] CRAN (R 4.0.4)
 posterior        1.1.0      2021-09-09 [1] CRAN (R 4.1.1)
 prettyunits      1.1.1      2020-01-24 [1] CRAN (R 4.0.4)
 processx         3.5.2      2021-04-30 [1] CRAN (R 4.0.5)
 projpred         2.0.5.9000 2021-10-22 [1] local         
 promises         1.2.0.1    2021-02-11 [1] CRAN (R 4.0.4)
 ps               1.6.0      2021-02-28 [1] CRAN (R 4.0.4)
 purrr            0.3.4      2020-04-17 [1] CRAN (R 4.0.4)
 R6               2.5.1      2021-08-19 [1] CRAN (R 4.1.1)
 Rcpp             1.0.7      2021-07-07 [1] CRAN (R 4.1.0)
 RcppParallel     5.1.4      2021-05-04 [1] CRAN (R 4.0.5)
 reshape2         1.4.4      2020-04-09 [1] CRAN (R 4.0.4)
 rlang            0.4.12     2021-10-18 [1] CRAN (R 4.1.1)
 rsconnect        0.8.24     2021-08-05 [1] CRAN (R 4.1.0)
 rstan            2.26.3     2021-08-09 [1] local         
 rstantools       2.1.1      2020-07-06 [1] CRAN (R 4.0.4)
 sandwich         3.0-1      2021-05-18 [1] CRAN (R 4.1.0)
 scales           1.1.1      2020-05-11 [1] CRAN (R 4.0.4)
 sessioninfo      1.1.1      2018-11-05 [1] CRAN (R 4.0.5)
 shiny          * 1.7.1      2021-10-02 [1] CRAN (R 4.1.1)
 shinyjs          2.0.0      2020-09-09 [1] CRAN (R 4.0.4)
 shinystan      * 2.5.0      2018-05-01 [1] CRAN (R 4.0.4)
 shinythemes      1.2.0      2021-01-25 [1] CRAN (R 4.0.4)
 StanHeaders      2.26.3     2021-08-09 [1] local         
 stringi          1.7.5      2021-10-04 [1] CRAN (R 4.1.1)
 stringr          1.4.0      2019-02-10 [1] CRAN (R 4.0.4)
 survival         3.2-13     2021-08-24 [4] CRAN (R 4.1.1)
 tensorA          0.36.2     2020-11-19 [1] CRAN (R 4.0.4)
 TH.data          1.1-0      2021-09-27 [1] CRAN (R 4.1.1)
 threejs          0.3.3      2020-01-21 [1] CRAN (R 4.0.4)
 tibble           3.1.5      2021-09-30 [1] CRAN (R 4.1.1)
 tidyselect       1.1.1      2021-04-30 [1] CRAN (R 4.0.5)
 utf8             1.2.2      2021-07-24 [1] CRAN (R 4.1.0)
 V8               3.4.2      2021-05-01 [1] CRAN (R 4.0.5)
 vctrs            0.3.8      2021-04-29 [1] CRAN (R 4.0.5)
 withr            2.4.2      2021-04-18 [1] CRAN (R 4.0.5)
 xfun             0.27       2021-10-18 [1] CRAN (R 4.1.1)
 xtable           1.8-4      2019-04-21 [1] CRAN (R 4.0.4)
 xts              0.12.1     2020-09-09 [1] CRAN (R 4.0.4)
 zoo              1.8-9      2021-03-09 [1] CRAN (R 4.0.4)

CmdStan version:

> cmdstanr::cmdstan_version()
[1] "2.28.1"

EDIT: Added CmdStan version and fixed syntax highlighting.

@fweber144 fweber144 changed the title **cmdstanr** backend with save_warmup = TRUE: **shinystan** error cmdstanr backend with save_warmup = TRUE: shinystan error Oct 31, 2021
@paul-buerkner
Copy link
Owner

I don't know what is going on there. Does the same thing happen with a manual cmdstanr fit?

@fweber144
Copy link
Contributor Author

You mean something like the following? That works for me.

library(cmdstanr)
options(mc.cores = parallel::detectCores())
sdat <- list(N = 10, y = c(0, 1, 0, 0, 0, 0, 0, 0, 0, 1))
smod <- cmdstan_model(
  stan_file = file.path(cmdstan_path(),
                        "examples",
                        "bernoulli",
                        "bernoulli.stan")
)
sfit <- smod$sample(
  data = sdat,
  refresh = 0,
  save_warmup = TRUE,
  seed = 15337L
)
# Create object of class `stanfit`:
sfit <- rstan::read_stan_csv(sfit$output_files())
library(shinystan)
launch_shinystan(sfit)

@paul-buerkner paul-buerkner added this to the brms 2.16.0++ milestone Dec 16, 2021
paul-buerkner added a commit that referenced this issue Dec 16, 2021
@paul-buerkner
Copy link
Owner

Should now be fixed.

@fweber144
Copy link
Contributor Author

Unfortunately, when running the reprex from my initial comment, I still get the same error. Does it work for you?

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

No branches or pull requests

2 participants