Skip to content

Commit

Permalink
progressr for batch simulation
Browse files Browse the repository at this point in the history
  • Loading branch information
sbfnk committed Sep 30, 2024
1 parent 452b8c1 commit 791cf83
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions R/simulate_infections.R
Original file line number Diff line number Diff line change
Expand Up @@ -470,14 +470,10 @@ forecast_infections <- function(estimates,

safe_batch <- safely(batch_simulate)

## simulate in batches
with_progress({
if (verbose && requireNamespace("progressr", quietly = TRUE)) {
p <- progressr::progressor(along = batches)
}
out <- lapply_func(batches,
process_batches <- function(p = NULL) {
lapply_func(batches,
function(batch) {
if (verbose && requireNamespace("progressr", quietly = TRUE)) {
if (!is.null(p)) {
p()
}
safe_batch(
Expand All @@ -491,7 +487,17 @@ forecast_infections <- function(estimates,
),
backend = backend
)
})
}

## simulate in batches
if (verbose && requireNamespace("progressr", quietly = TRUE)) {
p <- progressr::progressor(along = batches)
progressr::with_progress({
regional_out <- process_batches(p)
})
} else {
regional_out <- process_batches()
}

## join batches
out <- compact(out)
Expand Down

0 comments on commit 791cf83

Please sign in to comment.