Skip to content

Commit

Permalink
updated config file generating function removed the call from submit-…
Browse files Browse the repository at this point in the history
…model. Swapped around messages about setting slurmtools options.
  • Loading branch information
mduncans committed Aug 1, 2024
1 parent 1238a06 commit 01b4899
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 108 deletions.
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ Imports:
utils,
whisker,
withr,
configr,
rextendr,
here
Suggests:
Expand Down
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ export(generate_watcher_config)
export(get_slurm_jobs)
export(get_slurm_partitions)
export(submit_nonmem_model)
export(validate_toml)
importFrom(brio,read_file)
importFrom(brio,write_file)
importFrom(dplyr,"%>%")
Expand Down
59 changes: 0 additions & 59 deletions R/generate_watcher_config.R

This file was deleted.

61 changes: 61 additions & 0 deletions R/nmm-config.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#' Creates a default watcher configuration file
#'
#' @param .mod a bbi nonmem model object
#' @param model_number a string of model number e.g. 101a15. Default is pulled from .mod
#' @param files_to_track a vector of file extensions. Default is c("lst", "ext", "grd")
#' @param tmp_dir a temporary directory location to run nonmem. Default is /tmp
#' @param watched_dir the directory where nonmem will output. Default is ./model/nonmem
#' @param output_dir the directory where watcher will place log and any output files default is ./model/nonmem/in_progress
#' @param poll_duration the amount of time in seconds between the watchers polling
#' @param alert Where to send alerts if any. Default is None, available options are None or Slack
#' @param level What level to log at. Default is info. Available options are Trace, Debug, Info, Warn, Fatal
#' @param email if alert is set to Slack, this should be the email associated with slack to get messages sent directly to you.
#' @param threads number of threads if running a parallel job. Default is 1
#'
#' @return none
#' @keywords internal
#' @export
#'
#' @examples \dontrun{
#' generate_watcher_config(.mod)
#' }
generate_watcher_config <- function(
.mod,
model_number = "",
files_to_track = c("lst", "ext", "grd"),
tmp_dir = "/tmp",
watched_dir = file.path("model", "nonmem"),
output_dir = file.path(watched_dir, "in_progress"),
poll_duration = 1,
alert = "None",
level = "Debug",
email = "",
threads = 1
) {
if (model_number == "") {
model_number <- basename(.mod$absolute_model_path)
}

alert <- paste0(toupper(substring(alert, 1, 1)), substring(alert, 2))
level <- paste0(toupper(substring(level, 1, 1)), substring(level, 2))

if (alert == "Slack" && email == "") {
rlang::abort("If you want slack notifications you must also supply an email.")
}

toml <- list(
model_number = model_number,
files_to_track = files_to_track,
tmp_dir = tmp_dir,
watched_dir = file.path(here::here(), watched_dir),
output_dir = file.path(here::here(), output_dir),
poll_duration = poll_duration,
alert = alert,
level = level,
email = email,
threads = threads
)

config_toml_path <- paste0(.mod$absolute_model_path, ".toml")
write_file(rextendr::to_toml(toml), config_toml_path)
}
21 changes: 4 additions & 17 deletions R/submit-model.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,35 +55,22 @@ submit_nonmem_model <-

config_toml_path <- paste0(.mod$absolute_model_path, ".toml")
if (!fs::file_exists(config_toml_path)) {
generate_watcher_config(.mod, slurm_template_opts$watch_opts)
rlang::abort(sprintf("config.toml file not found, please run generate_config()"))
}

config <- configr::read.config(config_toml_path)
config$output_dir <- file.path(here::here(), config$output_dir)
config$watched_dir <-file.path(here::here(), config$watched_dir)

new_config_toml_path <-
file.path(
here::here(), "model", "nonmem", "submission-log",
paste0(config$model_number, ".toml")
)

write_file(rextendr::to_toml(config), new_config_toml_path)

default_template_list = list(
partition = partition,
parallel = parallel,
ncpu = ncpu,
job_name = sprintf("nonmem-run-%s", basename(.mod$absolute_model_path)),
job_name = sprintf("%s-nonmem-run", basename(.mod$absolute_model_path)),
model_path = .mod$absolute_model_path,
config_toml_path = new_config_toml_path,
config_toml_path = config_toml_path,
nmm_exe_path = Sys.which("nmm")
)

template_list = c(
default_template_list,
slurm_template_opts$alert_opts,
slurm_template_opts$watch_opts$log_level)
slurm_template_opts)

template_script <-
withr::with_dir(dirname(.mod$absolute_model_path), {
Expand Down
12 changes: 7 additions & 5 deletions R/zzz.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
.onLoad <- function(libname, pkgname) {
.onAttach <- function(libname, pkgname) {
if (is.null(getOption('slurmtools.slurm_job_template_path'))) {
rlang::warn(
"option('slurmtools.slurm_job_template_path') is not set. Please set it for job submission defaults to work."
)
# rlang::warn(
# "option('slurmtools.slurm_job_template_path') is not set. Please set it for job submission defaults to work."
# )
packageStartupMessage("option('slurmtools.slurm_job_template_path') is not set. Please set it for job submission defaults to work.")
}

if (is.null(getOption('slurmtools.submission_root'))) {
rlang::warn("option('slurmtools.submission_root') is not set. Please set it for job submission defaults to work.")
#rlang::warn("option('slurmtools.submission_root') is not set. Please set it for job submission defaults to work.")
packageStartupMessage("option('slurmtools.submission_root') is not set. Please set it for job submission defaults to work.")
}
}
36 changes: 33 additions & 3 deletions man/generate_watcher_config.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 0 additions & 22 deletions man/validate_toml.Rd

This file was deleted.

0 comments on commit 01b4899

Please sign in to comment.