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

Abstract single state runner #182

Merged
merged 24 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
3b3bfa8
modifying flatten_list_parameters to flatten any dim sampled parameters
arik-shurygin Jun 12, 2024
8104f1d
first run at an abstract azure runner class
arik-shurygin Jun 12, 2024
78c9443
checkpoint, load_posterior_particle half way
arik-shurygin Jun 12, 2024
b4d1ac3
redesigning the load_posterior_particles to use numpyro.handlers.subs…
arik-shurygin Jun 13, 2024
4d7bb2a
Merge branch 'run-posterior-particle' of https://github.com/cdcent/cf…
arik-shurygin Jun 14, 2024
9e03f4b
adding type hinting
arik-shurygin Jun 14, 2024
0af3ab5
Merge branch 'run-posterior-particle' of https://github.com/cdcent/cf…
arik-shurygin Jun 14, 2024
42973d3
checkpoint, merging in another branch
arik-shurygin Jun 14, 2024
79e5ae6
installing pre-commit on this wsl
arik-shurygin Jun 14, 2024
2522e74
implementing PR feedback
arik-shurygin Jun 18, 2024
9ddfc85
tests caught a bug!
arik-shurygin Jun 18, 2024
09ae7e9
merging main into this branch
arik-shurygin Jun 18, 2024
dd26d21
Merge branch 'run-posterior-particle' of https://github.com/cdcent/cf…
arik-shurygin Jun 18, 2024
7b87be1
checkpoint, working on example
arik-shurygin Jun 18, 2024
760d253
forgot to add example
arik-shurygin Jun 18, 2024
a2425e2
turning on pre-commit
arik-shurygin Jun 18, 2024
7c7d93b
Merge branch 'main' of https://github.com/cdcent/cfa-scenarios-model …
arik-shurygin Jun 20, 2024
c1df54b
better type aliasing, completed setup of abstrac_azure_runner class
arik-shurygin Jun 20, 2024
28d4284
Merge branch 'main' of https://github.com/cdcent/cfa-scenarios-model …
arik-shurygin Jun 20, 2024
139ac8e
fixing type hint
arik-shurygin Jun 20, 2024
ead9038
adding save_config function to easily save config classes
arik-shurygin Jun 26, 2024
c2336b1
fixing bug with save_config
arik-shurygin Jun 26, 2024
36e9805
implementing changes requested
arik-shurygin Jun 28, 2024
410187b
small bugfix
arik-shurygin Jun 28, 2024
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
2 changes: 1 addition & 1 deletion docker_template_configs/config_global.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
65
],
"NUM_STRAINS": 3,
"MAX_VAX_COUNT": 2,
"MAX_VACCINATION_COUNT": 2,
"NUM_WANING_COMPARTMENTS": 5,
"WANING_TIMES": [
131,
Expand Down
21 changes: 15 additions & 6 deletions docker_template_configs/config_inferer_covid.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"SCENARIO_NAME": "test covid run for testing suite",
"CONTACT_MATRIX_PATH": "/input/data/demographic-data/contact_matrices",
"SAVE_PATH": "/output/",
"HOSP_PATH": "/input/data/hospital_220213_220108.csv",
"VAX_MODEL_DATA": "/input/data/spline_fits.csv",
"VAX_MODEL_NUM_KNOTS": 18,
"HOSPITALIZATION_DATA_PATH": "/input/data/hospital_220213_220108.csv",
Copy link
Collaborator

Choose a reason for hiding this comment

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

We haven't actually used this before... wonder if we should just remove it

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will keep for now because we will eventually want to implement this rather than hardcoding in the runner like we did during SMH

Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't know. It's up to the person designing the inferer (likelihood and whatnot) to decide what's being pass into it... Just thought it being there is more confusing than useful

"VACCINATION_MODEL_DATA": "/input/data/spline_fits.csv",
"SEASONAL_VACCINATION": false,
"STRAIN_R0s": [
1.2,
1.8,
Expand Down Expand Up @@ -52,14 +52,20 @@
}
}
],
"INTRODUCTION_PERCENTAGE": 0.01,
"INTRODUCTION_SCALE": 10,
"CONSTANT_STEP_SIZE": 0,
"INTRODUCTION_PCTS": [
0.01
],
"INTRODUCTION_SCALES": [
10
],
"INTRODUCTION_AGE_MASK": [
false,
true,
false,
false
],
"MIN_HOMOLOGOUS_IMMUNITY": 0.1,
"WANING_PROTECTIONS": [
1.0,
0.942,
Expand All @@ -84,7 +90,7 @@
1.0
]
],
"VAX_EFF_MATRIX": [
"VACCINE_EFF_MATRIX": [
[
0,
0.34,
Expand All @@ -111,6 +117,9 @@
1.0,
1.0
],
"SEASONALITY_AMPLITUDE": 0.15,
"SEASONALITY_SECOND_WAVE": 0.5,
"SEASONALITY_SHIFT": 0,
"INFERENCE_PRNGKEY": 8675309,
"INFERENCE_NUM_WARMUP": 100,
"INFERENCE_NUM_SAMPLES": 500,
Expand Down
49 changes: 46 additions & 3 deletions docker_template_configs/config_initializer_covid.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,50 @@
{
"INITALIZER_NAME": "base initializer covid",
"SEROLOGICAL_DATA_PATH": "/input/data/serological-data/",
"SIM_DATA_PATH": "/input/data/abm-data/abm_population.csv",
"SEROLOGICAL_DATA_PATH": "/input/data/serological-data/sero-initializer-csvs",
"CONTACT_MATRIX_PATH": "/input/data/demographic-data/contact_matrices",
"POP_SIZE": 1000000,
"INITIAL_INFECTIONS": 32000
"INITIAL_INFECTIONS": 32000,
"WANING_PROTECTIONS": [
1.0,
0.942,
0.942,
0.942,
0.0
],
"INFECTIOUS_PERIOD": 7.0,
"EXPOSED_TO_INFECTIOUS": 3.6,
"STRAIN_INTERACTIONS": [
[
1.0,
0.7,
0.49
],
[
0.7,
1.0,
0.7
],
[
0.49,
0.7,
1.0
]
],
"VACCINE_EFF_MATRIX": [
[
0,
0.34,
0.68
],
[
0,
0.24,
0.48
],
[
0,
0.14,
0.28
]
]
}
19 changes: 14 additions & 5 deletions docker_template_configs/config_runner_covid.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"CONTACT_MATRIX_PATH": "/input/data/demographic-data/contact_matrices",
"SAVE_PATH": "/output/",
"HOSP_PATH": "/input/data/hospital_220213_220108.csv",
"VAX_MODEL_DATA": "/input/data/spline_fits.csv",
"VAX_MODEL_NUM_KNOTS": 18,
"VACCINATION_MODEL_DATA": "/input/data/spline_fits.csv",
"SEASONAL_VACCINATION": false,
"STRAIN_R0s": [
1.2,
1.8,
Expand All @@ -16,14 +16,19 @@
"INTRODUCTION_TIMES": [
60
],
"INTRODUCTION_PERCENTAGE": 0.01,
"INTRODUCTION_SCALE": 10,
"INTRODUCTION_PCTS": [
0.01
],
"INTRODUCTION_SCALES": [
10
],
"INTRODUCTION_AGE_MASK": [
false,
true,
false,
false
],
"MIN_HOMOLOGOUS_IMMUNITY": 0.1,
"WANING_PROTECTIONS": [
1.0,
0.942,
Expand All @@ -48,7 +53,7 @@
1.0
]
],
"VAX_EFF_MATRIX": [
"VACCINE_EFF_MATRIX": [
[
0,
0.34,
Expand All @@ -65,6 +70,7 @@
0.28
]
],
"CONSTANT_STEP_SIZE": 0,
"BETA_TIMES": [
0.0,
120.0,
Expand All @@ -75,6 +81,9 @@
1.0,
1.0
],
"SEASONALITY_AMPLITUDE": 0.15,
"SEASONALITY_SECOND_WAVE": 0.0,
"SEASONALITY_SHIFT": 20,
"MCMC_PRNGKEY": 8675309,
"MCMC_NUM_WARMUP": 100,
"MCMC_NUM_SAMPLES": 1000,
Expand Down
85 changes: 85 additions & 0 deletions exp/example_azure_experiment/example_single_state_runner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
"""
An example script similar to example_end_to_end_run.py
but adapted to show the differences between Azure runs and local ones.
"""

import argparse

from mechanistic_model.abstract_azure_runner import AbstractAzureRunner
from mechanistic_model.covid_sero_initializer import CovidSeroInitializer
from mechanistic_model.mechanistic_runner import MechanisticRunner
from mechanistic_model.static_value_parameters import StaticValueParameters
from model_odes.seip_model import seip_ode


class ExampleRunner(AbstractAzureRunner):
# __init__ already implemented by the abstract case
def __init__(self, azure_output_dir):
super().__init__(azure_output_dir)

# override the process state command since this is what
# each individual runner must figure out for itself
def process_state(self, state):
"""
A similar version to example_end_to_end_run.py but modified to run on Azure batch

Parameters
---------------
state: str
the USPS postal code of the state, e.g. CA, OR, NY, TX
"""
# step 1: define your paths NOTE: These are all within the docker container!
# /input is a MOUNTED drive that we upload these files into right before the job launched
config_path = "/app/exp/example_azure_experiment/states/%s/" % state
# global_config include definitions such as age bin bounds and strain definitions
# Any value or data structure that needs context to be interpretted is here.
GLOBAL_CONFIG_PATH = config_path + "config_global.json"
# defines the init conditions of the scenario: pop size, initial infections etc.
INITIALIZER_CONFIG_PATH = config_path + "config_initializer_covid.json"
# defines the running variables, strain R0s, external strain introductions etc.
RUNNER_CONFIG_PATH = config_path + "config_runner_covid.json"
# sets up the initial conditions, initializer.get_initial_state() passed to runner
initializer = CovidSeroInitializer(
INITIALIZER_CONFIG_PATH, GLOBAL_CONFIG_PATH
)
# reads and interprets values from config, sets up downstream parameters
# like beta = STRAIN_R0s / INFECTIOUS_PERIOD
static_params = StaticValueParameters(
initializer.get_initial_state(),
RUNNER_CONFIG_PATH,
GLOBAL_CONFIG_PATH,
)
# A runner that does ODE solving of a single run.
runner = MechanisticRunner(seip_ode)
# run for 200 days, using init state and parameters from StaticValueParameters
solution = runner.run(
initializer.get_initial_state(),
tf=200,
args=static_params.get_parameters(),
)
self.save_static_run_timelines(static_params, solution)
return solution


parser = argparse.ArgumentParser()
parser.add_argument(
"-s",
"--state",
type=str,
help="directory for the state to run, resembles USPS code of the state",
required=True,
)

parser.add_argument(
"-j",
"--jobid",
type=str,
help="job-id of the state being run on Azure",
required=True,
)
args = parser.parse_args()
state = args.state
jobid = args.jobid
save_path = "/output/example_output/%s/%s/" % (jobid, state)
runner = ExampleRunner(save_path)
runner.process_state(state)
21 changes: 14 additions & 7 deletions experiment_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,20 @@ def get_all_codes():
state_names = pd.read_csv("data/fips_to_name.csv")
pops = pd.read_csv("data/demographic-data/CenPop2020_Mean_ST.csv")
# adding a USA row with the sum of all state pops
pops.loc[-1] = [
"US",
"United States",
sum(pops["POPULATION"]),
None,
None,
]
usa_pop_row = pd.DataFrame(
[
[
"US",
"United States",
sum(pops["POPULATION"]),
None,
None,
]
],
columns=pops.columns,
)
pops = pd.concat([pops, usa_pop_row], ignore_index=True)
print(pops)
args = parser.parse_args()
exp = args.exp
states = args.states
Expand Down
8 changes: 8 additions & 0 deletions mechanistic_model/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
# needs to exist to define a module
import jax

SEIC_Compartments = tuple[
jax.Array,
jax.Array,
jax.Array,
jax.Array,
]
Loading
Loading