diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 486f3f4db..193943db9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,7 +30,7 @@ jobs: run: | source /var/python/3.10/virtualenv/bin/activate python -m pip install --upgrade pip - python -m pip install flepimop/gempyor_pkg/ + python -m pip install "flepimop/gempyor_pkg[test]" shell: bash - name: Install local R packages run: Rscript build/local_install.R diff --git a/flepimop/gempyor_pkg/setup.cfg b/flepimop/gempyor_pkg/setup.cfg index ce7fd7f1b..1ad3526b2 100644 --- a/flepimop/gempyor_pkg/setup.cfg +++ b/flepimop/gempyor_pkg/setup.cfg @@ -31,10 +31,17 @@ install_requires = pyarrow sympy dask - pytest scipy graphviz +# see https://stackoverflow.com/questions/58826164/dependencies-requirements-for-setting-up-testing-and-installing-a-python-lib +# installed for pip install -e ".[test]" +[options.extras_require] +test = + pytest + mock + + [options.entry_points] console_scripts = gempyor-outcomes = gempyor.simulate_outcome:simulate diff --git a/flepimop/gempyor_pkg/src/gempyor/compartments.py b/flepimop/gempyor_pkg/src/gempyor/compartments.py index ce36c9e55..51ce16993 100644 --- a/flepimop/gempyor_pkg/src/gempyor/compartments.py +++ b/flepimop/gempyor_pkg/src/gempyor/compartments.py @@ -283,7 +283,7 @@ def fromFile(self, compartments_file, transitions_file): return - def get_comp_idx(self, comp_dict: dict) -> int: + def get_comp_idx(self, comp_dict: dict, error_info: str = "no information") -> int: """ return the index of a compartiment given a filter. The filter has to isolate a compartiment, but it ignore columns that don't exist: @@ -294,7 +294,7 @@ def get_comp_idx(self, comp_dict: dict) -> int: comp_idx = self.compartments[mask].index.values if len(comp_idx) != 1: raise ValueError( - f"The provided dictionary does not allow to isolate a compartment: {comp_dict} isolate {self.compartments[mask]} from options {self.compartments}" + f"The provided dictionary does not allow to isolate a compartment: {comp_dict} isolate {self.compartments[mask]} from options {self.compartments}. The get_comp_idx function was called by'{error_info}'." ) return comp_idx[0] @@ -476,7 +476,7 @@ def parse_parameter_strings_to_numpy_arrays_v2(self, parameters, parameter_names f = sp.sympify(formula, locals=symbolic_parameters_namespace) parsed_formulas.append(f) except Exception as e: - print(f"Cannot parse formula: '{formula}' from paramters {parameter_names}") + print(f"Cannot parse formula: '{formula}' from parameters {parameter_names}") raise (e) # Print the error message for debugging # the list order needs to be right. diff --git a/flepimop/gempyor_pkg/src/gempyor/seeding_ic.py b/flepimop/gempyor_pkg/src/gempyor/seeding_ic.py index 89d7fa865..7dcdacee3 100644 --- a/flepimop/gempyor_pkg/src/gempyor/seeding_ic.py +++ b/flepimop/gempyor_pkg/src/gempyor/seeding_ic.py @@ -50,8 +50,8 @@ def _DataFrame2NumbaDict(df, amounts, setup) -> nb.typed.Dict: ) source_dict = {grp_name: row[f"source_{grp_name}"] for grp_name in cmp_grp_names} destination_dict = {grp_name: row[f"destination_{grp_name}"] for grp_name in cmp_grp_names} - seeding_dict["seeding_sources"][idx] = setup.compartments.get_comp_idx(source_dict) - seeding_dict["seeding_destinations"][idx] = setup.compartments.get_comp_idx(destination_dict) + seeding_dict["seeding_sources"][idx] = setup.compartments.get_comp_idx(source_dict, error_info = f"(seeding source at idx={idx}, row_index={row_index}, row=>>{row}<<)") + seeding_dict["seeding_destinations"][idx] = setup.compartments.get_comp_idx(destination_dict, error_info = f"(seeding destination at idx={idx}, row_index={row_index}, row=>>{row}<<)") seeding_dict["seeding_subpops"][idx] = setup.subpop_struct.subpop_names.index(row["subpop"]) seeding_amounts[idx] = amounts[idx] #id_seed+=1 @@ -326,14 +326,7 @@ def draw_seeding(self, sim_id: int, setup) -> nb.typed.Dict: return _DataFrame2NumbaDict(df=seeding, amounts=amounts, setup=setup) def load_seeding(self, sim_id: int, setup) -> nb.typed.Dict: - method = "NoSeeding" - - if self.seeding_config is not None and "method" in self.seeding_config.keys(): - method = self.seeding_config["method"].as_str() - if method not in ["FolderDraw", "SetInitialConditions", "InitialConditionsFolderDraw", "NoSeeding", "FromFile"]: - raise NotImplementedError( - f"Seeding method in inference run must be FolderDraw, SetInitialConditions, FromFile or InitialConditionsFolderDraw [got: {method}]" - ) + """ only difference with draw seeding is that the sim_id is now sim_id2load""" return self.draw_seeding(sim_id=sim_id, setup=setup) def load_ic(self, sim_id: int, setup) -> nb.typed.Dict: