From 085becaf742765218dbd494c197b9398d532bad1 Mon Sep 17 00:00:00 2001 From: Timothy Willard <9395586+TimothyWillard@users.noreply.github.com> Date: Wed, 8 Jan 2025 12:02:44 -0500 Subject: [PATCH] Call positional args with names * Per @pearsonca, @jcblemai suggestions call positional arguements with names. * Restyle call to `get_seeding_data` in `gempyor.seir.onerun_SEIR`. --- .../gempyor_pkg/src/gempyor/dev/dev_seir.py | 2 +- flepimop/gempyor_pkg/src/gempyor/inference.py | 4 ++-- .../gempyor_pkg/src/gempyor/model_info.py | 20 +++++++++---------- flepimop/gempyor_pkg/src/gempyor/seir.py | 5 +++-- .../gempyor_pkg/tests/seir/test_seeding.py | 12 +++++------ flepimop/gempyor_pkg/tests/seir/test_seir.py | 16 +++++++-------- 6 files changed, 30 insertions(+), 29 deletions(-) diff --git a/flepimop/gempyor_pkg/src/gempyor/dev/dev_seir.py b/flepimop/gempyor_pkg/src/gempyor/dev/dev_seir.py index 9a2219471..5637f667d 100644 --- a/flepimop/gempyor_pkg/src/gempyor/dev/dev_seir.py +++ b/flepimop/gempyor_pkg/src/gempyor/dev/dev_seir.py @@ -35,7 +35,7 @@ out_prefix=prefix, ) -seeding_data = modinf.get_seeding_data(100) +seeding_data = modinf.get_seeding_data(sim_id=100) initial_conditions = modinf.initial_conditions.get_from_config(sim_id=100, modinf=modinf) mobility_subpop_indices = modinf.mobility.indices diff --git a/flepimop/gempyor_pkg/src/gempyor/inference.py b/flepimop/gempyor_pkg/src/gempyor/inference.py index 28c7e5f30..7851ff946 100644 --- a/flepimop/gempyor_pkg/src/gempyor/inference.py +++ b/flepimop/gempyor_pkg/src/gempyor/inference.py @@ -164,7 +164,7 @@ def get_static_arguments(modinf: model_info.ModelInfo): ) initial_conditions = modinf.initial_conditions.get_from_config(sim_id=0, modinf=modinf) - seeding_data, seeding_amounts = modinf.get_seeding_data(0) + seeding_data, seeding_amounts = modinf.get_seeding_data(sim_id=0) # reduce them parameters = modinf.parameters.parameters_reduce(p_draw, npi_seir) @@ -673,7 +673,7 @@ def one_simulation( with Timer("onerun_SEIR.seeding"): seeding_data, seeding_amounts = self.modinf.get_seeding_data( - sim_id2load if load_ID else sim_id2write + sim_id=sim_id2load if load_ID else sim_id2write ) if load_ID: initial_conditions = self.modinf.initial_conditions.get_from_file( diff --git a/flepimop/gempyor_pkg/src/gempyor/model_info.py b/flepimop/gempyor_pkg/src/gempyor/model_info.py index 459598ab6..2cf4cf1c5 100644 --- a/flepimop/gempyor_pkg/src/gempyor/model_info.py +++ b/flepimop/gempyor_pkg/src/gempyor/model_info.py @@ -306,10 +306,10 @@ def get_filename( self, ftype: str, sim_id: int, input: bool, extension_override: str = "" ): return self.path_prefix / file_paths.create_file_name( - self.in_run_id if input else self.out_run_id, - self.in_prefix if input else self.out_prefix, - sim_id + self.first_sim_index - 1, - ftype, + run_id=self.in_run_id if input else self.out_run_id, + prefix=self.in_prefix if input else self.out_prefix, + index=sim_id + self.first_sim_index - 1, + ftype=ftype, extension=extension_override if extension_override else self.extension, inference_filepath_suffix=self.inference_filepath_suffix, inference_filename_prefix=self.inference_filename_prefix, @@ -368,12 +368,12 @@ def get_seeding_data(self, sim_id: int) -> tuple[nb.typed.Dict, npt.NDArray[np.n `gempyor.seeding.Seeding.get_from_config` """ return self.seeding.get_from_config( - self.compartments, - self.subpop_struct, - self.n_days, - self.ti, - self.tf, - ( + compartments=self.compartments, + subpop_struct=self.subpop_struct, + n_days=self.n_days, + ti=self.ti, + tf=self.tf, + input_filename=( None if self.seeding_config is None else self.get_input_filename( diff --git a/flepimop/gempyor_pkg/src/gempyor/seir.py b/flepimop/gempyor_pkg/src/gempyor/seir.py index 72a96bbe9..84c2c4d55 100644 --- a/flepimop/gempyor_pkg/src/gempyor/seir.py +++ b/flepimop/gempyor_pkg/src/gempyor/seir.py @@ -277,12 +277,13 @@ def onerun_SEIR( initial_conditions = modinf.initial_conditions.get_from_file( sim_id2load, modinf=modinf ) - seeding_data, seeding_amounts = modinf.get_seeding_data(sim_id2load) else: initial_conditions = modinf.initial_conditions.get_from_config( sim_id2write, modinf=modinf ) - seeding_data, seeding_amounts = modinf.get_seeding_data(sim_id2write) + seeding_data, seeding_amounts = modinf.get_seeding_data( + sim_id=sim_id2load if load_ID else sim_id2write + ) with Timer("onerun_SEIR.parameters"): # Draw or load parameters diff --git a/flepimop/gempyor_pkg/tests/seir/test_seeding.py b/flepimop/gempyor_pkg/tests/seir/test_seeding.py index 19bd7ad30..4a6090fb0 100644 --- a/flepimop/gempyor_pkg/tests/seir/test_seeding.py +++ b/flepimop/gempyor_pkg/tests/seir/test_seeding.py @@ -40,12 +40,12 @@ def test_Seeding_draw_success(self): s.seeding_config["method"] = "NoSeeding" seeding_result = sic.get_from_config( - s.compartments, - s.subpop_struct, - s.n_days, - s.ti, - s.tf, - s.get_input_filename( + compartments=s.compartments, + subpop_struct=s.subpop_struct, + n_days=s.n_days, + ti=s.ti, + tf=s.tf, + input_filename=s.get_input_filename( ftype=s.seeding_config["seeding_file_type"].get(), sim_id=0, extension_override="csv", diff --git a/flepimop/gempyor_pkg/tests/seir/test_seir.py b/flepimop/gempyor_pkg/tests/seir/test_seir.py index 8fc7ef024..6791e6ae4 100644 --- a/flepimop/gempyor_pkg/tests/seir/test_seir.py +++ b/flepimop/gempyor_pkg/tests/seir/test_seir.py @@ -73,7 +73,7 @@ def test_constant_population_legacy_integration(): ) integration_method = "legacy" - seeding_data, seeding_amounts = modinf.get_seeding_data(100) + seeding_data, seeding_amounts = modinf.get_seeding_data(sim_id=100) initial_conditions = modinf.initial_conditions.get_from_config( sim_id=100, modinf=modinf ) @@ -152,7 +152,7 @@ def test_constant_population_rk4jit_integration_fail(): ) modinf.seir_config["integration"]["method"] = "rk4.jit" - seeding_data, seeding_amounts = modinf.get_seeding_data(100) + seeding_data, seeding_amounts = modinf.get_seeding_data(sim_id=100) initial_conditions = modinf.initial_conditions.get_from_config( sim_id=100, modinf=modinf ) @@ -229,7 +229,7 @@ def test_constant_population_rk4jit_integration(): # s.integration_method = "rk4.jit" assert modinf.seir_config["integration"]["method"].get() == "rk4" - seeding_data, seeding_amounts = modinf.get_seeding_data(100) + seeding_data, seeding_amounts = modinf.get_seeding_data(sim_id=100) initial_conditions = modinf.initial_conditions.get_from_config( sim_id=100, modinf=modinf ) @@ -304,7 +304,7 @@ def test_steps_SEIR_nb_simple_spread_with_txt_matrices(): out_prefix=prefix, ) - seeding_data, seeding_amounts = modinf.get_seeding_data(100) + seeding_data, seeding_amounts = modinf.get_seeding_data(sim_id=100) initial_conditions = modinf.initial_conditions.get_from_config( sim_id=100, modinf=modinf ) @@ -413,7 +413,7 @@ def test_steps_SEIR_nb_simple_spread_with_csv_matrices(): out_prefix=prefix, ) - seeding_data, seeding_amounts = modinf.get_seeding_data(100) + seeding_data, seeding_amounts = modinf.get_seeding_data(sim_id=100) initial_conditions = modinf.initial_conditions.get_from_config( sim_id=100, modinf=modinf ) @@ -490,7 +490,7 @@ def test_steps_SEIR_no_spread(): out_prefix=prefix, ) - seeding_data, seeding_amounts = modinf.get_seeding_data(100) + seeding_data, seeding_amounts = modinf.get_seeding_data(sim_id=100) initial_conditions = modinf.initial_conditions.get_from_config( sim_id=100, modinf=modinf ) @@ -767,7 +767,7 @@ def test_parallel_compartments_with_vacc(): out_prefix=prefix, ) - seeding_data, seeding_amounts = modinf.get_seeding_data(100) + seeding_data, seeding_amounts = modinf.get_seeding_data(sim_id=100) initial_conditions = modinf.initial_conditions.get_from_config( sim_id=100, modinf=modinf ) @@ -861,7 +861,7 @@ def test_parallel_compartments_no_vacc(): out_prefix=prefix, ) - seeding_data, seeding_amounts = modinf.get_seeding_data(100) + seeding_data, seeding_amounts = modinf.get_seeding_data(sim_id=100) initial_conditions = modinf.initial_conditions.get_from_config( sim_id=100, modinf=modinf )