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
37 changes: 37 additions & 0 deletions R/furrr-options.R
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,43 @@
#' script calling `future_map()` multiple times should be numerically
#' reproducible given the same initial seed.
#'
#' Note that you cannot expect identical results between `map()` and
#' `future_map()` when using a `.f` that calls functions that generate random
#' numbers, even when calling `set.seed()` ahead of time. For one thing, the
#' default random number generation algorithm used by R during sequential
#' processing is Mersenne-Twister, different from the L'Ecuyer-CMRG seeds used
#' by furrr. But even aligning the [RNGkind()] would not be enough. `map()`
#' itself would have to change to use the same parallel compatible RNG strategy
#' as `future_map()` (pre-generating the seeds, and setting them before each
#' `.f` invocation). At the end of the day, you have to accept that the
#' following will produce different sequences of random numbers, but both are
#' statistically sound:
#'
#' ```r
#' set.seed(42)
#' purrr::map(1:10, ~ rnorm(1))
#'
#' set.seed(42)
#' furrr::future_map(1:10, ~ rnorm(1), .options = furrr_options(seed = TRUE))
#' ```
#'
#' But importantly, the `furrr::future_map()` example will always produce the
#' same sequence of random numbers, regardless of the `plan()` you choose:
#'
#' ```r
#' plan(sequential)
#' set.seed(42)
#' furrr::future_map(1:10, ~ rnorm(1), .options = furrr_options(seed = TRUE))
#'
#' plan(multisession, workers = 2)
#' set.seed(42)
#' furrr::future_map(1:10, ~ rnorm(1), .options = furrr_options(seed = TRUE))
#'
#' plan(cluster, workers = workers)
#' set.seed(42)
#' furrr::future_map(1:10, ~ rnorm(1), .options = furrr_options(seed = TRUE))
#' ```
#'
#' @export
#' @examples
#' furrr_options()
Expand Down
35 changes: 35 additions & 0 deletions man/furrr_options.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading