Skip to content

Commit

Permalink
WIP on NPIs
Browse files Browse the repository at this point in the history
  • Loading branch information
pearsonca committed Nov 13, 2024
1 parent aa66077 commit 7ba97ce
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 75 deletions.
11 changes: 6 additions & 5 deletions flepimop/gempyor_pkg/src/gempyor/NPI/MultiPeriodModifier.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import datetime

import numpy as np
import pandas as pd

from . import helpers
from .base import NPIBase
from ..model_info import ModelInfo


class MultiPeriodModifier(NPIBase):
def __init__(
self,
*,
npi_config,
modinf: ModelInfo,
modinf_ti: datetime.date,
modinf_tf: datetime.date,
modifiers_library,
subpops,
loaded_df=None,
Expand All @@ -29,8 +30,8 @@ def __init__(
)

self.sanitize = sanitize
self.start_date = modinf.ti
self.end_date = modinf.tf
self.start_date = modinf_ti
self.end_date = modinf_tf

self.subpops = subpops

Expand Down
11 changes: 6 additions & 5 deletions flepimop/gempyor_pkg/src/gempyor/NPI/SinglePeriodModifier.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import datetime

import numpy as np
import pandas as pd

from . import helpers
from .base import NPIBase
from ..model_info import ModelInfo


class SinglePeriodModifier(NPIBase):
def __init__(
self,
*,
npi_config,
modinf: ModelInfo,
modinf_ti: datetime.date,
modinf_tf: datetime.date,
modifiers_library,
subpops,
loaded_df=None,
Expand All @@ -27,8 +28,8 @@ def __init__(
)
)

self.start_date = modinf.ti
self.end_date = modinf.tf
self.start_date = modinf_ti
self.end_date = modinf_tf

self.pnames_overlap_operation_sum = pnames_overlap_operation_sum
self.pnames_overlap_operation_reductionprod = pnames_overlap_operation_reductionprod
Expand Down
12 changes: 6 additions & 6 deletions flepimop/gempyor_pkg/src/gempyor/NPI/StackedModifier.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import collections
import os
import warnings
import datetime

import confuse
import pandas as pd

from .base import NPIBase
from ..model_info import ModelInfo


debug_print = False

Expand All @@ -21,7 +20,8 @@ def __init__(
self,
*,
npi_config,
modinf: ModelInfo,
modinf_ti: datetime.date,
modinf_tf: datetime.date,
modifiers_library,
subpops,
loaded_df=None,
Expand All @@ -30,8 +30,8 @@ def __init__(
):
super().__init__(name=npi_config.name)

self.start_date = modinf.ti
self.end_date = modinf.tf
self.start_date = modinf_ti
self.end_date = modinf_tf

self.pnames_overlap_operation_sum = pnames_overlap_operation_sum
self.pnames_overlap_operation_reductionprod = pnames_overlap_operation_reductionprod
Expand Down Expand Up @@ -63,7 +63,7 @@ def __init__(

sub_npi = NPIBase.execute(
npi_config=scenario_npi_config,
modinf=modinf,
modinf_ti=modinf_ti, modinf_tf=modinf_tf,
modifiers_library=modifiers_library,
subpops=subpops,
loaded_df=loaded_df,
Expand Down
10 changes: 5 additions & 5 deletions flepimop/gempyor_pkg/src/gempyor/NPI/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import abc

from ..model_info import ModelInfo

import datetime

class NPIBase(abc.ABC):
__plugins__ = {}
Expand All @@ -28,7 +26,8 @@ def getReductionDF(self):
def execute(
*,
npi_config,
modinf: ModelInfo,
modinf_ti: datetime.date,
modinf_tf: datetime.date,
modifiers_library,
subpops,
loaded_df=None,
Expand All @@ -46,7 +45,8 @@ def execute(
npi_class = NPIBase.__plugins__[method]
return npi_class(
npi_config=npi_config,
modinf=modinf,
modinf_ti=modinf_ti,
modinf_tf=modinf_tf,
modifiers_library=modifiers_library,
subpops=subpops,
loaded_df=loaded_df,
Expand Down
2 changes: 1 addition & 1 deletion flepimop/gempyor_pkg/src/gempyor/dev/dev_seir.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

npi = NPI.NPIBase.execute(
npi_config=modinf.npi_config_seir,
modinf=modinf,
modinf_ti=modinf.ti, modinf_tf=modinf.tf,
modifiers_library=modinf.seir_modifiers_library,
subpops=modinf.subpop_struct.subpop_names,
pnames_overlap_operation_sum=modinf.parameters.stacked_modifier_method["sum"],
Expand Down
25 changes: 8 additions & 17 deletions flepimop/gempyor_pkg/src/gempyor/outcomes.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,23 +73,14 @@ def build_outcome_modifiers(
elif load_ID == True:
loaded_df = modinf.read_simID(ftype="hnpi", sim_id=sim_id2load)

if loaded_df is not None:
npi = NPI.NPIBase.execute(
npi_config=modinf.npi_config_outcomes,
modinf=modinf,
modifiers_library=modinf.outcome_modifiers_library,
subpops=modinf.subpop_struct.subpop_names,
loaded_df=loaded_df,
# TODO: support other operation than product
)
else:
npi = NPI.NPIBase.execute(
npi_config=modinf.npi_config_outcomes,
modinf=modinf,
modifiers_library=modinf.outcome_modifiers_library,
subpops=modinf.subpop_struct.subpop_names,
# TODO: support other operation than product
)
npi = NPI.NPIBase.execute(
npi_config=modinf.npi_config_outcomes,
modinf_ti=modinf.ti, modinf_tf=modinf.tf,
modifiers_library=modinf.outcome_modifiers_library,
subpops=modinf.subpop_struct.subpop_names,
loaded_df=loaded_df,
# TODO: support other operation than product
)
return npi


Expand Down
2 changes: 1 addition & 1 deletion flepimop/gempyor_pkg/src/gempyor/seeding.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Dict
from typing import Dict, TYPE_CHECKING

import numpy as np
import pandas as pd
Expand Down
40 changes: 13 additions & 27 deletions flepimop/gempyor_pkg/src/gempyor/seir.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,33 +235,19 @@ def build_npi_SEIR(
elif load_ID == True:
loaded_df = modinf.read_simID(ftype="snpi", sim_id=sim_id2load)

if loaded_df is not None:
npi = NPI.NPIBase.execute(
npi_config=modinf.npi_config_seir,
modinf=modinf,
modifiers_library=modinf.seir_modifiers_library,
subpops=modinf.subpop_struct.subpop_names,
loaded_df=loaded_df,
pnames_overlap_operation_sum=modinf.parameters.stacked_modifier_method[
"sum"
],
pnames_overlap_operation_reductionprod=modinf.parameters.stacked_modifier_method[
"reduction_product"
],
)
else:
npi = NPI.NPIBase.execute(
npi_config=modinf.npi_config_seir,
modinf=modinf,
modifiers_library=modinf.seir_modifiers_library,
subpops=modinf.subpop_struct.subpop_names,
pnames_overlap_operation_sum=modinf.parameters.stacked_modifier_method[
"sum"
],
pnames_overlap_operation_reductionprod=modinf.parameters.stacked_modifier_method[
"reduction_product"
],
)
npi = NPI.NPIBase.execute(
npi_config=modinf.npi_config_seir,
modinf_ti=modinf.ti, modinf_tf=modinf.tf,
modifiers_library=modinf.seir_modifiers_library,
subpops=modinf.subpop_struct.subpop_names,
loaded_df=loaded_df,
pnames_overlap_operation_sum=modinf.parameters.stacked_modifier_method[
"sum"
],
pnames_overlap_operation_reductionprod=modinf.parameters.stacked_modifier_method[
"reduction_product"
],
)
return npi


Expand Down
16 changes: 8 additions & 8 deletions flepimop/gempyor_pkg/tests/seir/test_seir.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def test_constant_population_legacy_integration():

npi = NPI.NPIBase.execute(
npi_config=modinf.npi_config_seir,
modinf=modinf,
modinf_ti=modinf.ti, modinf_tf=modinf.tf,
modifiers_library=modinf.seir_modifiers_library,
subpops=modinf.subpop_struct.subpop_names,
pnames_overlap_operation_sum=modinf.parameters.stacked_modifier_method["sum"],
Expand Down Expand Up @@ -157,7 +157,7 @@ def test_constant_population_rk4jit_integration_fail():

npi = NPI.NPIBase.execute(
npi_config=modinf.npi_config_seir,
modinf=modinf,
modinf_ti=modinf.ti, modinf_tf=modinf.tf,
modifiers_library=modinf.seir_modifiers_library,
subpops=modinf.subpop_struct.subpop_names,
pnames_overlap_operation_sum=modinf.parameters.stacked_modifier_method["sum"],
Expand Down Expand Up @@ -233,7 +233,7 @@ def test_constant_population_rk4jit_integration():

npi = NPI.NPIBase.execute(
npi_config=modinf.npi_config_seir,
modinf=modinf,
modinf_ti=modinf.ti, modinf_tf=modinf.tf,
modifiers_library=modinf.seir_modifiers_library,
subpops=modinf.subpop_struct.subpop_names,
pnames_overlap_operation_sum=modinf.parameters.stacked_modifier_method["sum"],
Expand Down Expand Up @@ -307,7 +307,7 @@ def test_steps_SEIR_nb_simple_spread_with_txt_matrices():

npi = NPI.NPIBase.execute(
npi_config=modinf.npi_config_seir,
modinf=modinf,
modinf_ti=modinf.ti, modinf_tf=modinf.tf,
modifiers_library=modinf.seir_modifiers_library,
subpops=modinf.subpop_struct.subpop_names,
pnames_overlap_operation_sum=modinf.parameters.stacked_modifier_method["sum"],
Expand Down Expand Up @@ -415,7 +415,7 @@ def test_steps_SEIR_nb_simple_spread_with_csv_matrices():

npi = NPI.NPIBase.execute(
npi_config=modinf.npi_config_seir,
modinf=modinf,
modinf_ti=modinf.ti, modinf_tf=modinf.tf,
modifiers_library=modinf.seir_modifiers_library,
subpops=modinf.subpop_struct.subpop_names,
pnames_overlap_operation_sum=modinf.parameters.stacked_modifier_method["sum"],
Expand Down Expand Up @@ -493,7 +493,7 @@ def test_steps_SEIR_no_spread():

npi = NPI.NPIBase.execute(
npi_config=modinf.npi_config_seir,
modinf=modinf,
modinf_ti=modinf.ti, modinf_tf=modinf.tf,
modifiers_library=modinf.seir_modifiers_library,
subpops=modinf.subpop_struct.subpop_names,
pnames_overlap_operation_sum=modinf.parameters.stacked_modifier_method["sum"],
Expand Down Expand Up @@ -767,7 +767,7 @@ def test_parallel_compartments_with_vacc():

npi = NPI.NPIBase.execute(
npi_config=modinf.npi_config_seir,
modinf=modinf,
modinf_ti=modinf.ti, modinf_tf=modinf.tf,
modifiers_library=modinf.seir_modifiers_library,
subpops=modinf.subpop_struct.subpop_names,
pnames_overlap_operation_sum=modinf.parameters.stacked_modifier_method["sum"],
Expand Down Expand Up @@ -860,7 +860,7 @@ def test_parallel_compartments_no_vacc():

npi = NPI.NPIBase.execute(
npi_config=modinf.npi_config_seir,
modinf=modinf,
modinf_ti=modinf.ti, modinf_tf=modinf.tf,
modifiers_library=modinf.seir_modifiers_library,
subpops=modinf.subpop_struct.subpop_names,
pnames_overlap_operation_sum=modinf.parameters.stacked_modifier_method["sum"],
Expand Down

0 comments on commit 7ba97ce

Please sign in to comment.