Skip to content

Commit

Permalink
Merge pull request #327 from nanglo123/add_control_variables
Browse files Browse the repository at this point in the history
Add control variables to the mapping of parameters for a MIRA template model ingested from a Vensim model
  • Loading branch information
bgyori authored Apr 11, 2024
2 parents 77ceea9 + 0b68e62 commit 31e0193
Show file tree
Hide file tree
Showing 6 changed files with 241 additions and 144 deletions.
11 changes: 2 additions & 9 deletions mira/sources/system_dynamics/pysd.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,6 @@

logger = logging.getLogger(__name__)

CONTROL_VARIABLE_NAMES = {
"FINALTIME",
"INITIALTIME",
"SAVEPER",
"TIMESTEP",
"FINAL TIME",
"INITIAL TIME",
"TIME STEP",
}
UNITS_MAPPING = {
sympy.Symbol("Person"): sympy.Symbol("person"),
sympy.Symbol("Persons"): sympy.Symbol("person"),
Expand Down Expand Up @@ -274,6 +265,8 @@ def template_model_from_pysd_model(
param_unit.expression = param_unit.expression.subs(
old_unit_symbol, new_unit_symbol
)


# construct transitions mapping that determine inputs and outputs states to a rate-law
transition_map = {}

Expand Down
7 changes: 0 additions & 7 deletions mira/sources/system_dynamics/vensim.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
)
UTF_ENCODING = "{UTF-8} "

CONTROL_VARIABLES = {"SAVEPER", "FINAL TIME", "INITIAL TIME", "TIME STEP"}


def template_model_from_mdl_file(
fname, *, grounding_map=None, initials=None, initials_from_integ: bool = False
Expand Down Expand Up @@ -203,11 +201,6 @@ def extract_vensim_variable_expressions(
# also, the initial value might be an expression that needs normalizing
initial_values[_norm(old_var_name)] = initial and _norm(initial)

# remove any control variables listed past the control section that were added to the
# expression map
for control_var in CONTROL_VARIABLES:
expression_map.pop(control_var)

return expression_map, initial_values


Expand Down
188 changes: 109 additions & 79 deletions notebooks/evaluation_2024.03/epi_scenario4/epi_scenario4.ipynb

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions notebooks/evaluation_2024.03/epi_scenario4/scenario4_petrinet.json
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,15 @@
"expression_mathml": "<ci>people</ci>"
}
},
{
"id": "time_step",
"description": "The time step for the simulation.",
"value": 0.125,
"units": {
"expression": "day",
"expression_mathml": "<ci>day</ci>"
}
},
{
"id": "behavior_reaction_time",
"description": "Time from first infection for behavioral risk reductions to be fully implemented.",
Expand Down Expand Up @@ -356,6 +365,24 @@
"expression": "people",
"expression_mathml": "<ci>people</ci>"
}
},
{
"id": "final_time",
"description": "The final time for the simulation.",
"value": 300.0,
"units": {
"expression": "day",
"expression_mathml": "<ci>day</ci>"
}
},
{
"id": "initial_time",
"description": "The initial time for the simulation.",
"value": 0.0,
"units": {
"expression": "day",
"expression_mathml": "<ci>day</ci>"
}
}
],
"observables": [],
Expand Down
99 changes: 66 additions & 33 deletions notebooks/evaluation_2024.03/epi_scenario4/scenario4_stockflow.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@
"expression": "n_imported_infections",
"expression_mathml": "<ci>n_imported_infections</ci>"
},
{
"id": "time_step",
"name": "time_step",
"expression": "time_step",
"expression_mathml": "<ci>time_step</ci>"
},
{
"id": "behavior_reaction_time",
"name": "behavior_reaction_time",
Expand Down Expand Up @@ -248,37 +254,37 @@
},
{
"id": "link3",
"source": "treated_fatality_rate",
"source": "hospital_capacity_sensitivity",
"target": "2"
},
{
"id": "link4",
"source": "infection_duration",
"source": "hospital_capacity",
"target": "2"
},
{
"id": "link5",
"source": "untreated_fatality_rate",
"source": "infection_duration",
"target": "2"
},
{
"id": "link6",
"source": "infected",
"source": "untreated_fatality_rate",
"target": "2"
},
{
"id": "link7",
"source": "hospital_capacity_sensitivity",
"source": "treated_fatality_rate",
"target": "2"
},
{
"id": "link8",
"source": "fraction_requiring_hospitalization",
"source": "infected",
"target": "2"
},
{
"id": "link9",
"source": "hospital_capacity",
"source": "fraction_requiring_hospitalization",
"target": "2"
},
{
Expand All @@ -288,132 +294,132 @@
},
{
"id": "link11",
"source": "import_time",
"source": "n_imported_infections",
"target": "3"
},
{
"id": "link12",
"source": "n_imported_infections",
"source": "import_time",
"target": "3"
},
{
"id": "link13",
"source": "susceptible",
"source": "behavior_reaction_time",
"target": "4"
},
{
"id": "link14",
"source": "initial_population",
"source": "public_health_capacity_sensitivity",
"target": "4"
},
{
"id": "link15",
"source": "public_health_capacity_sensitivity",
"source": "susceptible",
"target": "4"
},
{
"id": "link16",
"source": "seasonal_period",
"source": "behavioral_risk_reduction",
"target": "4"
},
{
"id": "link17",
"source": "behavioral_risk_reduction",
"source": "isolation_reaction_time",
"target": "4"
},
{
"id": "link18",
"source": "peak_season",
"source": "infected",
"target": "4"
},
{
"id": "link19",
"source": "infection_duration",
"source": "import_time",
"target": "4"
},
{
"id": "link20",
"source": "public_health_strain",
"source": "seasonal_amplitude",
"target": "4"
},
{
"id": "link21",
"source": "behavior_reaction_time",
"source": "infection_duration",
"target": "4"
},
{
"id": "link22",
"source": "potential_isolation_effectiveness",
"source": "peak_season",
"target": "4"
},
{
"id": "link23",
"source": "import_time",
"source": "time",
"target": "4"
},
{
"id": "link24",
"source": "infected",
"source": "potential_isolation_effectiveness",
"target": "4"
},
{
"id": "link25",
"source": "r0",
"source": "contact_density_decline",
"target": "4"
},
{
"id": "link26",
"source": "isolation_reaction_time",
"source": "r0",
"target": "4"
},
{
"id": "link27",
"source": "seasonal_amplitude",
"source": "initial_population",
"target": "4"
},
{
"id": "link28",
"source": "contact_density_decline",
"source": "public_health_strain",
"target": "4"
},
{
"id": "link29",
"source": "time",
"source": "seasonal_period",
"target": "4"
},
{
"id": "link30",
"source": "treated_fatality_rate",
"source": "hospital_capacity_sensitivity",
"target": "5"
},
{
"id": "link31",
"source": "infection_duration",
"source": "hospital_capacity",
"target": "5"
},
{
"id": "link32",
"source": "untreated_fatality_rate",
"source": "infection_duration",
"target": "5"
},
{
"id": "link33",
"source": "infected",
"source": "untreated_fatality_rate",
"target": "5"
},
{
"id": "link34",
"source": "hospital_capacity_sensitivity",
"source": "treated_fatality_rate",
"target": "5"
},
{
"id": "link35",
"source": "fraction_requiring_hospitalization",
"source": "infected",
"target": "5"
},
{
"id": "link36",
"source": "hospital_capacity",
"source": "fraction_requiring_hospitalization",
"target": "5"
}
]
Expand Down Expand Up @@ -490,6 +496,15 @@
"expression_mathml": "<ci>people</ci>"
}
},
{
"id": "time_step",
"description": "The time step for the simulation.",
"value": 0.125,
"units": {
"expression": "day",
"expression_mathml": "<ci>day</ci>"
}
},
{
"id": "behavior_reaction_time",
"description": "Time from first infection for behavioral risk reductions to be fully implemented.",
Expand Down Expand Up @@ -587,6 +602,24 @@
"expression": "people",
"expression_mathml": "<ci>people</ci>"
}
},
{
"id": "final_time",
"description": "The final time for the simulation.",
"value": 300.0,
"units": {
"expression": "day",
"expression_mathml": "<ci>day</ci>"
}
},
{
"id": "initial_time",
"description": "The initial time for the simulation.",
"value": 0.0,
"units": {
"expression": "day",
"expression_mathml": "<ci>day</ci>"
}
}
],
"initials": [
Expand Down
Loading

0 comments on commit 31e0193

Please sign in to comment.