Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ Depends:
Imports:
butcher (>= 0.1.3),
cli,
doFuture,
dplyr (>= 1.1.0),
foreach,
furrr,
future,
generics,
ggplot2,
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
* Added missing commas and addressed formatting issues throughout the vignettes and articles. Backticks for package names were removed and missing parentheses for functions were added (@Joscelinrocha, #218).

* Increased the minimum R version to R 4.1.

* Transitioned support for parallel processing fully to the
[future](https://www.futureverse.org/) framework. Parallelism backends
registered with foreach will be ignored with a warning (#234).

# stacks 1.0.5

Expand Down
49 changes: 26 additions & 23 deletions R/fit_members.R
Original file line number Diff line number Diff line change
Expand Up @@ -129,32 +129,20 @@
)
}

if (foreach::getDoParWorkers() > 1 || future::nbrOfWorkers() > 1) {
`%do_op%` <- switch(
# note some backends can return +Inf
min(future::nbrOfWorkers(), 2),
foreach::`%dopar%`,
doFuture::`%dofuture%`
)
} else {
`%do_op%` <- foreach::`%do%`
if (uses_foreach_only()) {
warn_foreach_deprecation()

Check warning on line 133 in R/fit_members.R

View check run for this annotation

Codecov / codecov/patch

R/fit_members.R#L133

Added line #L133 was not covered by tests
}

# fit each of them
member_fits <-
foreach::foreach(
mem = member_names,
.inorder = FALSE,
.options.future = list(seed = TRUE)
) %do_op%
{
asNamespace("stacks")$fit_member(
name = mem,
wflows = model_stack[["model_defs"]],
members_map = members_map,
train_dat = dat
)
}
furrr::future_map(
member_names,
.f = fit_member,
wflows = model_stack[["model_defs"]],
members_map = members_map,
train_dat = dat,
.options = furrr::furrr_options(seed = TRUE)
)

model_stack[["member_fits"]] <-
setNames(member_fits, member_names)
Expand Down Expand Up @@ -269,7 +257,8 @@

purrr::map(
pkgs,
function(.x) suppressPackageStartupMessages(requireNamespace(.x, quietly = TRUE))
function(.x)
suppressPackageStartupMessages(requireNamespace(.x, quietly = TRUE))
)

invisible(TRUE)
Expand All @@ -290,3 +279,17 @@
is_installed_ <- function(pkg) {
rlang::is_installed(pkg)
}

uses_foreach_only <- function() {
future::nbrOfWorkers() == 1 && foreach::getDoParWorkers() > 1
}

warn_foreach_deprecation <- function() {
cli::cli_warn(c(
"!" = "{.pkg stacks} detected a parallel backend registered with \\
foreach but no backend registered with future.",
"i" = "Support for parallel processing with foreach was \\
deprecated in {.pkg stacks} 1.0.6.",
"i" = "See {.help tune::parallelism} to learn more."
))

Check warning on line 294 in R/fit_members.R

View check run for this annotation

Codecov / codecov/patch

R/fit_members.R#L288-L294

Added lines #L288 - L294 were not covered by tests
}
1 change: 1 addition & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ utils::globalVariables(c(
".metric",
".pred",
".pred_class",
".sum",
"across",
"any_of",
"as.formula",
Expand Down