Skip to content

Commit 9922619

Browse files
CLEANUP: Remove ClusterFuture and MultisessionFuture
1 parent 8ab56b0 commit 9922619

8 files changed

+18
-195
lines changed

NAMESPACE

-2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ export("%plan%")
9797
export("%seed%")
9898
export("%stdout%")
9999
export("%tweak%")
100-
export(ClusterFuture)
101100
export(ClusterFutureBackend)
102101
export(ConstantFuture)
103102
export(Future)
@@ -114,7 +113,6 @@ export(GlobalEnvFutureError)
114113
export(GlobalEnvFutureWarning)
115114
export(MulticoreFutureBackend)
116115
export(MultiprocessFuture)
117-
export(MultisessionFuture)
118116
export(MultisessionFutureBackend)
119117
export(RngFutureCondition)
120118
export(RngFutureError)

R/backend_api-ClusterFuture-class.R

-99
Original file line numberDiff line numberDiff line change
@@ -1,102 +1,3 @@
1-
#' A cluster future is a future whose value will be resolved asynchronously in a parallel process
2-
#'
3-
#' @inheritParams MultiprocessFuture-class
4-
#' @inheritParams Future-class
5-
#'
6-
#' @param persistent If FALSE, the evaluation environment is cleared
7-
#' from objects prior to the evaluation of the future.
8-
#'
9-
#' @param workers A \code{\link[parallel:makeCluster]{cluster}} object,
10-
#' a character vector of host names, a positive numeric scalar,
11-
#' or a function.
12-
#' If a character vector or a numeric scalar, a `cluster` object
13-
#' is created using \code{\link[parallelly:makeClusterPSOCK]{makeClusterPSOCK}(workers)}.
14-
#' If a function, it is called without arguments _when the future
15-
#' is created_ and its value is used to configure the workers.
16-
#' The function should return any of the above types.
17-
#'
18-
#' @return
19-
#' `ClusterFuture()` returns an object of class `ClusterFuture`.
20-
#'
21-
#' @section Usage:
22-
#' To use 'cluster' futures, use `plan(cluster, ...)`, cf. [cluster].
23-
#'
24-
#' @aliases MultisessionFuture MultisessionFuture-class
25-
#' @export
26-
#' @export MultisessionFuture
27-
#' @importFrom digest digest
28-
#' @name ClusterFuture-class
29-
#' @keywords internal
30-
ClusterFuture <- function(expr = NULL, substitute = TRUE, envir = parent.frame(), persistent = FALSE, workers = NULL, ...) {
31-
if (substitute) expr <- substitute(expr)
32-
33-
stop_if_not(is.logical(persistent), length(persistent) == 1L,
34-
!is.na(persistent))
35-
36-
args <- list(...)
37-
38-
## Which '...' arguments should be passed to Future() and
39-
## which should be passed to makeClusterPSOCK()?
40-
future_args <- !is.element(names(args), makeClusterPSOCK_args())
41-
42-
future <- do.call(MultiprocessFuture, args = c(list(expr = quote(expr), substitute = FALSE, envir = envir, persistent = persistent, node = NA_integer_), args[future_args]), quote = FALSE)
43-
44-
future <- do.call(as_ClusterFuture, args = c(list(future, workers = workers), args[!future_args]), quote = TRUE)
45-
46-
future
47-
}
48-
49-
50-
as_ClusterFuture <- local({
51-
getDefaultCluster <- import_parallel_fcn("getDefaultCluster")
52-
53-
function(future, workers = NULL, ...) {
54-
if (is.function(workers)) workers <- workers()
55-
if (is.null(workers)) {
56-
workers <- getDefaultCluster()
57-
workers <- addCovrLibPath(workers)
58-
} else if (is.character(workers) || is.numeric(workers)) {
59-
workers <- ClusterRegistry("start", workers = workers, ...)
60-
} else {
61-
workers <- as.cluster(workers)
62-
workers <- addCovrLibPath(workers)
63-
}
64-
if (!inherits(workers, "cluster")) {
65-
stopf("Argument 'workers' is not of class 'cluster': %s", commaq(class(workers)))
66-
}
67-
stop_if_not(length(workers) > 0)
68-
69-
70-
## Attached workers' session information, unless already done.
71-
## FIXME: We cannot do this here, because it introduces a race condition
72-
## where multiple similar requests may appear at the same time bringing
73-
## the send/receive data to be out of sync and therefore corrupt the
74-
## futures' values.
75-
## workers <- add_cluster_session_info(workers)
76-
77-
## Attach name to cluster?
78-
name <- attr(workers, "name", exact = TRUE)
79-
if (is.null(name)) {
80-
name <- digest(workers)
81-
stop_if_not(length(name) > 0, nzchar(name))
82-
attr(workers, "name") <- name
83-
}
84-
85-
future[["backend"]] <- list(
86-
workers = workers,
87-
reg = sprintf("workers-%s", attr(workers, "name", exact = TRUE))
88-
)
89-
90-
## FIXME: To be cleaned out /HB 2025-02-19
91-
future[["workers"]] <- workers
92-
93-
future <- structure(future, class = c("ClusterFuture", class(future)))
94-
95-
future
96-
}
97-
})
98-
99-
1001
getSocketSelectTimeout <- function(future, timeout = NULL) {
1012
if (!is.null(timeout)) return(timeout)
1023

R/backend_api-MultisessionFuture-class.R

-19
This file was deleted.

R/backend_api-cluster.R

+14-3
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,25 @@
2727
#' plan(cluster, workers = c("localhost", "n1", "n1", "pi.example.org"))
2828
#' ```
2929
#'
30-
#' @inheritParams ClusterFuture-class
3130
#' @inheritParams Future-class
3231
#' @inheritParams future
3332
#'
34-
#' @param \dots Additional named elements passed to [ClusterFuture()].
33+
#' @param workers A \code{\link[parallel:makeCluster]{cluster}} object,
34+
#' a character vector of host names, a positive numeric scalar,
35+
#' or a function.
36+
#' If a character vector or a numeric scalar, a `cluster` object
37+
#' is created using \code{\link[parallelly:makeClusterPSOCK]{makeClusterPSOCK}(workers)}.
38+
#' If a function, it is called without arguments _when the future
39+
#' is created_ and its value is used to configure the workers.
40+
#' The function should return any of the above types.
41+
#'
42+
#' @param persistent If FALSE, the evaluation environment is cleared
43+
#' from objects prior to the evaluation of the future.
44+
#'
45+
#' @param \dots Additional named elements passed to [Future()].
3546
#'
3647
#' @return
37-
#' A \link{ClusterFuture}.
48+
#' A ClusterFuture.
3849
#'
3950
#' @example incl/cluster.R
4051
#'

R/backend_api-multisession.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#' This is passed down as-is to [parallelly::makeClusterPSOCK()].
3737
#'
3838
#' @return
39-
#' A \link{MultisessionFuture}.
39+
#' A MultisessionFuture.
4040
#' If `workers == 1`, then all processing is done in the
4141
#' current/main \R session and we therefore fall back to using a
4242
#' lazy future. To override this fallback, use `workers = I(1)`.

man/ClusterFuture-class.Rd

-68
This file was deleted.

man/cluster.Rd

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

man/multisession.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)