Skip to content

Commit

Permalink
crew_options_aws_batch()
Browse files Browse the repository at this point in the history
  • Loading branch information
wlandau committed Oct 9, 2024
1 parent 29e2716 commit 1e9728e
Show file tree
Hide file tree
Showing 8 changed files with 393 additions and 11 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export(crew_launcher_aws_batch)
export(crew_launcher_aws_batch_launch)
export(crew_launcher_aws_batch_terminate)
export(crew_monitor_aws_batch)
export(crew_options_aws_batch)
importFrom(R6,R6Class)
importFrom(cli,cli_progress_bar)
importFrom(cli,cli_progress_done)
Expand Down
4 changes: 2 additions & 2 deletions R/crew_definition_aws_batch.R
Original file line number Diff line number Diff line change
Expand Up @@ -653,10 +653,10 @@ crew_class_definition_aws_batch <- R6::R6Class(
submit = function(
command = c("sleep", "300"),
name = paste0("crew-aws-batch-job-", crew::crew_random_name()),
memory_units = "gigabytes",
memory = NULL,
cpus = NULL,
gpus = NULL,
memory_units = "gigabytes",
memory = NULL,
seconds_timeout = NULL,
share_identifier = NULL,
scheduling_priority_override = NULL,
Expand Down
204 changes: 204 additions & 0 deletions R/crew_options_aws_batch.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
#' @title AWS Batch options
#' @export
#' @keywords plugin_aws_batch
#' @description Options for the AWS Batch controller.
#' @return A classed list of options for the controller.
#' @param job_definition Character of length 1, name of the AWS
#' Batch job definition to use. There is no default for this argument,
#' and a job definition must be created prior to running the controller.
#' Please see <https://docs.aws.amazon.com/batch/> for details.
#'
#' To create a job definition, you will need to create a Docker-compatible
#' image which can run R and `crew`. You may which to inherit
#' from the images at <https://github.com/rocker-org/rocker-versioned2>.
#' @param job_queue Character of length 1, name of the AWS
#' Batch job queue to use. There is no default for this argument,
#' and a job queue must be created prior to running the controller.
#' Please see <https://docs.aws.amazon.com/batch/> for details.
#' @param cpus Number of virtual CPUs to request per job. Can be `NULL`
#' to go with the defaults in the job definition. Ignored if
#' `container_overrides` is not `NULL`.
#' @param gpus Number of GPUs to request per job. Can be `NULL`
#' to go with the defaults in the job definition. Ignored if
#' `container_overrides` is not `NULL`.
#' @param memory Positive number, amount of memory to request per job.
#' Choose the units of memory with the `memory_units` argument.
#' Fargate instances can only be certain discrete values of mebibytes,
#' so please choose `memory_units = "mebibytes"` in that case.
#' The `memory` argument can be `NULL`
#' to go with the defaults in the job definition. Ignored if
#' `container_overrides` is not `NULL`.
#' @param units_memory Character string, units of memory of the `memory`
#' argument. Can be `"gigabytes"` or `"mebibytes"`.
#' Fargate instances can only be certain discrete values of mebibytes,
#' so please choose `memory_units = "mebibytes"` in that case.
#' @param share_identifier `NULL` or character of length 1.
#' For details, visit
#' <https://www.paws-r-sdk.com/docs/batch_submit_job/> and the
#' "AWS arguments" sections of this help file.
#' @param scheduling_priority_override `NULL` or integer of length 1.
#' For details, visit
#' <https://www.paws-r-sdk.com/docs/batch_submit_job/> and the
#' "AWS arguments" sections of this help file.
#' @param parameters `NULL` or a nonempty list.
#' For details, visit
#' <https://www.paws-r-sdk.com/docs/batch_submit_job/> and the
#' "AWS arguments" sections of this help file.
#' @param container_overrides `NULL` or a nonempty named list of
#' fields to override
#' in the container specified in the job definition. Any overrides for the
#' `command` field are ignored because `crew.aws.batch` needs to override
#' the command to run the `crew` worker.
#' For more details, visit
#' <https://www.paws-r-sdk.com/docs/batch_submit_job/> and the
#' "AWS arguments" sections of this help file.
#' @param node_overrides `NULL` or a nonempty named list.
#' For more details, visit
#' <https://www.paws-r-sdk.com/docs/batch_submit_job/> and the
#' "AWS arguments" sections of this help file.
#' @param retry_strategy `NULL` or a nonempty named list.
#' For more details, visit
#' <https://www.paws-r-sdk.com/docs/batch_submit_job/> and the
#' "AWS arguments" sections of this help file.
#' @param propagate_tags `NULL` or a logical of length 1.
#' For more details, visit
#' <https://www.paws-r-sdk.com/docs/batch_submit_job/> and the
#' "AWS arguments" sections of this help file.
#' @param timeout `NULL` or a nonempty named list.
#' For more details, visit
#' <https://www.paws-r-sdk.com/docs/batch_submit_job/> and the
#' "AWS arguments" sections of this help file.
#' @param tags `NULL` or a nonempty named list.
#' For more details, visit
#' <https://www.paws-r-sdk.com/docs/batch_submit_job/> and the
#' "AWS arguments" sections of this help file.
#' @param eks_properties_override `NULL` or a nonempty named list.
#' For more details, visit
#' <https://www.paws-r-sdk.com/docs/batch_submit_job/> and the
#' "AWS arguments" sections of this help file.
crew_options_aws_batch <- function(
job_definition,
job_queue,
cpus = NULL,
gpus = NULL,
memory = NULL,
memory_units = "gigabytes",
config = list(),
credentials = list(),
endpoint = NULL,
region = NULL,
share_identifier = NULL,
scheduling_priority_override = NULL,
parameters = NULL,
container_overrides = NULL,
node_overrides = NULL,
retry_strategy = NULL,
propagate_tags = NULL,
timeout = NULL,
tags = NULL,
eks_properties_override = NULL
) {
crew::crew_assert(
job_definition,
is.character(.),
length(.) == 1L,
!anyNA(.),
nzchar(.),
message = "job_definition must be a valid nonempty character string"
)
crew::crew_assert(
job_queue,
is.character(.),
length(.) == 1L,
!anyNA(.),
nzchar(.),
message = "job_queue must be a valid nonempty character string"
)
crew::crew_assert(
memory_units,
is.character(.),
length(.) == 1L,
!anyNA(.),
nzchar(.),
. %in% c("gigabytes", "mebibytes"),
message = "memory_units must be \"gigabytes\" or \"mebibytes\""
)
crew::crew_assert(
cpus %|||% 1,
is.numeric(.),
length(.) == 1L,
is.finite(.),
. > 0,
message = "cpus must be NULL or a single positive number"
)
crew::crew_assert(
gpus %|||% 0,
is.numeric(.),
length(.) == 1L,
is.finite(.),
. >= 0,
message = "gpus must be NULL or a single non-negative number"
)
crew::crew_assert(
memory %|||% 0,
is.numeric(.),
length(.) == 1L,
is.finite(.),
. >= 0,
message = "memory must be NULL or a single positive number"
)
container_overrides <- container_overrides %|||% make_container_overrides(
cpus = cpus,
gpus = gpus,
memory = memory,
memory_units = memory_units
)
structure(
list(
job_definition = job_definition,
job_queue = job_queue,
config = config,
credentials = credentials,
endpoint = endpoint,
region = region,
share_identifier = share_identifier,
scheduling_priority_override = scheduling_priority_override,
parameters = parameters,
container_overrides = container_overrides,
node_overrides = node_overrides,
retry_strategy = retry_strategy,
propagate_tags = propagate_tags,
timeout = timeout,
tags = tags,
eks_properties_override = eks_properties_override
),
class = c("crew_options_aws_batch", "crew_options")
)
}

make_container_overrides <- function(
cpus = cpus,
gpus = gpus,
memory = memory,
memory_units = memory_units
) {
if (!is.null(memory) && identical(memory_units, "gigabytes")) {
memory <- memory * ((5L ^ 9L) / (2L ^ 11L))
}
resources <- list()
if (!is.null(memory)) {
memory <- as.character(round(memory))
resources$memory <- list(value = memory, type = "MEMORY")
}
if (!is.null(cpus)) {
resources$cpus <- list(value = as.character(cpus), type = "VCPU")
}
if (!is.null(gpus)) {
resources$gpus <- list(value = as.character(gpus), type = "GPU")
}
out <- list()
if (length(resources)) {
out$resourceRequirements <- resources
}
out
}
1 change: 1 addition & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ reference:
- title: AWS Batch launcher plugin
contents:
- 'crew_controller_aws_batch'
- 'crew_options_aws_batch'
- 'crew_launcher_aws_batch'
- 'crew_class_launcher_aws_batch'
- title: AWS Batch monitor
Expand Down
16 changes: 8 additions & 8 deletions man/crew_class_definition_aws_batch.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

126 changes: 126 additions & 0 deletions man/crew_options_aws_batch.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1e9728e

Please sign in to comment.