Skip to content

Commit 9e9bc54

Browse files
committed
Small fix to mod_SLURM and mod_CV_fit
1 parent 28d63e8 commit 9e9bc54

File tree

2 files changed

+35
-15
lines changed

2 files changed

+35
-15
lines changed

R/mod_CV_fit.R

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -408,11 +408,21 @@ mod_CV_fit <- function(
408408
# Save model fitting commands -----
409409
IASDT.R::cat_time("Save model fitting commands")
410410

411-
CommandFile <- IASDT.R::path(Path_CV, "Commands2Fit.txt")
412-
f <- file(CommandFile, open = "wb")
413-
on.exit(invisible(try(close(f), silent = TRUE)), add = TRUE)
414-
cat(unlist(CV_DT$Command_HPC), sep = "\n", append = FALSE, file = f)
415-
close(f)
411+
purrr::walk(
412+
.x = CV_name,
413+
.f = ~{
414+
Curr_CV_Name <- stringr::str_remove_all(.x, "CV_")
415+
CommandFile <- IASDT.R::path(Path_CV, paste0("Commands2Fit_", .x, ".txt"))
416+
f <- file(CommandFile, open = "wb")
417+
on.exit(invisible(try(close(f), silent = TRUE)), add = TRUE)
418+
419+
CV_DT %>%
420+
dplyr::filter(CV_name == Curr_CV_Name) %>%
421+
dplyr::pull(Command_HPC) %>%
422+
unlist() %>%
423+
cat(sep = "\n", append = FALSE, file = f)
424+
close(f)
425+
})
416426

417427
## # ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
418428

R/mod_SLURM.R

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,12 @@ mod_SLURM <- function(
9898
"HPC_partition", "path_Hmsc", "ProjNum", "Path_GPU_Check",
9999
"command_prefix", "SLURM_prefix")
100100
IASDT.R::check_args(
101-
args_all = AllArgs, args_to_check = CharArgs,
102-
args_type = "character")
101+
args_all = AllArgs, args_to_check = CharArgs, args_type = "character")
103102

104103
# numeric arguments
105104
NumericArgs <- c("gpus_per_node", "cpus_per_task", "ntasks")
106105
IASDT.R::check_args(
107-
args_all = AllArgs, args_to_check = NumericArgs,
108-
args_type = "numeric")
106+
args_all = AllArgs, args_to_check = NumericArgs, args_type = "numeric")
109107

110108
rm(AllArgs, envir = environment())
111109

@@ -131,15 +129,27 @@ mod_SLURM <- function(
131129
.x = seq_len(NCommandFiles),
132130
.f = function(x) {
133131

134-
if (NCommandFiles == 1) {
135-
OutFile <- paste0(SLURM_prefix, ".slurm")
136-
JobName0 <- job_name
132+
SLURM_suffix <- basename(ListCommands[x]) %>%
133+
stringr::str_remove_all(
134+
paste0(c(command_prefix, "CV_", ".txt"), collapse = "|")) %>%
135+
stringr::str_remove_all("^_")
136+
137+
if (nchar(SLURM_suffix) > 0) {
138+
OutFile <- c(SLURM_prefix, SLURM_suffix) %>%
139+
paste0(collapse = "_") %>%
140+
paste0(".slurm")
141+
JobName0 <- stringr::str_remove_all(OutFile, "_Fit|_Bash|.slurm$")
137142
} else {
138-
OutFile <- paste0(SLURM_prefix, "_", x, ".slurm")
139-
JobName0 <- paste0(job_name, "_", x)
143+
if (NCommandFiles == 1) {
144+
OutFile <- paste0(SLURM_prefix, ".slurm")
145+
JobName0 <- job_name
146+
} else {
147+
OutFile <- paste0(SLURM_prefix, "_", x, ".slurm")
148+
JobName0 <- paste0(job_name, "_", x)
149+
}
140150
}
141-
NJobs <- R.utils::countLines(ListCommands[x])[1]
142151

152+
NJobs <- R.utils::countLines(ListCommands[x])[1]
143153

144154
# create connection to SLURM file
145155

0 commit comments

Comments
 (0)