Skip to content

Commit b762c54

Browse files
authored
Merge pull request #1033 from stan-dev/error-message-fixed-param-diagnostics
Informative error message for sampler_diagnostics() with fixed_param
2 parents a9e2536 + 38a33ef commit b762c54

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

R/fit.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1616,6 +1616,9 @@ CmdStanMCMC$set("public", name = "loo", value = loo)
16161616
#' }
16171617
#'
16181618
sampler_diagnostics <- function(inc_warmup = FALSE, format = getOption("cmdstanr_draws_format", "draws_array")) {
1619+
if (isTRUE(private$metadata_$algorithm == "fixed_param")) {
1620+
stop("There are no sampler diagnostics when fixed_param = TRUE.", call. = FALSE)
1621+
}
16191622
if (is.null(private$sampler_diagnostics_) &&
16201623
!length(self$output_files(include_failed = FALSE))) {
16211624
stop("No chains finished successfully. Unable to retrieve the sampler diagnostics.", call. = FALSE)

tests/testthat/test-fit-mcmc.R

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ fit_mcmc_3 <- testing_fit("logistic", method = "sample",
1919
iter_sampling = 0,
2020
save_warmup = 1,
2121
refresh = 0, metric = "dense_e")
22+
fit_mcmc_fixed_param <- testing_fit("logistic", method = "sample",
23+
seed = 1234, chains = 1,
24+
iter_warmup = 100,
25+
iter_sampling = 0,
26+
save_warmup = 1,
27+
refresh = 0, fixed_param = TRUE)
2228
PARAM_NAMES <- c("alpha", "beta[1]", "beta[2]", "beta[3]")
2329

2430
test_that("draws() stops for unkown variables", {
@@ -399,3 +405,10 @@ test_that("metadata()$time has chains rowss", {
399405
expect_equal(nrow(fit_mcmc_2$metadata()$time), fit_mcmc_2$num_chains())
400406
expect_equal(nrow(fit_mcmc_3$metadata()$time), fit_mcmc_3$num_chains())
401407
})
408+
409+
test_that("sampler_diagnostics() throws informative error when fixed_param=TRUE", {
410+
expect_error(
411+
fit_mcmc_fixed_param$sampler_diagnostics(),
412+
"There are no sampler diagnostics when fixed_param = TRUE"
413+
)
414+
})

0 commit comments

Comments
 (0)