Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vax dedup #26

Merged
merged 15 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions emodpy_typhoid/interventions/typhoid_vaccine.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def new_intervention( camp, efficacy=0.82, mode="Shedding", constant_period=0, d
constant_period (float, optional): The constant period of the waning effect in days. Default is 0.
decay_constant (float, optional): The decay time constant for the waning effect. Default is 6935.0.
expected_expiration (float, optional): The mean duration before efficacy becomes 0. If this is set to non-zero value, the constant_period and decay_constant are ignored. These are two different modes of waning.

deduplication_policy (string, optional): Defaults to 'replace'. Can also be 'combine'.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line 28 for docstring should not be here. Should be moved to def new_vax function's doc string


Returns:
TyphoidVaccine: A fully configured instance of the TyphoidVaccine intervention with the specified parameters.
Expand All @@ -36,9 +36,10 @@ def new_intervention( camp, efficacy=0.82, mode="Shedding", constant_period=0, d
intervention.Mode = mode
intervention.Changing_Effect = _get_waning( constant_period=constant_period, decay_constant=decay_constant, expected_expiration=expected_expiration )
intervention.Changing_Effect.Initial_Effect = efficacy

return intervention

def new_vax( camp, efficacy=0.82, mode="Acquisition", constant_period=0, decay_constant=0, expected_expiration=0 ):
def new_vax( camp, efficacy=0.82, mode="Acquisition", constant_period=0, decay_constant=0, expected_expiration=0, deduplication_policy="replace" ):
"""
Create a new 'SimpleVaccine' intervention with specified parameters. If you use this function directly, you'll need to distribute the intervention with a function like ScheduledCampaignEvent or TriggeredCampaignEvent from emod_api.interventions.common.

Expand All @@ -64,6 +65,16 @@ def new_vax( camp, efficacy=0.82, mode="Acquisition", constant_period=0, decay_c
else:
raise ValueError( f"mode {mode} not recognized. Options are: 'Acquisition', 'Transmission', or 'All'." )

# replace: DAD=1, EIR=1
# combine: DAD=1, EIR=0
intervention.Dont_Allow_Duplicates = 1
if deduplication_policy == "replace":
intervention.Enable_Intervention_Replacement = 1
elif deduplication_policy == "combine":
intervention.Enable_Intervention_Replacement = 0
else:
raise ValueError( f"duplication_policy needs to be 'replace' or 'combine', not '{duplication_policy}'." )
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{duplication_policy} should be {deduplication_policy}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!


intervention.Waning_Config = _get_waning( constant_period=constant_period, decay_constant=decay_constant, expected_expiration=expected_expiration )
intervention.Waning_Config.Initial_Effect = efficacy
return intervention
Expand Down
48 changes: 33 additions & 15 deletions examples/future_campaign/multi_sweep.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ def add_historical_vax( camp, ria_coverage=0.75, camp_coverage=0.75, efficacy=0.
ria = tv.new_routine_immunization(camp,
efficacy=efficacy,
constant_period=0,
expected_expiration=expiration,
#decay_constant=values['decay_constant'],
#expected_expiration=expiration,
decay_constant=expiration,
start_day=year_to_days(CAMP_START_YEAR),
coverage=ria_coverage)
tv_iv = tv.new_vax(camp,
efficacy=efficacy,
expected_expiration=expiration,
#decay_constant=values['decay_constant'],
#expected_expiration=expiration,
decay_constant=expiration,
constant_period=0)

notification_iv = comm.BroadcastEvent(camp, "VaccineDistributed")
Expand All @@ -113,7 +113,7 @@ def add_historical_vax( camp, ria_coverage=0.75, camp_coverage=0.75, efficacy=0.
Demographic_Coverage=camp_coverage,
Target_Age_Min=0.75,
Target_Age_Max=15
)
)
camp.add(one_time_campaign)

#add_historical_vax( camp )
Expand Down Expand Up @@ -150,7 +150,10 @@ def add_vax_intervention(campaign, values, min_age=0.75, max_age=15, binary_immu
import emodpy_typhoid.interventions.typhoid_vaccine as tv
print(f"Telling emod-api to use {manifest.schema_file} as schema.")
campaign.set_schema(manifest.schema_file)
camp_coverage = values['coverage']
if 'coverage' in values:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not working for run('Coverage_RIA') case.
I changed to following to replace line 153 to line 156 which seems working for all cases

for key in values.keys():
        if 'coverage' in key:
            camp_coverage = values[key]
            break

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. Thanks.

camp_coverage = values['coverage']
else:
camp_coverage = values['coverage_camp']

if binary_immunity:
tv_iv = tv.new_vax(campaign,
Expand All @@ -164,6 +167,12 @@ def add_vax_intervention(campaign, values, min_age=0.75, max_age=15, binary_immu
constant_period=0)

notification_iv = comm.BroadcastEvent(campaign, "VaccineDistributed")
# NOTE: the order of interventions in Intervention_List matters. This is because multiple
# interventions are delivered using a MultiInterventionDistributor intervention and de-duplication
# operates on Intervention_Name, so that when we try to distribute this intervention 'package',
# the model looks at the name of the existing intervention, which is the vax, and the name of the
# 'package' here, which would be MultiInterventionDistributor. But there is code in emod_api which
# sets the MID name to the name of the first intervention in the list, which here will be SimpleVaccine.
one_time_campaign = comm.ScheduledCampaignEvent(campaign,
Start_Day=year_to_days(FWD_CAMP_START_YEAR),
Intervention_List=[tv_iv, notification_iv],
Expand Down Expand Up @@ -286,15 +295,26 @@ def get_sweep_list_duration():
sweep_list.append({'start_day_offset': c[0], 'efficacy': c[1], 'coverage': c[2], 'decay_constant': c[3]})
return sweep_list

def get_sweep_list_just_one():
start_day_offset = [1]
vax_effs = [1]
decay = [3000]
cov = [0.75]
combinations = list(itertools.product(start_day_offset, vax_effs, cov, decay))
sweep_list = []
for c in combinations:
sweep_list.append({'start_day_offset': c[0], 'efficacy': c[1], 'coverage_camp': c[2], 'decay_constant': c[3]})
return sweep_list

def get_sweep_list_from_csv():
# This is wrong. Just load rows. Code is recreating. But have to stop work for now.
import pandas as pd
df = pd.load_csv( manifest.sweep_config )
raise NotImplemented( "get_sweep_list_from_csv" )

def get_config_sweep_list():
tac = [ 13435, 15320 ]
tel = [ 5.0, 7.0 ]
tac = [ 13435 ]
tel = [ 7.0 ]
combinations = list(itertools.product(tac, tel))
sweep_list = []
for c in combinations:
Expand All @@ -307,7 +327,8 @@ def get_config_sweep_list():
"Coverage": get_sweep_list_coverage,
"Coverage_RIA": get_sweep_list_coverage_ria,
"Coverage_Camp": get_sweep_list_coverage_camp,
"Vax_Duration": get_sweep_list_duration
"Vax_Duration": get_sweep_list_duration,
"Just_One": get_sweep_list_just_one
}

if sweep_choice not in sweep_selections.keys():
Expand All @@ -319,10 +340,7 @@ def get_config_sweep_list():
else:
avi_age_coverage = partial( add_vax_intervention, min_age=0, max_age=125 )

if binary_immunity:
avi_decay = partial( avi_age_coverage, binary_immunity=True )
else:
avi_decay = partial( avi_age_coverage, binary_immunity=False )
avi_decay = partial( avi_age_coverage, binary_immunity=binary_immunity )

builders = get_sweep_builders(sweep_list, get_config_sweep_list(), add_vax_fn=avi_decay)

Expand All @@ -341,7 +359,7 @@ def get_config_sweep_list():
if __name__ == "__main__":
import emod_typhoid.bootstrap as dtk

dtk.setup(manifest.model_dl_dir)
#dtk.setup(manifest.model_dl_dir)

import sys
run( sys.argv[1] if len(sys.argv)>1 else "Efficacy" )
run( sys.argv[1] if len(sys.argv)>1 else "Just_One", binary_immunity=False )
2 changes: 1 addition & 1 deletion examples/future_campaign/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
emodpy-typhoid==0.0.6.dev0
emodpy==1.22.0.dev3
emod-api==1.31.0.dev1
emod-typhoid==0.0.4.dev5
emod-typhoid==0.0.4.dev7
Loading