Skip to content

Commit

Permalink
return a list of modules when calling intialize_fims()
Browse files Browse the repository at this point in the history
  • Loading branch information
Bai-Li-NOAA committed Dec 19, 2024
1 parent cf626cf commit 140c922
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 11 deletions.
20 changes: 19 additions & 1 deletion R/initialize_modules.R
Original file line number Diff line number Diff line change
Expand Up @@ -762,8 +762,26 @@ initialize_fims <- function(parameters, data) {
CreateTMBModel()
# Create parameter list from Rcpp modules
parameter_list <- list(p = get_fixed())
module_list <- list(
fleet = fleet,
fleet_selectivity = fleet_selectivity,
fleet_index = fleet_index,
fleet_index_distribution = fleet_index_distribution,
fleet_age_comp = fleet_age_comp,
fleet_agecomp_distribution = fleet_agecomp_distribution,
fleet_length_comp = fleet_length_comp,
fleet_lengthcomp_distribution = fleet_lengthcomp_distribution,
recruitment = recruitment,
recruitment_distribution = recruitment_distribution,
growth = growth,
maturity = maturity,
population = population
)

return(parameter_list)
output <- list(
parameter_list = parameter_list,
module_list = module_list
)
}

#' Set parameter vector values based on module input
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/helper-integration-tests-setup.R
Original file line number Diff line number Diff line change
Expand Up @@ -558,13 +558,13 @@ setup_and_run_FIMS_with_wrappers <- function(iter_id,
modified_parameters = modified_parameters
)

parameter_list <- initialize_fims(
output <- initialize_fims(
parameters = parameters,
data = data
)

input <- list()
input$parameters <- parameter_list
input$parameters <- output$parameter_list
input$version <- "Model Comparison Project example"
fit <- fit_fims(input, optimize = estimation_mode)

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-initialize_modules.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ test_that("initialize_fims works", {
result <- initialize_fims(parameters = default_parameters, data = data)

expect_type(result, "list")
expect_named(result, "p")
expect_named(result, c("parameter_list", "module_list"))
clear()
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,12 +302,12 @@ test_that("estimation test of fims using high-level wrappers", {

# Clear any previous FIMS settings
clear()
parameter_list <- initialize_fims(
output <- initialize_fims(
parameters = parameters,
data = data
)
input <- list()
input$parameters <- parameter_list
input$parameters <- output$parameter_list
input$version <- "Model Comparison Project example"
fit <- fit_fims(input, optimize = TRUE)

Expand Down
8 changes: 4 additions & 4 deletions vignettes/fims-demo.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,13 @@ With data and parameters in place, we can now initialize modules using `initiali
# Run the model without optimization to help ensure a viable model
test_fit <- parameters |>
initialize_fims(data = fims_frame) |>
(\(parameter_list) list(parameters = parameter_list, version = "FIMS run without optimization"))() |>
(\(output) list(parameters = output$parameter_list, version = "FIMS run without optimization"))() |>
fit_fims(optimize = FALSE)
# Run the model with optimization
fit <- parameters |>
initialize_fims(data = fims_frame) |>
(\(parameter_list) list(parameters = parameter_list, version = "FIMS run with optimization"))() |>
(\(output) list(parameters = output$parameter_list, version = "FIMS run with optimization"))() |>
fit_fims(optimize = TRUE)
# Clear memory post-run
Expand All @@ -194,14 +194,14 @@ parameters_low_slope <- parameters |>
high_slope_fit <- parameters_high_slope |>
initialize_fims(data = fims_frame) |>
(\(parameter_list) list(parameters = parameter_list, version = "High slope run"))() |>
(\(output) list(parameters = output$parameter_list, version = "High slope run"))() |>
fit_fims(optimize = TRUE)
clear()
low_slope_fit <- parameters_low_slope |>
initialize_fims(data = fims_frame) |>
(\(parameter_list) list(parameters = parameter_list, version = "Low slope run"))() |>
(\(output) list(parameters = output$parameter_list, version = "low slope run"))() |>
fit_fims(optimize = TRUE)
clear()
Expand Down
2 changes: 1 addition & 1 deletion vignettes/logging_system.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ Assuming a model has already been defined, below is an example of using the logg
```{r example_code, eval = TRUE}
fit <- default_parameters |>
initialize_fims(data = fims_frame) |>
(\(parameter_list) list(parameters = parameter_list, version = "FIMS run with optimization"))() |>
(\(output) list(parameters = output$parameter_list, version = "FIMS run with optimization"))() |>
fit_fims(optimize = TRUE)
# get the log as a string in JSON format and parse into a list
Expand Down

0 comments on commit 140c922

Please sign in to comment.