Skip to content

Commit 94d65d9

Browse files
committed
fix: Change MSE save paradigm to ensure available compute memory
A maximum of 66 simulations can be run and saved to a file at a time, due to memory constraints on the primary computer running simulations.
1 parent 74bfe86 commit 94d65d9

2 files changed

Lines changed: 28 additions & 14 deletions

File tree

R/run_mse.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ run_mse <- function(om, mp, mse_options, nyears_input=NA, seed=1120, file_suffix
3939
do_survey_ll <- generate_annual_frequency(mp$ll_survey_frequency, nyears_input - spinup_years)
4040
do_survey_tw <- generate_annual_frequency(mp$tw_survey_frequency, nyears_input - spinup_years)
4141

42-
assessment <- dget("data/sablefish_assessment_2023.rdat")
42+
assessment <- dget(file.path(here::here(), "data", "sablefish_assessment_2023.rdat"))
4343

4444
# Load OM parameters into global environment
4545
list2env(om, env=environment())

R/run_mse_multiple.R

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,29 +33,43 @@ run_mse_multiple <- function(om_list, hcr_list, seed_list, mse_options_list, nye
3333

3434
nsims <- length(seed_list)
3535

36-
j <- 1
36+
max_sims <- 66
37+
nsim_iters <- ifelse(nsims < max_sims, 1, round(nsims / max_sims)+1)
38+
39+
m <- 1
40+
counter <- 0
3741
for(i in 1:nrow(mse_run_grid)){
3842
# omi <- which(names(om_list) == mse_run_grid[i,1])[1]
3943
om <- om_list[[mse_run_grid[i,1]]]
4044
hcr <- hcr_list[[mse_run_grid[i,2]]]
4145
opt <- mse_options_list[[mse_run_grid[i,3]]]
46+
47+
for(j in 1:nsim_iters){
48+
seeds <- seed_list[(((j-1)*max_sims)+1):min((j*max_sims), length(seed_list))]
49+
nsims2 <- length(seeds)
50+
mse_run <- run_mse_parallel(nsims2, seeds, om, hcr, mse_options=opt, nyears=nyears, diagnostics=diagnostics)
51+
52+
counter <- counter+1
53+
mse_objects[[j]] <- mse_run
4254

43-
mse_run <- run_mse_parallel(nsims, seed_list, om, hcr, mse_options=opt, nyears=nyears, diagnostics=diagnostics)
44-
mse_objects[[i]] <- mse_run
45-
55+
print(save)
56+
if(save || nsim_iters>1){
57+
# Going to save files by HCR
58+
filename <- file.path(here::here(), "data", "active", paste0("mse_runs_", sub("/", "", sub(" ", "_", tolower(hcr$name))), "_",counter,".RDS"))
59+
obj <- listN(mse_objects, om, hcr, mse_options_list, seeds)
60+
saveRDS(obj, file=filename)
61+
# m <- m+1
62+
mse_objects <- list()
63+
}
64+
}
65+
4666
next_hcr <- hcr_list[[mse_run_grid[i+1, 2]]]
47-
print(save && !identical(next_hcr, hcr))
48-
if(save && !identical(next_hcr, hcr)){
49-
# Going to save files by HCR
50-
filename <- file.path(here::here(), "data", "active", paste0("mse_runs_", sub("/", "", sub(" ", "_", tolower(hcr$name))), ".RDS"))
51-
obj <- listN(mse_objects, om_list, hcr, mse_options_list, seed_list)
52-
saveRDS(obj, file=filename)
53-
j <- i
54-
mse_objects <- list()
67+
if(!identical(next_hcr, hcr)){
68+
counter <- 0
5569
}
5670

5771
}
5872

5973
return(mse_objects)
6074

61-
}
75+
}

0 commit comments

Comments
 (0)