Skip to content

Commit 60b6ffa

Browse files
future 1.40.0 is on CRAN
1 parent 63d70c7 commit 60b6ffa

13 files changed

+102
-148
lines changed

.github/workflows/R-CMD-check.yaml

-10
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,6 @@ jobs:
6262
extra-packages: any::rcmdcheck
6363
needs: check
6464

65-
- name: Test with specific future version?
66-
run: |
67-
future_version <- Sys.getenv("R_FUTURE_VERSION")
68-
if (!nzchar(future_version)) future_version <- "develop"
69-
if (nzchar(future_version)) {
70-
install.packages("remotes")
71-
remotes::install_github("futureverse/future", ref=future_version)
72-
}
73-
shell: Rscript {0}
74-
7565
- name: Install package itself (special case)
7666
run: |
7767
install.packages(".", repos = NULL, type = "source") ## needed by parallel workers

.github/workflows/future_tests.yaml

-10
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,6 @@ jobs:
4444
any::remotes
4545
needs: check
4646

47-
- name: Test with specific future version?
48-
run: |
49-
future_version <- Sys.getenv("R_FUTURE_VERSION")
50-
if (!nzchar(future_version)) future_version <- "develop"
51-
if (nzchar(future_version)) {
52-
install.packages("remotes")
53-
remotes::install_github("futureverse/future", ref=future_version)
54-
}
55-
shell: Rscript {0}
56-
5747
- name: Install R package dependencies
5848
run: |
5949
remotes::install_deps(dependencies = TRUE)

.github/workflows/test-coverage.yaml

-10
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,6 @@ jobs:
4747
any::covr
4848
needs: check
4949

50-
- name: Test with specific future version?
51-
run: |
52-
future_version <- Sys.getenv("R_FUTURE_VERSION")
53-
if (!nzchar(future_version)) future_version <- "develop"
54-
if (nzchar(future_version)) {
55-
install.packages("remotes")
56-
remotes::install_github("futureverse/future", ref=future_version)
57-
}
58-
shell: Rscript {0}
59-
6050
- name: Install dependencies
6151
run: |
6252
remotes::install_deps(dependencies = TRUE)

DESCRIPTION

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
Package: future.batchtools
2-
Version: 0.12.1-9103
2+
Version: 0.12.1-9104
33
Depends:
44
R (>= 3.2.0),
55
parallelly,
6-
future (>= 1.34.0)
6+
future (>= 1.40.0)
77
Imports:
88
batchtools,
99
utils

NAMESPACE

+6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ S3method(registerFuture,default)
2121
S3method(resolved,BatchtoolsFuture)
2222
S3method(result,BatchtoolsFuture)
2323
S3method(run,BatchtoolsFuture)
24+
S3method(stopWorkers,BatchtoolsBashFutureBackend)
25+
S3method(stopWorkers,BatchtoolsLocalFutureBackend)
26+
S3method(stopWorkers,BatchtoolsMulticoreFutureBackend)
2427
S3method(unregisterFuture,BatchtoolsFuture)
2528
S3method(unregisterFuture,BatchtoolsUniprocessFuture)
2629
S3method(unregisterFuture,default)
@@ -38,6 +41,7 @@ export(BatchtoolsInteractiveFutureBackend)
3841
export(BatchtoolsLocalFutureBackend)
3942
export(BatchtoolsLsfFuture)
4043
export(BatchtoolsMulticoreFuture)
44+
export(BatchtoolsMulticoreFutureBackend)
4145
export(BatchtoolsMultiprocessFuture)
4246
export(BatchtoolsOpenLavaFuture)
4347
export(BatchtoolsSGEFuture)
@@ -89,6 +93,7 @@ importFrom(batchtools,waitForJobs)
8993
importFrom(future,Future)
9094
importFrom(future,FutureBackend)
9195
importFrom(future,FutureError)
96+
importFrom(future,SequentialFutureBackend)
9297
importFrom(future,getExpression)
9398
importFrom(future,getGlobalsAndPackages)
9499
importFrom(future,launchFuture)
@@ -99,6 +104,7 @@ importFrom(future,plan)
99104
importFrom(future,resolved)
100105
importFrom(future,result)
101106
importFrom(future,run)
107+
importFrom(future,stopWorkers)
102108
importFrom(future,tweak)
103109
importFrom(future,withPlan)
104110
importFrom(parallelly,availableCores)

R/backend_api-BatchtoolsBashFutureBackend.R

+7
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ BatchtoolsBashFutureBackend <- function(..., template = "bash", cluster.function
1717
}
1818

1919

20+
#' @importFrom future stopWorkers
21+
#' @export
22+
stopWorkers.BatchtoolsBashFutureBackend <- function(backend, ...) {
23+
TRUE
24+
}
25+
26+
2027
#' @inheritParams batchtools_custom
2128
#' @inheritParams batchtools_template
2229
#' @param \ldots Additional arguments passed to [future::future()].

R/backend_api-BatchtoolsLocalFutureBackend.R

+7
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ BatchtoolsLocalFutureBackend <- function(..., cluster.functions = NULL) {
1616
}
1717

1818

19+
#' @importFrom future stopWorkers
20+
#' @export
21+
stopWorkers.BatchtoolsLocalFutureBackend <- function(backend, ...) {
22+
TRUE
23+
}
24+
25+
1926
#' batchtools local and interactive futures
2027
#'
2128
#' A batchtools local future is an synchronous uniprocess future that
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,51 @@
1+
#' @param \ldots Additional arguments passed to [BatchtoolsFutureBackend()].
2+
#'
3+
#' @rdname BatchtoolsFutureBackend
4+
#' @importFrom batchtools makeClusterFunctionsInteractive
5+
#' @importFrom future SequentialFutureBackend
6+
#' @export
7+
BatchtoolsMulticoreFutureBackend <- function(workers = availableCores(constraints = "multicore"), ...) {
8+
message("BatchtoolsMulticoreFutureBackend() ...")
9+
str(list(...))
10+
11+
if (is.null(workers)) {
12+
workers <- availableCores(constraints = "multicore")
13+
} else if (is.function(workers)) {
14+
workers <- workers()
15+
}
16+
stop_if_not(length(workers) == 1L, is.numeric(workers),
17+
is.finite(workers), workers >= 1L)
18+
19+
str(list(workers = workers, cores = availableCores(constraints = "multicore")))
20+
21+
## Fall back to batchtools_local if multicore processing is not supported
22+
asIs <- inherits(workers, "AsIs")
23+
if (!asIs && (workers == 1L && availableCores(constraints = "multicore") == 1L) || is_os("windows") || is_os("solaris")) {
24+
## covr: skip=1
25+
return(SequentialFutureBackend(...))
26+
}
27+
28+
cluster.functions <- makeClusterFunctionsMulticore(ncpus = workers)
29+
30+
core <- BatchtoolsFutureBackend(
31+
workers = workers,
32+
cluster.functions = cluster.functions,
33+
...
34+
)
35+
36+
core[["futureClasses"]] <- c("BatchtoolsMulticoreFuture", "BatchtoolsMultiprocessFuture", "MultiprocessFuture", core[["futureClasses"]])
37+
core <- structure(core, class = c("BatchtoolsMulticoreFutureBackend", "BatchtoolsMultiprocessFutureBackend", setdiff(class(core), "MultiprocessFutureBackend")))
38+
core
39+
}
40+
41+
42+
#' @importFrom future stopWorkers
43+
#' @export
44+
stopWorkers.BatchtoolsMulticoreFutureBackend <- function(backend, ...) {
45+
TRUE
46+
}
47+
48+
149
#' batchtools multicore futures
250
#'
351
#' A batchtools multicore future is an asynchronous multiprocess
@@ -27,52 +75,12 @@
2775
#' @importFrom future withPlan
2876
#' @export
2977
#' @keywords internal
30-
batchtools_multicore <- function(expr, envir = parent.frame(),
31-
substitute = TRUE, globals = TRUE,
32-
label = NULL,
33-
workers = availableCores(constraints = "multicore"),
34-
registry = list(), ...) {
35-
if (substitute) expr <- substitute(expr)
36-
37-
if (is.null(workers)) {
38-
workers <- availableCores(constraints = "multicore")
39-
} else if (is.function(workers)) {
40-
workers <- workers()
41-
}
42-
stop_if_not(length(workers) == 1L, is.numeric(workers),
43-
is.finite(workers), workers >= 1L)
44-
45-
## Fall back to batchtools_local if multicore processing is not supported
46-
if ((workers == 1L && !inherits(workers, "AsIs")) ||
47-
is_os("windows") || is_os("solaris") ||
48-
availableCores(constraints = "multicore") == 1L) {
49-
## covr: skip=1
50-
withPlan(batchtools_local, {
51-
future(expr, envir = envir, substitute = FALSE,
52-
globals = globals, label = label, registry = registry, ...)
53-
})
54-
}
55-
56-
oopts <- options(mc.cores = workers)
57-
on.exit(options(oopts))
58-
59-
cf <- makeClusterFunctionsMulticore(ncpus = workers)
60-
61-
future <- BatchtoolsMulticoreFuture(
62-
expr = expr, envir = envir, substitute = FALSE,
63-
globals = globals,
64-
label = label,
65-
cluster.functions = cf,
66-
registry = registry,
67-
...
68-
)
69-
70-
if (!future$lazy) future <- run(future)
71-
72-
invisible(future)
78+
batchtools_multicore <- function(workers = availableCores(constraints = "multicore"), ...) {
79+
stop("INTERNAL ERROR: The future.batchtools::batchtools_multicore() function implements the FutureBackend and should never be called directly")
7380
}
7481
class(batchtools_multicore) <- c(
7582
"batchtools_multicore", "batchtools_multiprocess", "batchtools",
7683
"multiprocess", "future", "function"
7784
)
7885
attr(batchtools_multicore, "tweakable") <- c("finalize")
86+
attr(batchtools_multicore, "factory") <- BatchtoolsMulticoreFutureBackend

R/nbrOfWorkers.R

+1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ nbrOfFreeWorkers.batchtools_multiprocess <- function(evaluator, background = FAL
102102
workers <- nbrOfWorkers(evaluator)
103103

104104
## Create a dummy future
105+
## FIXME
105106
future <- evaluator(NULL, globals = FALSE, lazy = TRUE)
106107
freg <- sprintf("workers-%s", class(future)[1])
107108
usedWorkers <- length(FutureRegistry(freg, action = "list"))

inst/testme/test-batchtools_multicore.R

+12-11
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,30 @@ library(listenv)
44
message("*** batchtools_multicore() ...")
55

66
for (cores in 1:min(2L, availableCores("multicore"))) {
7-
## FIXME:
87
if (!fullTest && cores > 1) next
98

109
## CRAN processing times:
1110
## On Windows 32-bit, don't run these tests
1211
if (!fullTest && isWin32) next
1312

1413
mprintf("Testing with %d cores ...\n", cores)
15-
options(mc.cores = cores - 1L)
14+
options(mc.cores = cores)
1615

1716
if (!supportsMulticore()) {
1817
mprintf("batchtools multicore futures are not supporting on '%s'. Falling back to use synchroneous batchtools local futures\n", .Platform$OS.type) #nolint
1918
}
2019

20+
plan(batchtools_multicore, workers = I(cores))
21+
2122
for (globals in c(FALSE, TRUE)) {
22-
mprintf("*** batchtools_multicore(..., globals = %s) without globals\n",
23-
globals)
23+
mprintf("*** batchtools_multicore(..., globals = %s) without globals\n", globals)
2424

25-
f <- batchtools_multicore({
25+
f <- future({
2626
42L
2727
}, globals = globals)
28+
print(f)
2829
stopifnot(
29-
inherits(f, "BatchtoolsFuture") ||
30-
((cores == 1 || !supportsMulticore()) && inherits(f, "SequentialFuture"))
30+
inherits(f, "BatchtoolsFuture")
3131
)
3232

3333
print(resolved(f))
@@ -39,7 +39,7 @@ for (cores in 1:min(2L, availableCores("multicore"))) {
3939
globals)
4040
## A global variable
4141
a <- 0
42-
f <- batchtools_multicore({
42+
f <- future({
4343
b <- 3
4444
c <- 2
4545
a * b * c
@@ -50,6 +50,7 @@ for (cores in 1:min(2L, availableCores("multicore"))) {
5050
## variable should not affect the result of the
5151
## future.
5252
a <- 7 ## Make sure globals are frozen
53+
5354
if (globals || f$config$reg$cluster.functions$name == "Multicore") {
5455
v <- value(f)
5556
print(v)
@@ -65,7 +66,7 @@ for (cores in 1:min(2L, availableCores("multicore"))) {
6566
x <- listenv()
6667
for (ii in 1:2) {
6768
mprintf(" - Creating batchtools_multicore future #%d ...\n", ii)
68-
x[[ii]] <- batchtools_multicore({ ii }, globals = globals)
69+
x[[ii]] <- future({ ii }, globals = globals)
6970
}
7071
mprintf(" - Resolving %d batchtools_multicore futures\n", length(x))
7172
if (globals || f$config$reg$cluster.functions$name == "Multicore") {
@@ -84,7 +85,7 @@ for (cores in 1:min(2L, availableCores("multicore"))) {
8485
b <- 3
8586
y_truth <- a * b
8687

87-
f <- batchtools_multicore({ a * b }, workers = 1L)
88+
f <- future({ a * b }, workers = 1L)
8889
rm(list = c("a", "b"))
8990

9091
v <- value(f)
@@ -102,7 +103,7 @@ for (cores in 1:min(2L, availableCores("multicore"))) {
102103
## On Windows 32-bit, don't run these tests
103104
if (fullTest || !isWin32) {
104105
mprintf("*** batchtools_multicore() and errors\n")
105-
f <- batchtools_multicore({
106+
f <- future({
106107
stop("Whoops!")
107108
1
108109
})

inst/testme/test-nbrOfWorkers.R

+6-28
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,6 @@ message("*** nbrOfWorkers() ...")
55

66
message("*** nbrOfWorkers() - local, interactive ...")
77

8-
n <- nbrOfWorkers(batchtools_local)
9-
message("Number of workers: ", n)
10-
stopifnot(n == 1L)
11-
12-
n <- nbrOfFreeWorkers(batchtools_local)
13-
message("Number of free workers: ", n)
14-
stopifnot(n == 1L)
15-
16-
n <- nbrOfFreeWorkers(batchtools_local, background = TRUE)
17-
message("Number of free background workers: ", n)
18-
stopifnot(n == 0L)
19-
20-
n <- nbrOfWorkers(batchtools_interactive)
21-
message("Number of workers: ", n)
22-
stopifnot(n == 1L)
23-
24-
n <- nbrOfFreeWorkers(batchtools_interactive)
25-
message("Number of free workers: ", n)
26-
stopifnot(n == 1L)
27-
28-
n <- nbrOfFreeWorkers(batchtools_interactive, background = TRUE)
29-
message("Number of free background workers: ", n)
30-
stopifnot(n == 0L)
31-
32-
338
plan(batchtools_local)
349
n <- nbrOfWorkers()
3510
message("Number of workers: ", n)
@@ -43,6 +18,7 @@ n <- nbrOfFreeWorkers(background = TRUE)
4318
message("Number of free background workers: ", n)
4419
stopifnot(n == 0L)
4520

21+
4622
plan(batchtools_interactive)
4723
n <- nbrOfWorkers()
4824
message("Number of workers: ", n)
@@ -63,15 +39,17 @@ ncores <- availableCores("multicore")
6339
if (ncores >= 2L) {
6440
message("*** nbrOfWorkers() - multicore ...")
6541

66-
n <- nbrOfWorkers(batchtools_multicore)
42+
plan(batchtools_multicore)
43+
44+
n <- nbrOfWorkers()
6745
message("Number of workers: ", n)
6846
stopifnot(n == ncores)
6947

70-
n <- nbrOfFreeWorkers(batchtools_multicore)
48+
n <- nbrOfFreeWorkers()
7149
message("Number of free workers: ", n)
7250
stopifnot(n == ncores)
7351

74-
n <- nbrOfFreeWorkers(batchtools_multicore, background = TRUE)
52+
n <- nbrOfFreeWorkers(background = TRUE)
7553
message("Number of free background workers: ", n)
7654
stopifnot(n == ncores)
7755

0 commit comments

Comments
 (0)