Skip to content

Commit 550cadb

Browse files
batchtools_lsf(): help + add template script
1 parent def5b0f commit 550cadb

File tree

7 files changed

+195
-31
lines changed

7 files changed

+195
-31
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-9921
2+
Version: 0.12.2-9922
33
Depends:
44
R (>= 3.2.0),
55
parallelly,

NEWS.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
## Significant Changes
44

55
* **future.batchtools** now implements the FutureBackend API
6-
introduced in **future** 1.40.0.
6+
introduced in **future** 1.40.0 (2025-04-10).
77

88
## New Features
99

@@ -13,6 +13,8 @@
1313

1414
* Canceling batchtools futures will now interrupt them by default,
1515
if the backend supports it.
16+
17+
* Add built-in template job script for LSF.
1618

1719
## Documentation
1820

R/batchtools_lsf.R

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#' @export
2+
BatchtoolsLsfFutureBackend <- function(...) {
3+
core <- BatchtoolsTemplateFutureBackend(..., type = "lsf")
4+
core[["futureClasses"]] <- c("BatchtoolsLsfFuture", core[["futureClasses"]])
5+
core <- structure(core, class = c("BatchtoolsLsfFutureBackend", class(core)))
6+
core
7+
}
8+
9+
10+
#' A batchtools LSF backend resolves futures in parallel via a LSF job scheduler
11+
#'
12+
#' @inheritParams BatchtoolsFutureBackend
13+
#' @inheritParams BatchtoolsTemplateFutureBackend
14+
#'
15+
#' @param template (optional) Name of job-script template to be searched
16+
#' for by [batchtools::findTemplateFile()]. If not found, it defaults to
17+
#' the `templates/lsf.tmpl` part of this package (see below).
18+
#'
19+
#' @param \ldots Not used.
20+
#'
21+
#' @details
22+
#' Batchtools lsf futures use \pkg{batchtools} cluster functions
23+
#' created by [batchtools::makeClusterFunctionsLSF()], which requires
24+
#' that LSF commands `bsub`, `bjobs`, and `bkill` are installed on
25+
#' the current machine.
26+
#'
27+
#' The default template script `templates/lsf.tmpl` can be found in:
28+
#'
29+
#' ```r
30+
#' system.file("templates", "lsf.tmpl", package = "future.batchtools")
31+
#' ```
32+
#'
33+
#' and comprise:
34+
#'
35+
#' `r paste(c("\x60\x60\x60bash", readLines("inst/templates/lsf.tmpl"), "\x60\x60\x60"), collapse = "\n")`
36+
#'
37+
#' @examplesIf interactive()
38+
#' # Limit runtime to 3 minutes and memory to 200 MiB per future
39+
#' plan(batchtools_lsf, resources = list(W = "00:03:00", M = "200"))
40+
#'
41+
#' message("Main process ID: ", Sys.getpid())
42+
#'
43+
#' f <- future(Sys.getpid())
44+
#' pid <- value(f)
45+
#' message("Worker process ID: ", pid)
46+
#'
47+
#' @export
48+
batchtools_lsf <- function(..., template = "lsf") {
49+
stop("INTERNAL ERROR: The future.batchtools::batchtools_lsf() must never be called directly")
50+
}
51+
class(batchtools_lsf) <- c(
52+
"batchtools_lsf", "batchtools_template",
53+
"batchtools_multiprocess", "batchtools",
54+
"multiprocess", "future", "function"
55+
)
56+
attr(batchtools_lsf, "tweakable") <- c(
57+
"workers",
58+
"finalize",
59+
## Arguments to batchtools::makeClusterFunctionsLSF()
60+
"scheduler.latency", "fs.latency"
61+
)
62+
attr(batchtools_lsf, "init") <- TRUE
63+
attr(batchtools_lsf, "factory") <- BatchtoolsLsfFutureBackend

R/batchtools_template.R

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#' [TORQUE](https://en.wikipedia.org/wiki/TORQUE) / PBS
3333
#'
3434
#' @aliases BatchtoolsLsfFutureBackend BatchtoolsOpenLavaFutureBackend BatchtoolsSGEFutureBackend BatchtoolsSlurmFutureBackend BatchtoolsTorqueFutureBackend
35-
#' @aliases batchtools_lsf batchtools_openlava
35+
#' @aliases batchtools_openlava
3636
#'
3737
#' @importFrom batchtools makeClusterFunctionsLSF
3838
#' @importFrom batchtools makeClusterFunctionsOpenLava
@@ -86,33 +86,6 @@ BatchtoolsTemplateFutureBackend <- function(..., template = NULL, type = c("lsf"
8686
}
8787

8888

89-
#' @export
90-
BatchtoolsLsfFutureBackend <- function(...) {
91-
core <- BatchtoolsTemplateFutureBackend(..., type = "lsf")
92-
core[["futureClasses"]] <- c("BatchtoolsLsfFuture", core[["futureClasses"]])
93-
core <- structure(core, class = c("BatchtoolsLsfFutureBackend", class(core)))
94-
core
95-
}
96-
97-
#' @export
98-
batchtools_lsf <- function(...) {
99-
stop("INTERNAL ERROR: The future.batchtools::batchtools_lsf() must never be called directly")
100-
}
101-
class(batchtools_lsf) <- c(
102-
"batchtools_lsf", "batchtools_template",
103-
"batchtools_multiprocess", "batchtools",
104-
"multiprocess", "future", "function"
105-
)
106-
attr(batchtools_lsf, "tweakable") <- c(
107-
"workers",
108-
"finalize",
109-
## Arguments to batchtools::makeClusterFunctionsLSF()
110-
"scheduler.latency", "fs.latency"
111-
)
112-
attr(batchtools_lsf, "init") <- TRUE
113-
attr(batchtools_lsf, "factory") <- BatchtoolsLsfFutureBackend
114-
115-
11689
#' @export
11790
BatchtoolsOpenLavaFutureBackend <- function(...) {
11891
core <- BatchtoolsTemplateFutureBackend(..., type = "openlava")

inst/templates/lsf.tmpl

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
######################################################################
3+
# A batchtools launch script template for LSF
4+
#
5+
# Author: Henrik Bengtsson
6+
######################################################################
7+
8+
## Job name:
9+
#BSUB -J <%= job.name %>
10+
11+
## Direct streams to logfile:
12+
#BSUB -o <%= log.file %>
13+
14+
## Resources needed:
15+
<% if (length(resources) > 0) {
16+
opts <- unlist(resources, use.names = TRUE)
17+
opts <- sprintf("-%s=%s", names(opts), opts)
18+
cat(sprintf("#BSUB %s\n", opts))
19+
<% } %>
20+
21+
echo "Batchtools job name: '<%= job.name %>'"
22+
23+
echo "Session information:"
24+
date
25+
hostname
26+
which Rscript
27+
Rscript --version
28+
Rscript -e ".libPaths()"
29+
30+
## Launch R and evaluate the batchtools R job
31+
echo "Command: Rscript -e 'batchtools::doJobCollection("<%= uri %>")' ..."
32+
Rscript -e 'batchtools::doJobCollection("<%= uri %>")'
33+
res=$?
34+
echo " - exit code: ${res}"
35+
echo "Command: Rscript -e 'batchtools::doJobCollection("<%= uri %>")' ... done"
36+
37+
## End-of-job summary
38+
bjobs -l "${LSB_JOBID}"
39+
40+
## Relay the exit code from Rscript
41+
exit "${res}"

man/BatchtoolsTemplateFutureBackend.Rd

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/batchtools_lsf.Rd

Lines changed: 86 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)