From 76973789c5f85031ffca4fce028d69db9609f9b8 Mon Sep 17 00:00:00 2001 From: Brock Date: Mon, 5 Aug 2024 17:02:11 +0200 Subject: [PATCH 1/6] Add testcase for Issue #765 Demonstrate inability to sample models with opencl from exe file. --- tests/testthat/test-opencl.R | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/testthat/test-opencl.R b/tests/testthat/test-opencl.R index 55c59e2c8..af58118dc 100644 --- a/tests/testthat/test-opencl.R +++ b/tests/testthat/test-opencl.R @@ -117,3 +117,13 @@ test_that("error for runtime selection of OpenCL devices if version less than 2. ) reset_cmdstan_version() }) + +test_that("model from exe_file retains open_cl option", { + skip_if_not(Sys.getenv("CMDSTANR_OPENCL_TESTS") %in% c("1", "true")) + stan_file <- testing_stan_file("bernoulli") + mod <- cmdstan_model(stan_file = stan_file, cpp_options = list(stan_opencl = TRUE)) + mod_from_exe <- cmdstan_model(exe_file = mod$exe_file()) + expect_sample_output( + fit <- mod_from_exe$sample(data = testing_data("bernoulli"), opencl_ids = c(0, 0), chains = 1) + ) +}) \ No newline at end of file From e9a03e3209209d9248c9e1cdbfed79f27f09ee7c Mon Sep 17 00:00:00 2001 From: Brock Date: Thu, 8 Aug 2024 15:08:29 +0200 Subject: [PATCH 2/6] use distinct binary for open_cl exe_file test --- tests/testthat/test-opencl.R | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-opencl.R b/tests/testthat/test-opencl.R index af58118dc..356741839 100644 --- a/tests/testthat/test-opencl.R +++ b/tests/testthat/test-opencl.R @@ -121,8 +121,9 @@ test_that("error for runtime selection of OpenCL devices if version less than 2. test_that("model from exe_file retains open_cl option", { skip_if_not(Sys.getenv("CMDSTANR_OPENCL_TESTS") %in% c("1", "true")) stan_file <- testing_stan_file("bernoulli") - mod <- cmdstan_model(stan_file = stan_file, cpp_options = list(stan_opencl = TRUE)) - mod_from_exe <- cmdstan_model(exe_file = mod$exe_file()) + exe_file <- tempfile('bernoulli-') + mod <- cmdstan_model(stan_file = stan_file, exe_file = exe_file, cpp_options = list(stan_opencl = TRUE)) + mod_from_exe <- cmdstan_model(exe_file = exe_file) expect_sample_output( fit <- mod_from_exe$sample(data = testing_data("bernoulli"), opencl_ids = c(0, 0), chains = 1) ) From 8a9229937d52c002dc0346e4cafcfa06cf3611cd Mon Sep 17 00:00:00 2001 From: Brock Date: Thu, 8 Aug 2024 15:08:59 +0200 Subject: [PATCH 3/6] Add testcase for stan_threads set in makefile --- tests/testthat/test-threads.R | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/testthat/test-threads.R b/tests/testthat/test-threads.R index 1a333e82c..8a924c930 100644 --- a/tests/testthat/test-threads.R +++ b/tests/testthat/test-threads.R @@ -178,3 +178,22 @@ test_that("correct output when stan_threads not TRUE", { fixed = TRUE ) }) + +test_that('correct output when stan threads set via make local',{ + #TODO clean this up so no leftover changes to make local + file.copy( + file.path(cmdstan_path(), 'make.local'), + file.path(cmdstan_path(), 'make.local.save') + ) + on.exit(file.rename( + file.path(cmdstan_path(), 'make.local.save'), + file.path(cmdstan_path(), 'make.local') + ), add = TRUE, after = FALSE) + cmdstan_make_local(cpp_options = list(stan_threads = TRUE)) + mod <- cmdstan_model(stan_program, force_recompile = TRUE) + expect_output( + f <- mod$sample(data = data_file_json, parallel_chains = 4, threads_per_chain = 1), + "Running MCMC with 4 parallel chains, with 1 thread(s) per chain..", + fixed = TRUE + ) +}) From d8d5e562950808420628cc0c087b5332c9f23b97 Mon Sep 17 00:00:00 2001 From: Brock Date: Thu, 8 Aug 2024 15:12:58 +0200 Subject: [PATCH 4/6] Fix Issue #765 --- R/model.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/model.R b/R/model.R index e17ffbd4c..c7391b33d 100644 --- a/R/model.R +++ b/R/model.R @@ -2399,7 +2399,7 @@ model_compile_info <- function(exe_file) { if (!is.na(as.logical(val))) { val <- as.logical(val) } - info[[toupper(key_val[1])]] <- val + info[[tolower(key_val[1])]] <- val } } info[["STAN_VERSION"]] <- paste0(info[["STAN_VERSION_MAJOR"]], ".", info[["STAN_VERSION_MINOR"]], ".", info[["STAN_VERSION_PATCH"]]) From 56d2791964c28022dc5c1b21a36acf4bc97accdb Mon Sep 17 00:00:00 2001 From: Brock Date: Thu, 8 Aug 2024 15:49:10 +0200 Subject: [PATCH 5/6] fix make local path --- tests/testthat/test-threads.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/testthat/test-threads.R b/tests/testthat/test-threads.R index 8a924c930..7bf8338f8 100644 --- a/tests/testthat/test-threads.R +++ b/tests/testthat/test-threads.R @@ -182,12 +182,12 @@ test_that("correct output when stan_threads not TRUE", { test_that('correct output when stan threads set via make local',{ #TODO clean this up so no leftover changes to make local file.copy( - file.path(cmdstan_path(), 'make.local'), - file.path(cmdstan_path(), 'make.local.save') + file.path(cmdstan_path(), 'make', 'local'), + file.path(cmdstan_path(), 'make', 'local.save') ) on.exit(file.rename( - file.path(cmdstan_path(), 'make.local.save'), - file.path(cmdstan_path(), 'make.local') + file.path(cmdstan_path(), 'make', 'local.save'), + file.path(cmdstan_path(), 'make', 'local') ), add = TRUE, after = FALSE) cmdstan_make_local(cpp_options = list(stan_threads = TRUE)) mod <- cmdstan_model(stan_program, force_recompile = TRUE) From 9fa43bb389f22a0bfe775b51faf685e4c9a1cd49 Mon Sep 17 00:00:00 2001 From: Brock Date: Thu, 8 Aug 2024 16:17:28 +0200 Subject: [PATCH 6/6] fix failing example testcase --- tests/testthat/test-example.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-example.R b/tests/testthat/test-example.R index 8d14d5d0e..157929e01 100644 --- a/tests/testthat/test-example.R +++ b/tests/testthat/test-example.R @@ -1,7 +1,7 @@ context("cmdstanr_example") test_that("cmdstanr_example works", { - fit_mcmc <- cmdstanr_example("logistic", chains = 2) + fit_mcmc <- cmdstanr_example("logistic", chains = 2, force_recompile = TRUE) checkmate::expect_r6(fit_mcmc, "CmdStanMCMC") expect_equal(fit_mcmc$num_chains(), 2)