-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add 4 vignettes introducing fixed/group sequential design simulations #306
base: main
Are you sure you want to change the base?
Add 4 vignettes introducing fixed/group sequential design simulations #306
Conversation
Hi @jdblischak, I have a question regarding parallel computing. My current implementation is as follows, and I’m wondering if both the
|
Reference 1: https://github.com/Merck/simtrial/blob/main/R/sim_fixed_n.R#L253 Also reduce the number of workers to 2, per CRAN requirements. |
Following up on our offline discussion: Your approach using {doFuture} and {doRNG} is valid. It produces reproducible results: library("foreach")
library("doFuture")
library("doRNG")
registerDoFuture()
registerDoRNG()
plan("multisession", workers = 4)
set.seed(2025)
ans1 <- foreach(
i = 1:10,
.combine = "c",
.errorhandling = "stop"
) %dorng% {
rnorm(1)
}
head(ans1)
## [1] -0.46387557 -0.05150034 -0.22384683 -0.60535060 1.52634253 0.31122695
set.seed(2025)
ans2 <- foreach(
i = 1:10,
.combine = "c",
.errorhandling = "stop"
) %dorng% {
rnorm(1)
}
head(ans2)
## [1] -0.46387557 -0.05150034 -0.22384683 -0.60535060 1.52634253 0.31122695
stopifnot(identical(ans1, ans2)) However, in {simtrial}, we've standardized on using {future} itself to handle the parallel random number generation. Using {doRNG} is an alternative to {doParallel}, but isn't required when using {doFuture} as the backend. library("foreach")
library("doFuture")
registerDoFuture()
plan("multisession", workers = 4)
set.seed(2025)
ans1 <- foreach(
i = 1:10,
.combine = "c",
.errorhandling = "stop",
.options.future = list(seed = TRUE)
) %dofuture% {
rnorm(1)
}
head(ans1)
## [1] -1.0860108 1.3469334 0.1314693 -1.5942347 1.3797186 0.2381956
set.seed(2025)
ans2 <- foreach(
i = 1:10,
.combine = "c",
.errorhandling = "stop",
.options.future = list(seed = TRUE)
) %dofuture% {
rnorm(1)
}
head(ans2)
## [1] -1.0860108 1.3469334 0.1314693 -1.5942347 1.3797186 0.2381956
stopifnot(identical(ans1, ans2)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this code takes a while to run, you can consider only publishing it to the pkgdown site but not including it in the distributed package. See the docs for info at https://r-pkgs.org/vignettes.html#sec-vignettes-article
tidyr | ||
tidyr, | ||
doRNG, | ||
tictoc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How informative are the timings in the vignettes? Is it worth adding another dependency to be installed during each CI run?
If the simulations are small, and they are running on minimal hardware like a CRAN or GitHub machine, it's not clear to me if this will be that informative to an end user that will want to run many simulations on more robust hardware.
This issue adds 4 vignettes introducing fixed/group sequential design simulations.
sim_fixed_n
sim_gs_n