From b6b7e387261e5483f1bdfafaaa975e2f24c6567c Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Fri, 18 Nov 2022 20:35:06 +0100 Subject: Use cluster with two cores to reduce windows check time --- tests/testthat/setup_script.R | 22 +++++++++++++++------- tests/testthat/test_saemix_parent.R | 2 +- 2 files changed, 16 insertions(+), 8 deletions(-) (limited to 'tests/testthat') diff --git a/tests/testthat/setup_script.R b/tests/testthat/setup_script.R index c554800d..2448886d 100644 --- a/tests/testthat/setup_script.R +++ b/tests/testthat/setup_script.R @@ -2,17 +2,23 @@ require(mkin) require(testthat) # Per default (on my box where I set NOT_CRAN in .Rprofile) use all cores minus one +# Otherwise (CRAN check systems) use the allowed maximum of two cores if (identical(Sys.getenv("NOT_CRAN"), "true")) { n_cores <- parallel::detectCores() - 1 } else { - n_cores <- 1 + n_cores <- 2 } # Use the two available cores on travis if (Sys.getenv("TRAVIS") != "") n_cores = 2 -# On Windows we would need to make a cluster first -if (Sys.info()["sysname"] == "Windows") n_cores = 1 +# On Windows we need to make a cluster, or use one core +if (Sys.info()["sysname"] == "Windows") { + cl <- parallel::makePSOCKcluster(n_cores) + n_cores = 1 +} else { + cl <- parallel::makeForkCluster(n_cores) +} # Very simple example fits f_1_mkin_trans <- mkinfit("SFO", FOCUS_2006_A, quiet = TRUE) @@ -24,7 +30,7 @@ models <- c("SFO", "FOMC", "DFOP", "HS") fits <- suppressWarnings( # FOCUS A FOMC was, it seems, in testthat output mmkin(models, list(FOCUS_A = FOCUS_2006_A, FOCUS_C = FOCUS_2006_C, FOCUS_D = FOCUS_2006_D), - quiet = TRUE, cores = n_cores)) + quiet = TRUE, cluster = cl)) # One metabolite SFO_SFO <- mkinmod(parent = mkinsub("SFO", to = "m1"), @@ -82,13 +88,14 @@ fit_tc_1 <- mkinfit(m_synth_SFO_lin, SFO_lin_a, error_model = "tc", quiet = TRUE error_model_algorithm = "threestep") # Mixed model fits -mmkin_sfo_1 <- mmkin("SFO", ds_sfo, quiet = TRUE, error_model = "tc", cores = n_cores) -mmkin_dfop_1 <- mmkin("DFOP", ds_dfop, quiet = TRUE, cores = n_cores, +mmkin_sfo_1 <- mmkin("SFO", ds_sfo, quiet = TRUE, error_model = "tc", cluster = cl) +mmkin_dfop_1 <- mmkin("DFOP", ds_dfop, quiet = TRUE, cluster = cl, error_model = "tc") DFOP_SFO <- mkinmod(parent = mkinsub("DFOP", "m1"), m1 = mkinsub("SFO"), quiet = TRUE) -mmkin_dfop_sfo <- mmkin(list("DFOP-SFO" = DFOP_SFO), ds_dfop_sfo, quiet = TRUE, cores = n_cores, +mmkin_dfop_sfo <- mmkin(list("DFOP-SFO" = DFOP_SFO), ds_dfop_sfo, quiet = TRUE, + cluster = cl, control = list(eval.max = 500, iter.max = 400), error_model = "tc") @@ -105,3 +112,4 @@ dfop_saem_1 <- saem(mmkin_dfop_1, quiet = TRUE, transformations = "mkin", saem_dfop_sfo_m <- saem(mmkin_dfop_sfo, transformations = "mkin", quiet = TRUE) saem_dfop_sfo_s <- saem(mmkin_dfop_sfo, transformations = "saemix", quiet = TRUE) +parallel::stopCluster(cl) diff --git a/tests/testthat/test_saemix_parent.R b/tests/testthat/test_saemix_parent.R index 31605931..7fbecd0c 100644 --- a/tests/testthat/test_saemix_parent.R +++ b/tests/testthat/test_saemix_parent.R @@ -15,7 +15,7 @@ test_that("Parent fits using saemix are correctly implemented", { expect_silent(print(illparms(sfo_saem_1_reduced))) # We cannot currently do the fit with completely fixed initial values - mmkin_sfo_2 <- update(mmkin_sfo_1, fixed_initials = c(parent = 100)) + mmkin_sfo_2 <- update(mmkin_sfo_1, fixed_initials = c(parent = 100), cluster = NULL, cores = n_cores) sfo_saem_3 <- expect_error(saem(mmkin_sfo_2, quiet = TRUE), "at least two parameters") # We get an error if we do not supply a suitable model specification -- cgit v1.2.1