Skip to content

Commit

Permalink
Merge branch 'breaking-improvments' of https://github.com/HopkinsIDD/…
Browse files Browse the repository at this point in the history
…flepiMoP into breaking-improvments
  • Loading branch information
shauntruelove committed Oct 16, 2023
2 parents 8f083fe + 9ba1854 commit 5d2f1bd
Show file tree
Hide file tree
Showing 9 changed files with 274 additions and 244 deletions.
2 changes: 1 addition & 1 deletion batch/inference_job_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ def launch_batch(
outcome_modifiers_scenarios = None
if config["seir_modifiers"]["scenarios"].exists():
seir_modifiers_scenarios = config["seir_modifiers"]["scenarios"]
if config["outcome_modifiers"]["scenarios"]:
if config["outcome_modifiers"]["scenarios"].exists():
outcome_modifiers_scenarios = config["outcome_modifiers"]["scenarios"]

handler.launch(job_name, config_file, seir_modifiers_scenarios, outcome_modifiers_scenarios)
Expand Down
6 changes: 3 additions & 3 deletions flepimop/R_packages/flepicommon/R/file_paths.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ create_prefix <- function(..., prefix='',sep='-',trailing_separator=""){

## Function for creating file names from their components
##' @export
create_file_name <- function(run_id, prefix, suffix, index, type, extension='parquet', create_directory = TRUE){
rc <- sprintf("model_output/%s/%s/%s/%09d.%s.%s.%s", prefix, type, suffix, index, run_id, type, extension)
if(create_directory){
create_file_name <- function(run_id, prefix, filepath_suffix, filename_prefix, index, type, extension='parquet', create_directory = TRUE){
rc <- sprintf("model_output/%s/%s/%s/%s/%s%09d.%s.%s.%s", prefix,run_id, type, filepath_suffix, filename_prefix, index, run_id, type, extension)
if(create_directory){ # Add filename prefix here.
if(!dir.exists(dirname(rc))){
dir.create(dirname(rc), recursive = TRUE)
}
Expand Down
238 changes: 122 additions & 116 deletions flepimop/R_packages/inference/R/inference_slot_runner_funcs.R

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ test_that("MCMC step copies (global) are correctly performed when we are not at
dir.create("MCMC_step_copy_test")
setwd("MCMC_step_copy_test")
##get file names
seed_src <- flepicommon::create_file_name(run_id,global_local_prefix,current_index,'seed','csv')
init_src <- flepicommon::create_file_name(run_id,global_local_prefix,current_index,'init','parquet')
seir_src <- flepicommon::create_file_name(run_id,global_local_prefix,current_index,'seir','parquet')
hosp_src <- flepicommon::create_file_name(run_id,global_local_prefix,current_index,'hosp','parquet')
llik_src <- flepicommon::create_file_name(run_id,global_local_prefix,current_index,'llik','parquet')
snpi_src <- flepicommon::create_file_name(run_id,global_local_prefix,current_index,'snpi','parquet')
spar_src <- flepicommon::create_file_name(run_id,global_local_prefix,current_index,'spar','parquet')
hnpi_src <- flepicommon::create_file_name(run_id,global_local_prefix,current_index,'hnpi','parquet')
hpar_src <- flepicommon::create_file_name(run_id,global_local_prefix,current_index,'hpar','parquet')
seed_src <- flepicommon::create_file_name(run_id=run_id, prefix=global_local_prefix,current_index,'seed','csv')
init_src <- flepicommon::create_file_name(run_id=run_id, prefix=global_local_prefix,current_index,'init','parquet')
seir_src <- flepicommon::create_file_name(run_id=run_id, prefix=global_local_prefix,current_index,'seir','parquet')
hosp_src <- flepicommon::create_file_name(run_id=run_id, prefix=global_local_prefix,current_index,'hosp','parquet')
llik_src <- flepicommon::create_file_name(run_id=run_id, prefix=global_local_prefix,current_index,'llik','parquet')
snpi_src <- flepicommon::create_file_name(run_id=run_id, prefix=global_local_prefix,current_index,'snpi','parquet')
spar_src <- flepicommon::create_file_name(run_id=run_id, prefix=global_local_prefix,current_index,'spar','parquet')
hnpi_src <- flepicommon::create_file_name(run_id=run_id, prefix=global_local_prefix,current_index,'hnpi','parquet')
hpar_src <- flepicommon::create_file_name(run_id=run_id, prefix=global_local_prefix,current_index,'hpar','parquet')



Expand All @@ -44,7 +44,7 @@ test_that("MCMC step copies (global) are correctly performed when we are not at
arrow::write_parquet(data.frame(file="hpar"), hpar_src)

##print(hosp_src)
##print(flepicommon::create_file_name(run_id,gf_prefix,slot,'hosp','parquet'))
##print(flepicommon::create_file_name(run_id=run_id, prefix=gf_prefix,slot,'hosp','parquet'))

res <- perform_MCMC_step_copies_global(current_index,
slot,
Expand Down Expand Up @@ -82,15 +82,15 @@ test_that("MCMC step copies (global) are correctly performed when we are at the
dir.create("MCMC_step_copy_test")
setwd("MCMC_step_copy_test")
##get file names
seed_src <- flepicommon::create_file_name(run_id,global_block_prefix,block-1,'seed','csv')
init_src <- flepicommon::create_file_name(run_id,global_block_prefix,block-1,'init','parquet')
seir_src <- flepicommon::create_file_name(run_id,global_block_prefix,block-1,'seir','parquet')
hosp_src <- flepicommon::create_file_name(run_id,global_block_prefix,block-1,'hosp','parquet')
llik_src <- flepicommon::create_file_name(run_id,global_block_prefix,block-1,'llik','parquet')
snpi_src <- flepicommon::create_file_name(run_id,global_block_prefix,block-1,'snpi','parquet')
spar_src <- flepicommon::create_file_name(run_id,global_block_prefix,block-1,'spar','parquet')
hnpi_src <- flepicommon::create_file_name(run_id,global_block_prefix,block-1,'hnpi','parquet')
hpar_src <- flepicommon::create_file_name(run_id,global_block_prefix,block-1,'hpar','parquet')
seed_src <- flepicommon::create_file_name(run_id=run_id, prefix=global_block_prefix,block-1,'seed','csv')
init_src <- flepicommon::create_file_name(run_id=run_id, prefix=global_block_prefix,block-1,'init','parquet')
seir_src <- flepicommon::create_file_name(run_id=run_id, prefix=global_block_prefix,block-1,'seir','parquet')
hosp_src <- flepicommon::create_file_name(run_id=run_id, prefix=global_block_prefix,block-1,'hosp','parquet')
llik_src <- flepicommon::create_file_name(run_id=run_id, prefix=global_block_prefix,block-1,'llik','parquet')
snpi_src <- flepicommon::create_file_name(run_id=run_id, prefix=global_block_prefix,block-1,'snpi','parquet')
spar_src <- flepicommon::create_file_name(run_id=run_id, prefix=global_block_prefix,block-1,'spar','parquet')
hnpi_src <- flepicommon::create_file_name(run_id=run_id, prefix=global_block_prefix,block-1,'hnpi','parquet')
hpar_src <- flepicommon::create_file_name(run_id=run_id, prefix=global_block_prefix,block-1,'hpar','parquet')

##create the copy from files
readr::write_csv(data.frame(file="seed"), seed_src)
Expand All @@ -104,7 +104,7 @@ test_that("MCMC step copies (global) are correctly performed when we are at the
arrow::write_parquet(data.frame(file="hpar"), hpar_src)

print(hosp_src)
print(flepicommon::create_file_name(run_id,global_block_prefix,block,'hosp','parquet'))
print(flepicommon::create_file_name(run_id=run_id, prefix=global_block_prefix,block,'hosp','parquet'))

res <- perform_MCMC_step_copies_global(current_index,
slot,
Expand Down Expand Up @@ -142,14 +142,14 @@ test_that("MCMC step copies (chimeric) are correctly performed when we are not a
dir.create("MCMC_step_copy_test")
setwd("MCMC_step_copy_test")
##get file names
seed_src <- flepicommon::create_file_name(run_id,chimeric_local_prefix,current_index,'seed','csv')
seir_src <- flepicommon::create_file_name(run_id,chimeric_local_prefix,current_index,'seir','parquet')
hosp_src <- flepicommon::create_file_name(run_id,chimeric_local_prefix,current_index,'hosp','parquet')
llik_src <- flepicommon::create_file_name(run_id,chimeric_local_prefix,current_index,'llik','parquet')
snpi_src <- flepicommon::create_file_name(run_id,chimeric_local_prefix,current_index,'snpi','parquet')
spar_src <- flepicommon::create_file_name(run_id,chimeric_local_prefix,current_index,'spar','parquet')
hnpi_src <- flepicommon::create_file_name(run_id,chimeric_local_prefix,current_index,'hnpi','parquet')
hpar_src <- flepicommon::create_file_name(run_id,chimeric_local_prefix,current_index,'hpar','parquet')
seed_src <- flepicommon::create_file_name(run_id=run_id, prefix=chimeric_local_prefix,current_index,'seed','csv')
seir_src <- flepicommon::create_file_name(run_id=run_id, prefix=chimeric_local_prefix,current_index,'seir','parquet')
hosp_src <- flepicommon::create_file_name(run_id=run_id, prefix=chimeric_local_prefix,current_index,'hosp','parquet')
llik_src <- flepicommon::create_file_name(run_id=run_id, prefix=chimeric_local_prefix,current_index,'llik','parquet')
snpi_src <- flepicommon::create_file_name(run_id=run_id, prefix=chimeric_local_prefix,current_index,'snpi','parquet')
spar_src <- flepicommon::create_file_name(run_id=run_id, prefix=chimeric_local_prefix,current_index,'spar','parquet')
hnpi_src <- flepicommon::create_file_name(run_id=run_id, prefix=chimeric_local_prefix,current_index,'hnpi','parquet')
hpar_src <- flepicommon::create_file_name(run_id=run_id, prefix=chimeric_local_prefix,current_index,'hpar','parquet')



Expand All @@ -164,7 +164,7 @@ test_that("MCMC step copies (chimeric) are correctly performed when we are not a
arrow::write_parquet(data.frame(file="hpar"), hpar_src)

##print(hosp_src)
##print(flepicommon::create_file_name(run_id,cf_prefix,slot,'hosp','parquet'))
##print(flepicommon::create_file_name(run_id=run_id, prefix=cf_prefix,slot,'hosp','parquet'))

res <- perform_MCMC_step_copies_chimeric(current_index,
slot,
Expand Down Expand Up @@ -203,14 +203,14 @@ test_that("MCMC step copies (chimeric) are correctly performed when we are at th
dir.create("MCMC_step_copy_test")
setwd("MCMC_step_copy_test")
##get file names
seed_src <- flepicommon::create_file_name(run_id,chimeric_block_prefix,block-1,'seed','csv')
seir_src <- flepicommon::create_file_name(run_id,chimeric_block_prefix,block-1,'seir','parquet')
hosp_src <- flepicommon::create_file_name(run_id,chimeric_block_prefix,block-1,'hosp','parquet')
llik_src <- flepicommon::create_file_name(run_id,chimeric_block_prefix,block-1,'llik','parquet')
snpi_src <- flepicommon::create_file_name(run_id,chimeric_block_prefix,block-1,'snpi','parquet')
spar_src <- flepicommon::create_file_name(run_id,chimeric_block_prefix,block-1,'spar','parquet')
hnpi_src <- flepicommon::create_file_name(run_id,chimeric_block_prefix,block-1,'hnpi','parquet')
hpar_src <- flepicommon::create_file_name(run_id,chimeric_block_prefix,block-1,'hpar','parquet')
seed_src <- flepicommon::create_file_name(run_id=run_id, prefix=chimeric_block_prefix,block-1,'seed','csv')
seir_src <- flepicommon::create_file_name(run_id=run_id, prefix=chimeric_block_prefix,block-1,'seir','parquet')
hosp_src <- flepicommon::create_file_name(run_id=run_id, prefix=chimeric_block_prefix,block-1,'hosp','parquet')
llik_src <- flepicommon::create_file_name(run_id=run_id, prefix=chimeric_block_prefix,block-1,'llik','parquet')
snpi_src <- flepicommon::create_file_name(run_id=run_id, prefix=chimeric_block_prefix,block-1,'snpi','parquet')
spar_src <- flepicommon::create_file_name(run_id=run_id, prefix=chimeric_block_prefix,block-1,'spar','parquet')
hnpi_src <- flepicommon::create_file_name(run_id=run_id, prefix=chimeric_block_prefix,block-1,'hnpi','parquet')
hpar_src <- flepicommon::create_file_name(run_id=run_id, prefix=chimeric_block_prefix,block-1,'hpar','parquet')



Expand All @@ -225,7 +225,7 @@ test_that("MCMC step copies (chimeric) are correctly performed when we are at th
arrow::write_parquet(data.frame(file="hpar"), hpar_src)

print(hosp_src)
print(flepicommon::create_file_name(run_id,chimeric_block_prefix,block,'hosp','parquet'))
print(flepicommon::create_file_name(run_id=run_id, prefix=chimeric_block_prefix,block,'hosp','parquet'))

res <- perform_MCMC_step_copies_chimeric(current_index,
slot,
Expand Down
4 changes: 1 addition & 3 deletions flepimop/gempyor_pkg/src/gempyor/file_paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ def create_file_name_without_extension(run_id, prefix, index, ftype, inference_f
if create_directory:
os.makedirs(create_dir_name(run_id, prefix, ftype, inference_filepath_suffix, inference_filename_prefix), exist_ok=True)
filename = pathlib.Path("model_output", prefix, ftype, inference_filepath_suffix,
f"{inference_filename_prefix}.{index:>09}.{run_id}.{ftype}")
print(f" making {filename}")
f"{inference_filename_prefix}{index:>09}.{run_id}.{ftype}")
# old: "model_output/%s/%s%09d.%s.%s" % (ftype, prefix, index, run_id, ftype)

return filename

def run_id():
Expand Down
4 changes: 2 additions & 2 deletions flepimop/gempyor_pkg/src/gempyor/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __init__(
self,
config_path,
run_id="test_run_id",
prefix="test_prefix",
prefix=None,
first_sim_index=1,
seir_modifiers_scenario=None,
outcome_modifiers_scenario=None,
Expand Down Expand Up @@ -97,7 +97,7 @@ def __init__(
print(
f""" gempyor >> Running ***{'STOCHASTIC' if stoch_traj_flag else 'DETERMINISTIC'}*** simulation;\n"""
f""" gempyor >> ModelInfo {self.modinf.setup_name}; index: {self.modinf.first_sim_index}; run_id: {in_run_id},\n"""
f""" gempyor >> prefix: {in_prefix};""" # ti: {s.ti}; tf: {s.tf};
f""" gempyor >> prefix: {self.modinf.in_prefix};""" # ti: {s.ti}; tf: {s.tf};
)

self.already_built = False # whether we have already build the costly objects that need just one build
Expand Down
2 changes: 1 addition & 1 deletion flepimop/gempyor_pkg/src/gempyor/seeding_ic.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def draw_seeding(self, sim_id: int, setup) -> nb.typed.Dict:
elif method == "FolderDraw":
seeding = pd.read_csv(
setup.get_input_filename(
ftype=setup.seeding_config["seeding_file_type"],
ftype=setup.seeding_config["seeding_file_type"].get(),
sim_id=sim_id,
extension_override="csv",
),
Expand Down
2 changes: 1 addition & 1 deletion flepimop/gempyor_pkg/src/gempyor/simulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def simulate(
outcome_modifiers_scenarios = None
if config["outcomes"].exists() and config["outcome_modifiers"].exists():
if config["outcome_modifiers"]["scenarios"].exists():
outcome_modifiers_scenarios = config["outcomes"]["scenarios"].as_str_seq()
outcome_modifiers_scenarios = config["outcome_modifiers"]["scenarios"].as_str_seq()

outcome_modifiers_scenarios = as_list(outcome_modifiers_scenarios)
seir_modifiers_scenarios = as_list(seir_modifiers_scenarios)
Expand Down
Loading

0 comments on commit 5d2f1bd

Please sign in to comment.