Skip to content

Commit

Permalink
when gempyor fails from R, the traceback is now printed so we don't h…
Browse files Browse the repository at this point in the history
…ave to track down bugs
  • Loading branch information
jcblemai committed Oct 14, 2023
1 parent ae5a75a commit e79b4ed
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
20 changes: 18 additions & 2 deletions flepimop/R_packages/inference/R/inference_slot_runner_funcs.R
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,15 @@ initialize_mcmc_first_block <- function(
if (!all(checked_sim_files %in% global_file_names)) {
stop("Provided only one of hosp or seir input file, with some output files. Not supported anymore")
}
gempyor_inference_runner$one_simulation(sim_id2write = block - 1)
tryCatch({
gempyor_inference_runner$one_simulation(sim_id2write = block - 1)
}, error = function(e) {
print("GempyorSimulator failed to run (call on l. 748 of inference_slot_runner_funcs.R).")
print("Here is all the debug information I could find:")
for(m in reticulate::py_last_error()) cat(m)
stop("GempyorSimulator failed to run... stopping")
})
#gempyor_inference_runner$one_simulation(sim_id2write = block - 1)
} else {
stop("Provided some InferenceSimulator output(seir, hosp), but not InferenceSimulator input")
}
Expand All @@ -754,7 +762,15 @@ initialize_mcmc_first_block <- function(
stop("Provided only one of hosp or seir input file, not supported anymore")
}
warning("SEIR and Hosp input provided, but output not found. This is unstable for stochastic runs")
gempyor_inference_runner$one_simulation(sim_id2write=block - 1, load_ID=TRUE, sim_id2load=block - 1)
tryCatch({
gempyor_inference_runner$one_simulation(sim_id2write = block - 1, load_ID = TRUE, sim_id2load = block - 1)
}, error = function(e) {
print("GempyorSimulator failed to run (call on l. 766 of inference_slot_runner_funcs.R).")
print("Here is all the debug information I could find:")
for(m in reticulate::py_last_error()) cat(m)
stop("GempyorSimulator failed to run... stopping")
})
#gempyor_inference_runner$one_simulation(sim_id2write=block - 1, load_ID=TRUE, sim_id2load=block - 1)
}
}

Expand Down
6 changes: 4 additions & 2 deletions flepimop/gempyor_pkg/src/gempyor/compartments.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,10 @@ def parse_parameter_strings_to_numpy_arrays(

if not operators: # empty list means all have been tried. Usually there just remains one string in string_list at that time.
raise ValueError(
f"""Could not parse string {string_list}. This usually mean that '{string_list[0]}' is a parameter name that is not defined
or that an operator is not in the list of supported operator: ^,*,/,+,-."""
f"""Could not parse string {string_list}.
This usually mean that '{string_list[0]}' is a parameter name that is not defined
or that it contains an operator that is not in the list of supported operator: ^,*,/,+,-.
The defined parameters are {parameter_names}."""
)

split_strings = [x.split(operators[0]) for x in string_list]
Expand Down
12 changes: 8 additions & 4 deletions flepimop/main_scripts/inference_slot.R
Original file line number Diff line number Diff line change
Expand Up @@ -534,13 +534,17 @@ for(seir_modifiers_scenario in seir_modifiers_scenarios) {
## Update the prefix
gempyor_inference_runner$update_prefix(new_prefix=global_local_prefix)
## Run the simulator
err <- gempyor_inference_runner$one_simulation(
tryCatch({
gempyor_inference_runner$one_simulation(
sim_id2write=this_index,
load_ID=TRUE,
sim_id2load=this_index)
if (err != 0){
stop("GempyorSimulator failed to run")
}
}, error = function(e) {
print("GempyorSimulator failed to run (call on l. 538 of inference_slot.R).")
print("Here is all the debug information I could find:")
for(m in reticulate::py_last_error()) cat(m)
stop("GempyorSimulator failed to run... stopping")
})

if (config$inference$do_inference){
sim_hosp <- flepicommon::read_file_of_type(gsub(".*[.]","",this_global_files[['hosp_filename']]))(this_global_files[['hosp_filename']]) %>%
Expand Down

0 comments on commit e79b4ed

Please sign in to comment.