Skip to content

Commit 5799535

Browse files
authored
Merge pull request #797 from camsys/perf-fix
Performance monitoring fixes
2 parents e2ed3a0 + bb01cdc commit 5799535

File tree

7 files changed

+49
-20
lines changed

7 files changed

+49
-20
lines changed

activitysim/abm/models/input_checker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ def input_checker(state: workflow.State):
385385
)
386386

387387
data_model_dir = state.get_injectable("data_model_dir")[0]
388-
logger.info("Data model directory:", data_model_dir)
388+
logger.info("Data model directory: %s", data_model_dir)
389389

390390
# FIXME: path doesn't recognize windows path object, so converting to string.
391391
# Is there a better way to get the data model directory than just adding it to the path?

activitysim/cli/run.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"configs_dir",
2323
"data_model_dir",
2424
"output_dir",
25+
"cache_dir",
2526
"settings_file_name",
2627
"imported_extensions",
2728
]
@@ -375,7 +376,13 @@ def run(args):
375376

376377
from activitysim.core import mp_tasks
377378

378-
injectables = {k: state.get_injectable(k) for k in INJECTABLES}
379+
injectables = {}
380+
for k in INJECTABLES:
381+
try:
382+
injectables[k] = state.get_injectable(k)
383+
except KeyError:
384+
# if injectable is not set, just ignore it
385+
pass
379386
injectables["settings"] = state.settings
380387
# injectables["settings_package"] = state.settings.dict()
381388
mp_tasks.run_multiprocess(state, injectables)

activitysim/examples/external_example_manifest.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@ prototype_mtc:
2020
url: https://github.com/ActivitySim/activitysim-prototype-mtc/releases/download/v1.3.1/prototype_mtc_reference_pipeline.zip
2121
sha256: 394e5b403d4c61d5214493cefe161432db840ba4967c23c999d914178d43a1f0
2222

23+
prototype_mtc_extended:
24+
url: https://github.com/ActivitySim/activitysim-prototype-mtc/archive/refs/tags/v1.3.2.tar.gz
25+
sha256: b3f8f60f6354a0ffce80dd67f058c2ef81645d2c8bedddfcb989d3878651f045
26+
assets:
27+
mtc_data_full.tar.zst:
28+
url: https://github.com/ActivitySim/activitysim-prototype-mtc/releases/download/v1.3.2/mtc_data_full.tar.zst
29+
sha256: ffc22b34b4990a1459829b101b43180d0f5d41da0d4535d58588f232c98bd44e
30+
unpack: data_full
31+
test/prototype_mtc_reference_pipeline.zip:
32+
url: https://github.com/ActivitySim/activitysim-prototype-mtc/releases/download/v1.3.2/prototype_mtc_extended_reference_pipeline.zip
33+
sha256: 4d94b6a8a83225dda17e9ca19c9110bc1df2df5b4b362effa153d1c8d31524f5
34+
2335
estimation_example:
2436
url: https://github.com/ActivitySim/activitysim-estimation-example/archive/refs/tags/v0.0.2.tar.gz
2537
sha256: 88c8208ee250a20e7d77036d77bc71122f21cbfeaba1eaf3b644120799f9d023

activitysim/examples/prototype_mtc_extended/data_model/input_checks.py

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,26 @@
33
44
Instructions: customize these example values for your own ActivitySim implementation
55
"""
6-
from typing import List, Optional
7-
import os, sys, logging
6+
from __future__ import annotations
87

9-
from pydantic import BaseModel, validator
10-
import pandera as pa
11-
import numpy as np
12-
import pandas as pd
13-
import openmatrix as omx
8+
import csv
9+
import logging
10+
import os
1411

1512
# for skim name parsing
1613
import re
17-
import csv
18-
19-
from activitysim.core import config
14+
import sys
15+
from typing import List, Optional
2016

2117
import enums as e
18+
import numpy as np
19+
import openmatrix as omx
20+
import pandas as pd
21+
import pandera as pa
22+
from pydantic import BaseModel, validator
2223

2324
from activitysim.abm.models.input_checker import TABLE_STORE, log_info
25+
from activitysim.core import config
2426

2527
logger = logging.getLogger(__name__)
2628

@@ -225,12 +227,13 @@ def check_hh_per_zone(cls, land_use: pd.DataFrame):
225227
def check_pop_per_zone(cls, land_use: pd.DataFrame):
226228
persons = TABLE_STORE["persons"]
227229
households = TABLE_STORE["households"]
228-
pop = persons.groupby(
229-
persons.household_id.map(
230-
lambda hhid: households.set_index("household_id").home_zone_id[hhid]
231-
)
232-
).person_id.nunique()
233-
return (pop == land_use.set_index("zone_id").TOTPOP).reindex(land_use.index)
230+
persons_per_household = persons.groupby("household_id").size()
231+
hh = households[["household_id", "home_zone_id"]].merge(
232+
persons_per_household.rename("persons_per_household"), on="household_id"
233+
)
234+
pop = hh.groupby(households.home_zone_id)["persons_per_household"].sum()
235+
lu = land_use.set_index("zone_id")
236+
return pop.reindex(lu.index) == lu.TOTPOP
234237

235238

236239
class NetworkLinks(pa.DataFrameModel):

activitysim/workflows/steps/wrapping.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,13 @@ def run_step(context: Context = None) -> None:
125125
reset_progress_step(description=progress_tag)
126126

127127
return_type = _annotations.get("return", "<missing>")
128-
_updates_context = updates_context or return_type in {dict, Context}
129-
if return_type not in {None, dict, Context}:
128+
_updates_context = updates_context or return_type in {
129+
dict,
130+
Context,
131+
"dict",
132+
"Context",
133+
}
134+
if return_type not in {None, dict, Context, "None", "dict", "Context"}:
130135
if returns_names is None and not _updates_context:
131136
context.assert_key_has_value(
132137
key="report", caller=wrapped_func.__module__

conda-environments/activitysim-dev-base.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ channels:
1515
dependencies:
1616
- python=3.10
1717
- pip
18+
- altair
1819
- asv # for benchmarking
1920
- black >= 22.0,<23
2021
- bump2version # for making a release

conda-environments/activitysim-dev.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ channels:
1111
dependencies:
1212
- python=3.10
1313
- pip
14+
- altair
1415
- asv # for benchmarking
1516
- black >= 22.0,<23
1617
- bump2version # for making a release

0 commit comments

Comments
 (0)