-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #724 from metrumresearchgroup/slurm
Add submission mode for Slurm
- Loading branch information
Showing
9 changed files
with
361 additions
and
285 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,117 +1,158 @@ | ||
context("submit_model(.dry_run=T)") | ||
context("submit_model(.dry_run=TRUE)") | ||
|
||
################################### | ||
# testing single model submission | ||
################################### | ||
|
||
|
||
|
||
model_dir <- ABS_MODEL_DIR | ||
mod_ctl_path <- file.path(model_dir, CTL_FILENAME) | ||
|
||
# create fake bbi.yaml | ||
readr::write_file("created_by: test-submit-model", file.path(model_dir, "bbi.yaml")) | ||
on.exit({ fs::file_delete(file.path(model_dir, "bbi.yaml"))}) | ||
|
||
withr::with_options(list(bbr.bbi_exe_path = read_bbi_path()), { | ||
default_mode <- getOption("bbr.bbi_exe_mode") | ||
cmd_prefix <- paste("cd", model_dir, ";", | ||
read_bbi_path(), "nonmem", "run", | ||
default_mode) | ||
test_that("submit_model(.dry_run=T) returns correct command string [BBR-SBMT-001]", | ||
{ | ||
|
||
# correctly parsing yaml | ||
expect_identical( | ||
submit_model(MOD1, .dry_run = T)[[PROC_CALL]], | ||
as.character(glue("{cmd_prefix} {mod_ctl_path} --overwrite --threads=4 --parallel")) | ||
) | ||
|
||
# switch to local mode | ||
expect_identical( | ||
submit_model(MOD1, .mode = "local", .dry_run = T)[[PROC_CALL]], | ||
as.character(glue("cd {model_dir} ; {read_bbi_path()} nonmem run local {mod_ctl_path} --overwrite --threads=4 --parallel")) | ||
) | ||
|
||
# over-riding yaml arg with passed args | ||
expect_identical( | ||
submit_model(MOD1, | ||
.bbi_args=list( | ||
"json" = T, | ||
"threads" = 2, | ||
"nm_version" = "nm74" | ||
), | ||
.dry_run = T)[[PROC_CALL]], | ||
as.character(glue("{cmd_prefix} {mod_ctl_path} --overwrite --threads=2 --json --nm_version=nm74 --parallel")) | ||
) | ||
}) | ||
|
||
test_that("submit_model(.dry_run=T) with bbi_nonmem_model object parses correctly [BBR-SBMT-002]", | ||
{ | ||
# correctly parsing yaml | ||
expect_identical( | ||
submit_model(MOD1, .dry_run = T)[[PROC_CALL]], | ||
as.character(glue("{cmd_prefix} {mod_ctl_path} --overwrite --threads=4 --parallel")) | ||
) | ||
|
||
# over-riding yaml arg with passed arg | ||
expect_identical( | ||
submit_model(MOD1, list(threads=2), .dry_run = T)[[PROC_CALL]], | ||
as.character(glue("{cmd_prefix} {mod_ctl_path} --overwrite --threads=2 --parallel")) | ||
) | ||
}) | ||
|
||
test_that("submit_model() creates correct call for non-NULL .config_path [BBR-SBMT-003]", { | ||
|
||
temp_config <- tempfile(fileext = ".yaml") | ||
readr::write_file("foo", temp_config) | ||
temp_config <- normalizePath(temp_config) | ||
on.exit(fs::file_delete(temp_config)) | ||
|
||
res <- submit_model(MOD1, .config_path = temp_config, .dry_run = TRUE) | ||
expect_identical( | ||
res[[PROC_CALL]], | ||
as.character( | ||
glue::glue( | ||
"{cmd_prefix} {mod_ctl_path} --overwrite --threads=4 --parallel", | ||
"--config={temp_config}", | ||
.sep = " " | ||
) | ||
on.exit(fs::file_delete(file.path(model_dir, "bbi.yaml"))) | ||
|
||
default_mode <- getOption("bbr.bbi_exe_mode") | ||
cmd_prefix <- paste("cd", model_dir, ";", read_bbi_path(), "nonmem", "run") | ||
|
||
withr::local_options(list( | ||
bbr.bbi_exe_path = read_bbi_path(), | ||
bbr.DEV_skip_system_mode_checks = TRUE | ||
)) | ||
|
||
test_that("submit_model(.dry_run=TRUE) returns correct command string", { | ||
# correctly parsing yaml | ||
expect_identical( | ||
submit_model(MOD1, .dry_run = TRUE)[[PROC_CALL]], | ||
as.character(glue("{cmd_prefix} {default_mode} {mod_ctl_path} --overwrite --threads=4 --parallel")) | ||
) | ||
|
||
# over-riding yaml arg with passed args | ||
expect_identical( | ||
submit_model(MOD1, | ||
.bbi_args = list( | ||
"json" = TRUE, | ||
"threads" = 2, | ||
"nm_version" = "nm74" | ||
), | ||
.dry_run = TRUE | ||
)[[PROC_CALL]], | ||
as.character(glue("{cmd_prefix} {default_mode} {mod_ctl_path} --overwrite --threads=2 --json --nm_version=nm74 --parallel")) | ||
) | ||
}) | ||
|
||
test_that("submit_model(.dry_run=TRUE) with bbi_nonmem_model object parses correctly", { | ||
# correctly parsing yaml | ||
expect_identical( | ||
submit_model(MOD1, .dry_run = TRUE)[[PROC_CALL]], | ||
as.character(glue("{cmd_prefix} {default_mode} {mod_ctl_path} --overwrite --threads=4 --parallel")) | ||
) | ||
|
||
# over-riding yaml arg with passed arg | ||
expect_identical( | ||
submit_model(MOD1, list(threads = 2), .dry_run = TRUE)[[PROC_CALL]], | ||
as.character(glue("{cmd_prefix} {default_mode} {mod_ctl_path} --overwrite --threads=2 --parallel")) | ||
) | ||
}) | ||
|
||
test_that("submit_model() creates correct call for non-NULL .config_path", { | ||
temp_config <- tempfile(fileext = ".yaml") | ||
readr::write_file("foo", temp_config) | ||
temp_config <- normalizePath(temp_config) | ||
on.exit(fs::file_delete(temp_config)) | ||
|
||
res <- submit_model(MOD1, .config_path = temp_config, .dry_run = TRUE) | ||
expect_identical( | ||
res[[PROC_CALL]], | ||
as.character( | ||
glue( | ||
"{cmd_prefix} {default_mode} {mod_ctl_path} --overwrite --threads=4 --parallel", | ||
"--config={temp_config}", | ||
.sep = " " | ||
) | ||
) | ||
}) | ||
) | ||
}) | ||
|
||
test_that("submit_model() throws an error if passed `output_dir` bbi arg [BBR-SBMT-004]", { | ||
expect_error( | ||
submit_model(MOD1, .bbi_args = list(output_dir = "foo")), | ||
"is not a valid argument" | ||
) | ||
}) | ||
test_that("submit_model() throws an error if passed `output_dir` bbi arg", { | ||
expect_error( | ||
submit_model(MOD1, .bbi_args = list(output_dir = "foo")), | ||
"is not a valid argument" | ||
) | ||
}) | ||
|
||
test_that("submit_model(.mode) inherits option [BBR-SBMT-005]", { | ||
other_mode <- switch(default_mode, sge = "local", "sge") | ||
withr::with_options(list(bbr.bbi_exe_mode = other_mode), { | ||
expect_identical( | ||
submit_model(MOD1, .dry_run = T)[[PROC_CALL]], | ||
as.character(glue("cd {model_dir} ; {read_bbi_path()} nonmem run {other_mode} {mod_ctl_path} --overwrite --threads=4 --parallel")) | ||
) | ||
}) | ||
}) | ||
test_that("submit_model() .mode argument overrides bbr.bbi_exe_mode default", { | ||
other_mode <- if (identical(default_mode, "local")) "slurm" else "local" | ||
expect_identical( | ||
submit_model(MOD1, .mode = other_mode, .dry_run = TRUE)[[PROC_CALL]], | ||
as.character(glue("{cmd_prefix} {other_mode} {mod_ctl_path} --overwrite --threads=4 --parallel")) | ||
) | ||
}) | ||
|
||
test_that("submit_model(.mode) errors when NULL [BBR-SBMT-006]", { | ||
withr::with_options(list(bbr.bbi_exe_mode = NULL), { | ||
expect_error( | ||
submit_model(MOD1, .dry_run = T), | ||
regexp = "Nothing was passed.+mode" | ||
) | ||
}) | ||
test_that("submit_model(.mode) inherits option", { | ||
other_mode <- if (identical(default_mode, "local")) "slurm" else "local" | ||
withr::with_options(list(bbr.bbi_exe_mode = other_mode), { | ||
expect_identical( | ||
submit_model(MOD1, .dry_run = TRUE)[[PROC_CALL]], | ||
as.character(glue("{cmd_prefix} {other_mode} {mod_ctl_path} --overwrite --threads=4 --parallel")) | ||
) | ||
}) | ||
}) | ||
|
||
test_that("submit_model(.mode) errors when invalid [BBR-SBMT-007]", { | ||
test_that("submit_model(.mode) errors when NULL", { | ||
withr::with_options(list(bbr.bbi_exe_mode = NULL), { | ||
expect_error( | ||
submit_model(MOD1, .dry_run = T, .mode = "naw"), | ||
regexp = "Invalid value passed.+mode" | ||
submit_model(MOD1, .dry_run = TRUE), | ||
regexp = "Nothing was passed.+mode" | ||
) | ||
}) | ||
}) | ||
|
||
test_that("submit_model(.mode) errors when invalid", { | ||
expect_error( | ||
submit_model(MOD1, .dry_run = TRUE, .mode = "naw"), | ||
regexp = "Invalid value passed.+mode" | ||
) | ||
}) | ||
|
||
test_that("submit_model aborts if .mode='sge' is used with Slurm's qsub", { | ||
skip_if_old_bbi("3.4.0") | ||
|
||
sbatch <- unname(Sys.which("sbatch")) | ||
if (identical(sbatch, "") || identical(Sys.getenv("METWORX_VERSION"), "")) { | ||
skip("not on Metworx with Slurm") | ||
} | ||
|
||
withr::local_options(list(bbr.DEV_skip_system_mode_checks = FALSE)) | ||
|
||
expect_error( | ||
submit_model(MOD1, .dry_run = TRUE, .mode = "sge"), | ||
regexp = "Slurm shim" | ||
) | ||
}) | ||
|
||
test_that("submit_model aborts if .mode='sge' and qsub is not available", { | ||
if (!identical(unname(Sys.which("qsub")), "")) { | ||
skip("qsub is available") | ||
} | ||
|
||
withr::local_options(list(bbr.DEV_skip_system_mode_checks = FALSE)) | ||
|
||
expect_error( | ||
submit_model(MOD1, .dry_run = TRUE, .mode = "sge"), | ||
regexp = "qsub is not available" | ||
) | ||
}) | ||
|
||
test_that("submit_model aborts if .mode='slurm' is used with incompatible bbi", { | ||
if (test_bbi_version(read_bbi_path(), "3.4.0")) { | ||
skip("installed bbi version is compatible with Slurm") | ||
} | ||
|
||
withr::local_options(list(bbr.DEV_skip_system_mode_checks = FALSE)) | ||
|
||
expect_error( | ||
submit_model(MOD1, .dry_run = TRUE, .mode = "slurm"), | ||
regexp = "at least version 3.4.0", | ||
fixed = TRUE | ||
) | ||
}) |
Oops, something went wrong.