Skip to content

Commit

Permalink
Merge pull request #6 from A2-ai/get_job_fix
Browse files Browse the repository at this point in the history
Get job fix
  • Loading branch information
mduncans authored Aug 26, 2024
2 parents 4fe7abd + 108eebe commit 536b3fc
Show file tree
Hide file tree
Showing 8 changed files with 481 additions and 109 deletions.
271 changes: 271 additions & 0 deletions .Rhistory
Original file line number Diff line number Diff line change
@@ -0,0 +1,271 @@
here::here()
devtools::check()
devtools::check()
here::here()
devtools::check()
here::here()
library(here)
install.packages("here")
install.packages("devtools")
devtools::check()
install.packages("dplyr")
install.packages("extendr")
install.packages("rextendr")
devtools::check()
install.packages("bbr")
devtools::check()
as.POSIXct("2024-08-23 12:34:56")
build_site()
library(pkgdown)
build_site()
getwd()
setwd("../scicalc")
getwd()
build_site()
library(scicalc)
getwd()
library(pkgdown)
sink("_pkgdown.yml")
template_navbar()
template_reference()
sink()
build_site()
build_site()
library(slurmtools)
#removing generated files from running this vignette
nonmem <- file.path("model", "nonmem")
unlink(file.path(nonmem, "1001"), recursive = TRUE)
unlink(file.path(nonmem, "1001.yaml"))
unlink(file.path(nonmem, "1001.toml"))
unlink(file.path(nonmem, "submission-log"), recursive = TRUE)
unlink(file.path(nonmem, "in_progress"), recursive = TRUE)
knitr::opts_chunk$set(
collapse = TRUE,
comment = ""
)
library(slurmtools)
options(repos = c(
"slurmtools" = "https://a2-ai.github.io/gh-pkg-mirror/slurmtools",
getOption("repos")))
install.packages("slurmtools")
library(slurmtools)
library(bbr)
library(here)
nonmem = file.path(here::here(), "vignettes", "model", "nonmem")
options('slurmtools.submission_root' = file.path(nonmem, "submission-log"))
mod_number <- "1001"
if (file.exists(file.path(nonmem, paste0(mod_number, ".yaml")))) {
mod <- bbr::read_model(file.path(nonmem, mod_number))
} else {
mod <- bbr::new_model(file.path(nonmem, mod_number))
}
submission <- slurmtools::submit_nonmem_model(
mod,
slurm_job_template_path = file.path(nonmem, "slurm-job-bbi.tmpl"),
slurm_template_opts = list(
bbi_exe_path = Sys.which("bbi"),
bbi_config_path = file.path(nonmem, "bbi.yaml"))
)
submission
submitted_job_id <- submission$stdout
submitted_job_id <- strsplit(submitted_job_id, "\n")[[1]]
submitted_job_id <- tail(strsplit(submitted_job_id, " ")[[1]], 1)
slurmtools::get_slurm_jobs() %>%
dplyr::filter(job_id == submitted_job_id)
?tail
?get_slurm_jobs
get_slurm_jobs
cmd <- list(cmd = "squeue", args = "--json")
res <- processx::run(cmd$cmd, args = cmd$args)
if (res$status != 0) {
# todo: better handle returning why
rlang::abort("unable to get slurm jobs, test what the output would be by running `squeue --json`")
}
res_df <- parse_jobs_json(jsonlite::fromJSON(res$stdout, simplifyVector = FALSE))
?parse_jobs_json
??parse_jobs_json
parse_jobs_json <- function(.json) {
if (!length(.json$jobs)) {
return(NULL)
}
purrr::list_rbind(purrr::map(.json$jobs, parse_job_to_row))
}
res_df <- parse_jobs_json(jsonlite::fromJSON(res$stdout, simplifyVector = FALSE))
parse_job_to_row <- function(job) {
tibble::tibble(
job_id = job$job_id,
job_state = job$job_state,
cpus = job$cpus$number,
partition = job$partition,
standard_input = job$standard_input,
standard_output = job$standard_output,
submit_time = job$submit_time,
start_time = job$start_time,
user_name = job$user_name,
current_working_directory = job$current_working_directory
)
}
res_df <- parse_jobs_json(jsonlite::fromJSON(res$stdout, simplifyVector = FALSE))
res_df$submit_time
class(res_df$submit_time)
?as.POSIXct
?jsonlite:::fromJSON
as.POSIXct(res_df$submit_time$number, origin = "1970-01-01")
res_df$start_time
build_site()
#removing generated files from running this vignette
nonmem <- file.path("model", "nonmem")
unlink(file.path(nonmem, "1001"), recursive = TRUE)
unlink(file.path(nonmem, "1001.yaml"))
unlink(file.path(nonmem, "1001.toml"))
unlink(file.path(nonmem, "submission-log"), recursive = TRUE)
unlink(file.path(nonmem, "in_progress"), recursive = TRUE)
knitr::opts_chunk$set(
collapse = TRUE,
comment = ""
)
library(slurmtools)
library(bbr)
library(here)
nonmem = file.path(here::here(), "vignettes", "model", "nonmem")
options('slurmtools.submission_root' = file.path(nonmem, "submission-log"))
mod_number <- "1001"
if (file.exists(file.path(nonmem, paste0(mod_number, ".yaml")))) {
mod <- bbr::read_model(file.path(nonmem, mod_number))
} else {
mod <- bbr::new_model(file.path(nonmem, mod_number))
}
submission <- slurmtools::submit_nonmem_model(
mod,
slurm_job_template_path = file.path(nonmem, "slurm-job-bbi.tmpl"),
slurm_template_opts = list(
bbi_exe_path = Sys.which("bbi"),
bbi_config_path = file.path(nonmem, "bbi.yaml"))
)
submission
submitted_job_id <- submission$stdout
submitted_job_id <- strsplit(submitted_job_id, "\n")[[1]]
submitted_job_id <- tail(strsplit(submitted_job_id, " ")[[1]], 1)
slurmtools::get_slurm_jobs() %>%
dplyr::filter(job_id == submitted_job_id)
open slurmtools::get_slurm_jobs()
open(slurmtools::get_slurm_jobs())
open(slurmtools::get_slurm_jobs
)
squeue --version
library(pkgdown)
build_site()
.Last.error
library(slurmtools)
#removing generated files from running this vignette
nonmem <- file.path("model", "nonmem")
unlink(file.path(nonmem, "1001"), recursive = TRUE)
unlink(file.path(nonmem, "1001.yaml"))
unlink(file.path(nonmem, "1001.toml"))
unlink(file.path(nonmem, "submission-log"), recursive = TRUE)
unlink(file.path(nonmem, "in_progress"), recursive = TRUE)
knitr::opts_chunk$set(
collapse = TRUE,
comment = ""
)
library(slurmtools)
library(bbr)
library(here)
nonmem = file.path(here::here(), "vignettes", "model", "nonmem")
options('slurmtools.submission_root' = file.path(nonmem, "submission-log"))
mod_number <- "1001"
if (file.exists(file.path(nonmem, paste0(mod_number, ".yaml")))) {
mod <- bbr::read_model(file.path(nonmem, mod_number))
} else {
mod <- bbr::new_model(file.path(nonmem, mod_number))
}
submission <- slurmtools::submit_nonmem_model(
mod,
slurm_job_template_path = file.path(nonmem, "slurm-job-bbi.tmpl"),
slurm_template_opts = list(
bbi_exe_path = Sys.which("bbi"),
bbi_config_path = file.path(nonmem, "bbi.yaml"))
)
submission
submitted_job_id <- submission$stdout
submitted_job_id <- strsplit(submitted_job_id, "\n")[[1]]
submitted_job_id <- tail(strsplit(submitted_job_id, " ")[[1]], 1)
slurmtools::get_slurm_jobs() %>%
dplyr::filter(job_id == submitted_job_id)
.libPaths()
install.packages("~/packages/slurmtools", repos = NULL, type = "source")
library(slurmtools)
#removing generated files from running this vignette
nonmem <- file.path("model", "nonmem")
unlink(file.path(nonmem, "1001"), recursive = TRUE)
unlink(file.path(nonmem, "1001.yaml"))
unlink(file.path(nonmem, "1001.toml"))
unlink(file.path(nonmem, "submission-log"), recursive = TRUE)
unlink(file.path(nonmem, "in_progress"), recursive = TRUE)
knitr::opts_chunk$set(
collapse = TRUE,
comment = ""
)
library(slurmtools)
library(bbr)
library(here)
nonmem = file.path(here::here(), "vignettes", "model", "nonmem")
options('slurmtools.submission_root' = file.path(nonmem, "submission-log"))
mod_number <- "1001"
if (file.exists(file.path(nonmem, paste0(mod_number, ".yaml")))) {
mod <- bbr::read_model(file.path(nonmem, mod_number))
} else {
mod <- bbr::new_model(file.path(nonmem, mod_number))
}
View(as.data.frame(available.packages()))
mod_number <- "1001"
if (file.exists(file.path(nonmem, paste0(mod_number, ".yaml")))) {
mod <- bbr::read_model(file.path(nonmem, mod_number))
} else {
mod <- bbr::new_model(file.path(nonmem, mod_number))
}
submission <- slurmtools::submit_nonmem_model(
mod,
slurm_job_template_path = file.path(nonmem, "slurm-job-bbi.tmpl"),
slurm_template_opts = list(
bbi_exe_path = Sys.which("bbi"),
bbi_config_path = file.path(nonmem, "bbi.yaml"))
)
submission
submitted_job_id <- submission$stdout
submitted_job_id <- strsplit(submitted_job_id, "\n")[[1]]
submitted_job_id <- tail(strsplit(submitted_job_id, " ")[[1]], 1)
slurmtools::get_slurm_jobs() %>%
dplyr::filter(job_id == submitted_job_id)
parse_job_to_row <- function(job) {
tibble::tibble(
job_id = job$job_id,
job_state = job$job_state,
cpus = job$cpus$number,
partition = job$partition,
standard_input = job$standard_input,
standard_output = job$standard_output,
submit_time = job$submit_time,
start_time = job$start_time,
user_name = job$user_name,
current_working_directory = job$current_working_directory
)
}
parse_jobs_json <- function(.json) {
if (!length(.json$jobs)) {
return(NULL)
}
purrr::list_rbind(purrr::map(.json$jobs, parse_job_to_row))
}
cmd <- list(cmd = "squeue", args = "--json")
res <- processx::run(cmd$cmd, args = cmd$args)
if (res$status != 0) {
# todo: better handle returning why
rlang::abort("unable to get slurm jobs, test what the output would be by running `squeue --json`")
}
res_df <- parse_jobs_json(jsonlite::fromJSON(res$stdout, simplifyVector = FALSE))
View(res_df)
View(res_df)
get_slurm_jobs
installed.packages()
View(as.data.frame(installed.packages()))
5 changes: 2 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Description: What the package does (one paragraph).
License: GPL (>= 3)
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.2
Imports:
brio,
dplyr,
Expand All @@ -29,7 +29,6 @@ Suggests:
knitr,
rmarkdown,
testthat (>= 3.0.0),
bbr,
pdftools,
bbr
Config/testthat/edition: 3
VignetteBuilder: knitr
1 change: 0 additions & 1 deletion R/attach.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#' Generates a tidyverse-esque onAttach message
#'
#' @return a message to display on attach
Expand Down
24 changes: 21 additions & 3 deletions R/get-jobs.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,33 @@ utils::globalVariables(c("user_name"))

# Function to parse each job into a tibble row
parse_job_to_row <- function(job) {
# check options for squeue version
# 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
### 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]]
} else {
job_state = job$job_state[[1]]
}
} else {
submit_time = job$submit_time
start_time = job$start_time
job_state = job$job_state
}

tibble::tibble(
job_id = job$job_id,
job_state = job$job_state,
job_state = job_state,
cpus = job$cpus$number,
partition = job$partition,
standard_input = job$standard_input,
standard_output = job$standard_output,
submit_time = job$submit_time,
start_time = job$start_time,
submit_time = submit_time,
start_time = start_time,
user_name = job$user_name,
current_working_directory = job$current_working_directory
)
Expand Down
13 changes: 13 additions & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,16 @@
msg <- slurmtools_options_message()
packageStartupMessage(msg)
}

.onLoad <- function(libname, pkgname) {
processx_output <- processx::run("squeue", args = "--version")
if (processx_output$status != 0) {
warning("squeue not installed correctly")
} else {
# stdout format is "slurm major.minor.patch/n"
version <- strsplit(processx_output$stdout," ")[[1]][[2]] %>%
trimws() %>%
package_version()
options("squeue.version" = version)
}
}
Loading

0 comments on commit 536b3fc

Please sign in to comment.