From 40f3848867784b0fbb185fc7b935fd8175375f80 Mon Sep 17 00:00:00 2001 From: "Zhao, Yujie" Date: Fri, 24 Jan 2025 18:21:17 -0500 Subject: [PATCH] change parallel simulation set up --- DESCRIPTION | 4 +--- vignettes/sim_fixed_design_custom.Rmd | 12 +++--------- vignettes/sim_gs_design_custom.Rmd | 18 ++++-------------- 3 files changed, 8 insertions(+), 26 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 4372f7d4..410115a6 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -60,9 +60,7 @@ Suggests: survMisc, survRM2, testthat, - tidyr, - doRNG, - tictoc + tidyr LinkingTo: Rcpp Roxygen: list(markdown = TRUE) diff --git a/vignettes/sim_fixed_design_custom.Rmd b/vignettes/sim_fixed_design_custom.Rmd index 45048bb6..a989d741 100644 --- a/vignettes/sim_fixed_design_custom.Rmd +++ b/vignettes/sim_fixed_design_custom.Rmd @@ -15,8 +15,6 @@ library(dplyr) library(tibble) library(gt) library(doFuture) -library(doRNG) -library(tictoc) set.seed(2025) ``` @@ -279,17 +277,14 @@ one_sim <- function(sim_id = 1, After that, we will execute `one_sim()` multiple times using parallel computation. The following lines of code takes 4 works to run 100 simulations. ```{r} -tic() -registerDoFuture() -registerDoRNG() -plan("multisession", workers = 4) set.seed(2025) ans <- foreach( sim_id = seq_len(n_sim), .combine = "rbind", - .errorhandling = "stop" - ) %dorng% { + .errorhandling = "stop", + .options.future = list(seed = TRUE) + ) %dofuture% { ans_new <- one_sim( sim_id = sim_id, # arguments from Step 1: design characteristic @@ -315,7 +310,6 @@ ans <- foreach( } plan("sequential") -toc() ``` The output from the parallel computation resembles the output of `sim_fix_n()` described in the vignette [Simulate Fixed Designs with Ease via sim_fixed_n](https://merck.github.io/simtrial/articles/sim_fixed_design_simple.html). Each row in the output corresponds to the simulation results for each testing method per each repeation. diff --git a/vignettes/sim_gs_design_custom.Rmd b/vignettes/sim_gs_design_custom.Rmd index 14425be6..4fca0e5f 100644 --- a/vignettes/sim_gs_design_custom.Rmd +++ b/vignettes/sim_gs_design_custom.Rmd @@ -15,8 +15,6 @@ library(dplyr) library(tibble) library(gt) library(doFuture) -library(doRNG) -library(tictoc) set.seed(2025) ``` @@ -35,7 +33,7 @@ If users are interested in more complex scenarios such as the ones listed below, The parameters setup to scratch a group sequential simulation is very similar to Step 1 of the vignette [Simulate Group Sequential Designs with Ease via sim_gs_n](https://merck.github.io/simtrial/articles/sim_gs_design_simple.html). To shorten the length of this vignette, we will use the same design characteristics and cutting method. ```{r} -n_sim <- 1e4 +n_sim <- 1e2 stratum <- data.frame(stratum = "All", p = 1) block <- rep(c("experimental", "control"), 2) enroll_rate <- data.frame(stratum = "All", rate = 1, duration = 12) @@ -128,17 +126,12 @@ one_sim <- function(sim_id = 1, Then we run `one_sim()` `r n_sim` times via parallel computation. ```{r} -tic() -registerDoFuture() -registerDoRNG() -plan("multisession", workers = 4) -set.seed(2025) - ans <- foreach( sim_id = seq_len(n_sim), .combine = "rbind", - .errorhandling = "stop" - ) %dorng% { + .errorhandling = "stop", + .options.future = list(seed = TRUE) + ) %dofuture% { ans_new <- one_sim( sim_id = sim_id, # arguments from Step 1: design characteristic @@ -159,9 +152,6 @@ ans <- foreach( ans_new } - -plan("sequential") -toc() ``` The output of `sim_gs_n` is a data frame with one row per simulation per analysis per testing method.