From b7f4035d4d163b4777fb9c9c41929364252020ac Mon Sep 17 00:00:00 2001 From: Sebastian Funk Date: Fri, 21 Jul 2023 08:05:10 +0100 Subject: [PATCH 01/10] disable verbosity for failing chains --- tests/testthat/test-estimate_infections.R | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-estimate_infections.R b/tests/testthat/test-estimate_infections.R index b705621b6..85af7b122 100644 --- a/tests/testthat/test-estimate_infections.R +++ b/tests/testthat/test-estimate_infections.R @@ -81,8 +81,14 @@ 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(default_estimate_infections( + verbose = FALSE, reported_cases, + add_stan = list(future = TRUE, max_execution_time = 1)) + ) + expect_error(default_estimate_infections( + verbose = FALSE, reported_cases, + add_stan = list(future = FALSE, max_execution_time = 1)) + ) }) From 6cb25cbd95efd9b0b8a93cf4ca5c2d248aa05fc5 Mon Sep 17 00:00:00 2001 From: Sebastian Funk Date: Fri, 21 Jul 2023 11:55:48 +0100 Subject: [PATCH 02/10] reduce verbosity on estimate_secondary test --- tests/testthat/test-estimate_secondary.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-estimate_secondary.R b/tests/testthat/test-estimate_secondary.R index 223ecca18..80955b272 100644 --- a/tests/testthat/test-estimate_secondary.R +++ b/tests/testthat/test-estimate_secondary.R @@ -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 From eba6b9603383a5ebcca58ac06c86ebd6304dcdb6 Mon Sep 17 00:00:00 2001 From: Sebastian Funk Date: Fri, 21 Jul 2023 22:21:54 +0100 Subject: [PATCH 03/10] return NULL if no samples --- R/estimate_infections.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/estimate_infections.R b/R/estimate_infections.R index b9188f55c..dbb3609a7 100644 --- a/R/estimate_infections.R +++ b/R/estimate_infections.R @@ -543,7 +543,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) || length(names(fit)) == 0) { return(NULL) } else { return(fit) From c99910c6920fb77f8feaa3d34cfdfc540566f0be Mon Sep 17 00:00:00 2001 From: Sebastian Funk Date: Fri, 21 Jul 2023 22:22:11 +0100 Subject: [PATCH 04/10] fix test to check for correct error --- tests/testthat/test-estimate_infections.R | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/tests/testthat/test-estimate_infections.R b/tests/testthat/test-estimate_infections.R index 85af7b122..cc639d858 100644 --- a/tests/testthat/test-estimate_infections.R +++ b/tests/testthat/test-estimate_infections.R @@ -81,14 +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( - verbose = FALSE, reported_cases, - add_stan = list(future = TRUE, max_execution_time = 1)) - ) - expect_error(default_estimate_infections( - verbose = FALSE, 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") }) From 8834bfbf9f068ee595253451b635e8f686173c81 Mon Sep 17 00:00:00 2001 From: Sebastian Funk Date: Fri, 21 Jul 2023 22:22:40 +0100 Subject: [PATCH 05/10] fix regional_epinow short timeout tests --- tests/testthat/test-regional_epinow.R | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/testthat/test-regional_epinow.R b/tests/testthat/test-regional_epinow.R index 59b593580..bb718e2d0 100644 --- a/tests/testthat/test-regional_epinow.R +++ b/tests/testthat/test-regional_epinow.R @@ -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), @@ -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), @@ -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))) }) From c1cb5e813b4a1ead161540e63da8fabd6a414904 Mon Sep 17 00:00:00 2001 From: Sebastian Funk Date: Sat, 22 Jul 2023 08:18:17 +0100 Subject: [PATCH 06/10] fix linting issues --- R/estimate_infections.R | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/R/estimate_infections.R b/R/estimate_infections.R index dbb3609a7..6d80a06f5 100644 --- a/R/estimate_infections.R +++ b/R/estimate_infections.R @@ -324,8 +324,8 @@ 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") { + if (!inherits(args$init_fit, "stanfit") && + args$init_fit %in% "cumulative") { args$init_fit <- init_cumulative_fit(args, warmup = 50, samples = 50, id = id, verbose = FALSE @@ -659,15 +659,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) } From 8b8359366dbb70f2fe5bec2cfb9a471cd1c0837a Mon Sep 17 00:00:00 2001 From: Sebastian Funk Date: Sat, 22 Jul 2023 08:23:04 +0100 Subject: [PATCH 07/10] bump version and add news item --- DESCRIPTION | 2 +- NEWS.md | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 1b90e779c..797b63a9b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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", diff --git a/NEWS.md b/NEWS.md index b118f4563..e47c77c1c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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. # EpiNow2 1.3.5 From 739cc9d89439206e8bd6a6732ccb766baaeeff61 Mon Sep 17 00:00:00 2001 From: Sebastian Funk Date: Sat, 22 Jul 2023 08:26:26 +0100 Subject: [PATCH 08/10] remove stray closing brace --- R/estimate_infections.R | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/R/estimate_infections.R b/R/estimate_infections.R index 6d80a06f5..b97ca9959 100644 --- a/R/estimate_infections.R +++ b/R/estimate_infections.R @@ -326,11 +326,10 @@ estimate_infections <- function(reported_cases, if (!is.null(args$init_fit)) { if (!inherits(args$init_fit, "stanfit") && args$init_fit %in% "cumulative") { - args$init_fit <- init_cumulative_fit(args, - warmup = 50, samples = 50, - id = id, verbose = FALSE - ) - } + 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, From 1967db6b2ce23fdfda8ca123a1cf7c1ea13af646 Mon Sep 17 00:00:00 2001 From: Sebastian Funk Date: Sat, 22 Jul 2023 11:16:44 +0100 Subject: [PATCH 09/10] remove obsolete check --- R/estimate_infections.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/estimate_infections.R b/R/estimate_infections.R index b97ca9959..165966a59 100644 --- a/R/estimate_infections.R +++ b/R/estimate_infections.R @@ -542,7 +542,7 @@ fit_model_with_nuts <- function(args, future = FALSE, max_execution_time = Inf, ) } - if (is.null(fit) || !is.array(fit) || length(names(fit)) == 0) { + if (is.null(fit) || !is.array(fit)) { return(NULL) } else { return(fit) From c87b8fea46da529ac98c53944d249660ac491154 Mon Sep 17 00:00:00 2001 From: Sam Abbott Date: Mon, 24 Jul 2023 10:44:01 +0100 Subject: [PATCH 10/10] Update NEWS.md --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index e47c77c1c..1f2a0ad32 100644 --- a/NEWS.md +++ b/NEWS.md @@ -23,7 +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. +* Reduced verbosity of tests. By @sbfnk in #433 and reviewed by @seabbs. # EpiNow2 1.3.5