You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It appears that if a CmdStanFit object is created with fixed_param = TRUE and saved to disk, the retrieved object cannot load sampler diagnostics. (I'm not sure it makes sense to look at diagnostics if the MCMC did not move, but a user reported this at ropensci/stantargets#68.)
cmdstanr::cmdstan_version()
#> [1] "2.35.0"
packageVersion("cmdstanr")
#> [1] '0.8.1.9000'
packageDescription("cmdstanr")$GithubSHA1#> [1] "a9e253616511327c53de9946d816177587ad181e"callr::r(function() {
library(cmdstanr)
lines<-" data { int <lower = 1> n; vector[n] x; vector[n] y; real true_beta; } parameters { real beta; } model { y ~ normal(x * beta, 1); beta ~ normal(0, 1); } generated quantities { real beta_sim = normal_rng(0, 1); vector[n] y_sim; for (i in 1:n) { y_sim[i] = normal_rng(x[i] * beta, 1); } }"
writeLines(lines, "x.stan")
model<- cmdstan_model("x.stan")
generate_data<-function(n=10) {
true_beta<-stats::rnorm(n=1, mean=0, sd=1)
x<- seq(from=-1, to=1, length.out=n)
y<-stats::rnorm(n, x*true_beta, 1)
list(n=n, x=x, y=y, true_beta=true_beta)
}
fit<-model$sample(data= generate_data(), fixed_param=TRUE)
fit$save_object("fit.rds")
invisible()
})
#> NULLfit<- readRDS("fit.rds")
fit$sampler_diagnostics()
#> Error in read_cmdstan_csv(files = self$output_files(include_failed = FALSE), : Assertion on 'files' failed: File does not exist: '/var/folders/4v/vh7xp8553lsbl49svl48g7p00000gp/T/RtmpM4WhNk/x-202411131414-1-6d70de.csv'.
Yeah, like @mitzimorris said, there are no diagnostics in this case. I'll make a PR with a better error message and ensure the behavior is the same regardless of whether or not the object is a previously saved object. Thanks for reporting this.
It appears that if a
CmdStanFit
object is created withfixed_param = TRUE
and saved to disk, the retrieved object cannot load sampler diagnostics. (I'm not sure it makes sense to look at diagnostics if the MCMC did not move, but a user reported this at ropensci/stantargets#68.)Created on 2024-11-13 with reprex v2.1.1
Session info
The text was updated successfully, but these errors were encountered: