Skip to content
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

disable verbosity for failing chains #433

Merged
merged 10 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Type: Package
Package: EpiNow2
Title: Estimate Real-Time Case Counts and Time-Varying
Epidemiological Parameters
Version: 1.3.6.9001
Version: 1.3.6.9002
Authors@R:
c(person(given = "Sam",
family = "Abbott",
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ This release is in development. For a stable release install 1.3.5 from CRAN.
* A small bug has been fixed where the seeding time was too long. When a single delay is used this shortens the seeding time by one day and when more delays are used it shortens the seeding time by n days where n is the number of delays used e.g. for two parametric delays it's two days. By @sbfnk in #413 and reviewed by @seabbs.
* Some tuning was done to speed up the renewal model. By @sbfnk in #416 and reviewed by @seabbs.
* An approximation of the negative binomial by the Poisson at low levels of overdispersion was disabled as it led to parameter identification issues. By @sbfnk in #432 and reviewed by @seabbs.
* Reduced verbosity of tests. By @sbfnk in #433 and reviewed by @seabbs.

# EpiNow2 1.3.5

Expand Down
31 changes: 14 additions & 17 deletions R/estimate_infections.R
Original file line number Diff line number Diff line change
Expand Up @@ -324,13 +324,12 @@ estimate_infections <- function(reported_cases,

# Initialise fitting by using a previous fit or fitting to cumulative cases
if (!is.null(args$init_fit)) {
if (!inherits(args$init_fit, "stanfit")) {
if (args$init_fit %in% "cumulative") {
args$init_fit <- init_cumulative_fit(args,
warmup = 50, samples = 50,
id = id, verbose = FALSE
)
}
if (!inherits(args$init_fit, "stanfit") &&
seabbs marked this conversation as resolved.
Show resolved Hide resolved
args$init_fit %in% "cumulative") {
args$init_fit <- init_cumulative_fit(args,
warmup = 50, samples = 50,
id = id, verbose = FALSE
)
}
args$init <- extract_inits(args$init_fit,
current_inits = args$init,
Expand Down Expand Up @@ -543,7 +542,7 @@ fit_model_with_nuts <- function(args, future = FALSE, max_execution_time = Inf,
)
}

if (is.null(fit) || length(names(fit)) == 0) {
if (is.null(fit) || !is.array(fit)) {
return(NULL)
} else {
return(fit)
Expand Down Expand Up @@ -659,15 +658,13 @@ fit_model_with_vb <- function(args, future = FALSE, id = "stan") {
}

if (is.null(fit)) {
if (is.null(fit)) {
futile.logger::flog.error(
"%s: Fitting failed - try increasing stan_args$trials or inspecting",
" the model input",
id,
name = "EpiNow2.epinow.estimate_infections.fit"
)
rlang::abort("Variational Inference failed due to: ", error)
}
futile.logger::flog.error(
"%s: Fitting failed - try increasing stan_args$trials or inspecting",
" the model input",
id,
name = "EpiNow2.epinow.estimate_infections.fit"
)
rlang::abort("Variational Inference failed due to: ", error)
}
return(fit)
}
Expand Down
12 changes: 10 additions & 2 deletions tests/testthat/test-estimate_infections.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,16 @@ test_that("estimate_infections successfully returns estimates using a random wal

test_that("estimate_infections fails as expected when given a very short timeout", {
skip_on_cran()
expect_error(default_estimate_infections(reported_cases, add_stan = list(future = TRUE, max_execution_time = 1)))
expect_error(default_estimate_infections(reported_cases, add_stan = list(future = FALSE, max_execution_time = 1)))
expect_error(output <- capture.output(suppressMessages(
out <- default_estimate_infections(
reported_cases,
add_stan = list(future = TRUE, max_execution_time = 1)
))), "all chains failed")
expect_error(output <- capture.output(suppressMessages(
out <- default_estimate_infections(
reported_cases,
add_stan = list(future = FALSE, max_execution_time = 1)
))), "timed out")
})


Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-estimate_secondary.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ prev <- estimate_secondary(cases[1:100],
week_effect = FALSE,
scale = list(mean = 0.4, sd = 0.1)
),
verbose = TRUE
verbose = FALSE
)

# extract posterior parameters of interest
Expand Down
20 changes: 10 additions & 10 deletions tests/testthat/test-regional_epinow.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ test_that("regional_epinow produces expected output when run with default settin
})

test_that("regional_epinow runs without error when given a very short timeout", {
expect_error(
regional_epinow(
output <- capture.output(suppressMessages(
out <- regional_epinow(
reported_cases = cases,
generation_time = generation_time_opts(generation_time),
delays = delay_opts(reporting_delay),
Expand All @@ -62,11 +62,11 @@ test_that("regional_epinow runs without error when given a very short timeout",
control = list(adapt_delta = 0.8),
max_execution_time = 1
), logs = NULL, verbose = FALSE
),
NA
)
expect_error(
regional_epinow(
)
))
expect_true(all(vapply(out$regional, function(x) !is.null(x$error), TRUE)))
output <- capture.output(suppressMessages(
out <- regional_epinow(
reported_cases = cases,
generation_time = generation_time_opts(generation_time),
delays = delay_opts(reporting_delay),
Expand All @@ -76,9 +76,9 @@ test_that("regional_epinow runs without error when given a very short timeout",
control = list(adapt_delta = 0.8),
max_execution_time = 1, future = TRUE
), logs = NULL, verbose = FALSE
),
NA
)
)
))
expect_true(all(vapply(out$regional, function(x) !is.null(x$error), TRUE)))
})


Expand Down