Skip to content

Commit

Permalink
yaml is updated
Browse files Browse the repository at this point in the history
  • Loading branch information
sima-njf committed Dec 10, 2024
1 parent 320606b commit cac9baa
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 80 deletions.
35 changes: 3 additions & 32 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -1,32 +1,3 @@
jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}
name: ${{ matrix.config.os }} (${{ matrix.config.r }})
strategy:
fail-fast: false
matrix:
config:
- {os: macos-12, r: 'release'}
- {os: windows-latest, r: 'release', build-vignettes: false}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}
steps:
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck
needs: check

- uses: r-lib/actions/check-r-package@v2
with:
build_args: ${{ matrix.config.build-vignettes && '--compact-vignettes=gs+qpdf' || '--no-build-vignettes' }}

on:
push:
branches: [main]
Expand All @@ -44,7 +15,7 @@ jobs:
fail-fast: false
matrix:
config:
- {os: macos-12, r: 'release'}
- {os: macos-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
Expand All @@ -53,7 +24,8 @@ jobs:
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes
steps:

steps:
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-pandoc@v2
Expand Down Expand Up @@ -83,4 +55,3 @@ jobs:
with:
upload-snapshots: true
build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")'

95 changes: 47 additions & 48 deletions R/run_simulations.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,59 +15,58 @@

run_simulations <- function(N, n, ndays, ncores, theta, seeds) {
library(epiworldR)
matrices <- parallel::mclapply(1:N, FUN = function(i) {
set.seed(seeds[i])
m <- epiworldR:: ModelSIRCONN(
"mycon",
prevalence = theta$preval[i],
contact_rate = theta$crate[i],
transmission_rate = theta$ptran[i],
recovery_rate = theta$prec[i],
n = n
)
library(parallel)

verbose_off(m)
run(m, ndays = ndays)
ans <- prepare_data(m,max_days=ndays)
# Detect the operating system
os_type <- .Platform$OS.type

return(ans)
}, mc.cores = ncores)
if (os_type == "windows") {
# Use parLapply for Windows
cl <- makeCluster(ncores)
on.exit(stopCluster(cl)) # Ensure the cluster is stopped after use

return(matrices)
}
clusterExport(cl, varlist = c("theta", "n", "ndays", "seeds", "prepare_data"), envir = environment())
clusterEvalQ(cl, library(epiworldR)) # Load necessary libraries on workers

matrices <- parLapply(cl, 1:N, function(i) {
set.seed(seeds[i])
m <- epiworldR::ModelSIRCONN(
"mycon",
prevalence = theta$preval[i],
contact_rate = theta$crate[i],
transmission_rate = theta$ptran[i],
recovery_rate = theta$prec[i],
n = n
)

verbose_off(m)
run(m, ndays = ndays)
ans <- prepare_data(m, max_days = ndays)

return(ans)
})

} else {
# Use mclapply for macOS/Linux
matrices <- mclapply(1:N, function(i) {
set.seed(seeds[i])
m <- epiworldR::ModelSIRCONN(
"mycon",
prevalence = theta$preval[i],
contact_rate = theta$crate[i],
transmission_rate = theta$ptran[i],
recovery_rate = theta$prec[i],
n = n
)

# run_simulations <- function(N, n, ndays, ncores, theta) {
# matrices <- parallel::mclapply(1:N, FUN = function(i) {
# fn <- sprintf("~/myfisrt.package/misc/simulated_data/sir-%06i.rds", i)
#
# if (file.exists(fn))
# return(readRDS(fn))
# seeds <- sample.int(.Machine$integer.max, N, TRUE)
# set.seed(seeds[i])
#
# m <- ModelSIRCONN(
# "mycon",
# prevalence = theta$preval[i],
# contact_rate = theta$crate[i],
# transmission_rate = theta$ptran[i],
# recovery_rate = theta$prec[i],
# n = n
# )
#
# verbose_off_and_run(m, ndays)
# ans <- prepare_data(m)
# saveRDS(ans, fn)
#
# return(ans)
# }, mc.cores = ncores)
#
# return(matrices)
# }
# run_simulations(2e4,5000,50,20,theta)
#path="~/myfisrt.package/misc/simulated_data/sir-%06i.rds"
# source("~/myfisrt.package/R/dataprep.R")
# Input dataset as a vector
verbose_off(m)
run(m, ndays = ndays)
ans <- prepare_data(m, max_days = ndays)

return(ans)
}, mc.cores = ncores)
}

return(matrices)
}

2 changes: 2 additions & 0 deletions vignettes/calibrate.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ head(seeds,5)
Next, the function runs the simulations for the SIR model using the generated parameters and seeds and using epiworldR package:

```{r}
N=10
n=5000
ndays=50
ncores=20
matrices <- run_simulations(N, n, ndays, ncores, theta, seeds)
Expand Down

0 comments on commit cac9baa

Please sign in to comment.