Skip to content

Commit

Permalink
Find logs relative to the directory containing the shell script, if r…
Browse files Browse the repository at this point in the history
…elative paths are used. Closes #1
  • Loading branch information
Nick-Eagles committed Jul 31, 2024
1 parent 496a504 commit 295d70f
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions R/array_submit.R
Original file line number Diff line number Diff line change
Expand Up @@ -103,25 +103,29 @@ array_submit <- function(name, task_ids = NULL, submit = FALSE, restore = TRUE,
# Find the log associated with that highest task
#-----------------------------------------------------------------------

max_log <- job_original[grep("^#SBATCH -o ", job_original)] |>
str_extract("-o (.*)$", group = 1) |>
str_replace("%a", max_task)

# For jobs created with 'job_loop', the actual log used will be on the
# line where 'log_path' is defined, not '/dev/null'
if (!is.na(max_log) && (max_log == "/dev/null")) {
max_log <- job_original[grep("^log_path=", job_original)] |>
str_extract("^log_path=(.*)/", group = 1) |>
list.files(
pattern = sprintf(
"%s.*_%s\\.txt$",
name,
max_task
),
full.names = TRUE
)
# For 'job_loop', use the path in the line starting with 'log_path='.
# Otherwise use the log in the line starting with '#SBATCH -o'.
last_occurence = rev(grep("^(#SBATCH -o |log_path=)", job_original))[1]
max_log = job_original[last_occurence] |>
# Extract just the path
str_replace("^(#SBATCH -o |log_path=)", "") |>
# Set the path for the highest task
str_replace("%a|\\$\\{SLURM_ARRAY_TASK_ID\\}", max_task)

# If the log is specified with a relative path, make sure it's
# relative to the directory containing the shell script
if (!grepl('^/', max_log)) {
max_log = file.path(dirname(sh_file), max_log)
}

# Find the precise path of the log in a way that's compatible with
# both 'job_single' and 'job_loop'
max_log = list.files(
dirname(max_log),
pattern = sprintf("^%s.*_%s\\.txt$", name, max_task),
full.names = TRUE
)

if (verbose) {
message(
sprintf(
Expand Down

0 comments on commit 295d70f

Please sign in to comment.