From d67429bc9644c02502faf05d3631689c3da142ed Mon Sep 17 00:00:00 2001 From: Matt Smith Date: Fri, 8 Nov 2024 17:18:03 +0000 Subject: [PATCH 1/2] updated cancel_slurm_job to require confirmaiton. Can auto confirm with confirm = FALSE argument --- R/cancel-job.R | 47 ++++++++++++++++++++---------------- vignettes/Running-nonmem.Rmd | 2 +- vignettes/custom-alerts.Rmd | 2 +- vignettes/slack-alerts.Rmd | 2 +- 4 files changed, 29 insertions(+), 24 deletions(-) diff --git a/R/cancel-job.R b/R/cancel-job.R index 62224fd..779e0a4 100644 --- a/R/cancel-job.R +++ b/R/cancel-job.R @@ -1,7 +1,7 @@ #' Cancels a running job #' #' @param job_id job id to cancel -#' @param user optional if not the current user. +#' @param confirm requires confirmation to cancel job #' @importFrom rlang .data #' @importFrom rlang .env #' @@ -10,28 +10,19 @@ #' @examples \dontrun{ #' cancel_job(243) #' } -cancel_slurm_job <- function(job_id, user = NULL) { +cancel_slurm_job <- function(job_id, confirm = TRUE) { current_user = if (is.null(Sys.getenv("USER"))) Sys.info()['user'] else Sys.getenv("USER") - if (!is.null(user) && user != current_user) { - cat("The supplied user does not match the current user.\n") - cat(paste0("\tsupplied user: ", user, "\n\tcurrent_user: ", current_user, "\n")) - cat("You might be cancelling someone elses job.") - continue <- readline("Are you sure you want to cancel this job? (Y/n)\n") - if (continue == "Y") { - current_user <- user - } else if (tolower(continue) == "n") { - stop(paste0("Not cancelling job: ", job_id)) - } else { - stop("Please enter Y or n") - } - } - jobs <- get_slurm_jobs(user = current_user) if (!job_id %in% jobs$job_id) { - stop("Please ensure the job id is correct.") + if (job_id %in% get_slurm_jobs()$job_id) { + message("This job is associated with a different user") + } + message(paste0("Below are the available jobs for you to cancel:")) + print(get_slurm_jobs(user = current_user)) + stop(paste0("Please ensure the job id is associated your user_name: ", current_user)) } job_id_filtered <- jobs %>% dplyr::filter(.data$job_id == .env$job_id) @@ -39,9 +30,23 @@ cancel_slurm_job <- function(job_id, user = NULL) { stop(paste0("Job: ", job_id, " is not running")) } - result <- processx::run("scancel", args = c(as.character(job_id))) - if (result$status != 0) { - print(paste0("Stdout: ", result$stdout)) - print(paste0("Stderr: ", result$stderr)) + if (confirm) { + continue <- readline( + paste0("You are about to cancel job: ", job_id, ". Are you sure you want to cancel? [Y/n]\n") + ) + } else { + continue <- "Y" + } + + if (continue == "Y") { + result <- processx::run("scancel", args = c(as.character(job_id))) + if (result$status != 0) { + print(paste0("Stdout: ", result$stdout)) + print(paste0("Stderr: ", result$stderr)) + } + } else if (tolower(continue) == 'n') { + stop("Job NOT cancelled.") + } else { + stop("You must enter Y or n") } } diff --git a/vignettes/Running-nonmem.Rmd b/vignettes/Running-nonmem.Rmd index f75a368..831b149 100644 --- a/vignettes/Running-nonmem.Rmd +++ b/vignettes/Running-nonmem.Rmd @@ -254,7 +254,7 @@ jobs <- get_slurm_jobs(user = "matthews") %>% dplyr::pull(job_id) for (job in jobs) { - cancel_slurm_job(job) + cancel_slurm_job(job, confirm = FALSE) } unlink(file.path(nonmem, "1001"), recursive = TRUE) diff --git a/vignettes/custom-alerts.Rmd b/vignettes/custom-alerts.Rmd index b50320e..a041d9b 100644 --- a/vignettes/custom-alerts.Rmd +++ b/vignettes/custom-alerts.Rmd @@ -237,7 +237,7 @@ jobs <- get_slurm_jobs(user = "matthews") %>% dplyr::pull(job_id) for (job in jobs) { - cancel_slurm_job(job) + cancel_slurm_job(job, confirm = FALSE) } unlink(file.path(nonmem, "1001"), recursive = TRUE) diff --git a/vignettes/slack-alerts.Rmd b/vignettes/slack-alerts.Rmd index 1dfbe09..da7bb9b 100644 --- a/vignettes/slack-alerts.Rmd +++ b/vignettes/slack-alerts.Rmd @@ -146,7 +146,7 @@ jobs <- get_slurm_jobs(user = "matthews") %>% dplyr::pull(job_id) for (job in jobs) { - cancel_slurm_job(job) + cancel_slurm_job(job, confirm = FALSE) } unlink(file.path(nonmem, "1001"), recursive = TRUE) From 834807d3a53c6aac64966814e45f4f6a647fab9c Mon Sep 17 00:00:00 2001 From: Matt Smith Date: Fri, 8 Nov 2024 18:13:48 +0000 Subject: [PATCH 2/2] soft deprecated submit_nonmem_model and moved to submit_slurm_job. updated vignettes and other docs accordingly --- DESCRIPTION | 5 +- NAMESPACE | 2 +- R/slurmtools.R | 2 +- R/submit-model.R | 139 ++++++++++++++++++++++++++++++++++- _pkgdown.yml | 2 +- man/cancel_slurm_job.Rd | 4 +- man/slurmtools.Rd | 2 +- man/submit_nonmem_model.Rd | 3 +- man/submit_slurm_job.Rd | 43 +++++++++++ vignettes/Running-nonmem.Rmd | 37 +++++----- vignettes/custom-alerts.Rmd | 24 +++--- vignettes/slack-alerts.Rmd | 8 +- 12 files changed, 231 insertions(+), 40 deletions(-) create mode 100644 man/submit_slurm_job.Rd diff --git a/DESCRIPTION b/DESCRIPTION index 4ca9ad0..4842af2 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: slurmtools Title: slurm tooling -Version: 0.0.0.9003 +Version: 0.0.0.9004 Authors@R: c(person("Devin", "Pastoor", , "devin@a2-ai.com", role = c("aut", "cre")), person("Jenna", "Elwing", email = "jenna@a2-ai.com", role = "aut"), person("Matthew", "Smith", email = "matthews@a2-ai.com", role = "aut")) @@ -25,7 +25,8 @@ Imports: here, cli, stringi, - hms + hms, + lifecycle Suggests: knitr, rmarkdown, diff --git a/NAMESPACE b/NAMESPACE index 5275fec..5e91044 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -13,7 +13,7 @@ export(cancel_slurm_job) export(generate_nmm_config) export(get_slurm_jobs) export(get_slurm_partitions) -export(submit_nonmem_model) +export(submit_slurm_job) importFrom(brio,read_file) importFrom(brio,write_file) importFrom(dplyr,"%>%") diff --git a/R/slurmtools.R b/R/slurmtools.R index 1058adf..37fcf99 100644 --- a/R/slurmtools.R +++ b/R/slurmtools.R @@ -5,7 +5,7 @@ #' #' @section submitting jobs: #' \itemize{ -#' \item \code{\link{submit_nonmem_model}}: Submits a job to slurm +#' \item \code{\link{submit_slurm_job}}: Submits a job to slurm #' \item \code{\link{generate_nmm_config}}: Generates a NONMEMmonitor config #' file #' } diff --git a/R/submit-model.R b/R/submit-model.R index 80f75d7..ac32d01 100644 --- a/R/submit-model.R +++ b/R/submit-model.R @@ -11,7 +11,11 @@ #' @param bbi_config_path path to bbi.yaml file for bbi configuration #' @param slurm_template_opts choose slurm template #' -#' @export +#' @description +#' `r lifecycle::badge("deprecated")` +#' +#' +#' @keywords internal submit_nonmem_model <- function(.mod, partition = get_slurm_partitions(), @@ -23,7 +27,7 @@ submit_nonmem_model <- submission_root = getOption('slurmtools.submission_root'), bbi_config_path = getOption('slurmtools.bbi_config_path'), slurm_template_opts = list()) { - + lifecycle::deprecate_soft("0.1.0", "submit_nonmem_model()", "submit_slurm_job()") if (is.null(partition)) { rlang::abort("no partition selected") } @@ -127,3 +131,134 @@ submit_nonmem_model <- processx::run(cmd$cmd, cmd$args, ...) }) } + +#' submit a nonmem model to slurm in parallel +#' +#' @param .mod a path to a model or a bbi nonmem model object +#' @param partition name of the partition to submit the model +#' @param ncpu number of cpus to run the model against +#' @param overwrite whether to overwrite existing model results +#' @param dry_run return the command that would have been invoked, without invoking +#' @param ... arguments to pass to processx::run +#' @param slurm_job_template_path path to slurm job template +#' @param submission_root directory to track job submission scripts and output +#' @param bbi_config_path path to bbi.yaml file for bbi configuration +#' @param slurm_template_opts choose slurm template +#' +#' @export +submit_slurm_job <- + function(.mod, + partition = get_slurm_partitions(), + ncpu = 1, + overwrite = FALSE, + dry_run = FALSE, + ..., + slurm_job_template_path = getOption('slurmtools.slurm_job_template_path'), + submission_root = getOption('slurmtools.submission_root'), + bbi_config_path = getOption('slurmtools.bbi_config_path'), + slurm_template_opts = list()) { + + if (is.null(partition)) { + rlang::abort("no partition selected") + } + partition <- match.arg(partition) + + check_slurm_partitions(ncpu, partition) + + if (!inherits(.mod, "bbi_nonmem_model") && + !fs::file_exists(.mod)) { + stop( + "please provide a bbi_nonmem_model created via read_model/new_model, or a path to the model file" + ) + } + if (!inherits(.mod, "bbi_nonmem_model")) { + # its a file path that exists so lets convert that into the structure bbi + # provides for now + .mod <- list(absolute_model_path = fs::path_abs(.mod)) + } + parallel <- if (ncpu > 1) { + TRUE + } else { + FALSE + } + + if (!fs::file_exists(slurm_job_template_path)) { + rlang::abort(sprintf("slurm job template path not valid: `%s`", slurm_job_template_path)) + } + if (overwrite && fs::dir_exists(.mod$absolute_model_path)) { + fs::dir_delete(.mod$absolute_model_path) + } + + config_toml_path <- paste0(.mod$absolute_model_path, ".toml") + #if (!fs::file_exists(config_toml_path)) { + # rlang::warn(sprintf("config.toml file not found, if submitting the job with nmm this is required. Please run generate_nmm_config()")) + #} + + if (is.null(slurm_template_opts$nmm_exe_path)) { + nmm_exe_path <- Sys.which("nmm") + } else { + nmm_exe_path <- slurm_template_opts$nmm_exe_path + } + + if (is.null(slurm_template_opts$bbi_exe_path)) { + bbi_exe_path <- Sys.which("bbi") + } else { + bbi_exe_path <- slurm_template_opts$bbi_exe_path + } + + if (is.null(slurm_template_opts$project_path)) { + project_path <- here::here() + } else { + project_path <- slurm_template_opts$project_path + } + if (is.null(slurm_template_opts$project_name)) { + project_name <- here::here() %>% basename() + } else { + project_name <- slurm_template_opts$project_name + } + + default_template_list = list( + partition = partition, + parallel = parallel, + ncpu = ncpu, + job_name = sprintf("%s-nonmem-run", basename(.mod$absolute_model_path)), + project_path = project_path, + project_name = project_name, + bbi_exe_path = bbi_exe_path, + bbi_config_path = bbi_config_path, + model_path = .mod$absolute_model_path, + config_toml_path = config_toml_path, + nmm_exe_path = nmm_exe_path + ) + + template_list = c( + default_template_list, + slurm_template_opts) + + template_script <- + withr::with_dir(dirname(.mod$absolute_model_path), { + tmpl <- brio::read_file(slurm_job_template_path) + whisker::whisker.render( + tmpl, + template_list + ) + }) + + script_file_path <- + file.path(submission_root, sprintf("%s.sh", basename(.mod$absolute_model_path))) + if (!dry_run) { + if (!fs::dir_exists(submission_root)) { + fs::dir_create(submission_root) + } + brio::write_file(template_script, script_file_path) + fs::file_chmod(script_file_path, "0755") + } + cmd <- list(cmd = Sys.which("sbatch"), args = script_file_path, template_script = template_script, partition = partition) + if (dry_run) { + return(cmd) + } + withr::with_dir(submission_root, { + processx::run(cmd$cmd, cmd$args, ...) + }) + } + diff --git a/_pkgdown.yml b/_pkgdown.yml index 09f8f78..e3e897b 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -37,7 +37,7 @@ navbar: reference: - title: Data Processing Functions contents: - - submit_nonmem_model + - submit_slurm_job - generate_nmm_config - get_slurm_jobs - cancel_slurm_job diff --git a/man/cancel_slurm_job.Rd b/man/cancel_slurm_job.Rd index bda3359..59b9b37 100644 --- a/man/cancel_slurm_job.Rd +++ b/man/cancel_slurm_job.Rd @@ -4,12 +4,12 @@ \alias{cancel_slurm_job} \title{Cancels a running job} \usage{ -cancel_slurm_job(job_id, user = NULL) +cancel_slurm_job(job_id, confirm = TRUE) } \arguments{ \item{job_id}{job id to cancel} -\item{user}{optional if not the current user.} +\item{confirm}{requires confirmation to cancel job} } \description{ Cancels a running job diff --git a/man/slurmtools.Rd b/man/slurmtools.Rd index f16c99e..f1be983 100644 --- a/man/slurmtools.Rd +++ b/man/slurmtools.Rd @@ -12,7 +12,7 @@ on slurm. \section{submitting jobs}{ \itemize{ -\item \code{\link{submit_nonmem_model}}: Submits a job to slurm +\item \code{\link{submit_slurm_job}}: Submits a job to slurm \item \code{\link{generate_nmm_config}}: Generates a NONMEMmonitor config file } diff --git a/man/submit_nonmem_model.Rd b/man/submit_nonmem_model.Rd index e2c1f8d..e19fe65 100644 --- a/man/submit_nonmem_model.Rd +++ b/man/submit_nonmem_model.Rd @@ -39,5 +39,6 @@ submit_nonmem_model( \item{slurm_template_opts}{choose slurm template} } \description{ -submit a nonmem model to slurm in parallel +\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} } +\keyword{internal} diff --git a/man/submit_slurm_job.Rd b/man/submit_slurm_job.Rd new file mode 100644 index 0000000..eaa1e8a --- /dev/null +++ b/man/submit_slurm_job.Rd @@ -0,0 +1,43 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/submit-model.R +\name{submit_slurm_job} +\alias{submit_slurm_job} +\title{submit a nonmem model to slurm in parallel} +\usage{ +submit_slurm_job( + .mod, + partition = get_slurm_partitions(), + ncpu = 1, + overwrite = FALSE, + dry_run = FALSE, + ..., + slurm_job_template_path = getOption("slurmtools.slurm_job_template_path"), + submission_root = getOption("slurmtools.submission_root"), + bbi_config_path = getOption("slurmtools.bbi_config_path"), + slurm_template_opts = list() +) +} +\arguments{ +\item{.mod}{a path to a model or a bbi nonmem model object} + +\item{partition}{name of the partition to submit the model} + +\item{ncpu}{number of cpus to run the model against} + +\item{overwrite}{whether to overwrite existing model results} + +\item{dry_run}{return the command that would have been invoked, without invoking} + +\item{...}{arguments to pass to processx::run} + +\item{slurm_job_template_path}{path to slurm job template} + +\item{submission_root}{directory to track job submission scripts and output} + +\item{bbi_config_path}{path to bbi.yaml file for bbi configuration} + +\item{slurm_template_opts}{choose slurm template} +} +\description{ +submit a nonmem model to slurm in parallel +} diff --git a/vignettes/Running-nonmem.Rmd b/vignettes/Running-nonmem.Rmd index 831b149..1a4ba64 100644 --- a/vignettes/Running-nonmem.Rmd +++ b/vignettes/Running-nonmem.Rmd @@ -15,7 +15,7 @@ knitr::opts_chunk$set( # Slurmtools for submitting NONMEM runs -`slurmtools` is an R package for interacting with slurm (fka **S**imple **L**inux **U**tility for **R**esource **M**anagement) and submitting NONMEM jobs. You can submit a NONMEM job with `submit_nonmem_model`, you can view current jobs with `get_slurm_jobs`, and you can see the available partitions with `get_slurm_partitions`. +`slurmtools` is an R package for interacting with slurm (fka **S**imple **L**inux **U**tility for **R**esource **M**anagement) and submitting NONMEM jobs. You can submit a NONMEM job with `submit_slurm_job`, you can view current jobs with `get_slurm_jobs`, and you can see the available partitions with `get_slurm_partitions`. ## Installing `slurmtools` @@ -25,7 +25,7 @@ To install `slurmtools` use the following commands: library(slurmtools) ``` -We are given a message when loading slurmtools that some options are not set and that default job submission will not work without them. These options are used for default arguments in the `submit_nonmem_model` function. Running `?submit_nonmem_model` we can see the documentation +We are given a message when loading slurmtools that some options are not set and that default job submission will not work without them. These options are used for default arguments in the `submit_slurm_job` function. Running `?submit_slurm_job` we can see the documentation ## Default variables and values provided to the template @@ -33,13 +33,13 @@ This function uses the inputs to populate a template Bash shell script that subm By default these values are provided to the slurm template file: -- `partition` is an argument to `submit_nonmem_model` by default this will be the first element of `get_slurm_partitions()` +- `partition` is an argument to `submit_slurm_job` by default this will be the first element of `get_slurm_partitions()` - `parallel` is `TRUE` if `ncpu > 1`, else `FALSE` -- `ncpu` is an argument to `submit_nonmem_model` - your input of `ncpu` must be less than or equal to the number of cpus on the `partition` +- `ncpu` is an argument to `submit_slurm_job` - your input of `ncpu` must be less than or equal to the number of cpus on the `partition` -- `job_name` is created from the `.mod` argument supplied to `submit_nonmem_model` - default is `-nonmem-run` +- `job_name` is created from the `.mod` argument supplied to `submit_slurm_job` - default is `-nonmem-run` - `project_path` is determined from `here::here()` and should be the root of the Rproject @@ -49,9 +49,9 @@ By default these values are provided to the slurm template file: - `bbi_config_path` is determined via getOption("slurmtools.bbi_config_path") -- `model_path` is determined from the `.mod` argument supplied to `submit_nonmem_model` +- `model_path` is determined from the `.mod` argument supplied to `submit_slurm_job` -- `config_toml_path` is determined from the `.mod` argument supplied to `submit_nonmem_model` and is required to use `nmm` (NONMEM monitor) +- `config_toml_path` is determined from the `.mod` argument supplied to `submit_slurm_job` and is required to use `nmm` (NONMEM monitor) - `nmm_exe_path` is determined via `Sys.which("nmm")` @@ -89,7 +89,7 @@ Here is an example of a template file that will call `bbi`: #SBATCH --account={{project_name}} #{{project_path}} -# submit_nonmem_model uses the whisker package to populate template files +# submit_slurm_job uses the whisker package to populate template files # https://github.com/edwindj/whisker {{#parallel}} @@ -102,13 +102,13 @@ Here is an example of a template file that will call `bbi`: {{/parallel}} ``` -This file will call `bbi` to run our supplied model (`{{model_path}}.mod`) if `ncpu > 1` then parallel will be true and the code between `{{#parallel}}` and `{{/parallel}}` will be populated. if `ncpu = 1` then parallel will be false and the code between `{{^parallel}}` and `{{/parallel}}` will be populated. By default, `submit_nonmem_model` will inject `Sys.which("bbi")` into the template, so if `bbi` is not on your path we'll have to supply the `bbi_exe_path` for it to start the NONMEM run. +This file will call `bbi` to run our supplied model (`{{model_path}}.mod`) if `ncpu > 1` then parallel will be true and the code between `{{#parallel}}` and `{{/parallel}}` will be populated. if `ncpu = 1` then parallel will be false and the code between `{{^parallel}}` and `{{/parallel}}` will be populated. By default, `submit_slurm_job` will inject `Sys.which("bbi")` into the template, so if `bbi` is not on your path we'll have to supply the `bbi_exe_path` for it to start the NONMEM run. ```{r} Sys.which("bbi") ``` -We will use a few different template files with different functionality so we'll inject those template file paths to `submit_nonmem_model`. However, we'll use the `submission-log` directory for the output, so we'll set that option as well as `bbi_config_path` so `submit_nonmem_model` defaults can be used. The slurm template files are saved in `~/model/nonmem/` Additionally, there is a simple NONMEM control stream in `1001.mod` in the same directory that we can use for testing. +We will use a few different template files with different functionality so we'll inject those template file paths to `submit_slurm_job`. However, we'll use the `submission-log` directory for the output, so we'll set that option as well as `bbi_config_path` so `submit_slurm_job` defaults can be used. The slurm template files are saved in `~/model/nonmem/` Additionally, there is a simple NONMEM control stream in `1001.mod` in the same directory that we can use for testing. ```{r} library(bbr) @@ -135,7 +135,7 @@ if (file.exists(file.path(nonmem, paste0(mod_number, ".yaml")))) { We can now submit the job and point to the template file in `model/nonmem/slurm-job-bbi.tmpl`. ```{r} -submission <- slurmtools::submit_nonmem_model( +submission <- slurmtools::submit_slurm_job( mod, overwrite = TRUE, slurm_job_template_path = file.path(nonmem, "slurm-job-bbi.tmpl"), @@ -150,7 +150,7 @@ We see a `status` with an exit code of 0 suggesting a successful command, and th slurmtools::get_slurm_jobs(user = "matthews") ``` -If we look in the `slurmtools.submisstion_root` directory we can see the shell script that was generated with `submit_nonmem_model`. Here is the whisker replaced call to bbi: +If we look in the `slurmtools.submisstion_root` directory we can see the shell script that was generated with `submit_slurm_job`. Here is the whisker replaced call to bbi: ``` 1001.sh #!/bin/bash @@ -162,7 +162,7 @@ If we look in the `slurmtools.submisstion_root` directory we can see the shell s #SBATCH --account=slurmtools #/cluster-data/user-homes/matthews/Packages/slurmtools -# submit_nonmem_model uses the whisker package to populate template files +# submit_slurm_job uses the whisker package to populate template files # https://github.com/edwindj/whisker /usr/local/bin/bbi nonmem run local /cluster-data/user-homes/matthews/Packages/slurmtools/vignettes/model/nonmem/1001.mod --config /cluster-data/user-homes/matthews/Packages/slurmtools/vignettes/model/nonmem/bbi.yaml @@ -174,7 +174,7 @@ Because the templates create a bash shell script there is an almost infinite num Let's add a notification feature that will send a notification when the job has started and finished. We can use [ntfy.sh](ntfy.sh) and add the necessary info to our template to achieve this. -Here is a modified template file that adds a `JOBID=$SLURM_JOBID` and some ntfy calls. To get a notification we can supply `submit_nonmem_model` with `ntfy` variable to send notifications. I'll use `ntfy = ntfy_demo` for this. +Here is a modified template file that adds a `JOBID=$SLURM_JOBID` and some ntfy calls. To get a notification we can supply `submit_slurm_job` with `ntfy` variable to send notifications. I'll use `ntfy = ntfy_demo` for this. ``` slurm-job-bbi-ntfy.tmpl #!/bin/bash @@ -187,7 +187,7 @@ Here is a modified template file that adds a `JOBID=$SLURM_JOBID` and some ntfy JOBID=$SLURM_JOBID -# submit_nonmem_model uses the whisker package to populate template files +# submit_slurm_job uses the whisker package to populate template files # https://github.com/edwindj/whisker {{#ntfy}} @@ -210,7 +210,7 @@ curl -d "Finished model run: {{job_name}} $JOBID" ntfy.sh/{{ntfy}} Since we've already run this model we will provide the `overwrite = TRUE` argument to force a new nonmem run. ```{r} -submission_ntfy <- slurmtools::submit_nonmem_model( +submission_ntfy <- slurmtools::submit_slurm_job( mod, slurm_job_template_path = file.path(nonmem, "slurm-job-bbi-ntfy.tmpl"), overwrite = TRUE, @@ -254,7 +254,10 @@ jobs <- get_slurm_jobs(user = "matthews") %>% dplyr::pull(job_id) for (job in jobs) { - cancel_slurm_job(job, confirm = FALSE) + tryCatch({ + cancel_slurm_job(job, confirm = FALSE) + }, error = function(e) {} + ) } unlink(file.path(nonmem, "1001"), recursive = TRUE) diff --git a/vignettes/custom-alerts.Rmd b/vignettes/custom-alerts.Rmd index a041d9b..b4aaf76 100644 --- a/vignettes/custom-alerts.Rmd +++ b/vignettes/custom-alerts.Rmd @@ -1,5 +1,5 @@ --- -title: "Custom-alerts" +title: "Setting up custom alerts" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{Setting up custom alerts} @@ -50,7 +50,7 @@ We can update the template file accordingly: {{nmm_exe_path}} -c {{config_toml_path}} run ``` -default, `submit_nonmem_model` will provide `nmm_exe_path` and +default, `submit_slurm_job` will provide `nmm_exe_path` and `config_toml_path` to the template. Just like with `bbi_exe_path`, `nmm_exe_path` is determined with `Sys.which("nmm")` which may or may not give you the path to the nmm binary if it is on your path or not. We @@ -105,12 +105,12 @@ watched_dir = '/cluster-data/user-homes/matthews/Packages/slurmtools/vignettes/m output_dir = '/cluster-data/user-homes/matthews/Packages/slurmtools/vignettes/model/nonmem/in_progress' ``` -We can now run `submit_nonmem_model` and get essentially the same -behavior as running with `bbi`. On linux `~/.local/bin/` will be on your -path so saving the downloaded binaries there is a good approach. +We can now run `submit_slurm_job` and get essentially the same behavior +as running with `bbi`. On linux `~/.local/bin/` will be on your path so +saving the downloaded binaries there is a good approach. ```{r} -submission_nmm <- slurmtools::submit_nonmem_model( +submission_nmm <- slurmtools::submit_slurm_job( mod, overwrite = TRUE, slurm_job_template_path = file.path(nonmem, "slurm-job-nmm.tmpl"), @@ -170,7 +170,7 @@ dig through a noisy log file. Let's update our call to `generate_nmm_config` to have `nmm` send notifications to the `NONMEMmonitor` topic on [ntfy.sh](ntfy.sh). Just -like how `submit_nonmem_model` can feed additional information to the +like how `submit_slurm_job` can feed additional information to the template with `slurm_template_opts`, we can add an alerter feature to nmm with `alerter_opts`. If we go to ntfy.sh we can see that to send a message to ntfy we can run @@ -205,13 +205,13 @@ command = 'ntfy.sh/NONMEMmonitor' message_flag = 'd' ``` -When we re-run the `submit_nonmem_model` call we will now get ntfy +When we re-run the `submit_slurm_job` call we will now get ntfy notifications. One thing to note is that `nmm` will print full paths in the log, but will only send notifications with the `model_number` (or `model_number.file_extension`). ```{r} -submission_nmm <- slurmtools::submit_nonmem_model( +submission_nmm <- slurmtools::submit_slurm_job( mod, overwrite = TRUE, slurm_job_template_path = file.path(nonmem, "slurm-job-nmm.tmpl"), @@ -237,9 +237,13 @@ jobs <- get_slurm_jobs(user = "matthews") %>% dplyr::pull(job_id) for (job in jobs) { - cancel_slurm_job(job, confirm = FALSE) + tryCatch({ + cancel_slurm_job(job, confirm = FALSE) + }, error = function(e) {} + ) } + unlink(file.path(nonmem, "1001"), recursive = TRUE) unlink(file.path(nonmem, "1001.yaml")) unlink(file.path(nonmem, "1001.toml")) diff --git a/vignettes/slack-alerts.Rmd b/vignettes/slack-alerts.Rmd index da7bb9b..dd1924e 100644 --- a/vignettes/slack-alerts.Rmd +++ b/vignettes/slack-alerts.Rmd @@ -121,7 +121,7 @@ in the .ext file and gives another message about any parameters that hit 0 gradient. ```{r} -submission_nmm <- slurmtools::submit_nonmem_model( +submission_nmm <- slurmtools::submit_slurm_job( mod, overwrite = TRUE, slurm_job_template_path = file.path(nonmem, "slurm-job-nmm.tmpl"), @@ -146,9 +146,13 @@ jobs <- get_slurm_jobs(user = "matthews") %>% dplyr::pull(job_id) for (job in jobs) { - cancel_slurm_job(job, confirm = FALSE) + tryCatch({ + cancel_slurm_job(job, confirm = FALSE) + }, error = function(e) {} + ) } + unlink(file.path(nonmem, "1001"), recursive = TRUE) unlink(file.path(nonmem, "1001.yaml")) unlink(file.path(nonmem, "1001.toml"))