In his reply on the brms issue, Paul notes, “cmdstanr seems to be unable to run a model compiled in another R session”. I’m guessing this is because the original example saved the fit to a file and loaded it back in. I removed this.
Should the following work without recompiling?
library(brms)
library(cmdstanr)
data <- data.frame(y = rnorm(500))
threads <- threading(threads = 4)
compiled <- brms::brm(y ~ 1, data = data,
chains = 1, iter = 100,
backend = 'cmdstanr')
newdata <- data.frame(y = rnorm(500, mean = 10))
fit <- update(compiled, newdata = newdata,
chains = 1, iter = 1000, warmup = 500)
Session
R version 4.0.2 (2020-06-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.7
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] bayestestR_0.11.5 sjPlot_2.8.9 tidybayes_3.0.2
[4] cmdstanr_0.2.2 brms_2.16.3 Rcpp_1.0.8
Hi @Eric_Green , can you try the current brms version from GitHub? We recently found a bug in the code that determined if an update required recompilation and fixed it.
Your code shouldn’t suffer from the problem of moving exec files between sessions from what I can see.
Just to make sure, did you update to the most recent cran version or actually grab the current github master branch via remotes::install_github("paul-buerkner/brms")
Alternatively, you can check the output of brms:::needs_recompilation (without the ()) for the line out <- !is.character(exe_file) || !file.exists(exe_file) If it just says !exists(exe_file) than you don’t have the fix yet.
The problem with the sessions is that the executable model files are stored in a tmp folder that gets cleared when the rsession is closed. You can get the folder via attributes(compiled$fit)$CmdStanModel$exe_file() and see if the file actually exists. If not, it has to be recompiled.
Now it is. Might be that you didn’t reload the package when you posted earlier?
Could you try if the problem is fixed without the options("cmdstanr_write_stan_file_dir" = "cmdstanr") option now? If not, there would be something else in brms we’d have to look for.
I started a new session and ran without options("cmdstanr_write_stan_file_dir" = "cmdstanr"). I did not get the note about recompiling. Seems like the update did the trick.
There is still the problem that the exe files are removed when the session is closed. Which is a problem I ran into when using cmdstan on my local cluster. Even without closing the cluster. So it would still be cool to be able to store those files somewhere permanent.
See here for a small summary of the problem I had.