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

[WIP] added missing 'partition' argument to slurm launcher #25

Merged
merged 1 commit into from
Oct 11, 2023
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
6 changes: 4 additions & 2 deletions R/crew_controller_slurm.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ crew_controller_slurm <- function(
slurm_log_error = "/dev/null",
slurm_memory_gigabytes_per_cpu = NULL,
slurm_cpus_per_task = NULL,
slurm_time_minutes = 1440
slurm_time_minutes = 1440,
slurm_partition = NULL
) {
if (!is.null(seconds_exit)) {
crew::crew_deprecate(
Expand Down Expand Up @@ -96,7 +97,8 @@ crew_controller_slurm <- function(
slurm_log_error = slurm_log_error,
slurm_memory_gigabytes_per_cpu = slurm_memory_gigabytes_per_cpu,
slurm_cpus_per_task = slurm_cpus_per_task,
slurm_time_minutes = slurm_time_minutes
slurm_time_minutes = slurm_time_minutes,
slurm_partition = slurm_partition
)
controller <- crew::crew_controller(client = client, launcher = launcher)
controller$validate()
Expand Down
22 changes: 18 additions & 4 deletions R/crew_launcher_slurm.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
#' SLURM cluster. `slurm_time_minutes = 60` translates to a line of
#' `#SBATCH --time=60` in the SLURM job script. `slurm_time_minutes = NULL`
#' omits this line.
#' @param slurm_partition Character of length 1, name of the slurm partition to
#' create workers on.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be great to have a mention of how this translates into the --partition flag, as in the above @param descriptions. Also how a NULL value omits the flag.

crew_launcher_slurm <- function(
name = NULL,
seconds_interval = NULL,
Expand All @@ -72,7 +74,8 @@ crew_launcher_slurm <- function(
slurm_log_error = "/dev/null",
slurm_memory_gigabytes_per_cpu = NULL,
slurm_cpus_per_task = NULL,
slurm_time_minutes = 1440
slurm_time_minutes = 1440,
slurm_partition = NULL
) {
crew_deprecate(
name = "seconds_interval",
Expand Down Expand Up @@ -106,7 +109,8 @@ crew_launcher_slurm <- function(
slurm_log_error = slurm_log_error,
slurm_memory_gigabytes_per_cpu = slurm_memory_gigabytes_per_cpu,
slurm_cpus_per_task = slurm_cpus_per_task,
slurm_time_minutes = slurm_time_minutes
slurm_time_minutes = slurm_time_minutes,
slurm_partition = slurm_partition
)
launcher$validate()
launcher
Expand All @@ -133,6 +137,8 @@ crew_class_launcher_slurm <- R6::R6Class(
slurm_cpus_per_task = NULL,
#' @field slurm_time_minutes See [crew_launcher_slurm()].
slurm_time_minutes = NULL,
#' @field slurm_partition See See [crew_launcher_slurm()].
slurm_partition = NULL,
#' @description SLURM launcher constructor.
#' @return an SLURM launcher object.
#' @param name See [crew_launcher_slurm()].
Expand All @@ -157,6 +163,7 @@ crew_class_launcher_slurm <- R6::R6Class(
#' @param slurm_memory_gigabytes_per_cpu See [crew_launcher_slurm()].
#' @param slurm_cpus_per_task See [crew_launcher_slurm()].
#' @param slurm_time_minutes See [crew_launcher_slurm()].
#' @param slurm_partition See [crew_launcher_slurm()].
initialize = function(
name = NULL,
seconds_launch = NULL,
Expand All @@ -179,7 +186,8 @@ crew_class_launcher_slurm <- R6::R6Class(
slurm_log_error = NULL,
slurm_memory_gigabytes_per_cpu = NULL,
slurm_cpus_per_task = NULL,
slurm_time_minutes = NULL
slurm_time_minutes = NULL,
slurm_partition = NULL
) {
super$initialize(
name = name,
Expand All @@ -205,12 +213,13 @@ crew_class_launcher_slurm <- R6::R6Class(
self$slurm_memory_gigabytes_per_cpu <- slurm_memory_gigabytes_per_cpu
self$slurm_cpus_per_task <- slurm_cpus_per_task
self$slurm_time_minutes <- slurm_time_minutes
self$slurm_partition <- slurm_partition
},
#' @description Validate the launcher.
#' @return `NULL` (invisibly). Throws an error if a field is invalid.
validate = function() {
super$validate()
fields <- c("slurm_log_output", "slurm_log_error")
fields <- c("slurm_log_output", "slurm_log_error", "slurm_partition")
for (field in fields) {
if (!is.null(self[[field]])) {
crew::crew_assert(
Expand Down Expand Up @@ -299,6 +308,11 @@ crew_class_launcher_slurm <- R6::R6Class(
character(0L),
paste0("#SBATCH --time=", self$slurm_time_minutes)
),
if_any(
is.null(self$slurm_partition),
character(0L),
paste0("#SBATCH --partition=", self$slurm_partition)
),
self$script_lines
)
},
Expand Down
Loading