Skip to content

Commit 3335166

Browse files
committed
Handle stan_threads cpp option consistent with cmdstan
* mod$cpp_options() now shows options as false if unset (same as the `info` cli command). Previously, this was inconsistent: sometimes showing the user-provided arg and sometimes showing the output of `info` * tests now match expected behavior of cmdstan
1 parent 3740633 commit 3335166

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

R/model.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ compile <- function(quiet = TRUE,
738738
} # End - if(!dry_run)
739739

740740
private$exe_file_ <- exe
741-
private$cpp_options_ <- cpp_options
741+
private$cpp_options_ <- model_compile_info(exe)
742742
private$precompile_cpp_options_ <- NULL
743743
private$precompile_stanc_options_ <- NULL
744744
private$precompile_include_paths_ <- NULL

tests/testthat/test-threads.R

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,20 +158,21 @@ test_that("threading works with generate_quantities()", {
158158
expect_equal(f_gq$metadata()$threads_per_chain, 4)
159159
})
160160

161-
test_that("correct output when stan_threads not TRUE", {
162-
mod <- cmdstan_model(stan_program, cpp_options = list(stan_threads = FALSE), force_recompile = TRUE)
161+
test_that("correct output when stan_threads unset", {
162+
mod <- cmdstan_model(stan_program, cpp_options = list(stan_threads = NULL), force_recompile = TRUE)
163163
expect_output(
164164
mod$sample(data = data_file_json),
165165
"Running MCMC with 4 sequential chains",
166166
fixed = TRUE
167167
)
168168
mod <- cmdstan_model(stan_program, cpp_options = list(stan_threads = "dummy string"), force_recompile = TRUE)
169-
expect_output(
169+
expect_error(
170170
mod$sample(data = data_file_json),
171-
"Running MCMC with 4 sequential chains",
171+
"The model was compiled with 'cpp_options = list(stan_threads = TRUE)' but 'threads_per_chain' was not set!",
172172
fixed = TRUE
173173
)
174-
mod <- cmdstan_model(stan_program, cpp_options = list(stan_threads = FALSE), force_recompile = TRUE)
174+
175+
mod <- cmdstan_model(stan_program, cpp_options = list(stan_threads = NULL), force_recompile = TRUE)
175176
expect_warning(
176177
mod$sample(data = data_file_json, threads_per_chain = 4),
177178
"'threads_per_chain' is set but the model was not compiled with 'cpp_options = list(stan_threads = TRUE)' so 'threads_per_chain' will have no effect!",

0 commit comments

Comments
 (0)