1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
|
source("incl/start.R")
if (requireNamespace("future.apply", quietly = TRUE)) {
future_lapply <- future.apply::future_lapply
library("listenv")
## Setup all strategies including custom once for testing on HPC environments
print(all_strategies())
message("All HPC strategies:")
strategies <- c("batchtools_lsf", "batchtools_openlava", "batchtools_sge",
"batchtools_slurm", "batchtools_torque")
mprint(strategies, debug = TRUE)
message("Supported HPC strategies:")
strategies <- strategies[sapply(strategies, FUN = test_strategy)]
mprint(strategies, debug = TRUE)
strategies <- c("batchtools_local", strategies)
if (fullTest) {
strategies <- c("batchtools_interactive", strategies)
batchtools_custom_local <- function(expr, substitute = TRUE,
cluster.functions = batchtools::makeClusterFunctionsInteractive(external = TRUE), ...) {
if (substitute) expr <- substitute(expr)
batchtools_custom(expr, substitute = FALSE, ...,
cluster.functions = cluster.functions)
}
class(batchtools_custom_local) <- c("batchtools_custom_local",
class(batchtools_custom))
strategies <- c("batchtools_custom_local", strategies)
}
## CRAN processing times: Don't run these tests on Windows 32-bit
if (!fullTest && isWin32) strategies <- character(0L)
message("Strategies to test with:")
mprint(strategies, debug = TRUE)
message("*** future_lapply() ...")
message("- future_lapply(x, FUN = vector, ...) ...")
x <- list(a = "integer", c = "character", c = "list")
str(list(x = x))
y0 <- lapply(x, FUN = vector, length = 2L)
str(list(y0 = y0))
for (strategy in strategies) {
mprintf("- plan('%s') ...\n", strategy)
plan(strategy)
mprint(plan, debug = TRUE)
if (nbrOfWorkers() > 2) plan(strategy, workers = 2L)
stopifnot(nbrOfWorkers() < Inf)
for (scheduling in list(FALSE, TRUE)) {
y <- future_lapply(x, FUN = vector, length = 2L,
future.scheduling = scheduling)
str(list(y = y))
stopifnot(identical(y, y0))
}
}
message("- future_lapply(x, FUN = base::vector, ...) ...")
x <- list(a = "integer", c = "character", c = "list")
str(list(x = x))
y0 <- lapply(x, FUN = base::vector, length = 2L)
str(list(y0 = y0))
for (strategy in strategies) {
mprintf("- plan('%s') ...\n", strategy)
plan(strategy)
mprint(plan, debug = TRUE)
if (nbrOfWorkers() > 2) plan(strategy, workers = 2L)
stopifnot(nbrOfWorkers() < Inf)
for (scheduling in list(FALSE, TRUE)) {
y <- future_lapply(x, FUN = base::vector, length = 2L,
future.scheduling = scheduling)
str(list(y = y))
stopifnot(identical(y, y0))
}
}
message("- future_lapply(x, FUN = future:::hpaste, ...) ...")
x <- list(a = c("hello", b = 1:100))
str(list(x = x))
y0 <- lapply(x, FUN = future:::hpaste, collapse = "; ", maxHead = 3L)
str(list(y0 = y0))
for (strategy in strategies) {
mprintf("- plan('%s') ...\n", strategy)
plan(strategy)
mprint(plan, debug = TRUE)
if (nbrOfWorkers() > 2) plan(strategy, workers = 2L)
stopifnot(nbrOfWorkers() < Inf)
for (scheduling in list(FALSE, TRUE)) {
y <- future_lapply(x, FUN = future:::hpaste, collapse = "; ",
maxHead = 3L, future.scheduling = scheduling)
str(list(y = y))
stopifnot(identical(y, y0))
}
}
message("- future_lapply(x, FUN = listenv::listenv, ...) ...")
x <- list()
y <- listenv()
y$A <- 3L
x$a <- y
y <- listenv()
y$A <- 3L
y$B <- c("hello", b = 1:100)
x$b <- y
print(x)
y0 <- lapply(x, FUN = listenv::mapping)
str(list(y0 = y0))
for (strategy in strategies) {
mprintf("- plan('%s') ...\n", strategy)
plan(strategy)
if (nbrOfWorkers() > 2) plan(strategy, workers = 2L)
stopifnot(nbrOfWorkers() < Inf)
for (scheduling in list(FALSE, TRUE)) {
y <- future_lapply(x, FUN = listenv::mapping, future.scheduling = scheduling)
str(list(y = y))
stopifnot(identical(y, y0))
}
}
message("- future_lapply(x, FUN, ...) for large length(x) ...")
a <- 3.14
x <- 1:1e5
y <- future_lapply(x, FUN = function(z) sqrt(z + a))
y <- unlist(y, use.names = FALSE)
stopifnot(all.equal(y, sqrt(x + a)))
message("- future_lapply() with global in non-attached package ...")
library("tools")
my_ext <- function(x) file_ext(x)
y_truth <- lapply("abc.txt", FUN = my_ext)
for (strategy in strategies) {
plan(strategy)
if (nbrOfWorkers() > 2) plan(strategy, workers = 2L)
stopifnot(nbrOfWorkers() < Inf)
y <- future_lapply("abc.txt", FUN = my_ext)
stopifnot(identical(y, y_truth))
}
message("*** future_lapply() ... DONE")
}
source("incl/end.R")
|