Skip to content

Commit

Permalink
Merge branch 'master' into document-structured-draws-via-draws_of
Browse files Browse the repository at this point in the history
  • Loading branch information
jgabry committed Apr 22, 2024
2 parents 0dbe050 + 4a865bb commit d79ffd8
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 12 deletions.
1 change: 0 additions & 1 deletion .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ jobs:
- {os: ubuntu-20.04, r: 'devel', rtools: ''}
- {os: ubuntu-20.04, r: 'release', rtools: ''}
- {os: ubuntu-20.04, r: 'oldrel', rtools: ''}
- {os: ubuntu-20.04, r: '3.6', rtools: ''}
env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
Expand Down
5 changes: 4 additions & 1 deletion tests/testthat/test-fit-mle.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ test_that("time is reported after optimization", {
})

test_that("no error when checking estimates after failure", {
fit <- cmdstanr_example("schools", method = "optimize", seed = 123) # optim ålways fails for this
expect_warning(
fit <- cmdstanr_example("schools", method = "optimize", seed = 123), # optim ålways fails for this
"Fitting finished unexpectedly"
)
expect_error(fit$summary(), "Fitting failed. Unable to retrieve the draws.")
})

Expand Down
5 changes: 4 additions & 1 deletion tests/testthat/test-fit-shared.R
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,10 @@ test_that("return_codes method works properly", {
expect_equal(fits[["generate_quantities"]]$return_codes(), c(0,0,0,0))

# non-zero
non_zero <- testing_fit("schools", method = "optimize", seed = 123)
expect_warning(
non_zero <- testing_fit("schools", method = "optimize", seed = 123),
"Fitting finished unexpectedly"
)
expect_gt(non_zero$return_codes(), 0)
})

Expand Down
12 changes: 7 additions & 5 deletions tests/testthat/test-model-laplace.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ test_that("laplace() runs when all arguments specified validly", {
expect_equal(fit1$metadata()$draws, as.integer(ok_arg_values$draws))
expect_equal(fit1$mode()$metadata()$jacobian, as.integer(ok_arg_values$jacobian))
expect_equal(fit1$mode()$metadata()$init_alpha, ok_arg_values$opt_args$init_alpha)

expect_equal(fit1$mode()$metadata()$tol_obj, ok_arg_values$opt_args$tol_obj, tolerance = 0)

# leaving all at default (except 'data')
Expand Down Expand Up @@ -121,11 +121,13 @@ test_that("laplace() errors with bad combinations of arguments", {
test_that("laplace() errors if optimize() fails", {
mod_schools <- testing_model("schools")
expect_error(
expect_message(
mod_schools$laplace(data = testing_data("schools"), refresh = 0),
"Line search failed to achieve a sufficient decrease"
expect_warning(
expect_message(
mod_schools$laplace(data = testing_data("schools"), refresh = 0),
"Line search failed to achieve a sufficient decrease"
),
"Fitting finished unexpectedly"
),
"Optimization failed"
)

})
2 changes: 1 addition & 1 deletion tests/testthat/test-model-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ test_that("Variable skeleton returns correct dimensions for matrices", {
N <- 4
K <- 3
fit <- mod$sample(data = list(N = N, K = K), chains = 1,
iter_warmup = 1, iter_sampling = 1)
iter_warmup = 1, iter_sampling = 5)

target_skeleton <- list(
x_real = array(0, dim = 1),
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-model-sample.R
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ test_that("print statements in transformed data work", {
}'
))

out <- capture.output(fit <- mod$sample(iter_warmup = 1, iter_sampling = 1, chains = 1))
out <- capture.output(fit <- mod$sample(iter_warmup = 1, iter_sampling = 5, chains = 1))
expect_true(any(grepl("*N = 2*", out)))
})

Expand Down Expand Up @@ -276,7 +276,7 @@ test_that("seed works for multi chain sampling", {
f <- write_stan_file(m, basename = "rngs.stan")
mod <- cmdstan_model(f)
utils::capture.output(
fit_sample <- mod$sample(chains = 2, iter_sampling = 1, iter_warmup = 100, seed = 2)
fit_sample <- mod$sample(chains = 2, iter_sampling = 5, iter_warmup = 100, seed = 2)
)
chain_tdata_1 <- posterior::subset_draws(fit_sample$draws("tdata"), chain = 1)
chain_tdata_2 <- posterior::subset_draws(fit_sample$draws("tdata"), chain = 2)
Expand All @@ -286,7 +286,7 @@ test_that("seed works for multi chain sampling", {
expect_false(all(chain_tdata_1 == chain_tdata_2))

utils::capture.output(
fit_sample <- mod$sample(chains = 2, iter_sampling = 1, iter_warmup = 100,
fit_sample <- mod$sample(chains = 2, iter_sampling = 5, iter_warmup = 100,
seed = c(1, 2))
)
chain_tdata_1 <- posterior::subset_draws(fit_sample$draws("tdata"), chain = 1)
Expand Down

0 comments on commit d79ffd8

Please sign in to comment.