Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated vignettes and added column for time in get_slurm_jobs #15

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions R/get-jobs.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@ parse_job_to_row <- function(job) {
# alter parsing based on result

if (getOption("squeue.version") > package_version("23.02.4")){
submit_time = job$submit_time$number
start_time = job$start_time$number
submit_time <- job$submit_time$number
start_time <- job$start_time$number
end_time <- job$end_time$number
### This is "hacky", it looks like for configuring model the list is 3 {"Running", "Configuring", "Power_up_node"}
if (length(job$job_state) > 1){
job_state = job$job_state[[2]]
job_state <- job$job_state[[2]]
} else {
job_state = job$job_state[[1]]
job_state <- job$job_state[[1]]
}
} else {
submit_time = job$submit_time
start_time = job$start_time
job_state = job$job_state
submit_time <- job$submit_time
start_time <- job$start_time
end_time <- job$end_time
job_state <- job$job_state
}

tibble::tibble(
Expand All @@ -29,6 +31,7 @@ parse_job_to_row <- function(job) {
standard_output = job$standard_output,
submit_time = submit_time,
start_time = start_time,
end_time = end_time,
user_name = job$user_name,
current_working_directory = job$current_working_directory
)
Expand All @@ -55,6 +58,16 @@ get_slurm_jobs <- function(user = NULL){
res_df <- parse_jobs_json(jsonlite::fromJSON(res$stdout, simplifyVector = FALSE))
res_df$submit_time <- as.POSIXct(res_df$submit_time, origin = "1970-01-01")
res_df$start_time <- as.POSIXct(res_df$start_time, origin = "1970-01-01")
res_df$end_time <- as.POSIXct(res_df$end_time, origin = "1970-01-01")
res_df <- res_df %>%
dplyr::mutate(
time = dplyr::case_when(
job_state == "RUNNING" ~ Sys.time() - start_time,
job_state == "CONFIGURING" ~ Sys.time() - submit_time,
TRUE ~ end_time - start_time
)
)

if (!is.null(user)) {
df <- tryCatch(
{
Expand All @@ -67,5 +80,7 @@ get_slurm_jobs <- function(user = NULL){
} else {
df <- res_df
}
df <- df %>%
dplyr::select(job_id, partition, user_name, job_state, time, dplyr::everything())
return(df)
}
41 changes: 23 additions & 18 deletions vignettes/Running-nonmem.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,16 @@ 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

![Help view for `submit_nonmem_model` function](data/images/submit_nonmem_model_help.png)
```{r}
?submit_nonmem_model
```

## Default variables and values provided to the template

This function uses the inputs to populate a template Bash shell script that submits the NONMEM job to slurm. A default template file is supplied with the Project Starter and it can be modified to do additional tasks as long as they are possible within Bash.

By default these values are provided to the slurm template file:

``` r
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 = Sys.which("bbi"),
bbi_config_path = bbi_config_path,
model_path = .mod$absolute_model_path,
config_toml_path = config_toml_path,
nmm_exe_path = Sys.which("nmm")
)
```

- `partition` is an argument to `submit_nonmem_model`

- `parallel` is `TRUE` if `ncpu > 1`, else `FALSE`
Expand All @@ -81,6 +69,22 @@ default_template_list = list(

If you need to feed more arguments to the template you simply supply them in the `slurm_template_opts` argument as a list. More on that later.

``` r
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 = Sys.which("bbi"),
bbi_config_path = bbi_config_path,
model_path = .mod$absolute_model_path,
config_toml_path = config_toml_path,
nmm_exe_path = Sys.which("nmm")
)
```

## Submitting a NONMEM job with `bbi`

To submit a NONMEM job, we need to supply either the path to a mod file or create a model object from `bbr`, and supply a `slurm-template.tmpl` file. To use `bbi` we also need a `bbi.yaml` file, which I've also supplied in `/model/nonmem/bbi.yaml` (and is also supplied with the R project starter).
Expand Down Expand Up @@ -144,6 +148,7 @@ We can now submit the job and point to the template file in `model/nonmem/slurm-
```{r}
submission <- slurmtools::submit_nonmem_model(
mod,
overwrite = TRUE,
slurm_job_template_path = file.path(nonmem, "slurm-job-bbi.tmpl"),
)

Expand All @@ -153,7 +158,7 @@ submission
We see a `status` with an exit code of 0 suggesting a successful command, and the `stdout` gives us the batch job number. We can use `slurmtools::get_slurm_jobs()` to monitor the status of the job. Here, we can supply the user = "matthews" argument to filter to just the jobs I've submitted.

```{r}
slurmtools::get_slurm_jobs(user = 'matthews')
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:
Expand Down
5 changes: 3 additions & 2 deletions vignettes/custom-alerts.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ look for files and how to alert you. We'll use `generate_nmm_config()`
to create this file. First we can look at the documentation to see what
type of information we should pass to this function.

![documentation for
generate_nmm_config()](data/images/generate_nmm_config_help.png)
```{r}
?generate_nmm_config
```

```{r}
mod_number <- "1001"
Expand Down
2 changes: 1 addition & 1 deletion vignettes/model/nonmem/1001.mod
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ IWRES = IRES/W
Y = IPRED * (1 + EPS(1)) + EPS(2)

$THETA
(0, 0.5) ;1 CL (L/d)
(0, 1.5) ;1 CL (L/d)
(0, 20) ;2 VC (L)

$OMEGA
Expand Down
2 changes: 1 addition & 1 deletion vignettes/slack-alerts.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ submission_nmm
```

```{r}
slurmtools::get_slurm_jobs(user = "matthews")
slurmtools::get_slurm_jobs()
```

![nmm slack alerts](data/images/nmm_slack_notifications.png)
Expand Down
Loading