Seed setting for 0 and N daemons #508
-
|
Hello, I'm writing a function using library(mirai)
library(purrr)
library(testthat)
mirai::daemons(0)
daemons_0 <- purrr::map(
1:4,
purrr::in_parallel(function(i) {
rnorm(3)
})
)
mirai::daemons(2)
daemons_2 <- purrr::map(
1:4,
purrr::in_parallel(function(i) {
rnorm(3)
})
)
expect_equal(daemons_0, daemons_2)I'd love to know if it's possible to have (And thanks for this wonderful extension to purrr) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Thanks for asking - and doubly so as it led me to find a subtle bug (#509). So try this after installing the dev version of mirai using e.g.: pak::pak("r-lib/mirai")As parallel seeds work fundamentally differently to normal seeds, I suggest setting synchronous daemons with the same seed value rather than try to replicate what happens on a daemon in the main session (although that is also possible). library(mirai)
library(purrr)
library(testthat)
seed <- 12
daemons(sync = TRUE, seed = seed)
daemons_0 <- map(1:4, in_parallel(function(i) { rnorm(3) }))
daemons(2, seed = seed)
daemons_2 <- map(1:4, in_parallel(function(i) { rnorm(3) }))
expect_equal(daemons_0, daemons_2)When you specify For completeness, if this usage is contemplated within a CRAN package then the guidance at https://mirai.r-lib.org/articles/v06-packages.html#guidance does allow you to use |
Beta Was this translation helpful? Give feedback.
Thanks for asking - and doubly so as it led me to find a subtle bug (#509).
So try this after installing the dev version of mirai using e.g.:
As parallel seeds work fundamentally differently to normal seeds, I suggest setting synchronous daemons with the same seed value rather than try to replicate what happens on a daemon in the main session (although that is also possible).
When you specify
s…