Skip to content

Commit f56a713

Browse files
Better documentation for 'batchtools_interactive', 'batchtools_local', and 'batchtools_bash'
1 parent 7181c81 commit f56a713

19 files changed

+548
-308
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Package: future.batchtools
2-
Version: 0.12.2-9914
2+
Version: 0.12.2-9915
33
Depends:
44
R (>= 3.2.0),
55
parallelly,

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export(batchtools_ssh)
5656
export(batchtools_torque)
5757
export(loggedError)
5858
export(loggedOutput)
59+
export(makeClusterFunctionsBash)
5960
importFrom(batchtools,Worker)
6061
importFrom(batchtools,batchExport)
6162
importFrom(batchtools,batchMap)

R/BatchtoolsFutureBackend-class.R

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
#'
33
#' @inheritParams future::FutureBackend
44
#'
5-
#' @param resources (optional) A named list passed to the \pkg{batchtools}
6-
#' template (available as variable `resources`). See Section 'Resources'
7-
#' in [batchtools::submitJobs()] more details.
8-
#'
95
#' @param workers (optional) The maximum number of workers the batchtools
106
#' backend may use at any time. Interactive and "local" backends can only
117
#' process one future at the time (`workers = 1L`), whereas HPC backends,
@@ -15,32 +11,42 @@
1511
#' \code{getOption("\link{future.batchtools.workers}")}.
1612
#' If neither are specified, then the default is `100`.
1713
#'
18-
#' @param finalize If TRUE, any underlying registries are
19-
#' deleted when this object is garbage collected, otherwise not.
14+
#' @param finalize If TRUE, a future's \pkg{batchtools}
15+
#' \link[batchtools:makeRegistry]{Registry} is automatically deleted when
16+
#' the future is garbage collected, otherwise not.
2017
#'
21-
#' @param conf.file (optional) A batchtools configuration file.
18+
#' @param cluster.functions (optional) Assigned as-is to the each future's
19+
#' \pkg{batchtools} \link[batchtools:makeRegistry]{Registry}.
2220
#'
23-
#' @param cluster.functions (optional) A batchtools
24-
#' [ClusterFunctions][batchtools::ClusterFunctions] object.
21+
#' @param registry (optional) A named list of settings applied to each
22+
#' future's \pkg{batchtools} \link[batchtools:makeRegistry]{Registry}.
23+
#' This is a more convenient alternative to using argument `conf.file`.
2524
#'
26-
#' @param registry (optional) A named list of settings to control the setup
27-
#' of the batchtools registry.
25+
#' @param conf.file (optional) A "batchtools-configuration" R script, which
26+
#' is sourced when each future's \pkg{batchtools}
27+
#' \link[batchtools:makeRegistry]{Registry} is created. Any variables
28+
#' created by this script is assigned to the registry.
29+
#' The default file is the one found by [batchtools::findConfFile()], if any.
30+
#'
31+
#' @param resources (optional) A named list passed to the \pkg{batchtools}
32+
#' job-script template as variable `resources`. See Section 'Resources'
33+
#' in [batchtools::submitJobs()] more details.
2834
#'
2935
#' @param \ldots Not used.
3036
#'
3137
#' @return A [future::FutureBackend] object of class BatchtoolsFutureBackend
3238
#'
3339
#' @aliases BatchtoolsUniprocessFutureBackend BatchtoolsMultiprocessFutureBackend
34-
#' @rdname BatchtoolsFuture
3540
#' @importFrom utils file_test
3641
#' @importFrom future FutureBackend
3742
#' @keywords internal
3843
#' @export
39-
BatchtoolsFutureBackend <- function(workers = NULL, resources = list(),
44+
BatchtoolsFutureBackend <- function(
45+
workers = NULL, resources = list(),
4046
finalize = getOption("future.finalize", TRUE),
41-
conf.file = findConfFile(),
4247
cluster.functions = NULL,
4348
registry = list(),
49+
conf.file = findConfFile(),
4450
interrupts = TRUE,
4551
...) {
4652
assert_no_positional_args_but_first()
@@ -103,6 +109,8 @@ BatchtoolsFutureBackend <- function(workers = NULL, resources = list(),
103109
}
104110

105111

112+
#' @inheritParams BatchtoolsFutureBackend
113+
#'
106114
#' @export
107115
BatchtoolsUniprocessFutureBackend <- function(workers = 1L, ...) {
108116
assert_no_positional_args_but_first()
@@ -111,6 +119,8 @@ BatchtoolsUniprocessFutureBackend <- function(workers = 1L, ...) {
111119
core
112120
}
113121

122+
#' @inheritParams BatchtoolsFutureBackend
123+
#'
114124
#' @export
115125
BatchtoolsMultiprocessFutureBackend <- function(...) {
116126
assert_no_positional_args_but_first()

R/batchtools_bash.R

Lines changed: 66 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
#' @inheritParams batchtools_custom
2-
#' @inheritParams batchtools_template
1+
#' @inheritParams BatchtoolsTemplateFutureBackend
2+
#' @rdname BatchtoolsFutureBackend
3+
#' @keywords internal
34
#'
45
#' @export
5-
BatchtoolsBashFutureBackend <- function(..., template = "bash") {
6+
BatchtoolsBashFutureBackend <- function(...,
7+
cluster.functions = makeClusterFunctionsBash(template = template),
8+
template = "bash") {
69
assert_no_positional_args_but_first()
710

811
core <- BatchtoolsMultiprocessFutureBackend(
9-
cluster.functions = makeClusterFunctionsBash(template = template),
10-
...
12+
...,
13+
cluster.functions = cluster.functions,
14+
template = template
1115
)
1216

1317
core[["futureClasses"]] <- c("BatchtoolsBashFuture", core[["futureClasses"]])
@@ -16,8 +20,55 @@ BatchtoolsBashFutureBackend <- function(..., template = "bash") {
1620
}
1721

1822

23+
#' A batchtools bash backend that resolves futures in a single background R session via Bash
24+
#'
25+
#' The `batchtools_bash` backend was added to illustrate how to write a
26+
#' custom \pkg{future.batchtools} backend that uses a job-script template.
27+
#' Please see the source code, for details.
28+
#'
29+
#' @inheritParams BatchtoolsFutureBackend
30+
#' @inheritParams BatchtoolsTemplateFutureBackend
31+
#' @inheritParams BatchtoolsBashFutureBackend
32+
#'
33+
#' @param template (optional) Name of job-script template to be searched
34+
#' for by [batchtools::findTemplateFile()]. If not found, it defaults to
35+
#' the `templates/bash.tmpl` part of this package (see below).
36+
#'
37+
#' @param \ldots Not used.
38+
#'
39+
#' @details
40+
#' Batchtools bash futures uses \pkg{batchtools} cluster functions
41+
#' created by [makeClusterFunctionsBash()] and requires that Bash is
42+
#' installed on the current machine.
43+
#'
44+
#' The default template script `templates/bash.tmpl` can be found in:
45+
#'
46+
#' ```r
47+
#' system.file("templates", "bash.tmpl", package = "future.batchtools")
48+
#' ```
49+
#'
50+
#' and comprise:
51+
#'
52+
#' `r paste(c("\x60\x60\x60bash", readLines("inst/templates/bash.tmpl"), "\x60\x60\x60"), collapse = "\n")`
53+
#'
54+
#' @examplesIf interactive()
55+
#' plan(batchtools_bash)
56+
#'
57+
#' message("Main process ID: ", Sys.getpid())
58+
#'
59+
#' f <- future(Sys.getpid())
60+
#' pid <- value(f)
61+
#' message("Workers process ID: ", pid)
62+
#'
1963
#' @export
20-
batchtools_bash <- function(..., envir = parent.frame(), template = "bash") {
64+
batchtools_bash <- function(
65+
cluster.functions = makeClusterFunctionsBash(template = "bash"),
66+
template = "bash",
67+
registry = list(),
68+
conf.file = findConfFile(),
69+
resources = list(),
70+
finalize = getOption("future.finalize", TRUE),
71+
...) {
2172
stop("INTERNAL ERROR: The future.batchtools::batchtools_bash() must never be called directly")
2273
}
2374
class(batchtools_bash) <- c(
@@ -31,8 +82,17 @@ attr(batchtools_bash, "init") <- TRUE
3182
attr(batchtools_bash, "factory") <- BatchtoolsBashFutureBackend
3283

3384

85+
#' @inheritParams batchtools::makeClusterFunctions
86+
#'
87+
#' @return
88+
#' `makeClusterFunctionsBash()` returns a
89+
#' \link[batchtools:makeClusterFunctions]{ClusterFunctions} object.
90+
#'
91+
#' @rdname batchtools_bash
92+
#'
3493
#' @importFrom batchtools cfReadBrewTemplate cfBrewTemplate makeClusterFunctions makeSubmitJobResult
3594
#' @importFrom utils file_test
95+
#' @export
3696
makeClusterFunctionsBash <- function(template = "bash") {
3797
bin <- Sys.which("bash")
3898
stop_if_not(file_test("-f", bin), file_test("-x", bin))

R/batchtools_custom.R

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
#'
99
#' @example incl/batchtools_custom.R
1010
#'
11-
#' @aliases batchtools_custom
11+
#' @rdname BatchtoolsFutureBackend
12+
#' @keywords internal
13+
#'
1214
#' @export
1315
#' @importFrom batchtools findConfFile
1416
BatchtoolsCustomFutureBackend <- function(...) {
@@ -23,8 +25,10 @@ BatchtoolsCustomFutureBackend <- function(...) {
2325
core
2426
}
2527

28+
#' @inheritParams BatchtoolsCustomFutureBackend
29+
#'
2630
#' @export
27-
batchtools_custom <- function(..., envir = parent.frame()) {
31+
batchtools_custom <- function(...) {
2832
stop("INTERNAL ERROR: The future.batchtools::batchtools_custom() must never be called directly")
2933
}
3034
class(batchtools_custom) <- c(

R/batchtools_interactive.R

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#' @inheritParams BatchtoolsFuture
1+
#' @rdname BatchtoolsFutureBackend
2+
#' @keywords internal
23
#'
34
#' @importFrom batchtools makeClusterFunctionsInteractive
45
#' @export
@@ -15,8 +16,38 @@ BatchtoolsInteractiveFutureBackend <- function(...) {
1516
core
1617
}
1718

19+
#' A batchtools backend that resolves futures sequentially in the current R session
20+
#'
21+
#' The batchtools interactive backend is useful for verifying parts of your
22+
#' \pkg{batchtools} setup locally, while still being able to do interactive
23+
#' debugging.
24+
#' An alternative to the batchtools interactive backend is to use
25+
#' `plan(future::sequential)`, which is a faster way process futures
26+
#' sequentially and that also can be debugged interactively.
27+
#'
28+
#' @inheritParams BatchtoolsFutureBackend
29+
#' @inheritParams BatchtoolsInteractiveFutureBackend
30+
#'
31+
#' @param \ldots Not used.
32+
#'
33+
#' @details
34+
#' Batchtools interactive futures uses \pkg{batchtools} cluster functions
35+
#' created by [batchtools::makeClusterFunctionsInteractive()] with
36+
#' `external = TRUE`.
37+
#'
38+
#' @examples
39+
#' plan(batchtools_interactive)
40+
#'
41+
#' message("Main process ID: ", Sys.getpid())
42+
#'
43+
#' f <- future(Sys.getpid())
44+
#' pid <- value(f)
45+
#' message("Workers process ID: ", pid)
46+
#'
47+
#' @inheritParams BatchtoolsInteractiveFutureBackend
48+
#'
1849
#' @export
19-
batchtools_interactive <- function(..., envir = parent.frame()) {
50+
batchtools_interactive <- function(...) {
2051
stop("INTERNAL ERROR: The future.batchtools::batchtools_interactive() must never be called directly")
2152
}
2253
class(batchtools_interactive) <- c(
@@ -27,5 +58,3 @@ attr(batchtools_interactive, "tweakable") <- c("finalize")
2758
attr(batchtools_interactive, "untweakable") <- c("workers")
2859
attr(batchtools_interactive, "init") <- TRUE
2960
attr(batchtools_interactive, "factory") <- BatchtoolsInteractiveFutureBackend
30-
31-

R/batchtools_local.R

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#' @details
1717
#' batchtools local futures rely on the batchtools backend set up by
1818
#' \code{\link[batchtools:makeClusterFunctionsInteractive]{batchtools::makeClusterFunctionsInteractive(external = TRUE)}}
19-
#' and batchtools interactive futures on the one set up by
19+
#' and batchtools interactive futures on the one sQet up by
2020
#' [batchtools::makeClusterFunctionsInteractive()].
2121
#' These are supported by all operating systems.
2222
#'
@@ -30,11 +30,11 @@
3030
#'
3131
#' @example incl/batchtools_local.R
3232
#'
33-
#' @rdname BatchtoolsInteractiveFutureBackend
33+
#' @rdname BatchtoolsFutureBackend
34+
#' @keywords internal
3435
#'
3536
#' @importFrom batchtools makeClusterFunctionsInteractive
36-
#' @aliases batchtools_local batchtools_interactive batchtools_bash
37-
#' @aliases BatchtoolsLocalFutureBackend BatchtoolsInteractiveFutureBackend BatchtoolsBashFutureBackend
37+
#' @aliases BatchtoolsLocalFutureBackend BatchtoolsBashFutureBackend
3838
#' @export
3939
BatchtoolsLocalFutureBackend <- function(...) {
4040
assert_no_positional_args_but_first()
@@ -50,8 +50,37 @@ BatchtoolsLocalFutureBackend <- function(...) {
5050
}
5151

5252

53+
#' A batchtools backend that resolves futures sequentially in transient background R sessions
54+
#'
55+
#' The batchtools local backend is useful for verifying parts of your
56+
#' \pkg{batchtools} setup locally, before using a more advanced backend such
57+
#' as the job-scheduler backends.
58+
#' An alternative to the batchtools interactive backend is to use
59+
#' `plan(future::cluster, workers = I(1))`.
60+
#'
61+
#' @inheritParams BatchtoolsFutureBackend
62+
#' @inheritParams BatchtoolsLocalFutureBackend
63+
#'
64+
#' @param \ldots Not used.
65+
#'
66+
#' @details
67+
#' Batchtools local futures uses \pkg{batchtools} cluster functions
68+
#' created by [batchtools::makeClusterFunctionsInteractive()] with
69+
#' `external = TRUE`.
70+
#'
71+
#' @examples
72+
#' plan(batchtools_local)
73+
#'
74+
#' message("Main process ID: ", Sys.getpid())
75+
#'
76+
#' f <- future(Sys.getpid())
77+
#' pid <- value(f)
78+
#' message("Workers process ID: ", pid)
79+
#'
80+
#' @inheritParams BatchtoolsLocalFutureBackend
81+
#'
5382
#' @export
54-
batchtools_local <- function(..., envir = parent.frame()) {
83+
batchtools_local <- function(...) {
5584
stop("INTERNAL ERROR: The future.batchtools::batchtools_local() must never be called directly")
5685
}
5786
class(batchtools_local) <- c(

R/batchtools_multicore.R

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,13 @@
2323
#' The batchtools multicore backend only works on operating systems
2424
#' supporting the `ps` command-line tool, e.g. Linux and macOS.
2525
#'
26+
#' @rdname BatchtoolsFutureBackend
27+
#' @keywords internal
28+
#'
29+
#' @aliases batchtools_custom batchtools_multicore
2630
#' @importFrom batchtools makeClusterFunctionsMulticore
2731
#' @importFrom parallelly availableCores supportsMulticore
2832
#' @importFrom tools pskill
29-
#' @keywords internal
3033
#' @export
3134
BatchtoolsMulticoreFutureBackend <- function(workers = availableCores(constraints = "multicore"), ...) {
3235
assert_no_positional_args_but_first()
@@ -68,9 +71,10 @@ BatchtoolsMulticoreFutureBackend <- function(workers = availableCores(constraint
6871
}
6972

7073

71-
#' @rdname BatchtoolsMulticoreFutureBackend
74+
#' @inheritParams BatchtoolsMulticoreFutureBackend
75+
#'
7276
#' @export
73-
batchtools_multicore <- function(..., workers = availableCores(constraints = "multicore"), envir = parent.frame()) {
77+
batchtools_multicore <- function(..., workers = availableCores(constraints = "multicore")) {
7478
stop("INTERNAL ERROR: The future.batchtools::batchtools_multicore() must never be called directly")
7579
}
7680
class(batchtools_multicore) <- c(

R/batchtools_ssh.R

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@
99
#'
1010
#' @inheritParams BatchtoolsFutureBackend
1111
#'
12-
#' @param workers The number of SSH processes to be
13-
#' available for concurrent batchtools SSH futures.
14-
#' @param \ldots Additional arguments passed
15-
#' to [BatchtoolsFutureBackend()].
16-
#'
1712
#' @return An object of class `BatchtoolsMulticoreFuture`.
1813
#'
1914
#' @details
@@ -22,9 +17,10 @@
2217
#' The batchtools SSH backend only works on operating systems
2318
#' supporting the `ssh` and `ps` command-line tool, e.g. Linux and macOS.
2419
#'
25-
#' @importFrom parallelly availableWorkers
26-
#'
20+
#' @rdname BatchtoolsFutureBackend
2721
#' @keywords internal
22+
#'
23+
#' @importFrom parallelly availableWorkers
2824
#' @importFrom batchtools makeClusterFunctionsSSH
2925
#' @importFrom parallelly availableCores
3026
#' @export
@@ -76,8 +72,10 @@ BatchtoolsSSHFutureBackend <- function(workers = availableWorkers(), ...) {
7672
}
7773

7874

75+
#' @inheritParams BatchtoolsSSHFutureBackend
76+
#'
7977
#' @export
80-
batchtools_ssh <- function(..., workers = availableWorkers(), envir = parent.frame()) {
78+
batchtools_ssh <- function(..., workers = availableWorkers()) {
8179
stop("INTERNAL ERROR: The future.batchtools::batchtools_ssh() must never be called directly")
8280
}
8381
class(batchtools_ssh) <- c(

0 commit comments

Comments
 (0)