From 798644d13cded9c0c0904ce6b981d30d462a9d7c Mon Sep 17 00:00:00 2001 From: hb Date: Thu, 3 May 2018 21:58:32 -0700 Subject: [PATCH 01/35] Bump develop version [ci skip] --- DESCRIPTION | 2 +- NEWS | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 4fdd558..5dfb57e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: future.batchtools -Version: 0.7.0 +Version: 0.7.0-9000 Depends: R (>= 3.2.0), future (>= 1.8.1) diff --git a/NEWS b/NEWS index 6ea18db..ef3b42a 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,11 @@ Package: future.batchtools ========================== +Version: 0.7.0-9000 [2018-05-03] + + o ... + + Version: 0.7.0 [2018-05-03] NEW FEATURES: From 16025e1fac7abc67e6ad32f3008de5ffec6a7d21 Mon Sep 17 00:00:00 2001 From: hb Date: Sat, 5 May 2018 15:45:43 -0700 Subject: [PATCH 02/35] BUG FIX: future 1.8.0 could produce "Error in readLog(id, reg = reg) : Log file for job with id 1 not available" [#22] --- NEWS | 11 ++++++++++- R/BatchtoolsFuture-class.R | 2 +- tests/batchtools_hpc.R | 10 ++++++++-- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/NEWS b/NEWS index ef3b42a..87c674e 100644 --- a/NEWS +++ b/NEWS @@ -1,10 +1,19 @@ Package: future.batchtools ========================== -Version: 0.7.0-9000 [2018-05-03] +Version: 0.7.0-9000 [2018-05-05] o ... +BUG FIXES: + + o A bug was introduced in future 1.8.0 that could result in "Error in + readLog(id, reg = reg) : Log file for job with id 1 not available" when + using one of the batchtools backends. It occurred when the value was + queried. It was observered using 'batchtools_torque' but not when using + 'batchools_local'. This bug was missed because the 1.8.0 release was not + tested on an HPC scheduled as it should have. + Version: 0.7.0 [2018-05-03] diff --git a/R/BatchtoolsFuture-class.R b/R/BatchtoolsFuture-class.R index 7c637d4..8ef397f 100644 --- a/R/BatchtoolsFuture-class.R +++ b/R/BatchtoolsFuture-class.R @@ -282,7 +282,7 @@ value.BatchtoolsFuture <- function(future, signal = TRUE, onMissing = c("default", "error"), default = NULL, cleanup = TRUE, ...) { ## Has the value already been collected? - if (future$state %in% c("done", "failed", "interrupted")) { + if (future$state %in% c("done", "finished", "failed", "interrupted")) { return(NextMethod("value")) } diff --git a/tests/batchtools_hpc.R b/tests/batchtools_hpc.R index 38bcd4c..4bc4d37 100644 --- a/tests/batchtools_hpc.R +++ b/tests/batchtools_hpc.R @@ -12,10 +12,16 @@ for (strategy in strategies) { plan(strategy) print(plan()) - + + f <- future(42L) + print(f) + v <- value(f) + print(v) + stopifnot(v == 42L) + x %<-% Sys.info() print(x) - + message(sprintf("*** %s() ... DONE", strategy)) } From d42c0a673a9eca030516c2e424d9c34047574e96 Mon Sep 17 00:00:00 2001 From: hb Date: Sat, 5 May 2018 17:49:38 -0700 Subject: [PATCH 03/35] TESTS: Adding more testing of HPC backends [#22] --- tests/batchtools_hpc.R | 14 ++++++++------ tests/zzz,future_lapply.R | 20 +++++++++++++++++++- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/tests/batchtools_hpc.R b/tests/batchtools_hpc.R index 38bcd4c..c34532a 100644 --- a/tests/batchtools_hpc.R +++ b/tests/batchtools_hpc.R @@ -1,15 +1,17 @@ source("incl/start.R") +print(all_strategies()) + +message("All HPC strategies:") strategies <- c("batchtools_lsf", "batchtools_openlava", "batchtools_sge", "batchtools_slurm", "batchtools_torque") -print(all_strategies()) +mprint(strategies) -for (strategy in strategies) { - if (!test_strategy(strategy)) { - message(sprintf("*** %s() ... NOT SUPPORTED", strategy)) - next - } +message("Supported HPC strategies:") +strategies <- strategies[sapply(strategies, FUN = test_strategy)] +mprint(strategies) +for (strategy in strategies) { plan(strategy) print(plan()) diff --git a/tests/zzz,future_lapply.R b/tests/zzz,future_lapply.R index 16bf971..fd1131c 100644 --- a/tests/zzz,future_lapply.R +++ b/tests/zzz,future_lapply.R @@ -12,8 +12,20 @@ batchtools_custom_local <- function(expr, substitute = TRUE, class(batchtools_custom_local) <- c("batchtools_custom_local", class(batchtools_custom)) +message("All HPC strategies:") +strategies <- c("batchtools_lsf", "batchtools_openlava", "batchtools_sge", + "batchtools_slurm", "batchtools_torque") +mprint(strategies) + +message("Supported HPC strategies:") +strategies <- strategies[sapply(strategies, FUN = test_strategy)] +mprint(strategies) + +message("Strategies to test with:") strategies <- c("batchtools_interactive", "batchtools_local", - "batchtools_custom_local") + "batchtools_custom_local", strategies) +mprint(strategies) + message("*** future_lapply() ...") @@ -29,6 +41,7 @@ for (scheduling in list(FALSE, TRUE)) { for (strategy in strategies) { mprintf("- plan('%s') ...", strategy) plan(strategy) + if (is.infinite(nbrOfWorkers())) plan(strategy, workers = 3L) stopifnot(nbrOfWorkers() < Inf) y <- future_lapply(x, FUN = vector, length = 2L, @@ -51,6 +64,7 @@ for (scheduling in list(FALSE, TRUE)) { for (strategy in strategies) { mprintf("- plan('%s') ...", strategy) plan(strategy) + if (is.infinite(nbrOfWorkers())) plan(strategy, workers = 3L) stopifnot(nbrOfWorkers() < Inf) y <- future_lapply(x, FUN = base::vector, length = 2L, @@ -72,6 +86,7 @@ for (scheduling in list(FALSE, TRUE)) { for (strategy in strategies) { mprintf("- plan('%s') ...", strategy) plan(strategy) + if (is.infinite(nbrOfWorkers())) plan(strategy, workers = 3L) stopifnot(nbrOfWorkers() < Inf) y <- future_lapply(x, FUN = future:::hpaste, collapse = "; ", @@ -104,6 +119,7 @@ for (scheduling in list(FALSE, TRUE)) { for (strategy in strategies) { mprintf("- plan('%s') ...", strategy) plan(strategy) + if (is.infinite(nbrOfWorkers())) plan(strategy, workers = 3L) stopifnot(nbrOfWorkers() < Inf) y <- future_lapply(x, FUN = listenv::map, future.scheduling = scheduling) @@ -130,6 +146,8 @@ y_truth <- lapply("abc.txt", FUN = my_ext) for (strategy in strategies) { plan(strategy) + if (is.infinite(nbrOfWorkers())) plan(strategy, workers = 3L) + stopifnot(nbrOfWorkers() < Inf) y <- future_lapply("abc.txt", FUN = my_ext) stopifnot(identical(y, y_truth)) } From 314a37a8dc55c95eef60a16146ce4219c133b6fc Mon Sep 17 00:00:00 2001 From: hb Date: Sat, 12 May 2018 05:32:44 -0700 Subject: [PATCH 04/35] tweaks --- NEWS | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/NEWS b/NEWS index 87c674e..dd5dce1 100644 --- a/NEWS +++ b/NEWS @@ -7,12 +7,12 @@ Version: 0.7.0-9000 [2018-05-05] BUG FIXES: - o A bug was introduced in future 1.8.0 that could result in "Error in - readLog(id, reg = reg) : Log file for job with id 1 not available" when + o A bug was introduced in future.batchtools 0.7.0 that could result in "Error + in readLog(id, reg = reg) : Log file for job with id 1 not available" when using one of the batchtools backends. It occurred when the value was queried. It was observered using 'batchtools_torque' but not when using - 'batchools_local'. This bug was missed because the 1.8.0 release was not - tested on an HPC scheduled as it should have. + 'batchools_local'. This bug was missed because the 0.7.0 release was not + tested on an TORQUE/PBS HPC scheduler as it should have. Version: 0.7.0 [2018-05-03] @@ -50,7 +50,7 @@ NEW FEATURES: o The error message for expired batchtools futures now include the last few lines of the logged output, which sometimes includes clues on why the future - expired. For instance, if a TORQUE / PBS job use more than the allocated + expired. For instance, if a TORQUE/PBS job use more than the allocated amount of memory it might be terminated by the scheduler leaving the message "PBS: job killed: vmem 1234000 exceeded limit 1048576" in the output. From 2340f6298942816ec5f62a2f7257ccac1cfd5d16 Mon Sep 17 00:00:00 2001 From: hb Date: Sat, 12 May 2018 06:43:16 -0700 Subject: [PATCH 05/35] AD HOC: Use try() to grab stdout log [#22] --- R/BatchtoolsFuture-class.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/BatchtoolsFuture-class.R b/R/BatchtoolsFuture-class.R index 8ef397f..704ef94 100644 --- a/R/BatchtoolsFuture-class.R +++ b/R/BatchtoolsFuture-class.R @@ -499,7 +499,7 @@ await.BatchtoolsFuture <- function(future, cleanup = TRUE, result <- loadResult(reg = reg, id = jobid) if (inherits(result, "FutureResult")) { prototype_fields <- c(prototype_fields, "stdout") - result$stdout <- getLog(id = jobid, reg = reg) + result$stdout <- try(getLog(id = jobid, reg = reg), silent = TRUE) if (inherits(result$condition, "error")) { cleanup <- FALSE } From a28ede4718f31cd499f49dbbfc4980bf56569d0f Mon Sep 17 00:00:00 2001 From: hb Date: Tue, 29 May 2018 20:22:35 -0700 Subject: [PATCH 06/35] CLEANUP: Don't specify arguments for NextMethod(). https://github.com/HenrikBengtsson/Wishlist-for-R/issues/44 --- R/BatchtoolsFuture-class.R | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/R/BatchtoolsFuture-class.R b/R/BatchtoolsFuture-class.R index 704ef94..c964741 100644 --- a/R/BatchtoolsFuture-class.R +++ b/R/BatchtoolsFuture-class.R @@ -112,7 +112,7 @@ BatchtoolsFuture <- function(expr = NULL, envir = parent.frame(), #' @export #' @keywords internal print.BatchtoolsFuture <- function(x, ...) { - NextMethod("print") + NextMethod() ## batchtools specific reg <- x$config$reg @@ -265,7 +265,7 @@ loggedOutput.BatchtoolsFuture <- function(future, ...) { #' @keywords internal resolved.BatchtoolsFuture <- function(x, ...) { ## Has internal future state already been switched to be resolved - resolved <- NextMethod("resolved") + resolved <- NextMethod() if (resolved) return(TRUE) ## If not, checks the batchtools registry status @@ -283,7 +283,7 @@ value.BatchtoolsFuture <- function(future, signal = TRUE, default = NULL, cleanup = TRUE, ...) { ## Has the value already been collected? if (future$state %in% c("done", "finished", "failed", "interrupted")) { - return(NextMethod("value")) + return(NextMethod()) } if (future$state == "created") { @@ -305,7 +305,7 @@ value.BatchtoolsFuture <- function(future, signal = TRUE, future$state <- "finished" if (cleanup) delete(future, ...) - NextMethod("value") + NextMethod() } # value() From fcb6aa35e554179da42481626dfef29a93008715 Mon Sep 17 00:00:00 2001 From: hb Date: Fri, 6 Jul 2018 21:19:47 -0700 Subject: [PATCH 07/35] CLEANUP: Implementing result() method - value() method is no longer needed --- NAMESPACE | 5 ++-- NEWS | 4 ++-- R/BatchtoolsFuture-class.R | 42 ++++++++++++++++------------------ man/status.BatchtoolsFuture.Rd | 2 +- tests/BatchtoolsFuture.R | 6 +---- 5 files changed, 26 insertions(+), 33 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 00ec499..c72988e 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -8,8 +8,8 @@ S3method(loggedOutput,BatchtoolsFuture) S3method(nbrOfWorkers,batchtools) S3method(print,BatchtoolsFuture) S3method(resolved,BatchtoolsFuture) +S3method(result,BatchtoolsFuture) S3method(status,BatchtoolsFuture) -S3method(value,BatchtoolsFuture) export("%resources%") export(BatchtoolsFuture) export(BatchtoolsFutureError) @@ -26,7 +26,6 @@ export(finished) export(loggedError) export(loggedOutput) export(status) -export(value) importFrom(batchtools,batchExport) importFrom(batchtools,batchMap) importFrom(batchtools,clearRegistry) @@ -55,8 +54,8 @@ importFrom(future,getGlobalsAndPackages) importFrom(future,nbrOfWorkers) importFrom(future,plan) importFrom(future,resolved) +importFrom(future,result) importFrom(future,tweak) -importFrom(future,value) importFrom(utils,capture.output) importFrom(utils,file_test) importFrom(utils,sessionInfo) diff --git a/NEWS b/NEWS index dd5dce1..8f33390 100644 --- a/NEWS +++ b/NEWS @@ -1,7 +1,7 @@ Package: future.batchtools ========================== -Version: 0.7.0-9000 [2018-05-05] +Version: 0.7.0-9000 [2018-07-06] o ... @@ -13,7 +13,7 @@ BUG FIXES: queried. It was observered using 'batchtools_torque' but not when using 'batchools_local'. This bug was missed because the 0.7.0 release was not tested on an TORQUE/PBS HPC scheduler as it should have. - + Version: 0.7.0 [2018-05-03] diff --git a/R/BatchtoolsFuture-class.R b/R/BatchtoolsFuture-class.R index c964741..1c82fcf 100644 --- a/R/BatchtoolsFuture-class.R +++ b/R/BatchtoolsFuture-class.R @@ -76,7 +76,9 @@ BatchtoolsFuture <- function(expr = NULL, envir = parent.frame(), gp <- getGlobalsAndPackages(expr, envir = envir, globals = globals) future <- Future(expr = gp$expr, envir = envir, substitute = FALSE, - workers = workers, label = label, version = "1.8", ...) + workers = workers, label = label, + version = "1.8", .callResult = TRUE, + ...) future$globals <- gp$globals future$packages <- unique(c(packages, gp$packages)) @@ -152,14 +154,13 @@ loggedOutput <- function(...) UseMethod("loggedOutput") #' #' @return A character vector or a logical scalar. #' -#' @aliases status finished value +#' @aliases status finished result #' loggedError loggedOutput #' @keywords internal #' #' @export #' @export status #' @export finished -#' @export value #' @export loggedError #' @export loggedOutput #' @importFrom batchtools getStatus @@ -192,13 +193,15 @@ status.BatchtoolsFuture <- function(future, ...) { status <- status[status] status <- sort(names(status)) status <- setdiff(status, c("n")) + +## status[status == "done"] <- "finished" result <- future$result if (inherits(result, "FutureResult")) { condition <- result$condition if (inherits(condition, "error")) status <- c("error", status) } - + status } @@ -208,7 +211,7 @@ status.BatchtoolsFuture <- function(future, ...) { finished.BatchtoolsFuture <- function(future, ...) { status <- status(future) if (is_na(status)) return(NA) - any(c("done", "error", "expired") %in% status) + any(c("done", "finished", "error", "expired") %in% status) } #' @export @@ -275,13 +278,15 @@ resolved.BatchtoolsFuture <- function(x, ...) { resolved } -#' @importFrom future value +#' @importFrom future result #' @export #' @keywords internal -value.BatchtoolsFuture <- function(future, signal = TRUE, - onMissing = c("default", "error"), - default = NULL, cleanup = TRUE, ...) { +result.BatchtoolsFuture <- function(future, ...) { ## Has the value already been collected? + result <- future$result + if (inherits(result, "FutureResult")) return(result) + + ## Has the value already been collected? - take two if (future$state %in% c("done", "finished", "failed", "interrupted")) { return(NextMethod()) } @@ -292,22 +297,19 @@ value.BatchtoolsFuture <- function(future, signal = TRUE, stat <- status(future) if (is_na(stat)) { - onMissing <- match.arg(onMissing) - if (onMissing == "default") return(default) label <- future$label if (is.null(label)) label <- "" - stop(sprintf("The value no longer exists (or never existed) for Future ('%s') of class %s", label, paste(sQuote(class(future)), collapse = ", "))) #nolint + stop(sprintf("The result no longer exists (or never existed) for Future ('%s') of class %s", label, paste(sQuote(class(future)), collapse = ", "))) #nolint } result <- await(future, cleanup = FALSE) stop_if_not(inherits(result, "FutureResult")) future$result <- result future$state <- "finished" - if (cleanup) delete(future, ...) + delete(future) NextMethod() -} # value() - +} run <- function(...) UseMethod("run") @@ -485,7 +487,7 @@ await.BatchtoolsFuture <- function(future, cleanup = TRUE, mdebug("- status(): %s", paste(sQuote(stat), collapse = ", ")) mdebug("batchtools::waitForJobs() ... done") - finished <- is_na(stat) || any(c("done", "error", "expired") %in% stat) + finished <- is_na(stat) || any(c("done", "finished", "error", "expired") %in% stat) ## PROTOTYPE RESULTS BELOW: prototype_fields <- NULL @@ -621,13 +623,9 @@ delete.BatchtoolsFuture <- function(future, } } - ## FIXME: Make sure to collect the results before deleting + ## Make sure to collect the results before deleting ## the internal batchtools registry - result <- future$result - if (is.null(result)) { - value(future, signal = FALSE) - result <- future$result - } + result <- result(future) stop_if_not(inherits(result, "FutureResult")) ## To simplify post mortem troubleshooting in non-interactive sessions, diff --git a/man/status.BatchtoolsFuture.Rd b/man/status.BatchtoolsFuture.Rd index b48980f..3dab989 100644 --- a/man/status.BatchtoolsFuture.Rd +++ b/man/status.BatchtoolsFuture.Rd @@ -4,7 +4,7 @@ \alias{status.BatchtoolsFuture} \alias{status} \alias{finished} -\alias{value} +\alias{result} \alias{loggedError} \alias{loggedOutput} \title{Status of batchtools future} diff --git a/tests/BatchtoolsFuture.R b/tests/BatchtoolsFuture.R index d0cfff7..9fee0b9 100644 --- a/tests/BatchtoolsFuture.R +++ b/tests/BatchtoolsFuture.R @@ -51,12 +51,8 @@ f$state <- "running" path <- f$config$reg$file.dir unlink(path, recursive = TRUE) -res <- value(f, onMissing = "default") -print(res) -stopifnot(is.null(res)) - res <- tryCatch({ - value(f, onMissing = "error") + value(f) }, error = function(ex) ex) print(res) stopifnot(inherits(res, "error")) From 43bfc0d51c9f7ae270762923b951e1ec1d08adbc Mon Sep 17 00:00:00 2001 From: hb Date: Fri, 6 Jul 2018 21:28:26 -0700 Subject: [PATCH 08/35] CLEANUP/HARMONIZATION: Replacing status 'done' with 'finished' --- R/BatchtoolsFuture-class.R | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/R/BatchtoolsFuture-class.R b/R/BatchtoolsFuture-class.R index 1c82fcf..2a05869 100644 --- a/R/BatchtoolsFuture-class.R +++ b/R/BatchtoolsFuture-class.R @@ -194,7 +194,7 @@ status.BatchtoolsFuture <- function(future, ...) { status <- sort(names(status)) status <- setdiff(status, c("n")) -## status[status == "done"] <- "finished" + status[status == "done"] <- "finished" result <- future$result if (inherits(result, "FutureResult")) { @@ -211,7 +211,7 @@ status.BatchtoolsFuture <- function(future, ...) { finished.BatchtoolsFuture <- function(future, ...) { status <- status(future) if (is_na(status)) return(NA) - any(c("done", "finished", "error", "expired") %in% status) + any(c("finished", "error", "expired") %in% status) } #' @export @@ -274,7 +274,7 @@ resolved.BatchtoolsFuture <- function(x, ...) { ## If not, checks the batchtools registry status resolved <- finished(x) if (is.na(resolved)) return(FALSE) - + resolved } @@ -287,7 +287,7 @@ result.BatchtoolsFuture <- function(future, ...) { if (inherits(result, "FutureResult")) return(result) ## Has the value already been collected? - take two - if (future$state %in% c("done", "finished", "failed", "interrupted")) { + if (future$state %in% c("finished", "failed", "interrupted")) { return(NextMethod()) } @@ -487,7 +487,7 @@ await.BatchtoolsFuture <- function(future, cleanup = TRUE, mdebug("- status(): %s", paste(sQuote(stat), collapse = ", ")) mdebug("batchtools::waitForJobs() ... done") - finished <- is_na(stat) || any(c("done", "finished", "error", "expired") %in% stat) + finished <- is_na(stat) || any(c("finished", "error", "expired") %in% stat) ## PROTOTYPE RESULTS BELOW: prototype_fields <- NULL @@ -497,7 +497,7 @@ await.BatchtoolsFuture <- function(future, cleanup = TRUE, mdebug("Results:") label <- future$label if (is.null(label)) label <- "" - if ("done" %in% stat) { + if ("finished" %in% stat) { result <- loadResult(reg = reg, id = jobid) if (inherits(result, "FutureResult")) { prototype_fields <- c(prototype_fields, "stdout") From 58dec15adc4cb9eb46e5fb9f100c2d99eee7ad1d Mon Sep 17 00:00:00 2001 From: hb Date: Fri, 6 Jul 2018 21:34:45 -0700 Subject: [PATCH 09/35] Preparing for standard output captured during evaluation of futures --- NEWS | 4 ++++ R/BatchtoolsFuture-class.R | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index 8f33390..b8d4cd8 100644 --- a/NEWS +++ b/NEWS @@ -14,6 +14,10 @@ BUG FIXES: 'batchools_local'. This bug was missed because the 0.7.0 release was not tested on an TORQUE/PBS HPC scheduler as it should have. +CODE REFACTORING: + + o Preparing for standard output captured during evaluation of futures. + Version: 0.7.0 [2018-05-03] diff --git a/R/BatchtoolsFuture-class.R b/R/BatchtoolsFuture-class.R index 2a05869..9626d80 100644 --- a/R/BatchtoolsFuture-class.R +++ b/R/BatchtoolsFuture-class.R @@ -500,8 +500,10 @@ await.BatchtoolsFuture <- function(future, cleanup = TRUE, if ("finished" %in% stat) { result <- loadResult(reg = reg, id = jobid) if (inherits(result, "FutureResult")) { - prototype_fields <- c(prototype_fields, "stdout") - result$stdout <- try(getLog(id = jobid, reg = reg), silent = TRUE) + if (is.null(result$stdout)) { + prototype_fields <- c(prototype_fields, "stdout") + result$stdout <- try(getLog(id = jobid, reg = reg), silent = TRUE) + } if (inherits(result$condition, "error")) { cleanup <- FALSE } From b8a498af1745c58bb08248ef03f9da20d712d142 Mon Sep 17 00:00:00 2001 From: hb Date: Fri, 6 Jul 2018 21:39:25 -0700 Subject: [PATCH 10/35] CLEANUP: Argument 'output' is deprecated in future::FutureError() --- R/BatchtoolsFuture-class.R | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/R/BatchtoolsFuture-class.R b/R/BatchtoolsFuture-class.R index 9626d80..1c03131 100644 --- a/R/BatchtoolsFuture-class.R +++ b/R/BatchtoolsFuture-class.R @@ -512,8 +512,7 @@ await.BatchtoolsFuture <- function(future, cleanup = TRUE, cleanup <- FALSE msg <- sprintf("BatchtoolsError in %s ('%s'): %s", class(future)[1], label, loggedError(future)) - stop(BatchtoolsFutureError(msg, future = future, - output = loggedOutput(future))) + stop(BatchtoolsFutureError(msg, future = future)) } else if ("expired" %in% stat) { cleanup <- FALSE msg <- sprintf("BatchtoolsExpiration: Future ('%s') expired (registry path %s).", label, reg$file.dir) @@ -528,7 +527,7 @@ await.BatchtoolsFuture <- function(future, cleanup = TRUE, } else { msg <- sprintf("%s. No logged output exist.", msg) } - stop(BatchtoolsFutureError(msg, future = future, output = output)) + stop(BatchtoolsFutureError(msg, future = future)) } else if (is_na(stat)) { msg <- sprintf("BatchtoolsDeleted: Cannot retrieve value. Future ('%s') deleted: %s", label, reg$file.dir) #nolint stop(BatchtoolsFutureError(msg, future = future)) From 9e62b5ebac88173eb59660beae28204714cd4273 Mon Sep 17 00:00:00 2001 From: hb Date: Fri, 6 Jul 2018 23:28:44 -0700 Subject: [PATCH 11/35] tweak [ci skip] --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 5dfb57e..34880d5 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -20,7 +20,7 @@ Description: Implementation of the Future API on top of the 'batchtools' package in parallel out of the box, not only on your local machine or ad-hoc cluster of machines, but also via high-performance compute ('HPC') job schedulers such as 'LSF', 'OpenLava', 'Slurm', 'SGE', and 'TORQUE' / 'PBS', - e.g. 'y <- future_lapply(files, FUN = process)'. + e.g. 'y <- future.apply::future_lapply(files, FUN = process)'. License: LGPL (>= 2.1) LazyLoad: TRUE URL: https://github.com/HenrikBengtsson/future.batchtools From 40d5a5636f9e597352a79da112b8294a5848f42d Mon Sep 17 00:00:00 2001 From: hb Date: Tue, 10 Jul 2018 08:27:08 -0700 Subject: [PATCH 12/35] Add prototype field 'batchtools_log' to result() --- NEWS | 11 +++++------ R/BatchtoolsFuture-class.R | 8 ++++---- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/NEWS b/NEWS index b8d4cd8..c9eaf36 100644 --- a/NEWS +++ b/NEWS @@ -1,9 +1,12 @@ Package: future.batchtools ========================== -Version: 0.7.0-9000 [2018-07-06] +Version: 0.7.0-9000 [2018-07-10] - o ... +NEW FEATURES: + + o The batchtools_* backends support the handling of the standard output as + implemented in future (>= 1.9.0). BUG FIXES: @@ -14,10 +17,6 @@ BUG FIXES: 'batchools_local'. This bug was missed because the 0.7.0 release was not tested on an TORQUE/PBS HPC scheduler as it should have. -CODE REFACTORING: - - o Preparing for standard output captured during evaluation of futures. - Version: 0.7.0 [2018-05-03] diff --git a/R/BatchtoolsFuture-class.R b/R/BatchtoolsFuture-class.R index 1c03131..13cb674 100644 --- a/R/BatchtoolsFuture-class.R +++ b/R/BatchtoolsFuture-class.R @@ -500,10 +500,10 @@ await.BatchtoolsFuture <- function(future, cleanup = TRUE, if ("finished" %in% stat) { result <- loadResult(reg = reg, id = jobid) if (inherits(result, "FutureResult")) { - if (is.null(result$stdout)) { - prototype_fields <- c(prototype_fields, "stdout") - result$stdout <- try(getLog(id = jobid, reg = reg), silent = TRUE) - } + prototype_fields <- c(prototype_fields, "batchtools_log") + result[["batchtools_log"]] <- try({ + getLog(id = jobid, reg = reg) + }, silent = TRUE) if (inherits(result$condition, "error")) { cleanup <- FALSE } From 94864a7b009c29a06a0f82c69ab35fb1d78d3427 Mon Sep 17 00:00:00 2001 From: hb Date: Tue, 10 Jul 2018 22:21:25 -0700 Subject: [PATCH 13/35] TESTS: Add tests for 'stdout' --- tests/stdout.R | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 tests/stdout.R diff --git a/tests/stdout.R b/tests/stdout.R new file mode 100644 index 0000000..4847e24 --- /dev/null +++ b/tests/stdout.R @@ -0,0 +1,74 @@ +source("incl/start.R") + +## Only validate 'stdout' output if future (>= 1.9.0) +test_stdout <- ("stdout" %in% names(formals(future::Future))) +if (!test_stdout) `%stdout%` <- function(x, ...) x + +message("*** Standard output ...") + +truth_rows <- utils::capture.output({ + print(1:50) + str(1:50) + cat(letters, sep = "-") + cat(1:6, collapse = "\n") + write.table(datasets::iris[1:10,], sep = "\t") +}) +truth <- paste0(paste(truth_rows, collapse = "\n"), "\n") +print(truth) + +message("batchtools_local ...") +plan(batchtools_local) + +for (stdout in c(TRUE, FALSE, NA)) { + message(sprintf("- stdout = %s", stdout)) + + f <- future({ + print(1:50) + str(1:50) + cat(letters, sep = "-") + cat(1:6, collapse = "\n") + write.table(datasets::iris[1:10,], sep = "\t") + 42L + }, stdout = stdout) + r <- result(f) + str(r) + stopifnot(value(f) == 42L) + + + if (test_stdout) { + if (is.na(stdout)) { + stopifnot(!"stdout" %in% names(r)) + } else if (stdout) { + print(r) + stopifnot(identical(r$stdout, truth)) + } else { + stopifnot(is.null(r$stdout)) + } + } + + v %<-% { + print(1:50) + str(1:50) + cat(letters, sep = "-") + cat(1:6, collapse = "\n") + write.table(datasets::iris[1:10,], sep = "\t") + 42L + } %stdout% stdout + out <- utils::capture.output(y <- v) + stopifnot(y == 42L) + + if (test_stdout) { + if (is.na(stdout) || !stdout) { + stopifnot(out == "") + } else { + print(out) + stopifnot(identical(out, truth_rows)) + } + } +} ## for (stdout ...) + +message("batchtools_local ... DONE") + +message("*** Standard output ... DONE") + +source("incl/end.R") From 480a26506dbaff9864ead9ded9ddf750f0c29722 Mon Sep 17 00:00:00 2001 From: hb Date: Wed, 18 Jul 2018 12:47:06 +0200 Subject: [PATCH 14/35] future.batchtools 0.7.1 --- DESCRIPTION | 2 +- NEWS | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 34880d5..c959376 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: future.batchtools -Version: 0.7.0-9000 +Version: 0.7.1 Depends: R (>= 3.2.0), future (>= 1.8.1) diff --git a/NEWS b/NEWS index c9eaf36..1421d3f 100644 --- a/NEWS +++ b/NEWS @@ -1,7 +1,7 @@ Package: future.batchtools ========================== -Version: 0.7.0-9000 [2018-07-10] +Version: 0.7.1 [2018-07-18] NEW FEATURES: From c38eb586798b1e08ebd500a1171e033755c0061f Mon Sep 17 00:00:00 2001 From: hb Date: Wed, 18 Jul 2018 12:48:44 +0200 Subject: [PATCH 15/35] Update README [ci skip] --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9ccbaa8..b7570ab 100644 --- a/README.md +++ b/README.md @@ -191,14 +191,14 @@ demo("mandelbrot", package = "future", ask = FALSE) ## Installation R package future.batchtools is available on [CRAN](https://cran.r-project.org/package=future.batchtools) and can be installed in R as: ```r -install.packages('future.batchtools') +install.packages("future.batchtools") ``` ### Pre-release version To install the pre-release version that is available in Git branch `develop` on GitHub, use: ```r -source('http://callr.org/install#HenrikBengtsson/future.batchtools@develop') +remotes::install_github("HenrikBengtsson/future.batchtools@develop") ``` This will install the package from source. From 99823bf2f833ab13ffcaf54a0193ec5520941a6d Mon Sep 17 00:00:00 2001 From: hb Date: Wed, 18 Jul 2018 13:07:55 +0200 Subject: [PATCH 16/35] REVDEP: Ran revdep checks on 3 CRAN packages [ci skip] --- revdep/README.md | 61 ++++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 28 deletions(-) diff --git a/revdep/README.md b/revdep/README.md index d96e4a0..d691697 100644 --- a/revdep/README.md +++ b/revdep/README.md @@ -2,47 +2,52 @@ |field |value | |:--------|:----------------------------| -|version |R version 3.5.0 (2018-04-23) | +|version |R version 3.5.1 (2018-07-02) | |os |Ubuntu 16.04.4 LTS | |system |x86_64, linux-gnu | |ui |X11 | |language |en | |collate |en_US.UTF-8 | -|tz |America/Los_Angeles | -|date |2018-05-03 | +|tz |Europe/Copenhagen | +|date |2018-07-18 | # Dependencies -|package |old |new |Δ | -|:-----------------|:------|:----------|:--| -|future.batchtools |0.6.0 |0.6.0-9000 |* | -|assertthat |0.2.0 |0.2.0 | | -|backports |1.1.2 |1.1.2 | | -|base64url |1.3 |1.3 | | -|batchtools |0.9.8 |0.9.8 | | -|brew |1.0-6 |1.0-6 | | -|checkmate |1.8.5 |1.8.5 | | -|data.table |1.11.0 |1.11.0 | | -|digest |0.6.15 |0.6.15 | | -|future |1.8.1 |1.8.1 | | -|globals |0.11.0 |0.11.0 | | -|listenv |0.7.0 |0.7.0 | | -|magrittr |1.5 |1.5 | | -|prettyunits |1.0.2 |1.0.2 | | -|progress |1.1.2 |1.1.2 | | -|R6 |2.2.2 |2.2.2 | | -|rappdirs |0.3.1 |0.3.1 | | -|stringi |1.2.2 |1.2.2 | | -|withr |2.1.2 |2.1.2 | | +|package |old |new |Δ | +|:-----------------|:-------|:-------|:--| +|future.batchtools |0.7.0 |0.7.1 |* | +|assertthat |0.2.0 |0.2.0 | | +|backports |1.1.2 |1.1.2 | | +|base64url |1.4 |1.4 | | +|batchtools |0.9.10 |0.9.10 | | +|brew |1.0-6 |1.0-6 | | +|checkmate |1.8.5 |1.8.5 | | +|crayon |1.3.4 |1.3.4 | | +|data.table |1.11.4 |1.11.4 | | +|digest |0.6.15 |0.6.15 | | +|fs |1.2.3 |1.2.3 | | +|future |1.8.1 |1.8.1 | | +|globals |0.12.1 |0.12.1 | | +|hms |0.4.2 |0.4.2 | | +|listenv |0.7.0 |0.7.0 | | +|magrittr |1.5 |1.5 | | +|pkgconfig |2.0.1 |2.0.1 | | +|prettyunits |1.0.2 |1.0.2 | | +|progress |1.2.0 |1.2.0 | | +|R6 |2.2.2 |2.2.2 | | +|rappdirs |0.3.1 |0.3.1 | | +|Rcpp |0.12.17 |0.12.17 | | +|rlang |0.2.1 |0.2.1 | | +|stringi |1.2.3 |1.2.3 | | +|withr |2.1.2 |2.1.2 | | # Revdeps -## All (4) +## All (3) |package |version |error |warning |note | |:----------|:-------|:-----|:-------|:----| -|batchtools |0.9.8 | | | | -|drake |5.1.2 | | | | -|drtmle |1.0.2 | | | | +|batchtools |0.9.10 | | | | +|drtmle |1.0.3 | | | | |origami |1.0.0 | | | | From 68808136b6b3e666a68e5f92cb6ffb58f6c65485 Mon Sep 17 00:00:00 2001 From: hb Date: Wed, 18 Jul 2018 13:23:29 +0200 Subject: [PATCH 17/35] future.batchtools 0.7.1 --- cran-comments.md | 61 +++++++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/cran-comments.md b/cran-comments.md index ad4722a..a6121a7 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,10 +1,6 @@ -# CRAN submission future.batchtools 0.7.0 +# CRAN submission future.batchtools 0.7.1 -on 2018-05-03 - -This submission has been validated using 'R CMD check --as-cran' on Linux, Solaris, macOS, and Windows on the r-oldrel, r-release, and r-devel versions. - -I've verified that this submission causes no issues for any of the 4 reverse (non-recursive) package dependencies available on CRAN. +on 2018-07-18 Thanks in advance @@ -13,43 +9,50 @@ Thanks in advance The package has been verified using `R CMD check --as-cran` on: -* Platform x86_64-apple-darwin13.4.0 (64-bit) [Travis CI]: - - R version 3.3.3 (2017-03-06) - -* Platform x86_64-apple-darwin15.6.0 (64-bit) [Travis CI]: -# - R version 3.5.0 (2018-04-23) ## future 1.8.1 not available yet - * Platform x86_64-apple-darwin15.6.0 (64-bit) [r-hub; single-core]: -# - R version 3.5.0 (2018-04-23) ## data.table not available + - R version 3.5.0 (2018-04-23) * Platform x86_64-unknown-linux-gnu (64-bit) [Travis CI]: - - R version 3.3.3 (2017-01-27) + - R version 3.4.4 (2017-01-27) - R version 3.5.0 (2017-01-27) - - R Under development (unstable) (2018-05-03 r74693) + - R Under development (unstable) (2018-06-20 r74923) * Platform x86_64-pc-linux-gnu (64-bit) [r-hub]: - R version 3.4.4 (2018-03-15) - - R Under development (unstable) (2018-04-29 r74671) + - R Under development (unstable) (2018-07-16 r74967) * Platform x86_64-pc-linux-gnu (64-bit): + - R version 3.2.0 (2015-04-16) + - R version 3.3.0 (2016-05-03) + - R version 3.4.0 (2017-04-21) - R version 3.5.0 (2018-04-23) + - R version 3.5.1 (2018-07-02) -* Platform i686-pc-linux-gnu (32-bit): - - R version 3.4.4 (2018-03-15) - -* Platform i386-pc-solaris2.10 (32-bit) [r-hub]: - - R version 3.5.0 Patched (2018-04-30 r74674) +* Platform i386-w64-mingw32 (32-bit) (64-bit) [Appveyor CI]: + - R Under development (unstable) (2018-07-16 r74967) -* Platform i386-w64-mingw32 (32-bit) [Appveyor CI]: - - R Under development (unstable) (2018-05-02 r74682) +* Platform x86_64-w64-mingw32/x64 (64-bit) [Appveyor CI]: + - R version 3.5.1 (2018-07-02) + - R Under development (unstable) (2018-07-16 r74967) * Platform x86_64-w64-mingw32 (64-bit) [r-hub]: - - R Under development (unstable) (2018-05-02 r74679) - -* Platform x86_64-w64-mingw32/x64 (64-bit) [Appveyor CI]: - - R version 3.5.0 (2018-04-23) - - R Under development (unstable) (2018-05-02 r74682) + - R Under development (unstable) (2018-07-16 r74967) * Platform x86_64-w64-mingw32/x64 (64-bit) [win-builder]: + - R version 3.5.1 (2018-07-02) + - R Under development (unstable) (2018-07-16 r74967) + + +The following setups were skipped due to non-availability: + +* Platform x86_64-apple-darwin13.4.0 (64-bit) [Travis CI]: + - R version 3.4.4 (2017-01-27) + +* Platform x86_64-apple-darwin15.6.0 (64-bit) [Travis CI]: - R version 3.5.0 (2018-04-23) - - R Under development (unstable) (2018-04-30 r74674) + +* Platform i686-pc-linux-gnu (32-bit): + - R version 3.4.4 (2018-03-15) + +* Platform i686-pc-linux-gnu (32-bit): + - R version 3.4.4 (2018-03-15) From 438ce6a286eeee077f343d56a03224c1c32c4c45 Mon Sep 17 00:00:00 2001 From: hb Date: Wed, 18 Jul 2018 14:41:33 +0200 Subject: [PATCH 18/35] TESTS: Trying to speed up overall test timings --- tests/BatchtoolsFutureError.R | 2 +- tests/batchtools_custom.R | 4 +-- tests/batchtools_interactive.R | 4 +-- tests/batchtools_local.R | 4 +-- tests/batchtools_multicore.R | 6 ++-- tests/plan.R | 1 - tests/stdout.R | 12 ++++---- tests/zzz,future_lapply.R | 52 +++++++++++++++++----------------- 8 files changed, 42 insertions(+), 43 deletions(-) diff --git a/tests/BatchtoolsFutureError.R b/tests/BatchtoolsFutureError.R index da2b2a5..f149336 100644 --- a/tests/BatchtoolsFutureError.R +++ b/tests/BatchtoolsFutureError.R @@ -80,7 +80,7 @@ if (fullTest) { plan(batchtools_multicore) f <- future({ - Sys.sleep(5) + Sys.sleep(2) 42L }) diff --git a/tests/batchtools_custom.R b/tests/batchtools_custom.R index 9b2d36c..815b509 100644 --- a/tests/batchtools_custom.R +++ b/tests/batchtools_custom.R @@ -52,11 +52,11 @@ stopifnot(v == 0) message("*** batchtools_custom() with globals (tricky)") x <- listenv() -for (ii in 1:5) { +for (ii in 1:2) { x[[ii]] <- batchtools_custom({ ii }, globals = TRUE, cluster.functions = cf) } v <- sapply(x, FUN = value) -stopifnot(all(v == 1:5)) ## Make sure globals are frozen +stopifnot(all(v == 1:2)) ## Make sure globals are frozen message("*** batchtools_custom() and errors") diff --git a/tests/batchtools_interactive.R b/tests/batchtools_interactive.R index 4c9b1e0..b1408a8 100644 --- a/tests/batchtools_interactive.R +++ b/tests/batchtools_interactive.R @@ -45,9 +45,9 @@ stopifnot(v == 0) message("*** batchtools_interactive() with globals (tricky)") x <- listenv() -for (ii in 1:5) x[[ii]] <- batchtools_interactive({ ii }, globals = TRUE) +for (ii in 1:2) x[[ii]] <- batchtools_interactive({ ii }, globals = TRUE) v <- sapply(x, FUN = value) -stopifnot(all(v == 1:5)) ## Make sure globals are frozen +stopifnot(all(v == 1:2)) ## Make sure globals are frozen message("*** batchtools_interactive() and errors") diff --git a/tests/batchtools_local.R b/tests/batchtools_local.R index ca9b083..316df11 100644 --- a/tests/batchtools_local.R +++ b/tests/batchtools_local.R @@ -45,9 +45,9 @@ stopifnot(v == 0) message("*** batchtools_local() with globals (tricky)") x <- listenv() -for (ii in 1:5) x[[ii]] <- batchtools_local({ ii }, globals = TRUE) +for (ii in 1:2) x[[ii]] <- batchtools_local({ ii }, globals = TRUE) v <- sapply(x, FUN = value) -stopifnot(all(v == 1:5)) ## Make sure globals are frozen +stopifnot(all(v == 1:2)) ## Make sure globals are frozen message("*** batchtools_local() and errors") diff --git a/tests/batchtools_multicore.R b/tests/batchtools_multicore.R index e277c25..6f78b7d 100644 --- a/tests/batchtools_multicore.R +++ b/tests/batchtools_multicore.R @@ -4,7 +4,7 @@ library("listenv") message("*** batchtools_multicore() ...") -for (cores in 1:min(3L, availableCores("multicore"))) { +for (cores in 1:min(2L, availableCores("multicore"))) { ## FIXME: if (!fullTest && cores > 1) next @@ -62,14 +62,14 @@ for (cores in 1:min(3L, availableCores("multicore"))) { mprintf("*** batchtools_multicore(..., globals = %s) with globals and blocking", globals) #nolint x <- listenv() - for (ii in 1:4) { + for (ii in 1:2) { mprintf(" - Creating batchtools_multicore future #%d ...", ii) x[[ii]] <- batchtools_multicore({ ii }, globals = globals) } mprintf(" - Resolving %d batchtools_multicore futures", length(x)) if (globals || f$config$reg$cluster.functions$name == "Multicore") { v <- sapply(x, FUN = value) - stopifnot(all(v == 1:4)) + stopifnot(all(v == 1:2)) } else { v <- lapply(x, FUN = function(f) tryCatch(value(f), error = identity)) stopifnot(all(sapply(v, FUN = inherits, "simpleError"))) diff --git a/tests/plan.R b/tests/plan.R index 724e263..d7819ad 100644 --- a/tests/plan.R +++ b/tests/plan.R @@ -10,7 +10,6 @@ print(future::plan()) library("future.batchtools") -plan(batchtools_local) for (type in c("batchtools_interactive", "batchtools_local")) { mprintf("*** plan('%s') ...", type) diff --git a/tests/stdout.R b/tests/stdout.R index 4847e24..351a931 100644 --- a/tests/stdout.R +++ b/tests/stdout.R @@ -7,8 +7,8 @@ if (!test_stdout) `%stdout%` <- function(x, ...) x message("*** Standard output ...") truth_rows <- utils::capture.output({ - print(1:50) - str(1:50) + print(1:20) + str(1:20) cat(letters, sep = "-") cat(1:6, collapse = "\n") write.table(datasets::iris[1:10,], sep = "\t") @@ -23,8 +23,8 @@ for (stdout in c(TRUE, FALSE, NA)) { message(sprintf("- stdout = %s", stdout)) f <- future({ - print(1:50) - str(1:50) + print(1:20) + str(1:20) cat(letters, sep = "-") cat(1:6, collapse = "\n") write.table(datasets::iris[1:10,], sep = "\t") @@ -47,8 +47,8 @@ for (stdout in c(TRUE, FALSE, NA)) { } v %<-% { - print(1:50) - str(1:50) + print(1:20) + str(1:20) cat(letters, sep = "-") cat(1:6, collapse = "\n") write.table(datasets::iris[1:10,], sep = "\t") diff --git a/tests/zzz,future_lapply.R b/tests/zzz,future_lapply.R index fd1131c..adfe6ec 100644 --- a/tests/zzz,future_lapply.R +++ b/tests/zzz,future_lapply.R @@ -37,13 +37,13 @@ str(list(x = x)) y0 <- lapply(x, FUN = vector, length = 2L) str(list(y0 = y0)) -for (scheduling in list(FALSE, TRUE)) { - for (strategy in strategies) { - mprintf("- plan('%s') ...", strategy) - plan(strategy) - if (is.infinite(nbrOfWorkers())) plan(strategy, workers = 3L) - stopifnot(nbrOfWorkers() < Inf) +for (strategy in strategies) { + mprintf("- plan('%s') ...", strategy) + plan(strategy) + if (is.infinite(nbrOfWorkers())) 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)) @@ -60,13 +60,13 @@ str(list(x = x)) y0 <- lapply(x, FUN = base::vector, length = 2L) str(list(y0 = y0)) -for (scheduling in list(FALSE, TRUE)) { - for (strategy in strategies) { - mprintf("- plan('%s') ...", strategy) - plan(strategy) - if (is.infinite(nbrOfWorkers())) plan(strategy, workers = 3L) - stopifnot(nbrOfWorkers() < Inf) +for (strategy in strategies) { + mprintf("- plan('%s') ...", strategy) + plan(strategy) + if (is.infinite(nbrOfWorkers())) 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)) @@ -82,13 +82,13 @@ str(list(x = x)) y0 <- lapply(x, FUN = future:::hpaste, collapse = "; ", maxHead = 3L) str(list(y0 = y0)) -for (scheduling in list(FALSE, TRUE)) { - for (strategy in strategies) { - mprintf("- plan('%s') ...", strategy) - plan(strategy) - if (is.infinite(nbrOfWorkers())) plan(strategy, workers = 3L) - stopifnot(nbrOfWorkers() < Inf) +for (strategy in strategies) { + mprintf("- plan('%s') ...", strategy) + plan(strategy) + if (is.infinite(nbrOfWorkers())) 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)) @@ -115,13 +115,13 @@ print(x) y0 <- lapply(x, FUN = listenv::map) str(list(y0 = y0)) -for (scheduling in list(FALSE, TRUE)) { - for (strategy in strategies) { - mprintf("- plan('%s') ...", strategy) - plan(strategy) - if (is.infinite(nbrOfWorkers())) plan(strategy, workers = 3L) - stopifnot(nbrOfWorkers() < Inf) - +for (strategy in strategies) { + mprintf("- plan('%s') ...", strategy) + plan(strategy) + if (is.infinite(nbrOfWorkers())) plan(strategy, workers = 2L) + stopifnot(nbrOfWorkers() < Inf) + + for (scheduling in list(FALSE, TRUE)) { y <- future_lapply(x, FUN = listenv::map, future.scheduling = scheduling) str(list(y = y)) stopifnot(identical(y, y0)) @@ -146,7 +146,7 @@ y_truth <- lapply("abc.txt", FUN = my_ext) for (strategy in strategies) { plan(strategy) - if (is.infinite(nbrOfWorkers())) plan(strategy, workers = 3L) + if (is.infinite(nbrOfWorkers())) plan(strategy, workers = 2L) stopifnot(nbrOfWorkers() < Inf) y <- future_lapply("abc.txt", FUN = my_ext) stopifnot(identical(y, y_truth)) From 963ee5685fcc6edd4689b6fc2d34fd97e6e55277 Mon Sep 17 00:00:00 2001 From: hb Date: Wed, 18 Jul 2018 16:53:48 +0200 Subject: [PATCH 19/35] TESTS: sapply(x, value) -> values(x) --- tests/batchtools_custom.R | 2 +- tests/batchtools_interactive.R | 2 +- tests/batchtools_local.R | 2 +- tests/batchtools_multicore.R | 2 +- tests/incl/start,load-only.R | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/batchtools_custom.R b/tests/batchtools_custom.R index 815b509..fbbe2d9 100644 --- a/tests/batchtools_custom.R +++ b/tests/batchtools_custom.R @@ -55,7 +55,7 @@ x <- listenv() for (ii in 1:2) { x[[ii]] <- batchtools_custom({ ii }, globals = TRUE, cluster.functions = cf) } -v <- sapply(x, FUN = value) +v <- values(x) stopifnot(all(v == 1:2)) ## Make sure globals are frozen diff --git a/tests/batchtools_interactive.R b/tests/batchtools_interactive.R index b1408a8..29f1697 100644 --- a/tests/batchtools_interactive.R +++ b/tests/batchtools_interactive.R @@ -46,7 +46,7 @@ stopifnot(v == 0) message("*** batchtools_interactive() with globals (tricky)") x <- listenv() for (ii in 1:2) x[[ii]] <- batchtools_interactive({ ii }, globals = TRUE) -v <- sapply(x, FUN = value) +v <- values(x) stopifnot(all(v == 1:2)) ## Make sure globals are frozen diff --git a/tests/batchtools_local.R b/tests/batchtools_local.R index 316df11..e32513a 100644 --- a/tests/batchtools_local.R +++ b/tests/batchtools_local.R @@ -46,7 +46,7 @@ stopifnot(v == 0) message("*** batchtools_local() with globals (tricky)") x <- listenv() for (ii in 1:2) x[[ii]] <- batchtools_local({ ii }, globals = TRUE) -v <- sapply(x, FUN = value) +v <- values(x) stopifnot(all(v == 1:2)) ## Make sure globals are frozen diff --git a/tests/batchtools_multicore.R b/tests/batchtools_multicore.R index 6f78b7d..c3b67ee 100644 --- a/tests/batchtools_multicore.R +++ b/tests/batchtools_multicore.R @@ -68,7 +68,7 @@ for (cores in 1:min(2L, availableCores("multicore"))) { } mprintf(" - Resolving %d batchtools_multicore futures", length(x)) if (globals || f$config$reg$cluster.functions$name == "Multicore") { - v <- sapply(x, FUN = value) + v <- values(x) stopifnot(all(v == 1:2)) } else { v <- lapply(x, FUN = function(f) tryCatch(value(f), error = identity)) diff --git a/tests/incl/start,load-only.R b/tests/incl/start,load-only.R index 1395ba2..bcc81c8 100644 --- a/tests/incl/start,load-only.R +++ b/tests/incl/start,load-only.R @@ -5,7 +5,7 @@ oopts$future.delete <- getOption("future.delete") oplan <- future::plan() ## Use local batchtools futures by default -future::plan(future.batchtools:::batchtools_local) +future::plan(future.batchtools::batchtools_local) fullTest <- (Sys.getenv("_R_CHECK_FULL_") != "") From b168621d4d65be4c61e994f83eb57bb19161959a Mon Sep 17 00:00:00 2001 From: hb Date: Wed, 18 Jul 2018 17:45:16 +0200 Subject: [PATCH 20/35] SPEEDUP: Avoid calling delete() twice --- R/BatchtoolsFuture-class.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/BatchtoolsFuture-class.R b/R/BatchtoolsFuture-class.R index 13cb674..19fdac2 100644 --- a/R/BatchtoolsFuture-class.R +++ b/R/BatchtoolsFuture-class.R @@ -281,7 +281,7 @@ resolved.BatchtoolsFuture <- function(x, ...) { #' @importFrom future result #' @export #' @keywords internal -result.BatchtoolsFuture <- function(future, ...) { +result.BatchtoolsFuture <- function(future, cleanup = TRUE, ...) { ## Has the value already been collected? result <- future$result if (inherits(result, "FutureResult")) return(result) @@ -306,7 +306,7 @@ result.BatchtoolsFuture <- function(future, ...) { stop_if_not(inherits(result, "FutureResult")) future$result <- result future$state <- "finished" - delete(future) + if (cleanup) delete(future) NextMethod() } @@ -626,7 +626,7 @@ delete.BatchtoolsFuture <- function(future, ## Make sure to collect the results before deleting ## the internal batchtools registry - result <- result(future) + result <- result(future, cleanup = FALSE) stop_if_not(inherits(result, "FutureResult")) ## To simplify post mortem troubleshooting in non-interactive sessions, From 3db6a2683a77103de4ef71e6de8ded7aa3657ca2 Mon Sep 17 00:00:00 2001 From: hb Date: Wed, 18 Jul 2018 17:50:06 +0200 Subject: [PATCH 21/35] TESTS: Some minor shortcuts to decrease overall processing times --- tests/batchtools_custom.R | 2 +- tests/batchtools_interactive.R | 2 +- tests/batchtools_local.R | 2 +- tests/batchtools_multicore.R | 2 +- tests/dotdotdot.R | 3 +-- tests/globals,tricky.R | 2 +- tests/zzz,future_lapply.R | 4 ++-- 7 files changed, 8 insertions(+), 9 deletions(-) diff --git a/tests/batchtools_custom.R b/tests/batchtools_custom.R index fbbe2d9..f9ca24b 100644 --- a/tests/batchtools_custom.R +++ b/tests/batchtools_custom.R @@ -55,7 +55,7 @@ x <- listenv() for (ii in 1:2) { x[[ii]] <- batchtools_custom({ ii }, globals = TRUE, cluster.functions = cf) } -v <- values(x) +v <- unlist(values(x)) stopifnot(all(v == 1:2)) ## Make sure globals are frozen diff --git a/tests/batchtools_interactive.R b/tests/batchtools_interactive.R index 29f1697..344d356 100644 --- a/tests/batchtools_interactive.R +++ b/tests/batchtools_interactive.R @@ -46,7 +46,7 @@ stopifnot(v == 0) message("*** batchtools_interactive() with globals (tricky)") x <- listenv() for (ii in 1:2) x[[ii]] <- batchtools_interactive({ ii }, globals = TRUE) -v <- values(x) +v <- unlist(values(x)) stopifnot(all(v == 1:2)) ## Make sure globals are frozen diff --git a/tests/batchtools_local.R b/tests/batchtools_local.R index e32513a..c44e9ba 100644 --- a/tests/batchtools_local.R +++ b/tests/batchtools_local.R @@ -46,7 +46,7 @@ stopifnot(v == 0) message("*** batchtools_local() with globals (tricky)") x <- listenv() for (ii in 1:2) x[[ii]] <- batchtools_local({ ii }, globals = TRUE) -v <- values(x) +v <- unlist(values(x)) stopifnot(all(v == 1:2)) ## Make sure globals are frozen diff --git a/tests/batchtools_multicore.R b/tests/batchtools_multicore.R index c3b67ee..73e0857 100644 --- a/tests/batchtools_multicore.R +++ b/tests/batchtools_multicore.R @@ -68,7 +68,7 @@ for (cores in 1:min(2L, availableCores("multicore"))) { } mprintf(" - Resolving %d batchtools_multicore futures", length(x)) if (globals || f$config$reg$cluster.functions$name == "Multicore") { - v <- values(x) + v <- unlist(values(x)) stopifnot(all(v == 1:2)) } else { v <- lapply(x, FUN = function(f) tryCatch(value(f), error = identity)) diff --git a/tests/dotdotdot.R b/tests/dotdotdot.R index 976e8a1..2db577f 100644 --- a/tests/dotdotdot.R +++ b/tests/dotdotdot.R @@ -34,8 +34,7 @@ sum_fcns$D <- function(x, y) { } -for (strategy in c("sequential", "multiprocess", - "batchtools_interactive", "batchtools_local")) { +for (strategy in c("batchtools_interactive", "batchtools_local")) { plan(strategy, substitute = FALSE) for (name in names(sum_fcns)) { diff --git a/tests/globals,tricky.R b/tests/globals,tricky.R index 1a1bb83..d9f4da6 100644 --- a/tests/globals,tricky.R +++ b/tests/globals,tricky.R @@ -51,7 +51,7 @@ flapply <- function(x, FUN, ...) { as.list(res) } -x <- list(a = "integer", b = "numeric", c = "character", c = "list") +x <- list(a = "integer", c = "character", c = "list") str(list(x = x)) y0 <- lapply(x, FUN = base::vector, length = 2L) diff --git a/tests/zzz,future_lapply.R b/tests/zzz,future_lapply.R index adfe6ec..45256a7 100644 --- a/tests/zzz,future_lapply.R +++ b/tests/zzz,future_lapply.R @@ -31,7 +31,7 @@ message("*** future_lapply() ...") message("- future_lapply(x, FUN = vector, ...) ...") -x <- list(a = "integer", b = "numeric", c = "character", c = "list") +x <- list(a = "integer", c = "character", c = "list") str(list(x = x)) y0 <- lapply(x, FUN = vector, length = 2L) @@ -54,7 +54,7 @@ for (strategy in strategies) { message("- future_lapply(x, FUN = base::vector, ...) ...") -x <- list(a = "integer", b = "numeric", c = "character", c = "list") +x <- list(a = "integer", c = "character", c = "list") str(list(x = x)) y0 <- lapply(x, FUN = base::vector, length = 2L) From 5df0713e0266b020d67faaf007d10293c7dc37ba Mon Sep 17 00:00:00 2001 From: hb Date: Wed, 18 Jul 2018 17:58:31 +0200 Subject: [PATCH 22/35] TESTS: Speedup by decreasing poll intervals for await() and delete() --- tests/incl/start,load-only.R | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/incl/start,load-only.R b/tests/incl/start,load-only.R index bcc81c8..4ad3f63 100644 --- a/tests/incl/start,load-only.R +++ b/tests/incl/start,load-only.R @@ -1,6 +1,11 @@ ## Record original state ovars <- ls() -oopts <- options(warn = 1L, mc.cores = 2L, future.debug = TRUE) +oopts <- options( + warn = 1L, + mc.cores = 2L, + future.debug = TRUE, + future.wait.interval = 0.1 ## Speed up await() and delete() +) oopts$future.delete <- getOption("future.delete") oplan <- future::plan() From ccd49f1557e7857719a8b0b8545fa5b3a34f2254 Mon Sep 17 00:00:00 2001 From: hb Date: Wed, 18 Jul 2018 18:28:25 +0200 Subject: [PATCH 23/35] TESTS: Decrease processing time a bit by disabling debug output --- tests/batchtools_multicore.R | 33 +++++++++++++++++---------------- tests/incl/start,load-only.R | 2 +- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/tests/batchtools_multicore.R b/tests/batchtools_multicore.R index 73e0857..007235c 100644 --- a/tests/batchtools_multicore.R +++ b/tests/batchtools_multicore.R @@ -1,7 +1,6 @@ source("incl/start.R") library("listenv") - message("*** batchtools_multicore() ...") for (cores in 1:min(2L, availableCores("multicore"))) { @@ -12,7 +11,7 @@ for (cores in 1:min(2L, availableCores("multicore"))) { options(mc.cores = cores - 1L) if (!supportsMulticore()) { - mprintf("batchtools multicore futures are not supporting on '%s'. Falling back to use synchroneous batchtools local futures", .Platform$OS.type) #nolint + mprintf("batchtools multicore futures are not supporting on '%s'. Falling back to use synchroneous batchtools local futures\n", .Platform$OS.type) #nolint } for (globals in c(FALSE, TRUE)) { @@ -97,20 +96,22 @@ for (cores in 1:min(2L, availableCores("multicore"))) { } # for (globals ...) - message("*** batchtools_multicore(..., workers = 1L) ...") - - a <- 2 - b <- 3 - y_truth <- a * b - - f <- batchtools_multicore({ a * b }, workers = 1L) - rm(list = c("a", "b")) - - v <- value(f) - print(v) - stopifnot(v == y_truth) - - message("*** batchtools_multicore(..., workers = 1L) ... DONE") + if (cores > 1) { + message("*** batchtools_multicore(..., workers = 1L) ...") + + a <- 2 + b <- 3 + y_truth <- a * b + + f <- batchtools_multicore({ a * b }, workers = 1L) + rm(list = c("a", "b")) + + v <- value(f) + print(v) + stopifnot(v == y_truth) + + message("*** batchtools_multicore(..., workers = 1L) ... DONE") + } mprintf("Testing with %d cores ... DONE", cores) } ## for (cores ...) diff --git a/tests/incl/start,load-only.R b/tests/incl/start,load-only.R index 4ad3f63..836bfbb 100644 --- a/tests/incl/start,load-only.R +++ b/tests/incl/start,load-only.R @@ -3,7 +3,7 @@ ovars <- ls() oopts <- options( warn = 1L, mc.cores = 2L, - future.debug = TRUE, + future.debug = FALSE, future.wait.interval = 0.1 ## Speed up await() and delete() ) oopts$future.delete <- getOption("future.delete") From 5aa3d0fcce29b1dc5d3431b0c280f2ce1943fc9d Mon Sep 17 00:00:00 2001 From: hb Date: Wed, 18 Jul 2018 18:47:33 +0200 Subject: [PATCH 24/35] TESTS: Don't assume future.apply is available --- tests/zzz,future_lapply.R | 297 +++++++++++++++++++------------------- 1 file changed, 150 insertions(+), 147 deletions(-) diff --git a/tests/zzz,future_lapply.R b/tests/zzz,future_lapply.R index 45256a7..ed2e254 100644 --- a/tests/zzz,future_lapply.R +++ b/tests/zzz,future_lapply.R @@ -1,157 +1,160 @@ source("incl/start.R") library("listenv") -future_lapply <- future.apply::future_lapply -cf <- batchtools::makeClusterFunctionsInteractive(external = TRUE) -batchtools_custom_local <- function(expr, substitute = TRUE, - cluster.functions = cf, ...) { - 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)) - -message("All HPC strategies:") -strategies <- c("batchtools_lsf", "batchtools_openlava", "batchtools_sge", - "batchtools_slurm", "batchtools_torque") -mprint(strategies) - -message("Supported HPC strategies:") -strategies <- strategies[sapply(strategies, FUN = test_strategy)] -mprint(strategies) - -message("Strategies to test with:") -strategies <- c("batchtools_interactive", "batchtools_local", - "batchtools_custom_local", strategies) -mprint(strategies) - - -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') ...", strategy) - plan(strategy) - if (is.infinite(nbrOfWorkers())) 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)) +if (requireNamespace("future.apply", quietly = TRUE)) { + future_lapply <- future.apply::future_lapply + + cf <- batchtools::makeClusterFunctionsInteractive(external = TRUE) + batchtools_custom_local <- function(expr, substitute = TRUE, + cluster.functions = cf, ...) { + if (substitute) expr <- substitute(expr) + batchtools_custom(expr, substitute = FALSE, ..., + cluster.functions = cluster.functions) } -} - - -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') ...", strategy) - plan(strategy) - if (is.infinite(nbrOfWorkers())) 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)) + class(batchtools_custom_local) <- c("batchtools_custom_local", + class(batchtools_custom)) + + message("All HPC strategies:") + strategies <- c("batchtools_lsf", "batchtools_openlava", "batchtools_sge", + "batchtools_slurm", "batchtools_torque") + mprint(strategies) + + message("Supported HPC strategies:") + strategies <- strategies[sapply(strategies, FUN = test_strategy)] + mprint(strategies) + + message("Strategies to test with:") + strategies <- c("batchtools_interactive", "batchtools_local", + "batchtools_custom_local", strategies) + mprint(strategies) + + + 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') ...", strategy) + plan(strategy) + if (is.infinite(nbrOfWorkers())) 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 = 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') ...", strategy) - plan(strategy) - if (is.infinite(nbrOfWorkers())) 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 = 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') ...", strategy) + plan(strategy) + if (is.infinite(nbrOfWorkers())) 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 = 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::map) -str(list(y0 = y0)) - -for (strategy in strategies) { - mprintf("- plan('%s') ...", strategy) - plan(strategy) - if (is.infinite(nbrOfWorkers())) plan(strategy, workers = 2L) - stopifnot(nbrOfWorkers() < Inf) - - for (scheduling in list(FALSE, TRUE)) { - y <- future_lapply(x, FUN = listenv::map, 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') ...", strategy) + plan(strategy) + if (is.infinite(nbrOfWorkers())) 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::map) + str(list(y0 = y0)) + + for (strategy in strategies) { + mprintf("- plan('%s') ...", strategy) + plan(strategy) + if (is.infinite(nbrOfWorkers())) plan(strategy, workers = 2L) + stopifnot(nbrOfWorkers() < Inf) + + for (scheduling in list(FALSE, TRUE)) { + y <- future_lapply(x, FUN = listenv::map, 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:1e6 + + 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 (is.infinite(nbrOfWorkers())) plan(strategy, workers = 2L) + stopifnot(nbrOfWorkers() < Inf) + y <- future_lapply("abc.txt", FUN = my_ext) + stopifnot(identical(y, y_truth)) + } + + message("*** future_lapply() ... DONE") } - -message("- future_lapply(x, FUN, ...) for large length(x) ...") -a <- 3.14 -x <- 1:1e6 - -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 (is.infinite(nbrOfWorkers())) 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") From ed9855de209865d0bedece3df129bd9206307866 Mon Sep 17 00:00:00 2001 From: hb Date: Wed, 18 Jul 2018 19:17:53 +0200 Subject: [PATCH 25/35] TESTS: Avoid default 5 sec wait before removing registry --- tests/BatchtoolsFutureError.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/BatchtoolsFutureError.R b/tests/BatchtoolsFutureError.R index f149336..b4caf35 100644 --- a/tests/BatchtoolsFutureError.R +++ b/tests/BatchtoolsFutureError.R @@ -45,7 +45,7 @@ for (cleanup in c(FALSE, TRUE)) { print(log) ## Now manually delete batchtools Registry - batchtools::removeRegistry(reg = reg) + batchtools::removeRegistry(wait = 0.0, reg = reg) } stopifnot(!file_test("-d", reg$file.dir)) From c0a663a78fd8a724ba48b336296dfaa3ea176476 Mon Sep 17 00:00:00 2001 From: hb Date: Wed, 18 Jul 2018 19:22:06 +0200 Subject: [PATCH 26/35] TESTS: Drop duplicated test --- tests/globals,tricky.R | 9 --------- 1 file changed, 9 deletions(-) diff --git a/tests/globals,tricky.R b/tests/globals,tricky.R index d9f4da6..b5c4918 100644 --- a/tests/globals,tricky.R +++ b/tests/globals,tricky.R @@ -8,13 +8,11 @@ message("*** Tricky use cases related to globals ...") message("- Globals with the same name as 'base' objects ...") ## 'col' is masked by 'base::col' (Issue #55) - col <- 3 x %<-% { stopifnot(is.numeric(col)); col } print(x) stopifnot(x == col) - ## https://github.com/mllg/batchtools/issues/88 message("- Globals that don't necessarily map to filenames ...") .a <- 42L @@ -28,13 +26,6 @@ print(x) stopifnot(x == `$foo`) -## 'col' is masked by 'base::col' (Issue #55) - -col <- 3 -x %<-% { stopifnot(is.numeric(col)); col } -stopifnot(x == col) - - message("- flapply(x, FUN = base::vector, ...) ...") flapply <- function(x, FUN, ...) { From 9ba4e2f8af8783f7d6b8a3c141b108508b7038ca Mon Sep 17 00:00:00 2001 From: hb Date: Wed, 18 Jul 2018 19:30:11 +0200 Subject: [PATCH 27/35] TESTS: Drop stray function call from the BatchJobs era --- tests/BatchtoolsFutureError.R | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/BatchtoolsFutureError.R b/tests/BatchtoolsFutureError.R index b4caf35..98a2b25 100644 --- a/tests/BatchtoolsFutureError.R +++ b/tests/BatchtoolsFutureError.R @@ -49,8 +49,6 @@ for (cleanup in c(FALSE, TRUE)) { } stopifnot(!file_test("-d", reg$file.dir)) - fail <- try(checkIds(reg, ids = 1L), silent = TRUE) - stopifnot(inherits(fail, "try-error")) mprintf("*** batchtools future error w/ future.delete = %s ... DONE", cleanup) } ## for (cleanup ...) From 40c53cd7a3649027976a36d6ce009b4b9c59962d Mon Sep 17 00:00:00 2001 From: hb Date: Wed, 18 Jul 2018 19:37:36 +0200 Subject: [PATCH 28/35] TESTS: Only test with errors once --- tests/batchtools_multicore.R | 55 ++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/tests/batchtools_multicore.R b/tests/batchtools_multicore.R index 007235c..401b3fe 100644 --- a/tests/batchtools_multicore.R +++ b/tests/batchtools_multicore.R @@ -7,7 +7,7 @@ for (cores in 1:min(2L, availableCores("multicore"))) { ## FIXME: if (!fullTest && cores > 1) next - mprintf("Testing with %d cores ...", cores) + mprintf("Testing with %d cores ...\n", cores) options(mc.cores = cores - 1L) if (!supportsMulticore()) { @@ -15,7 +15,11 @@ for (cores in 1:min(2L, availableCores("multicore"))) { } for (globals in c(FALSE, TRUE)) { - mprintf("*** batchtools_multicore(..., globals = %s) without globals", + ## SPEEDUP: Skip part of the tests on Windows to decrease + ## the overall testing time on CRAN. /HB 2018-07-18 + if (!supportsMulticore() && !globals) next + + mprintf("*** batchtools_multicore(..., globals = %s) without globals\n", globals) f <- batchtools_multicore({ @@ -31,7 +35,7 @@ for (cores in 1:min(2L, availableCores("multicore"))) { print(y) stopifnot(y == 42L) - mprintf("*** batchtools_multicore(..., globals = %s) with globals", + mprintf("*** batchtools_multicore(..., globals = %s) with globals\n", globals) ## A global variable a <- 0 @@ -40,8 +44,6 @@ for (cores in 1:min(2L, availableCores("multicore"))) { c <- 2 a * b * c }, globals = globals) - print(f) - ## A multicore future is evaluated in a separated ## forked process. Changing the value of a global @@ -59,13 +61,13 @@ for (cores in 1:min(2L, availableCores("multicore"))) { } - mprintf("*** batchtools_multicore(..., globals = %s) with globals and blocking", globals) #nolint + mprintf("*** batchtools_multicore(..., globals = %s) with globals and blocking\n", globals) #nolint x <- listenv() for (ii in 1:2) { - mprintf(" - Creating batchtools_multicore future #%d ...", ii) + mprintf(" - Creating batchtools_multicore future #%d ...\n", ii) x[[ii]] <- batchtools_multicore({ ii }, globals = globals) } - mprintf(" - Resolving %d batchtools_multicore futures", length(x)) + mprintf(" - Resolving %d batchtools_multicore futures\n", length(x)) if (globals || f$config$reg$cluster.functions$name == "Multicore") { v <- unlist(values(x)) stopifnot(all(v == 1:2)) @@ -73,29 +75,28 @@ for (cores in 1:min(2L, availableCores("multicore"))) { v <- lapply(x, FUN = function(f) tryCatch(value(f), error = identity)) stopifnot(all(sapply(v, FUN = inherits, "simpleError"))) } + } # for (globals ...) - mprintf("*** batchtools_multicore(..., globals = %s) and errors", globals) - f <- batchtools_multicore({ - stop("Whoops!") - 1 - }, globals = globals) - print(f) - v <- value(f, signal = FALSE) - print(v) - stopifnot(inherits(v, "simpleError")) - - res <- try(value(f), silent = TRUE) - print(res) - stopifnot(inherits(res, "try-error")) - ## Error is repeated - res <- try(value(f), silent = TRUE) - print(res) - stopifnot(inherits(res, "try-error")) + mprintf("*** batchtools_multicore() and errors\n", globals) + f <- batchtools_multicore({ + stop("Whoops!") + 1 + }) + v <- value(f, signal = FALSE) + print(v) + stopifnot(inherits(v, "simpleError")) - } # for (globals ...) + res <- try(value(f), silent = TRUE) + print(res) + stopifnot(inherits(res, "try-error")) + ## Error is repeated + res <- try(value(f), silent = TRUE) + print(res) + stopifnot(inherits(res, "try-error")) + if (cores > 1) { message("*** batchtools_multicore(..., workers = 1L) ...") @@ -113,7 +114,7 @@ for (cores in 1:min(2L, availableCores("multicore"))) { message("*** batchtools_multicore(..., workers = 1L) ... DONE") } - mprintf("Testing with %d cores ... DONE", cores) + mprintf("Testing with %d cores ... DONE\n", cores) } ## for (cores ...) message("*** batchtools_multicore() ... DONE") From 89f3419f060198998171f66fb7fdb26a8b16bfeb Mon Sep 17 00:00:00 2001 From: hb Date: Wed, 18 Jul 2018 19:42:26 +0200 Subject: [PATCH 29/35] TESTS: Speedup of Mandelbrot demo --- tests/demo.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/demo.R b/tests/demo.R index a89f9f2..d2ed768 100644 --- a/tests/demo.R +++ b/tests/demo.R @@ -1,6 +1,8 @@ source("incl/start.R") -options("R_FUTURE_DEMO_MANDELBROT_PLANES" = 4L) +options(future.demo.mandelbrot.nrow = 2L) +options(future.demo.mandelbrot.resolution = 50L) +options(future.demo.mandelbrot.delay = FALSE) message("*** Demos ...") From fb609c2930d8465a54e319dc457d78db0bc939a7 Mon Sep 17 00:00:00 2001 From: hb Date: Wed, 18 Jul 2018 19:54:20 +0200 Subject: [PATCH 30/35] TESTS: Small speedup + fix lacking newlines --- tests/BatchtoolsFutureError.R | 4 ++-- tests/dotdotdot.R | 2 +- tests/future,labels.R | 4 ++-- tests/future,lazy.R | 4 ++-- tests/globals,formulas.R | 2 +- tests/plan.R | 4 ++-- tests/zzz,future_lapply.R | 10 +++++----- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/tests/BatchtoolsFutureError.R b/tests/BatchtoolsFutureError.R index 98a2b25..c468c21 100644 --- a/tests/BatchtoolsFutureError.R +++ b/tests/BatchtoolsFutureError.R @@ -5,7 +5,7 @@ message("*** BatchtoolsFutureError() ...") plan(batchtools_local) for (cleanup in c(FALSE, TRUE)) { - mprintf("*** batchtools future error w/ future.delete = %s ...", cleanup) + mprintf("*** batchtools future error w/ future.delete = %s ...\n", cleanup) options(future.delete = cleanup) @@ -50,7 +50,7 @@ for (cleanup in c(FALSE, TRUE)) { stopifnot(!file_test("-d", reg$file.dir)) - mprintf("*** batchtools future error w/ future.delete = %s ... DONE", cleanup) + mprintf("*** batchtools future error w/ future.delete = %s ... DONE\n", cleanup) } ## for (cleanup ...) diff --git a/tests/dotdotdot.R b/tests/dotdotdot.R index 2db577f..cb863bf 100644 --- a/tests/dotdotdot.R +++ b/tests/dotdotdot.R @@ -38,7 +38,7 @@ for (strategy in c("batchtools_interactive", "batchtools_local")) { plan(strategy, substitute = FALSE) for (name in names(sum_fcns)) { - mprintf("** Sum function '%s' with plan('%s') ...", name, strategy) + mprintf("** Sum function '%s' with plan('%s') ...\n", name, strategy) sum_fcn <- sum_fcns[[name]] print(sum_fcn) y <- try(sum_fcn(1:2, 3)) diff --git a/tests/future,labels.R b/tests/future,labels.R index ce2bddc..4a86adf 100644 --- a/tests/future,labels.R +++ b/tests/future,labels.R @@ -5,7 +5,7 @@ message("*** Futures - labels ...") strategies <- c("batchtools_local") for (strategy in strategies) { - mprintf("- plan('%s') ...", strategy) + mprintf("- plan('%s') ...\n", strategy) plan(strategy) for (label in list(NULL, sprintf("strategy_%s", strategy))) { @@ -31,7 +31,7 @@ for (strategy in strategies) { } ## for (label ...) - mprintf("- plan('%s') ... DONE", strategy) + mprintf("- plan('%s') ... DONE\n", strategy) } ## for (strategy ...) message("*** Futures - labels ... DONE") diff --git a/tests/future,lazy.R b/tests/future,lazy.R index 2d8b7b0..77c7f02 100644 --- a/tests/future,lazy.R +++ b/tests/future,lazy.R @@ -5,7 +5,7 @@ message("*** Futures - lazy ...") strategies <- c("batchtools_local") for (strategy in strategies) { - mprintf("- plan('%s') ...", strategy) + mprintf("- plan('%s') ...\n", strategy) plan(strategy) a <- 42 @@ -19,7 +19,7 @@ for (strategy in strategies) { a <- 21 stopifnot(v == 84) - mprintf("- plan('%s') ... DONE", strategy) + mprintf("- plan('%s') ... DONE\n", strategy) } ## for (strategy ...) message("*** Futures - lazy ... DONE") diff --git a/tests/globals,formulas.R b/tests/globals,formulas.R index 086bdb3..1696280 100644 --- a/tests/globals,formulas.R +++ b/tests/globals,formulas.R @@ -73,7 +73,7 @@ exprs <- list( for (kk in seq_along(exprs)) { expr <- exprs[[kk]] name <- names(exprs)[kk] - mprintf("- Globals - lm(, data = cars) ...", + mprintf("- Globals - lm(, data = cars) ...\n", kk, sQuote(name)) fit0 <- eval(expr) diff --git a/tests/plan.R b/tests/plan.R index d7819ad..bbe3d62 100644 --- a/tests/plan.R +++ b/tests/plan.R @@ -12,7 +12,7 @@ print(future::plan()) library("future.batchtools") for (type in c("batchtools_interactive", "batchtools_local")) { - mprintf("*** plan('%s') ...", type) + mprintf("*** plan('%s') ...\n", type) plan(type) stopifnot(inherits(plan(), "batchtools")) @@ -28,7 +28,7 @@ for (type in c("batchtools_interactive", "batchtools_local")) { print(v) stopifnot(v == 0) - mprintf("*** plan('%s') ... DONE", type) + mprintf("*** plan('%s') ... DONE\n", type) } # for (type ...) diff --git a/tests/zzz,future_lapply.R b/tests/zzz,future_lapply.R index ed2e254..9511ef9 100644 --- a/tests/zzz,future_lapply.R +++ b/tests/zzz,future_lapply.R @@ -40,7 +40,7 @@ if (requireNamespace("future.apply", quietly = TRUE)) { str(list(y0 = y0)) for (strategy in strategies) { - mprintf("- plan('%s') ...", strategy) + mprintf("- plan('%s') ...\n", strategy) plan(strategy) if (is.infinite(nbrOfWorkers())) plan(strategy, workers = 2L) stopifnot(nbrOfWorkers() < Inf) @@ -63,7 +63,7 @@ if (requireNamespace("future.apply", quietly = TRUE)) { str(list(y0 = y0)) for (strategy in strategies) { - mprintf("- plan('%s') ...", strategy) + mprintf("- plan('%s') ...\n", strategy) plan(strategy) if (is.infinite(nbrOfWorkers())) plan(strategy, workers = 2L) stopifnot(nbrOfWorkers() < Inf) @@ -85,7 +85,7 @@ if (requireNamespace("future.apply", quietly = TRUE)) { str(list(y0 = y0)) for (strategy in strategies) { - mprintf("- plan('%s') ...", strategy) + mprintf("- plan('%s') ...\n", strategy) plan(strategy) if (is.infinite(nbrOfWorkers())) plan(strategy, workers = 2L) stopifnot(nbrOfWorkers() < Inf) @@ -118,7 +118,7 @@ if (requireNamespace("future.apply", quietly = TRUE)) { str(list(y0 = y0)) for (strategy in strategies) { - mprintf("- plan('%s') ...", strategy) + mprintf("- plan('%s') ...\n", strategy) plan(strategy) if (is.infinite(nbrOfWorkers())) plan(strategy, workers = 2L) stopifnot(nbrOfWorkers() < Inf) @@ -133,7 +133,7 @@ if (requireNamespace("future.apply", quietly = TRUE)) { message("- future_lapply(x, FUN, ...) for large length(x) ...") a <- 3.14 - x <- 1:1e6 + x <- 1:1e5 y <- future_lapply(x, FUN = function(z) sqrt(z + a)) y <- unlist(y, use.names = FALSE) From ae35a0ec7d9309e2ef6687b669f5a47fb9325fc7 Mon Sep 17 00:00:00 2001 From: hb Date: Wed, 18 Jul 2018 20:18:16 +0200 Subject: [PATCH 31/35] TESTS: Some speedup by avoiding print():ing Future:s --- tests/BatchtoolsFuture,gc.R | 1 - tests/BatchtoolsFuture.R | 6 ------ tests/BatchtoolsFutureError.R | 1 - tests/batchtools_custom.R | 1 - tests/batchtools_interactive.R | 2 -- tests/batchtools_local.R | 2 -- tests/future,labels.R | 4 +--- tests/globals,manual.R | 4 ---- 8 files changed, 1 insertion(+), 20 deletions(-) diff --git a/tests/BatchtoolsFuture,gc.R b/tests/BatchtoolsFuture,gc.R index 8933e1f..cde1ac4 100644 --- a/tests/BatchtoolsFuture,gc.R +++ b/tests/BatchtoolsFuture,gc.R @@ -6,7 +6,6 @@ plan(batchtools_local) for (how in c("resolve", "value")) { f <- future({ 1 }) - print(f) if (how == "value") { v <- value(f) diff --git a/tests/BatchtoolsFuture.R b/tests/BatchtoolsFuture.R index 9fee0b9..4967efb 100644 --- a/tests/BatchtoolsFuture.R +++ b/tests/BatchtoolsFuture.R @@ -5,7 +5,6 @@ message("*** BatchtoolsFuture() ...") message("*** BatchtoolsFuture() - cleanup ...") f <- batchtools_local({ 1L }) -print(f) res <- await(f, cleanup = TRUE) print(res) # future (>= 1.7.0-9000) @@ -19,7 +18,6 @@ message("*** BatchtoolsFuture() - deleting exceptions ...") ## Deleting a non-resolved future f <- BatchtoolsFuture({ x <- 1 }) -print(f) res <- tryCatch({ delete(f) }, warning = function(w) w) @@ -44,7 +42,6 @@ message("*** BatchtoolsFuture() - registry exceptions ...") ## Non-existing batchtools registry f <- BatchtoolsFuture({ x <- 1 }) -print(f) ## Hack to emulate where batchtools registry is deleted or fails f$state <- "running" @@ -69,7 +66,6 @@ message("*** BatchtoolsFuture() - registry exceptions ... DONE") message("*** BatchtoolsFuture() - exceptions ...") f <- BatchtoolsFuture({ 42L }) -print(f) res <- tryCatch({ loggedError(f) }, error = function(ex) ex) @@ -77,7 +73,6 @@ print(res) stopifnot(inherits(res, "error")) f <- BatchtoolsFuture({ 42L }) -print(f) res <- tryCatch({ loggedOutput(f) }, error = function(ex) ex) @@ -110,7 +105,6 @@ if (fullTest && availableCores(constraints = "multicore") > 1) { Sys.sleep(5) x <- 1 }) - print(f) res <- tryCatch({ value(f) diff --git a/tests/BatchtoolsFutureError.R b/tests/BatchtoolsFutureError.R index c468c21..8a50ea8 100644 --- a/tests/BatchtoolsFutureError.R +++ b/tests/BatchtoolsFutureError.R @@ -14,7 +14,6 @@ for (cleanup in c(FALSE, TRUE)) { print(x) stop("Woops!") }) - print(f) resolve(f) diff --git a/tests/batchtools_custom.R b/tests/batchtools_custom.R index f9ca24b..521bdd9 100644 --- a/tests/batchtools_custom.R +++ b/tests/batchtools_custom.R @@ -64,7 +64,6 @@ f <- batchtools_custom({ stop("Whoops!") 1 }, cluster.functions = cf) -print(f) v <- value(f, signal = FALSE) print(v) stopifnot(inherits(v, "simpleError")) diff --git a/tests/batchtools_interactive.R b/tests/batchtools_interactive.R index 344d356..0121199 100644 --- a/tests/batchtools_interactive.R +++ b/tests/batchtools_interactive.R @@ -28,7 +28,6 @@ f <- batchtools_interactive({ c <- 2 a * b * c }) -print(f) ## Although 'f' is a batchtools_interactive future and therefore ## resolved/evaluates the future expression only @@ -55,7 +54,6 @@ f <- batchtools_interactive({ stop("Whoops!") 1 }) -print(f) v <- value(f, signal = FALSE) print(v) stopifnot(inherits(v, "simpleError")) diff --git a/tests/batchtools_local.R b/tests/batchtools_local.R index c44e9ba..ce1d7c0 100644 --- a/tests/batchtools_local.R +++ b/tests/batchtools_local.R @@ -28,7 +28,6 @@ f <- batchtools_local({ c <- 2 a * b * c }) -print(f) ## Although 'f' is a batchtools_local future and therefore ## resolved/evaluates the future expression only @@ -55,7 +54,6 @@ f <- batchtools_local({ stop("Whoops!") 1 }) -print(f) v <- value(f, signal = FALSE) print(v) stopifnot(inherits(v, "simpleError")) diff --git a/tests/future,labels.R b/tests/future,labels.R index 4a86adf..32108d7 100644 --- a/tests/future,labels.R +++ b/tests/future,labels.R @@ -12,20 +12,18 @@ for (strategy in strategies) { fcn <- get(strategy, mode = "function") stopifnot(inherits(fcn, strategy)) f <- fcn(42, label = label) - print(f) stopifnot(identical(f$label, label)) v <- value(f) stopifnot(v == 42) + print(f) f <- future(42, label = label) - print(f) stopifnot(identical(f$label, label)) v <- value(f) stopifnot(v == 42) v %<-% { 42 } %label% label f <- futureOf(v) - print(f) stopifnot(identical(f$label, label)) stopifnot(v == 42) diff --git a/tests/globals,manual.R b/tests/globals,manual.R index dabbb2e..d10926b 100644 --- a/tests/globals,manual.R +++ b/tests/globals,manual.R @@ -29,7 +29,6 @@ f <- future({ x <- 1:10 sumtwo(a + b * x) }, globals = TRUE) -print(f) rm(list = names(globals)) y <- value(f) print(y) @@ -55,7 +54,6 @@ f <- future({ x <- 1:10 sumtwo(a + b * x) }, globals = FALSE) -print(f) rm(list = names(globals)) y <- tryCatch(value(f), error = identity) if (!inherits(f, c("EagerFuture", "MulticoreFuture"))) { @@ -74,7 +72,6 @@ f <- future({ x <- 1:10 sumtwo(a + b * x) }, globals = globals) -print(f) v <- value(f) print(v) stopifnot(all.equal(v, v0)) @@ -96,7 +93,6 @@ f <- future({ x <- 1:10 sumtwo(a + b * x) }, globals = c("a", "b", "sumtwo")) -print(f) rm(list = names(globals)) v <- value(f) print(v) From ea0550005b6abe1eea7f728c1cb341d2a84230c1 Mon Sep 17 00:00:00 2001 From: hb Date: Wed, 18 Jul 2018 20:27:53 +0200 Subject: [PATCH 32/35] TESTS: Skip more tests unless _R_CHECK_FULL_=true --- appveyor.yml | 1 + tests/batchtools_multicore.R | 2 ++ tests/zzz,future_lapply.R | 31 ++++++++++++++++++------------- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 05a61e0..324df40 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -5,6 +5,7 @@ #---------------------------------------------------------------- environment: _R_CHECK_FORCE_SUGGESTS_: false + _R_CHECK_FULL_: true matrix: - R_VERSION: devel diff --git a/tests/batchtools_multicore.R b/tests/batchtools_multicore.R index 401b3fe..edad69e 100644 --- a/tests/batchtools_multicore.R +++ b/tests/batchtools_multicore.R @@ -34,6 +34,8 @@ for (cores in 1:min(2L, availableCores("multicore"))) { y <- value(f) print(y) stopifnot(y == 42L) + + if (!supportsMulticore()) next mprintf("*** batchtools_multicore(..., globals = %s) with globals\n", globals) diff --git a/tests/zzz,future_lapply.R b/tests/zzz,future_lapply.R index 9511ef9..e315b55 100644 --- a/tests/zzz,future_lapply.R +++ b/tests/zzz,future_lapply.R @@ -3,17 +3,7 @@ library("listenv") if (requireNamespace("future.apply", quietly = TRUE)) { future_lapply <- future.apply::future_lapply - - cf <- batchtools::makeClusterFunctionsInteractive(external = TRUE) - batchtools_custom_local <- function(expr, substitute = TRUE, - cluster.functions = cf, ...) { - 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)) - + message("All HPC strategies:") strategies <- c("batchtools_lsf", "batchtools_openlava", "batchtools_sge", "batchtools_slurm", "batchtools_torque") @@ -22,10 +12,25 @@ if (requireNamespace("future.apply", quietly = TRUE)) { message("Supported HPC strategies:") strategies <- strategies[sapply(strategies, FUN = test_strategy)] mprint(strategies) + + strategies <- c("batchtools_local", strategies) + + if (fullTest) { + strategies <- c("batchtools_interactive", strategies) + + cf <- batchtools::makeClusterFunctionsInteractive(external = TRUE) + batchtools_custom_local <- function(expr, substitute = TRUE, + cluster.functions = cf, ...) { + 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) + } message("Strategies to test with:") - strategies <- c("batchtools_interactive", "batchtools_local", - "batchtools_custom_local", strategies) mprint(strategies) From da2321b4e3fb24ab842fec418339b26bd33a7c2b Mon Sep 17 00:00:00 2001 From: hb Date: Wed, 18 Jul 2018 21:09:59 +0200 Subject: [PATCH 33/35] CRAN/TESTS: Skipping some tests when running on Windows 32-bit and not explicitly requesting _R_CHECK_FULL_=true --- tests/batchtools_custom.R | 4 +-- tests/batchtools_interactive.R | 4 +-- tests/batchtools_local.R | 4 +-- tests/batchtools_multicore.R | 53 +++++++++++++++++----------------- tests/demo.R | 7 ++++- tests/dotdotdot.R | 9 +++++- tests/future,labels.R | 4 +++ tests/future,lazy.R | 4 +++ tests/globals,formulas.R | 4 +++ tests/globals,manual.R | 4 +++ tests/globals,subassignment.R | 4 +++ tests/globals,tricky.R | 4 +++ tests/incl/start,load-only.R | 2 ++ tests/zzz,future_lapply.R | 3 ++ 14 files changed, 76 insertions(+), 34 deletions(-) diff --git a/tests/batchtools_custom.R b/tests/batchtools_custom.R index 521bdd9..9bfc37c 100644 --- a/tests/batchtools_custom.R +++ b/tests/batchtools_custom.R @@ -19,8 +19,8 @@ stopifnot(inherits(f, "BatchtoolsFuture")) ## Check whether a batchtools_custom future is resolved ## or not will force evaluation -print(resolved(f)) -stopifnot(resolved(f)) +print(is_resolved <- resolved(f)) +stopifnot(is_resolved) y <- value(f) print(y) diff --git a/tests/batchtools_interactive.R b/tests/batchtools_interactive.R index 0121199..33d504c 100644 --- a/tests/batchtools_interactive.R +++ b/tests/batchtools_interactive.R @@ -12,8 +12,8 @@ stopifnot(inherits(f, "BatchtoolsFuture")) ## Check whether a batchtools_interactive future is resolved ## or not will force evaluation -print(resolved(f)) -stopifnot(resolved(f)) +print(is_resolved <- resolved(f)) +stopifnot(is_resolved) y <- value(f) print(y) diff --git a/tests/batchtools_local.R b/tests/batchtools_local.R index ce1d7c0..63e117a 100644 --- a/tests/batchtools_local.R +++ b/tests/batchtools_local.R @@ -12,8 +12,8 @@ stopifnot(inherits(f, "BatchtoolsFuture")) ## Check whether a batchtools_local future is resolved ## or not will force evaluation -print(resolved(f)) -stopifnot(resolved(f)) +print(is_resolved <- resolved(f)) +stopifnot(is_resolved) y <- value(f) print(y) diff --git a/tests/batchtools_multicore.R b/tests/batchtools_multicore.R index edad69e..b42a3fc 100644 --- a/tests/batchtools_multicore.R +++ b/tests/batchtools_multicore.R @@ -7,6 +7,10 @@ for (cores in 1:min(2L, availableCores("multicore"))) { ## FIXME: if (!fullTest && cores > 1) next + ## CRAN processing times: + ## On Windows 32-bit, don't run these tests + if (!fullTest && isWin32) next + mprintf("Testing with %d cores ...\n", cores) options(mc.cores = cores - 1L) @@ -15,10 +19,6 @@ for (cores in 1:min(2L, availableCores("multicore"))) { } for (globals in c(FALSE, TRUE)) { - ## SPEEDUP: Skip part of the tests on Windows to decrease - ## the overall testing time on CRAN. /HB 2018-07-18 - if (!supportsMulticore() && !globals) next - mprintf("*** batchtools_multicore(..., globals = %s) without globals\n", globals) @@ -35,8 +35,6 @@ for (cores in 1:min(2L, availableCores("multicore"))) { print(y) stopifnot(y == 42L) - if (!supportsMulticore()) next - mprintf("*** batchtools_multicore(..., globals = %s) with globals\n", globals) ## A global variable @@ -79,26 +77,6 @@ for (cores in 1:min(2L, availableCores("multicore"))) { } } # for (globals ...) - - mprintf("*** batchtools_multicore() and errors\n", globals) - f <- batchtools_multicore({ - stop("Whoops!") - 1 - }) - v <- value(f, signal = FALSE) - print(v) - stopifnot(inherits(v, "simpleError")) - - res <- try(value(f), silent = TRUE) - print(res) - stopifnot(inherits(res, "try-error")) - - ## Error is repeated - res <- try(value(f), silent = TRUE) - print(res) - stopifnot(inherits(res, "try-error")) - - if (cores > 1) { message("*** batchtools_multicore(..., workers = 1L) ...") @@ -119,6 +97,29 @@ for (cores in 1:min(2L, availableCores("multicore"))) { mprintf("Testing with %d cores ... DONE\n", cores) } ## for (cores ...) + +## CRAN processing times: +## On Windows 32-bit, don't run these tests +if (fullTest || !isWin32) { + mprintf("*** batchtools_multicore() and errors\n", globals) + f <- batchtools_multicore({ + stop("Whoops!") + 1 + }) + v <- value(f, signal = FALSE) + print(v) + stopifnot(inherits(v, "simpleError")) + + res <- try(value(f), silent = TRUE) + print(res) + stopifnot(inherits(res, "try-error")) + + ## Error is repeated + res <- try(value(f), silent = TRUE) + print(res) + stopifnot(inherits(res, "try-error")) +} + message("*** batchtools_multicore() ... DONE") source("incl/end.R") diff --git a/tests/demo.R b/tests/demo.R index d2ed768..ab7afca 100644 --- a/tests/demo.R +++ b/tests/demo.R @@ -1,5 +1,11 @@ source("incl/start.R") +plan(batchtools_local) + +## CRAN processing times: +## On Windows 32-bit, don't run these tests via batchtools +if (!fullTest && isWin32) plan(sequential) + options(future.demo.mandelbrot.nrow = 2L) options(future.demo.mandelbrot.resolution = 50L) options(future.demo.mandelbrot.delay = FALSE) @@ -8,7 +14,6 @@ message("*** Demos ...") message("*** Mandelbrot demo of the 'future' package ...") -plan(batchtools_local) demo("mandelbrot", package = "future", ask = FALSE) message("*** Demos ... DONE") diff --git a/tests/dotdotdot.R b/tests/dotdotdot.R index cb863bf..9c0e2ab 100644 --- a/tests/dotdotdot.R +++ b/tests/dotdotdot.R @@ -1,6 +1,13 @@ source("incl/start.R") library("listenv") +strategies <- c("batchtools_interactive", "batchtools_local") + +## CRAN processing times: +## On Windows 32-bit, don't run these tests +if (!fullTest && isWin32) strategies <- character(0L) + + message("*** Global argument '...' in futures ...") sum_fcns <- list() @@ -34,7 +41,7 @@ sum_fcns$D <- function(x, y) { } -for (strategy in c("batchtools_interactive", "batchtools_local")) { +for (strategy in strategies) { plan(strategy, substitute = FALSE) for (name in names(sum_fcns)) { diff --git a/tests/future,labels.R b/tests/future,labels.R index 32108d7..79adc3a 100644 --- a/tests/future,labels.R +++ b/tests/future,labels.R @@ -4,6 +4,10 @@ message("*** Futures - labels ...") strategies <- c("batchtools_local") +## CRAN processing times: +## On Windows 32-bit, don't run these tests +if (!fullTest && isWin32) strategies <- character(0L) + for (strategy in strategies) { mprintf("- plan('%s') ...\n", strategy) plan(strategy) diff --git a/tests/future,lazy.R b/tests/future,lazy.R index 77c7f02..282dab3 100644 --- a/tests/future,lazy.R +++ b/tests/future,lazy.R @@ -4,6 +4,10 @@ message("*** Futures - lazy ...") strategies <- c("batchtools_local") +## CRAN processing times: +## On Windows 32-bit, don't run these tests +if (!fullTest && isWin32) strategies <- character(0L) + for (strategy in strategies) { mprintf("- plan('%s') ...\n", strategy) plan(strategy) diff --git a/tests/globals,formulas.R b/tests/globals,formulas.R index 1696280..a1fdcd5 100644 --- a/tests/globals,formulas.R +++ b/tests/globals,formulas.R @@ -5,6 +5,10 @@ library("stats") ## lm(), poly(), xtabs() plan(batchtools_local) +## CRAN processing times: +## On Windows 32-bit, don't run these tests on batchtools +if (!fullTest && isWin32) plan(sequential) + message("*** Globals - formulas ...") message("*** Globals - lm() ...") diff --git a/tests/globals,manual.R b/tests/globals,manual.R index d10926b..cb0f3a2 100644 --- a/tests/globals,manual.R +++ b/tests/globals,manual.R @@ -2,6 +2,10 @@ source("incl/start.R") plan(batchtools_local) +## CRAN processing times: +## On Windows 32-bit, don't run these tests on batchtools +if (!fullTest && isWin32) plan(sequential) + message("*** Globals - manually ...") message("*** Globals manually specified as named list ...") diff --git a/tests/globals,subassignment.R b/tests/globals,subassignment.R index 5af8f8a..62cec25 100644 --- a/tests/globals,subassignment.R +++ b/tests/globals,subassignment.R @@ -2,6 +2,10 @@ source("incl/start.R") plan(batchtools_local) +## CRAN processing times: +## On Windows 32-bit, don't run these tests on batchtools +if (!fullTest && isWin32) plan(sequential) + oopts <- c(oopts, options( future.globals.resolve = TRUE, future.globals.onMissing = "error" diff --git a/tests/globals,tricky.R b/tests/globals,tricky.R index b5c4918..5cf1938 100644 --- a/tests/globals,tricky.R +++ b/tests/globals,tricky.R @@ -3,6 +3,10 @@ library("listenv") plan(batchtools_local) +## CRAN processing times: +## On Windows 32-bit, don't run these tests on batchtools +if (!fullTest && isWin32) plan(sequential) + message("*** Tricky use cases related to globals ...") message("- Globals with the same name as 'base' objects ...") diff --git a/tests/incl/start,load-only.R b/tests/incl/start,load-only.R index 836bfbb..823ff9a 100644 --- a/tests/incl/start,load-only.R +++ b/tests/incl/start,load-only.R @@ -14,6 +14,8 @@ future::plan(future.batchtools::batchtools_local) fullTest <- (Sys.getenv("_R_CHECK_FULL_") != "") +isWin32 <- (.Platform$OS.type == "windows" && .Platform$r_arch == "i386") + all_strategies <- function() { strategies <- Sys.getenv("R_FUTURE_TESTS_STRATEGIES") strategies <- unlist(strsplit(strategies, split = ",")) diff --git a/tests/zzz,future_lapply.R b/tests/zzz,future_lapply.R index e315b55..60200db 100644 --- a/tests/zzz,future_lapply.R +++ b/tests/zzz,future_lapply.R @@ -29,6 +29,9 @@ if (requireNamespace("future.apply", quietly = TRUE)) { 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) From 33f191293f457a3f51220d41cbdc9b6a9c415852 Mon Sep 17 00:00:00 2001 From: hb Date: Wed, 18 Jul 2018 21:36:11 +0200 Subject: [PATCH 34/35] TESTS: Fix EagerFuture -> SequentialFuture --- tests/batchtools_multicore.R | 2 +- tests/globals,manual.R | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/batchtools_multicore.R b/tests/batchtools_multicore.R index b42a3fc..f4e0fd7 100644 --- a/tests/batchtools_multicore.R +++ b/tests/batchtools_multicore.R @@ -27,7 +27,7 @@ for (cores in 1:min(2L, availableCores("multicore"))) { }, globals = globals) stopifnot( inherits(f, "BatchtoolsFuture") || - ((cores == 1 || !supportsMulticore()) && inherits(f, "EagerFuture")) + ((cores == 1 || !supportsMulticore()) && inherits(f, "SequentialFuture")) ) print(resolved(f)) diff --git a/tests/globals,manual.R b/tests/globals,manual.R index cb0f3a2..75c3292 100644 --- a/tests/globals,manual.R +++ b/tests/globals,manual.R @@ -60,7 +60,7 @@ f <- future({ }, globals = FALSE) rm(list = names(globals)) y <- tryCatch(value(f), error = identity) -if (!inherits(f, c("EagerFuture", "MulticoreFuture"))) { +if (!inherits(f, c("SequentialFuture", "MulticoreFuture"))) { stopifnot(inherits(y, "simpleError")) } From 70d79231553495e145c509b785a235b17485eb50 Mon Sep 17 00:00:00 2001 From: hb Date: Wed, 18 Jul 2018 23:31:23 +0200 Subject: [PATCH 35/35] future.batchtools 0.7.1 --- cran-comments.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cran-comments.md b/cran-comments.md index a6121a7..21430f1 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -2,8 +2,14 @@ on 2018-07-18 +## Submission 1 + Thanks in advance +## Submission 2 + +Resubmission of future.batchtools 0.7.1 where the overall R CMD check time has been decreased significantly. + ### R CMD check --as-cran validation