Skip to content

Commit

Permalink
Merge pull request #9 from A2-ai/workflow_test
Browse files Browse the repository at this point in the history
Workflow test
  • Loading branch information
mduncans authored Sep 9, 2024
2 parents a9eae76 + 1159134 commit 531ea0e
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 78 deletions.
40 changes: 27 additions & 13 deletions .github/workflows/RunChecks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
branches: [main, master, workflow_test]
pull_request:
branches: [main, master]
branches: [main, master, workflow_test]

name: R-CMD-check

Expand Down Expand Up @@ -39,34 +39,48 @@ jobs:
run: |
mkdir -p /usr/local/bin
cd /tmp
gh release download "sinfo/v0.2.0" -R a2-ai-tech-training/slurm-mocks -p "*Linux_x86_64.tar.gz" -D /usr/local/bin/
gh release download "sinfo/v0.2.1" -R a2-ai-tech-training/slurm-mocks -p "*Linux_x86_64.tar.gz" -D /usr/local/bin/
tar -xvf /usr/local/bin/sinfo_Linux_x86_64.tar.gz
mv ./sinfo /usr/local/bin/sinfo
chmod +x /usr/local/bin/sinfo
chmod 755 /usr/local/bin/sinfo
gh release download "sacct/v0.2.0" -R a2-ai-tech-training/slurm-mocks -p "*Linux_x86_64.tar.gz" -D /usr/local/bin/
tar -xvf /usr/local/bin/sacct_Linux_x86_64.tar.gz
mv ./sacct /usr/local/bin/sacct
chmod +x /usr/local/bin/sacct
chmod 755 /usr/local/bin/sacct
gh release download "squeue/v0.2.0" -R a2-ai-tech-training/slurm-mocks -p "*Linux_x86_64.tar.gz" -D /usr/local/bin/
tar -xvf /usr/local/bin/squeue_Linux_x86_64.tar.gz
mv ./squeue /usr/local/bin/squeue
chmod 755 /usr/local/bin/squeue
gh release download "sbatch/v0.2.0" -R a2-ai-tech-training/slurm-mocks -p "*Linux_x86_64.tar.gz" -D /usr/local/bin/
tar -xvf /usr/local/bin/sbatch_Linux_x86_64.tar.gz
mv ./sbatch /usr/local/bin/sbatch
chmod 755 /usr/local/bin/sbatch
echo "/usr/local/bin" >> $GITHUB_PATH
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Grab outputs directory from mocked repo
- name: Check mocked binaries work in different step
run: |
cd /tmp
gh repo clone a2-ai-tech-training/slurm-mocks
mv /tmp/slurm-mocks/sinfo/outputs $GITHUB_WORKSPACE/
rm -rf /tmp/slurm-mocks
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Rscript -e 'if (!requireNamespace("processx", quietly = TRUE)) install.packages("processx"); processx::run("sinfo", args = c("--format", "%P,%c,%m"),)'
Rscript -e 'processx::run("sacct", args = "--json")'
Rscript -e 'processx::run("squeue", args = "--version")'
Rscript -e 'processx::run("squeue", args = "--json")'
Rscript -e 'processx::run("sbatch", args = "path_to_file")'
- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck
extra-packages: |
metrumresearchgroup/mrgmisc
metrumresearchgroup/nmrec
metrumresearchgroup/bbr
any::rcmdcheck
needs: check

- uses: r-lib/actions/check-r-package@v2
with:
upload-snapshots: true

1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.Rproj.user
docs
inst/doc
/doc/
/Meta/
16 changes: 13 additions & 3 deletions R/get-jobs.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ parse_jobs_json <- function(.json) {
#' @param user user filter
#' @export
get_slurm_jobs <- function(user = NULL){
cmd <- list(cmd = "squeue", args = "--json")

cmd <- list(cmd = Sys.which("squeue"), args = "--json")
res <- processx::run(cmd$cmd, args = cmd$args)
if (res$status != 0) {
# todo: better handle returning why
Expand All @@ -55,7 +56,16 @@ get_slurm_jobs <- function(user = NULL){
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")
if (!is.null(user)) {
return(dplyr::filter(res_df, user_name == user))
df <- tryCatch(
{
dplyr::filter(res_df, user_name == user)
},
error = function(e) {
res_df
}
)
} else {
df <- res_df
}
res_df
return(df)
}
3 changes: 2 additions & 1 deletion R/submit-model.R
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ submit_nonmem_model <-
template_list
)
})

script_file_path <-
file.path(submission_root, sprintf("%s.sh", basename(.mod$absolute_model_path)))
if (!dry_run) {
Expand All @@ -118,7 +119,7 @@ submit_nonmem_model <-
brio::write_file(template_script, script_file_path)
fs::file_chmod(script_file_path, "0755")
}
cmd <- list(cmd = "sbatch", args = script_file_path, template_script = template_script, partition = partition)
cmd <- list(cmd = Sys.which("sbatch"), args = script_file_path, template_script = template_script, partition = partition)
if (dry_run) {
return(cmd)
}
Expand Down
27 changes: 18 additions & 9 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,23 @@
}

.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)
result <- tryCatch(
{processx::run(Sys.which("squeue"), args = "--version")},
error = function(e) {
warning("'squeue' command not found or failed to run.")
return(NULL)
}
)

if (!is.null(result)) {
if (result$status != 0) {
warning("squeue not installed correctly")
} else {
# stdout format is "slurm major.minor.patch/n"
version <- strsplit(result$stdout," ")[[1]][[2]] %>%
trimws() %>%
package_version()
options("squeue.version" = version)
}
}
}
32 changes: 16 additions & 16 deletions vignettes/Running-nonmem.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -250,20 +250,20 @@ To reiterate, this template file is run as a bash shell script so anything you c

```{r, include = FALSE}
#cancelling any running nonmem jobs
state <- slurmtools::get_slurm_jobs(user = "matthews")
if (any(state$job_state %in% c("RUNNING", "CONFIGURING"))) {
for (job_id in state %>% dplyr::filter(job_state == "RUNNING") %>% dplyr::pull("job_id")) {
processx::run("scancel", args = paste0(job_id))
}
}
#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)
# state <- slurmtools::get_slurm_jobs(user = "matthews")
#
# if (any(state$job_state %in% c("RUNNING", "CONFIGURING"))) {
# for (job_id in state %>% dplyr::filter(job_state == "RUNNING") %>% dplyr::pull("job_id")) {
# processx::run("scancel", args = paste0(job_id))
# }
# }
#
# #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)
```
34 changes: 17 additions & 17 deletions vignettes/custom-alerts.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -247,21 +247,21 @@ This gives us the notifications in a much more digestible format
![nmm ntfy.sh alerts](data/images/nmm_ntfy_alerts.png)

```{r, include = FALSE}
#cancelling any running nonmem jobs
state <- slurmtools::get_slurm_jobs(user = "matthews")
if (any(state$job_state %in% c("RUNNING", "CONFIGURING"))) {
for (job_id in state %>% dplyr::filter(job_state == "RUNNING") %>% dplyr::pull("job_id")) {
processx::run("scancel", args = paste0(job_id))
}
}
#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)
# #cancelling any running nonmem jobs
# state <- slurmtools::get_slurm_jobs(user = "matthews")
#
# if (any(state$job_state %in% c("RUNNING", "CONFIGURING"))) {
# for (job_id in state %>% dplyr::filter(job_state == "RUNNING") %>% dplyr::pull("job_id")) {
# processx::run("scancel", args = paste0(job_id))
# }
# }
#
# #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)
```
36 changes: 18 additions & 18 deletions vignettes/slack-alerts.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Sys.which("slack_notifier")

slack_notifier requires an additional `slack_notifier/config.yaml` file
that contains the slack bot OAuth token which is found from
[[[https://api.slack.com/apps/\\\\](https://api.slack.com/apps/\\){.uri}]([https://api.slack.com/apps/\\](https://api.slack.com/apps/\){.uri}){.uri}\<YOUR
[[[https://api.slack.com/apps/\\\\](https://api.slack.com/apps/){.uri}](%5Bhttps://api.slack.com/apps/%5D(https://api.slack.com/apps/)%7B.uri%7D){.uri}\<YOUR
APP ID\> /oauth?].

``` slack_notifier/config.yaml
Expand Down Expand Up @@ -125,21 +125,21 @@ slurmtools::get_slurm_jobs()
![nmm slack alerts](data/images/nmm_slack_notifications.png)

```{r, include = FALSE}
#cancelling any running nonmem jobs
state <- slurmtools::get_slurm_jobs(user = "matthews")
if (any(state$job_state %in% c("RUNNING", "CONFIGURING"))) {
for (job_id in state %>% dplyr::filter(job_state == "RUNNING") %>% dplyr::pull("job_id")) {
processx::run("scancel", args = paste0(job_id))
}
}
#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)
# #cancelling any running nonmem jobs
# state <- slurmtools::get_slurm_jobs(user = "matthews")
#
# if (any(state$job_state %in% c("RUNNING", "CONFIGURING"))) {
# for (job_id in state %>% dplyr::filter(job_state == "RUNNING") %>% dplyr::pull("job_id")) {
# processx::run("scancel", args = paste0(job_id))
# }
# }
#
# #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)
```

0 comments on commit 531ea0e

Please sign in to comment.