Skip to content

Commit 591b4ab

Browse files
authored
Merge pull request #1046 from stan-dev/no-fixed-param-error
Don't require `fixed_param` for models with zero parameters (only GQs) for CmdStan >= 2.36
2 parents 2cd3a30 + 5a9156d commit 591b4ab

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

R/csv.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ read_csv_metadata <- function(csv_file) {
719719
dense_inv_metric <- TRUE
720720
} else if (inv_metric_next) {
721721
inv_metric_split <- strsplit(gsub("# ", "", line), ",")
722-
numeric_inv_metric_split <- rapply(inv_metric_split, as.numeric)
722+
numeric_inv_metric_split <- suppressWarnings(rapply(inv_metric_split, as.numeric))
723723
if (inv_metric_rows == -1 && dense_inv_metric) {
724724
inv_metric_rows <- length(inv_metric_split[[1]])
725725
inv_metric_rows_to_read <- inv_metric_rows
@@ -786,6 +786,7 @@ read_csv_metadata <- function(csv_file) {
786786
}
787787
}
788788
if (csv_file_info$method != "diagnose" &&
789+
!isTRUE(csv_file_info$algorithm == "fixed_param") &&
789790
length(csv_file_info$sampler_diagnostics) == 0 &&
790791
length(csv_file_info$variables) == 0) {
791792
stop("Supplied CSV file does not contain any variable names or data!", call. = FALSE)

R/model.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1208,7 +1208,7 @@ sample <- function(data = NULL,
12081208
}
12091209
}
12101210

1211-
if (cmdstan_version() >= "2.27.0" && !fixed_param) {
1211+
if (cmdstan_version() >= "2.27.0" && cmdstan_version() < "2.36.0" && !fixed_param) {
12121212
if (self$has_stan_file() && file.exists(self$stan_file())) {
12131213
if (!is.null(self$variables()) && length(self$variables()$parameters) == 0) {
12141214
stop("Model contains no parameters. Please use 'fixed_param = TRUE'.", call. = FALSE)

tests/testthat/test-model-sample.R

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ test_that("seed works for multi chain sampling", {
307307
expect_false(all(chain_tdata_1 == chain_tdata_2))
308308
})
309309

310-
test_that("fixed_param is set when the model has no parameters", {
310+
test_that("Correct behavior if fixed_param not set when the model has no parameters", {
311311
code <- "
312312
model {}
313313
generated quantities {
@@ -316,10 +316,21 @@ test_that("fixed_param is set when the model has no parameters", {
316316
"
317317
stan_file <- write_stan_file(code)
318318
m <- cmdstan_model(stan_file)
319+
fake_cmdstan_version("2.35.0")
319320
expect_error(
320321
m$sample(),
321322
"Model contains no parameters. Please use 'fixed_param = TRUE'."
322323
)
324+
325+
reset_cmdstan_version()
326+
if (cmdstan_version() >= "2.36.0") {
327+
# as of 2.36.0 we don't need fixed_param if no parameters
328+
expect_no_error(
329+
utils::capture.output(
330+
fit <- m$sample(iter_warmup = 10, iter_sampling = 10, diagnostics = NULL)
331+
)
332+
)
333+
}
323334
})
324335

325336
test_that("sig_figs warning if version less than 2.25", {

0 commit comments

Comments
 (0)