Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# cmdstanr (development version)

* `pathfinder()` now respects `save_single_paths = TRUE` instead of always
passing `0` to CmdStan.
* Informative error when exposing functions using names that are reserved
keywords (@VisruthSK, #1154)
* `save_cmdstan_config` and `save_metric` default to `FALSE` but can be
Expand Down
2 changes: 1 addition & 1 deletion R/args.R
Original file line number Diff line number Diff line change
Expand Up @@ -989,7 +989,7 @@ validate_pathfinder_args <- function(self) {
checkmate::assert_integerish(self$save_single_paths, null.ok = TRUE,
lower = 0, upper = 1, len = 1)
if (!is.null(self$save_single_paths)) {
self$save_single_paths <- 0
self$save_single_paths <- as.integer(self$save_single_paths)
}
if (!is.null(self$psis_resample) && is.logical(self$psis_resample)) {
self$psis_resample <- as.integer(self$psis_resample)
Expand Down
25 changes: 25 additions & 0 deletions tests/testthat/test-model-pathfinder.R
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,31 @@ test_that("pathfinder() method runs when all arguments specified", {
expect_s3_class(fit, "CmdStanPathfinder")
})

test_that("pathfinder() saves single path outputs", {
output_dir <- withr::local_tempdir()

expect_pathfinder_output(
fit <- mod$pathfinder(
data = data_list,
output_dir = output_dir,
output_basename = "pathfinder",
seed = 123,
refresh = 0,
num_paths = 2,
single_path_draws = 10,
draws = 10,
save_single_paths = TRUE
)
)

expect_equal(basename(fit$output_files()), "pathfinder-1.csv")
single_path_files <- file.path(
output_dir,
paste0("pathfinder-1_path_", 1:2, ".csv")
)
expect_equal(file.exists(single_path_files), rep(TRUE, 2))
})

test_that("pathfinder() method runs when the stan file is removed", {
stan_file_tmp <- tempfile(pattern = "tmp", fileext = ".stan")
file.copy(stan_program, stan_file_tmp)
Expand Down
Loading