Skip to content

Commit e92d05e

Browse files
authored
Initializer, ADRIO, SimFunc improvements (#223)
* Improved validation and type permissiveness of Initializer array parameters. * Allow strings as compartment identifiers for Initializers * LODES and PRISM time frames are optional and default to the simulation's time frame. * SimFunctions allow dynamic requirements. * Remove last vestiges of SimDimensions.
1 parent 2e31cdc commit e92d05e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+1903
-1707
lines changed

USAGE.ipynb

+12-13
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,16 @@
113113
"output_type": "stream",
114114
"text": [
115115
"Loading epymorph.adrio.commuting_flows.Commuters:\n",
116-
" |####################| 100% (7.570s)\n",
116+
" |####################| 100% (9.727s)\n",
117117
"Loading epymorph.adrio.acs5.Population:\n",
118-
" |####################| 100% (1.584s)\n",
118+
" |####################| 100% (1.296s)\n",
119119
"Loading epymorph.adrio.us_tiger.PostalCode:\n",
120-
" |####################| 100% (0.126s)\n",
120+
" |####################| 100% (0.171s)\n",
121121
"Running simulation (BasicSimulator):\n",
122-
"• 2015-01-01 to 2015-05-31 (150 days)\n",
122+
"• 2015-01-01 to 2015-05-30 (150 days)\n",
123123
"• 6 geo nodes\n",
124124
" |####################| 100% \n",
125-
"Runtime: 0.145s\n"
125+
"Runtime: 0.313s\n"
126126
]
127127
}
128128
],
@@ -297,21 +297,20 @@
297297
"output_type": "stream",
298298
"text": [
299299
"There were 6 nodes!\n",
300-
"Whose labels are: ['FL', 'GA', 'MD', 'NC', 'SC', 'VA']\n",
301-
"\n",
302-
"IPM compartments: ['S', 'I', 'R']\n",
303-
"IPM events: ['S → I', 'I → R', 'R → S']\n"
300+
"Whose labels are: ['FL' 'GA' 'MD' 'NC' 'SC' 'VA']\n",
301+
"\n"
304302
]
305303
}
306304
],
307305
"source": [
308-
"print(f\"There were {out.dim.nodes} nodes!\")\n",
309-
"print(f\"Whose labels are: {out.geo_labels}\")\n",
306+
"print(f\"There were {out.rume.scope.nodes} nodes!\")\n",
307+
"print(f\"Whose labels are: {out.rume.scope.labels}\")\n",
310308
"\n",
311309
"print()\n",
312310
"\n",
313-
"print(f\"IPM compartments: {out.compartment_labels}\")\n",
314-
"print(f\"IPM events: {out.event_labels}\")"
311+
"# TODO: come up with a replacement for this...\n",
312+
"# print(f\"IPM compartments: {out.rume.ipm.compartment_labels}\")\n",
313+
"# print(f\"IPM events: {out.event_labels}\")"
315314
]
316315
}
317316
],

doc/demo/02-states-GEO.ipynb

+19-19
Large diffs are not rendered by default.

doc/demo/03-counties-GEO.ipynb

+17-17
Large diffs are not rendered by default.

doc/demo/04-time-varying-beta.ipynb

+8-19
Large diffs are not rendered by default.

doc/demo/05-visualizing-mm.ipynb

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"output_type": "stream",
5252
"text": [
5353
"Loading epymorph.adrio.us_tiger.GeometricCentroid:\n",
54-
" |####################| 100% (7.674s)\n"
54+
" |####################| 100% (8.255s)\n"
5555
]
5656
}
5757
],
@@ -136,7 +136,7 @@
136136
"output_type": "stream",
137137
"text": [
138138
"Loading epymorph.adrio.commuting_flows.Commuters:\n",
139-
" |####################| 100% (6.463s)\n"
139+
" |####################| 100% (8.503s)\n"
140140
]
141141
}
142142
],

doc/devlog/2024-06-05.ipynb

+25-20
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,14 @@
7676
"\n",
7777
"\n",
7878
"state_scope = StateScope.in_states([\"AZ\", \"CO\", \"NV\", \"NM\"], 2020)\n",
79-
"time_period = 2015\n",
80-
"geoids = state_scope.node_ids\n",
81-
"\n",
82-
"commuters_adrio = lodes.Commuters(time_period)\n",
79+
"commuters_adrio = lodes.Commuters()\n",
8380
"\n",
8481
"rume = SingleStrataRume.build(\n",
8582
" ipm=NoIpm(),\n",
8683
" mm=NoMm(),\n",
8784
" init=init.NoInfection(),\n",
8885
" scope=state_scope,\n",
89-
" time_frame=TimeFrame.year(time_period),\n",
86+
" time_frame=TimeFrame.year(2015),\n",
9087
" params={\n",
9188
" \"population\": acs5.Population(),\n",
9289
" \"commuters\": commuters_adrio,\n",
@@ -106,13 +103,16 @@
106103
"output_type": "stream",
107104
"text": [
108105
"Loading epymorph.adrio.lodes.Commuters:\n",
109-
" |####################| 100% (7.113s)\n"
106+
" |####################| 100% (9.997s)\n"
110107
]
111108
}
112109
],
113110
"source": [
114111
"with sim_messaging():\n",
115-
" commuters = commuters_adrio.with_context(scope=state_scope).evaluate()"
112+
" commuters = commuters_adrio.with_context(\n",
113+
" scope=rume.scope,\n",
114+
" time_frame=rume.time_frame,\n",
115+
" ).evaluate()"
116116
]
117117
},
118118
{
@@ -137,7 +137,7 @@
137137
}
138138
],
139139
"source": [
140-
"print(f\"Home/Work GEOIDs:\\n {geoids}\\n\")\n",
140+
"print(f\"Home/Work GEOIDs:\\n {state_scope.node_ids}\\n\")\n",
141141
"\n",
142142
"print(f\"Commuters Matrix:\\n {commuters}\\n\")"
143143
]
@@ -232,20 +232,18 @@
232232
"from epymorph.kit import *\n",
233233
"from epymorph.adrio import acs5, lodes\n",
234234
"\n",
235-
"time_period = 2015\n",
236235
"county_scope = CountyScope.in_counties([\"04013\", \"08041\", \"32003\", \"35001\"], year=2020)\n",
237-
"geoids = county_scope.node_ids\n",
238236
"\n",
239-
"commuters_29_under_adrio = lodes.CommutersByAge(time_period, \"29 and Under\")\n",
240-
"commuters_30_54_adrio = lodes.CommutersByAge(time_period, \"30_54\")\n",
241-
"commuters_55_over_adrio = lodes.CommutersByAge(time_period, \"55 and Over\")\n",
237+
"commuters_29_under_adrio = lodes.CommutersByAge(\"29 and Under\")\n",
238+
"commuters_30_54_adrio = lodes.CommutersByAge(\"30_54\")\n",
239+
"commuters_55_over_adrio = lodes.CommutersByAge(\"55 and Over\")\n",
242240
"\n",
243241
"rume = SingleStrataRume.build(\n",
244242
" ipm=NoIpm(),\n",
245243
" mm=NoMm(),\n",
246244
" init=init.NoInfection(),\n",
247245
" scope=county_scope,\n",
248-
" time_frame=TimeFrame.year(time_period),\n",
246+
" time_frame=TimeFrame.year(2015),\n",
249247
" params={\n",
250248
" \"population\": acs5.Population(),\n",
251249
" \"commuters_29_under\": commuters_29_under_adrio,\n",
@@ -267,22 +265,29 @@
267265
"output_type": "stream",
268266
"text": [
269267
"Loading epymorph.adrio.lodes.CommutersByAge:\n",
270-
" |####################| 100% (5.839s)\n",
268+
" |####################| 100% (8.012s)\n",
271269
"Loading epymorph.adrio.lodes.CommutersByAge:\n",
272-
" |####################| 100% (5.998s)\n",
270+
" |####################| 100% (7.702s)\n",
273271
"Loading epymorph.adrio.lodes.CommutersByAge:\n",
274-
" |####################| 100% (5.848s)\n"
272+
" |####################| 100% (7.700s)\n"
275273
]
276274
}
277275
],
278276
"source": [
279277
"with sim_messaging():\n",
280278
" commuters_29_under = commuters_29_under_adrio.with_context(\n",
281-
" scope=county_scope\n",
279+
" scope=rume.scope,\n",
280+
" time_frame=rume.time_frame,\n",
282281
" ).evaluate()\n",
283-
" commuters_30_54 = commuters_30_54_adrio.with_context(scope=county_scope).evaluate()\n",
282+
"\n",
283+
" commuters_30_54 = commuters_30_54_adrio.with_context(\n",
284+
" scope=rume.scope,\n",
285+
" time_frame=rume.time_frame,\n",
286+
" ).evaluate()\n",
287+
"\n",
284288
" commuters_55_over = commuters_55_over_adrio.with_context(\n",
285-
" scope=county_scope\n",
289+
" scope=rume.scope,\n",
290+
" time_frame=rume.time_frame,\n",
286291
" ).evaluate()"
287292
]
288293
},

doc/devlog/2024-06-12.ipynb

+28-42
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,25 @@
2323
"source": [
2424
"from datetime import date\n",
2525
"from pathlib import Path\n",
26+
"from typing import Iterable, Mapping, TypeVar\n",
2627
"from urllib.parse import quote\n",
2728
"\n",
2829
"import numpy as np\n",
2930
"from pandas import DataFrame, read_csv, to_datetime\n",
3031
"\n",
3132
"from epymorph.kit import *\n",
3233
"from epymorph.adrio import acs5, commuting_flows, csv\n",
33-
"from epymorph.geography.scope import GeoScope\n",
3434
"from epymorph.geography.us_census import (\n",
3535
" get_counties,\n",
3636
" get_states,\n",
3737
")\n",
38-
"from epymorph.util import dict_map\n",
3938
"\n",
39+
"A = TypeVar(\"A\")\n",
40+
"B = TypeVar(\"B\")\n",
4041
"\n",
41-
"def placeholder_dim(scope: GeoScope, time_frame: TimeFrame) -> SimDimensions:\n",
42-
" return SimDimensions.build(\n",
43-
" tau_step_lengths=[1.0],\n",
44-
" start_date=time_frame.start_date,\n",
45-
" days=time_frame.duration_days,\n",
46-
" nodes=scope.nodes,\n",
47-
" compartments=1,\n",
48-
" events=0,\n",
49-
" )\n",
42+
"\n",
43+
"def dict_map(m: Mapping[A, B], xs: Iterable[A]) -> list[B]:\n",
44+
" return [m[x] for x in xs]\n",
5045
"\n",
5146
"\n",
5247
"TEST_FILE_PATH = Path(\"./scratch/test\")\n",
@@ -64,7 +59,6 @@
6459
" year=2015,\n",
6560
" )\n",
6661
" time_frame = TimeFrame.year(2015)\n",
67-
" dim = placeholder_dim(scope, time_frame)\n",
6862
" states_info = get_states(2015)\n",
6963
"\n",
7064
" (\n",
@@ -75,7 +69,7 @@
7569
" acs5.Population()\n",
7670
" .with_context(\n",
7771
" scope=scope,\n",
78-
" dim=dim,\n",
72+
" time_frame=time_frame,\n",
7973
" )\n",
8074
" .evaluate()\n",
8175
" ),\n",
@@ -95,7 +89,7 @@
9589
" scope = CountyScope.in_states([\"04\", \"08\", \"49\", \"35\", \"32\"], year=2015)\n",
9690
" context = {\n",
9791
" \"scope\": scope,\n",
98-
" \"dim\": placeholder_dim(scope, TimeFrame.year(2015)),\n",
92+
" \"time_frame\": TimeFrame.year(2015),\n",
9993
" \"params\": {\n",
10094
" \"population_by_age_table\": acs5.PopulationByAgeTable(),\n",
10195
" },\n",
@@ -152,14 +146,10 @@
152146
"\n",
153147
" scope = CountyScope.in_counties([\"08001\", \"35001\", \"04013\", \"04017\"], year=2020)\n",
154148
" time_frame = TimeFrame.year(2020)\n",
155-
" dim = placeholder_dim(scope, time_frame)\n",
156149
"\n",
157150
" commuters = (\n",
158151
" commuting_flows.Commuters()\n",
159-
" .with_context(\n",
160-
" scope=scope,\n",
161-
" dim=dim,\n",
162-
" )\n",
152+
" .with_context(scope=scope, time_frame=time_frame)\n",
163153
" .evaluate()\n",
164154
" )\n",
165155
"\n",
@@ -222,20 +212,19 @@
222212
"output_type": "stream",
223213
"text": [
224214
"Loading epymorph.adrio.csv.CSV:\n",
225-
" |####################| 100% (0.002s)\n",
215+
" |####################| 100% (0.004s)\n",
226216
"Loading epymorph.adrio.acs5.Population:\n",
227-
" |####################| 100% (1.201s)\n",
217+
" |####################| 100% (0.600s)\n",
228218
"Population data ✓\n",
229219
"\n"
230220
]
231221
}
232222
],
233223
"source": [
234224
"# Check pei_population.csv\n",
235-
"scope = StateScope.in_states([\"12\", \"13\", \"24\", \"37\", \"45\", \"51\"], year=2015)\n",
236225
"context = {\n",
237-
" \"scope\": scope,\n",
238-
" \"dim\": placeholder_dim(scope, TimeFrame.year(2015)),\n",
226+
" \"scope\": StateScope.in_states([\"12\", \"13\", \"24\", \"37\", \"45\", \"51\"], year=2015),\n",
227+
" \"time_frame\": TimeFrame.year(2015),\n",
239228
"}\n",
240229
"\n",
241230
"test_adrios(\n",
@@ -263,25 +252,25 @@
263252
"output_type": "stream",
264253
"text": [
265254
"Loading epymorph.adrio.csv.CSV:\n",
266-
" |####################| 100% (0.008s)\n",
255+
" |####################| 100% (0.013s)\n",
267256
"Loading epymorph.adrio.acs5.PopulationByAgeTable:\n",
268-
" |####################| 100% (12.587s)\n",
257+
" |####################| 100% (0.534s)\n",
269258
"Loading epymorph.adrio.acs5.PopulationByAge:\n",
270259
" |####################| 100% (0.000s)\n",
271260
"Young data ✓\n",
272261
"\n",
273262
"Loading epymorph.adrio.csv.CSV:\n",
274-
" |####################| 100% (0.006s)\n",
263+
" |####################| 100% (0.018s)\n",
275264
"Loading epymorph.adrio.acs5.PopulationByAgeTable:\n",
276-
" |####################| 100% (0.528s)\n",
265+
" |####################| 100% (0.526s)\n",
277266
"Loading epymorph.adrio.acs5.PopulationByAge:\n",
278267
" |####################| 100% (0.000s)\n",
279268
"Adult data ✓\n",
280269
"\n",
281270
"Loading epymorph.adrio.csv.CSV:\n",
282-
" |####################| 100% (0.009s)\n",
271+
" |####################| 100% (0.011s)\n",
283272
"Loading epymorph.adrio.acs5.PopulationByAgeTable:\n",
284-
" |####################| 100% (0.507s)\n",
273+
" |####################| 100% (0.521s)\n",
285274
"Loading epymorph.adrio.acs5.PopulationByAge:\n",
286275
" |####################| 100% (0.000s)\n",
287276
"Elderly data ✓\n",
@@ -291,10 +280,9 @@
291280
],
292281
"source": [
293282
"# Check us_sw_counties_population.csv\n",
294-
"scope = CountyScope.in_states([\"04\", \"08\", \"49\", \"35\", \"32\"], year=2015)\n",
295283
"context = {\n",
296-
" \"scope\": scope,\n",
297-
" \"dim\": placeholder_dim(scope, TimeFrame.year(2015)),\n",
284+
" \"scope\": CountyScope.in_states([\"04\", \"08\", \"49\", \"35\", \"32\"], year=2015),\n",
285+
" \"time_frame\": TimeFrame.year(2015),\n",
298286
" \"params\": {\n",
299287
" \"population_by_age_table\": acs5.PopulationByAgeTable(),\n",
300288
" },\n",
@@ -353,17 +341,16 @@
353341
"output_type": "stream",
354342
"text": [
355343
"Loading epymorph.adrio.csv.CSVTimeSeries:\n",
356-
" |####################| 100% (0.007s)\n",
344+
" |####################| 100% (0.006s)\n",
357345
"Vaccination data ✓\n"
358346
]
359347
}
360348
],
361349
"source": [
362350
"# Check vaccination_time_series.csv\n",
363-
"scope = CountyScope.in_counties([\"08001\", \"04013\", \"35001\"], year=2021)\n",
364351
"context = {\n",
365-
" \"scope\": scope,\n",
366-
" \"dim\": placeholder_dim(scope, TimeFrame.year(2021)),\n",
352+
" \"scope\": CountyScope.in_counties([\"08001\", \"04013\", \"35001\"], year=2021),\n",
353+
" \"time_frame\": TimeFrame.year(2021),\n",
367354
"}\n",
368355
"\n",
369356
"with sim_messaging():\n",
@@ -398,20 +385,19 @@
398385
"output_type": "stream",
399386
"text": [
400387
"Loading epymorph.adrio.csv.CSVMatrix:\n",
401-
" |####################| 100% (0.004s)\n",
388+
" |####################| 100% (0.016s)\n",
402389
"Loading epymorph.adrio.commuting_flows.Commuters:\n",
403-
" |####################| 100% (6.561s)\n",
390+
" |####################| 100% (8.149s)\n",
404391
"Commuters data ✓\n",
405392
"\n"
406393
]
407394
}
408395
],
409396
"source": [
410397
"# Check counties_commuters_2020.csv\n",
411-
"scope = CountyScope.in_counties([\"35001\", \"04013\", \"04017\"], year=2020)\n",
412398
"context = {\n",
413-
" \"scope\": scope,\n",
414-
" \"dim\": placeholder_dim(scope, TimeFrame.year(2020)),\n",
399+
" \"scope\": CountyScope.in_counties([\"35001\", \"04013\", \"04017\"], year=2020),\n",
400+
" \"time_frame\": TimeFrame.year(2020),\n",
415401
"}\n",
416402
"\n",
417403
"test_adrios(\n",

0 commit comments

Comments
 (0)