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

Style code and document #647

Merged
merged 1 commit into from
Jul 9, 2024
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
5 changes: 3 additions & 2 deletions tests/testthat/fixtures/simulate-integration-test-data.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ on.exit(setwd(working_dir), add = TRUE)
# .RData files and save them into one file
om_input_list <- om_output_list <- em_input_list <-
vector(mode = "list", length = sim_num)
for (i in 1:sim_num){
for (i in 1:sim_num) {
load(file.path(maindir, "FIMS_100iter", "output", "OM", paste0("OM", i, ".RData")))
om_input_list[[i]] <- om_input
om_output_list[[i]] <- om_output
em_input_list[[i]] <- em_input
}

save(om_input_list, om_output_list, em_input_list,
file = test_path("fixtures", "integration_test_data.RData"))
file = test_path("fixtures", "integration_test_data.RData")
)
9 changes: 4 additions & 5 deletions tests/testthat/helper-integration-tests-setup.R
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,12 @@ setup_and_run_FIMS <- function(iter_id,
CreateTMBModel()
# Create parameter list from Rcpp modules
parameters <- list(p = get_fixed())
obj <- TMB::MakeADFun(data = list(), parameters, DLL = "FIMS", silent=TRUE)

if (estimation_mode == TRUE){
obj <- TMB::MakeADFun(data = list(), parameters, DLL = "FIMS", silent = TRUE)

if (estimation_mode == TRUE) {
opt <- with(obj, optim(par, fn, gr,
method = "BFGS",
control = list(maxit = 1000000, reltol = 1e-15)
method = "BFGS",
control = list(maxit = 1000000, reltol = 1e-15)
))
}
# Call report using MLE parameter values, or
Expand Down
26 changes: 16 additions & 10 deletions tests/testthat/test-parallel-with-snowfall.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ for (i in 1:length(om_input_list)) {
om_input_list = om_input_list,
om_output_list = om_output_list,
em_input_list = em_input_list,
estimation_mode = TRUE)
estimation_mode = TRUE
)
}
end_time_serial <- Sys.time()
estimation_time_serial <- end_time_serial - start_time_serial

test_that("Run FIMS in parallel using {snowfall}", {

core_num <- parallel::detectCores() - 1
snowfall::sfInit(parallel = TRUE, cpus = core_num)
start_time_parallel <- Sys.time()
Expand All @@ -39,7 +39,8 @@ test_that("Run FIMS in parallel using {snowfall}", {
om_input_list,
om_output_list,
em_input_list,
TRUE)
TRUE
)

end_time_parallel <- Sys.time()

Expand All @@ -53,17 +54,22 @@ test_that("Run FIMS in parallel using {snowfall}", {

# Compare parameters in results:
# Verify that the results from both runs are equivalent.
expect_setequal(unname(unlist(lapply(results_parallel, `[[`, "parameters"))),
unname(unlist(lapply(estimation_results_serial, `[[`, "parameters"))))
expect_setequal(
unname(unlist(lapply(results_parallel, `[[`, "parameters"))),
unname(unlist(lapply(estimation_results_serial, `[[`, "parameters")))
)

# Compare sdr_fixed values in results:
# Verify that the results from both runs are equivalent.
expect_setequal(unlist(lapply(results_parallel, `[[`, "sdr_fixed")),
unlist(lapply(estimation_results_serial, `[[`, "sdr_fixed")))
expect_setequal(
unlist(lapply(results_parallel, `[[`, "sdr_fixed")),
unlist(lapply(estimation_results_serial, `[[`, "sdr_fixed"))
)

# Compare sdr_report values in results:
# Verify that the results from both runs are equivalent.
expect_setequal(unlist(lapply(results_parallel, `[[`, "sdr_report")),
unlist(lapply(estimation_results_serial, `[[`, "sdr_report")))

expect_setequal(
unlist(lapply(results_parallel, `[[`, "sdr_report")),
unlist(lapply(estimation_results_serial, `[[`, "sdr_report"))
)
})
Loading