Skip to content

Commit 4d28739

Browse files
Implement BatchtoolsBashFutureBackend
1 parent 5761212 commit 4d28739

8 files changed

+66
-54
lines changed

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Package: future.batchtools
2-
Version: 0.12.1-9101
2+
Version: 0.12.1-9102
33
Depends:
44
R (>= 3.2.0),
55
parallelly,

NAMESPACE

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
S3method(add_finalizer,BatchtoolsFuture)
44
S3method(delete,BatchtoolsFuture)
55
S3method(launchFuture,BatchtoolsFutureBackend)
6-
S3method(listFutures,BatchtoolsLocalFutureBackend)
6+
S3method(listFutures,BatchtoolsSequentialFutureBackend)
77
S3method(loggedError,BatchtoolsFuture)
88
S3method(loggedOutput,BatchtoolsFuture)
9-
S3method(nbrOfFreeWorkers,BatchtoolsLocalFutureBackend)
9+
S3method(nbrOfFreeWorkers,BatchtoolsSequentialFutureBackend)
1010
S3method(nbrOfFreeWorkers,batchtools)
1111
S3method(nbrOfFreeWorkers,batchtools_multiprocess)
1212
S3method(nbrOfFreeWorkers,batchtools_uniprocess)
13-
S3method(nbrOfWorkers,BatchtoolsLocalFutureBackend)
13+
S3method(nbrOfWorkers,BatchtoolsSequentialFutureBackend)
1414
S3method(nbrOfWorkers,batchtools)
1515
S3method(nbrOfWorkers,batchtools_multicore)
1616
S3method(nbrOfWorkers,batchtools_uniprocess)
@@ -29,6 +29,7 @@ S3method(waitForWorker,BatchtoolsUniprocessFuture)
2929
S3method(waitForWorker,default)
3030
export("%resources%")
3131
export(BatchtoolsBashFuture)
32+
export(BatchtoolsBashFutureBackend)
3233
export(BatchtoolsCustomFuture)
3334
export(BatchtoolsFuture)
3435
export(BatchtoolsFutureBackend)

R/batchtools_bash.R renamed to R/backend_api-BatchtoolsBashFutureBackend.R

+21-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,28 @@
1+
#' @param template (optional) A batchtools template file or a template string
2+
#' (in \pkg{brew} format). If not specified, it is left to the
3+
#' \pkg{batchtools} package to locate such file using its search rules.
4+
#'
5+
#' @rdname BatchtoolsFutureBackend
6+
#' @export
7+
BatchtoolsBashFutureBackend <- function(..., template = "bash", cluster.functions = NULL) {
8+
cluster.functions <- makeClusterFunctionsBash(template = template)
9+
core <- BatchtoolsFutureBackend(
10+
...,
11+
cluster.functions = cluster.functions
12+
)
13+
14+
core[["futureClasses"]] <- c("BatchtoolsBashFuture", core[["futureClasses"]])
15+
core <- structure(core, class = c("BatchtoolsBashFutureBackend", "BatchtoolsSequentialFutureBackend", setdiff(class(core), "MultiprocessFutureBackend")))
16+
core
17+
}
18+
19+
120
#' @inheritParams batchtools_custom
221
#' @inheritParams batchtools_template
322
#'
423
#' @export
524
batchtools_bash <- function(..., envir = parent.frame(), template = "bash") {
6-
cf <- makeClusterFunctionsBash(template = template)
7-
future <- BatchtoolsBashFuture(..., envir = envir, cluster.functions = cf)
8-
if (!future$lazy) future <- run(future)
9-
invisible(future)
25+
stop("INTERNAL ERROR: The future.batchtools::batchtools_bash() function implements the FutureBackend and should never be called directly")
1026
}
1127
class(batchtools_bash) <- c(
1228
"batchtools_bash", "batchtools_custom",
@@ -15,6 +31,7 @@ class(batchtools_bash) <- c(
1531
)
1632
attr(batchtools_bash, "tweakable") <- c("finalize")
1733
attr(batchtools_bash, "untweakable") <- c("workers")
34+
attr(batchtools_bash, "factory") <- BatchtoolsBashFutureBackend
1835

1936

2037
#' @importFrom batchtools cfReadBrewTemplate cfBrewTemplate makeClusterFunctions makeSubmitJobResult

R/batchtools_local.R renamed to R/backend_api-BatchtoolsLocalFutureBackend.R

+1-35
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
#' Future backends based on the 'batchtools' framework
2-
#'
3-
#' @inheritParams future::FutureBackend
4-
#'
5-
#' @param \ldots Additional arguments passed to `FutureBackend()`.
6-
#'
7-
#' @return An object of class `BatchtoolsFutureBackend`.
8-
#'
91
#' @rdname BatchtoolsFutureBackend
102
#' @importFrom batchtools makeClusterFunctionsInteractive
113
#' @export
@@ -17,37 +9,11 @@ BatchtoolsLocalFutureBackend <- function(..., cluster.functions = NULL) {
179
)
1810

1911
core[["futureClasses"]] <- c("BatchtoolsLocalFuture", core[["futureClasses"]])
20-
core <- structure(core, class = c("BatchtoolsLocalFutureBackend", setdiff(class(core), "MultiprocessFutureBackend")))
12+
core <- structure(core, class = c("BatchtoolsLocalFutureBackend", "BatchtoolsSequentialFutureBackend", setdiff(class(core), "MultiprocessFutureBackend")))
2113
core
2214
}
2315

2416

25-
#' @export
26-
nbrOfWorkers.BatchtoolsLocalFutureBackend <- function(evaluator) {
27-
1L
28-
}
29-
30-
31-
#' @export
32-
nbrOfFreeWorkers.BatchtoolsLocalFutureBackend <- function(evaluator, background = FALSE, ...) {
33-
assert_no_positional_args_but_first()
34-
if (isTRUE(background)) 0L else 1L
35-
}
36-
37-
38-
#' @importFrom future listFutures
39-
#' @export
40-
listFutures.BatchtoolsLocalFutureBackend <- function(backend, ...) {
41-
data.frame(
42-
counter = integer(0L),
43-
start = proc.time()[[3]][integer(0L)],
44-
label = character(0L),
45-
resolved = logical(0L),
46-
future = list()[integer(0L)]
47-
)
48-
}
49-
50-
5117
#' batchtools local and interactive futures
5218
#'
5319
#' A batchtools local future is an synchronous uniprocess future that
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#' @export
2+
nbrOfWorkers.BatchtoolsSequentialFutureBackend <- function(evaluator) {
3+
1L
4+
}
5+
6+
7+
#' @export
8+
nbrOfFreeWorkers.BatchtoolsSequentialFutureBackend <- function(evaluator, background = FALSE, ...) {
9+
assert_no_positional_args_but_first()
10+
if (isTRUE(background)) 0L else 1L
11+
}
12+
13+
14+
#' @importFrom future listFutures
15+
#' @export
16+
listFutures.BatchtoolsSequentialFutureBackend <- function(backend, ...) {
17+
data.frame(
18+
counter = integer(0L),
19+
start = proc.time()[[3]][integer(0L)],
20+
label = character(0L),
21+
resolved = logical(0L),
22+
future = list()[integer(0L)]
23+
)
24+
}

man/BatchtoolsFutureBackend.Rd

+14-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/batchtools_local.Rd

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)