Skip to content

Commit

Permalink
Edits to make test_outcome_scenario pass
Browse files Browse the repository at this point in the history
* 'compartments' and 'seir' sections are now required in the config for
  inferece.
* Added logic to `get_static_arguments` to allow it to work without an
  'seir_modifiers' section in the config.
  • Loading branch information
TimothyWillard committed Nov 19, 2024
1 parent 0055ed8 commit fc23642
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 8 deletions.
8 changes: 5 additions & 3 deletions flepimop/gempyor_pkg/src/gempyor/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,10 @@ def get_static_arguments(modinf: model_info.ModelInfo):
) = modinf.compartments.get_transition_array()

outcomes_parameters = outcomes.read_parameters_from_config(modinf)
npi_seir = seir.build_npi_SEIR(
modinf=modinf, load_ID=False, sim_id2load=None, config=config
npi_seir = (
seir.build_npi_SEIR(modinf=modinf, load_ID=False, sim_id2load=None, config=config)
if modinf.npi_config_seir is not None
else None
)
if modinf.npi_config_outcomes:
npi_outcomes = outcomes.build_outcome_modifiers(
Expand Down Expand Up @@ -211,7 +213,7 @@ def get_static_arguments(modinf: model_info.ModelInfo):
), # TODO add more information
)

snpi_df_ref = npi_seir.getReductionDF()
snpi_df_ref = npi_seir.getReductionDF() if npi_seir is not None else pd.DataFrame()

outcomes_df, hpar_df = outcomes.compute_all_multioutcomes(
modinf=modinf,
Expand Down
1 change: 1 addition & 0 deletions flepimop/gempyor_pkg/src/gempyor/model_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ def __init__(

# 4. the SEIR structure
self.seir_config = None
self.seir_modifiers_library = None
if config["seir"].exists():
self.seir_config = config["seir"]
self.parameters_config = config["seir"]["parameters"]
Expand Down
30 changes: 30 additions & 0 deletions flepimop/gempyor_pkg/tests/outcomes/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,36 @@ nslots: 1
subpop_setup:
geodata: data/geodata.csv

compartments:
infection_stage: ["S", "E", "I", "R"]

seir:
integration:
method: rk4
dt: 1
parameters:
sigma:
value: 1 / 4
gamma:
value: 1 / 5
Ro:
value: 2.5
transitions:
- source: ["S"]
destination: ["E"]
rate: ["Ro * gamma"]
proportional_to: [["S"],["I"]]
proportion_exponent: ["1","1"]
- source: ["E"]
destination: ["I"]
rate: ["sigma"]
proportional_to: ["E"]
proportion_exponent: ["1"]
- source: ["I"]
destination: ["R"]
rate: ["gamma"]
proportional_to: ["I"]
proportion_exponent: ["1"]

outcomes:
method: delayframe
Expand Down
8 changes: 3 additions & 5 deletions flepimop/gempyor_pkg/tests/outcomes/test_outcomes0.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
import pyarrow as pa
from gempyor import file_paths, model_info, outcomes

config_filepath_prefix = "" #'tests/outcomes/'

### To generate files for this test, see notebook Test Outcomes playbook.ipynb in COVID19_Maryland

geoid = ["15005", "15007", "15009", "15001", "15003"]
Expand All @@ -29,10 +27,10 @@
os.chdir(os.path.dirname(__file__))


def test_outcome_scenario():
os.chdir(os.path.dirname(__file__)) ## this is redundant but necessary. Why ?
def test_outcome_scenario(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.chdir(os.path.dirname(__file__))
inference_simulator = gempyor.GempyorInference(
config_filepath=f"{config_filepath_prefix}config.yml",
config_filepath=f"config.yml",
run_id=1,
prefix="",
first_sim_index=1,
Expand Down

0 comments on commit fc23642

Please sign in to comment.