Skip to content

Commit 9935b74

Browse files
authored
Deprecate SIMULATE_CHOOSER_COLUMNS and LOGSUM_CHOOSER_COLUMNS settings
1 parent 21254e5 commit 9935b74

59 files changed

Lines changed: 161 additions & 700 deletions

File tree

Some content is hidden

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

activitysim/abm/models/location_choice.py

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -242,14 +242,7 @@ def location_sample(
242242
chunk_tag,
243243
trace_label,
244244
):
245-
# FIXME - MEMORY HACK - only include columns actually used in spec
246-
chooser_columns = model_settings.SIMULATE_CHOOSER_COLUMNS
247-
# Drop this when PR #1017 is merged
248-
if ("household_id" not in chooser_columns) and (
249-
"household_id" in persons_merged.columns
250-
):
251-
chooser_columns = chooser_columns + ["household_id"]
252-
choosers = persons_merged[chooser_columns]
245+
choosers = persons_merged
253246

254247
# create wrapper with keys for this lookup - in this case there is a home_zone_id in the choosers
255248
# and a zone_id in the alternatives which get merged during interaction
@@ -441,17 +434,7 @@ def location_presample(
441434
HOME_TAZ in persons_merged
442435
) # 'TAZ' should already be in persons_merged from land_use
443436

444-
# FIXME - MEMORY HACK - only include columns actually used in spec
445-
# FIXME we don't actually require that land_use provide a TAZ crosswalk
446-
# FIXME maybe we should add it for multi-zone (from maz_taz) if missing?
447-
chooser_columns = model_settings.SIMULATE_CHOOSER_COLUMNS
448-
chooser_columns = [HOME_TAZ if c == HOME_MAZ else c for c in chooser_columns]
449-
# Drop this when PR #1017 is merged
450-
if ("household_id" not in chooser_columns) and (
451-
"household_id" in persons_merged.columns
452-
):
453-
chooser_columns = chooser_columns + ["household_id"]
454-
choosers = persons_merged[chooser_columns]
437+
choosers = persons_merged
455438

456439
# create wrapper with keys for this lookup - in this case there is a HOME_TAZ in the choosers
457440
# and a DEST_TAZ in the alternatives which get merged during interaction
@@ -627,11 +610,6 @@ def run_location_logsums(
627610
mandatory=False,
628611
)
629612

630-
# FIXME - MEMORY HACK - only include columns actually used in spec
631-
persons_merged_df = logsum.filter_chooser_columns(
632-
persons_merged_df, logsum_settings, model_settings
633-
)
634-
635613
logger.info(f"Running {trace_label} with {len(location_sample_df.index)} rows")
636614

637615
choosers = location_sample_df.join(persons_merged_df, how="left")
@@ -691,14 +669,7 @@ def run_location_simulate(
691669
"""
692670
assert not persons_merged.empty
693671

694-
# FIXME - MEMORY HACK - only include columns actually used in spec
695-
chooser_columns = model_settings.SIMULATE_CHOOSER_COLUMNS
696-
# Drop this when PR #1017 is merged
697-
if ("household_id" not in chooser_columns) and (
698-
"household_id" in persons_merged.columns
699-
):
700-
chooser_columns = chooser_columns + ["household_id"]
701-
choosers = persons_merged[chooser_columns]
672+
choosers = persons_merged
702673

703674
alt_dest_col_name = model_settings.ALT_DEST_COL_NAME
704675

activitysim/abm/models/school_escorting.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
from __future__ import annotations
44

55
import logging
6+
import warnings
67
from typing import Any, Literal
78

89
import numpy as np
910
import pandas as pd
11+
from pydantic import field_validator
1012

1113
from activitysim.abm.models.util import school_escort_tours_trips
1214
from activitysim.core import (
@@ -335,7 +337,26 @@ class SchoolEscortSettings(BaseLogitComponentSettings, extra="forbid"):
335337
GENDER_WEIGHT: float = 10.0
336338
AGE_WEIGHT: float = 1.0
337339

338-
SIMULATE_CHOOSER_COLUMNS: list[str] | None = None
340+
SIMULATE_CHOOSER_COLUMNS: Any | None = None
341+
"""Was used to help reduce the memory needed for the model.
342+
343+
This setting is now obsolete and does nothing. Its functionality has been
344+
replaced by :func:`activitysim.core.util.drop_unused_columns`.
345+
346+
.. deprecated:: 1.4
347+
"""
348+
349+
@field_validator("SIMULATE_CHOOSER_COLUMNS", mode="before")
350+
@classmethod
351+
def _deprecate_simulate_chooser_columns(cls, value):
352+
if value is not None:
353+
warnings.warn(
354+
"SIMULATE_CHOOSER_COLUMNS is deprecated and no longer used, "
355+
"unused columns are now dropped automatically",
356+
DeprecationWarning,
357+
stacklevel=2,
358+
)
359+
return None
339360

340361
SPEC: None = None
341362
"""The school escort model does not use this setting."""
@@ -465,17 +486,6 @@ def school_escorting(
465486
# else:
466487
# locals_dict.pop("_sharrow_skip", None)
467488

468-
# reduce memory by limiting columns if selected columns are supplied
469-
chooser_columns = model_settings.SIMULATE_CHOOSER_COLUMNS
470-
if chooser_columns is not None:
471-
# Drop this when PR #1017 is merged
472-
if ("household_id" not in chooser_columns) and (
473-
"household_id" in choosers.columns
474-
):
475-
chooser_columns = chooser_columns + ["household_id"]
476-
chooser_columns = chooser_columns + participant_columns
477-
choosers = choosers[chooser_columns]
478-
479489
# add previous data to stage
480490
if stage_num >= 1:
481491
choosers = add_prev_choices_to_choosers(

activitysim/abm/models/util/logsums.py

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import pandas as pd
88

99
from activitysim.core import config, expressions, los, simulate, tracing, workflow
10-
from activitysim.core.configuration import PydanticBase
1110
from activitysim.core.configuration.logit import (
1211
TourLocationComponentSettings,
1312
TourModeComponentSettings,
@@ -16,41 +15,6 @@
1615
logger = logging.getLogger(__name__)
1716

1817

19-
def filter_chooser_columns(
20-
choosers, logsum_settings: dict | PydanticBase, model_settings: dict | PydanticBase
21-
):
22-
try:
23-
chooser_columns = logsum_settings.LOGSUM_CHOOSER_COLUMNS
24-
except AttributeError:
25-
chooser_columns = logsum_settings.get("LOGSUM_CHOOSER_COLUMNS", [])
26-
27-
if (
28-
isinstance(model_settings, dict)
29-
and "CHOOSER_ORIG_COL_NAME" in model_settings
30-
and model_settings["CHOOSER_ORIG_COL_NAME"] not in chooser_columns
31-
):
32-
chooser_columns.append(model_settings["CHOOSER_ORIG_COL_NAME"])
33-
if (
34-
isinstance(model_settings, PydanticBase)
35-
and hasattr(model_settings, "CHOOSER_ORIG_COL_NAME")
36-
and model_settings.CHOOSER_ORIG_COL_NAME
37-
and model_settings.CHOOSER_ORIG_COL_NAME not in chooser_columns
38-
):
39-
chooser_columns.append(model_settings.CHOOSER_ORIG_COL_NAME)
40-
41-
missing_columns = [c for c in chooser_columns if c not in choosers]
42-
if missing_columns:
43-
logger.debug(
44-
"logsum.filter_chooser_columns missing_columns %s" % missing_columns
45-
)
46-
47-
# ignore any columns not appearing in choosers df
48-
chooser_columns = [c for c in chooser_columns if c in choosers]
49-
50-
choosers = choosers[chooser_columns]
51-
return choosers
52-
53-
5418
def compute_location_choice_logsums(
5519
state: workflow.State,
5620
choosers: pd.DataFrame,

activitysim/abm/models/util/tour_destination.py

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -691,23 +691,9 @@ def run_destination_sample(
691691
chunk_size,
692692
trace_label,
693693
):
694-
# FIXME - MEMORY HACK - only include columns actually used in spec (omit them pre-merge)
695-
chooser_columns = model_settings.SIMULATE_CHOOSER_COLUMNS
696-
697694
# if special person id is passed
698695
chooser_id_column = model_settings.CHOOSER_ID_COLUMN
699696

700-
# Drop this when PR #1017 is merged
701-
if ("household_id" not in chooser_columns) and (
702-
"household_id" in persons_merged.columns
703-
):
704-
chooser_columns = chooser_columns + ["household_id"]
705-
persons_merged = persons_merged[
706-
[c for c in persons_merged.columns if c in chooser_columns]
707-
]
708-
tours = tours[
709-
[c for c in tours.columns if c in chooser_columns or c == chooser_id_column]
710-
]
711697
choosers = pd.merge(
712698
tours, persons_merged, left_on=chooser_id_column, right_index=True, how="left"
713699
)
@@ -805,11 +791,6 @@ def run_destination_logsums(
805791

806792
chunk_tag = "tour_destination.logsums"
807793

808-
# FIXME - MEMORY HACK - only include columns actually used in spec
809-
persons_merged = logsum.filter_chooser_columns(
810-
persons_merged, logsum_settings, model_settings
811-
)
812-
813794
# merge persons into tours
814795
choosers = pd.merge(
815796
destination_sample,
@@ -872,23 +853,9 @@ def run_destination_simulate(
872853
coefficients_file_name=model_settings.COEFFICIENTS,
873854
)
874855

875-
# FIXME - MEMORY HACK - only include columns actually used in spec (omit them pre-merge)
876-
chooser_columns = model_settings.SIMULATE_CHOOSER_COLUMNS
877-
878856
# if special person id is passed
879857
chooser_id_column = model_settings.CHOOSER_ID_COLUMN
880858

881-
# Drop this when PR #1017 is merged
882-
if ("household_id" not in chooser_columns) and (
883-
"household_id" in persons_merged.columns
884-
):
885-
chooser_columns = chooser_columns + ["household_id"]
886-
persons_merged = persons_merged[
887-
[c for c in persons_merged.columns if c in chooser_columns]
888-
]
889-
tours = tours[
890-
[c for c in tours.columns if c in chooser_columns or c == chooser_id_column]
891-
]
892859
choosers = pd.merge(
893860
tours, persons_merged, left_on=chooser_id_column, right_index=True, how="left"
894861
)

activitysim/abm/models/util/tour_od.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -737,12 +737,6 @@ def run_od_sample(
737737
)
738738

739739
choosers = tours
740-
# FIXME - MEMORY HACK - only include columns actually used in spec
741-
chooser_columns = model_settings.SIMULATE_CHOOSER_COLUMNS
742-
# Drop this when PR #1017 is merged
743-
if ("household_id" not in chooser_columns) and ("household_id" in choosers.columns):
744-
chooser_columns = chooser_columns + ["household_id"]
745-
choosers = choosers[chooser_columns]
746740

747741
# interaction_sample requires that choosers.index.is_monotonic_increasing
748742
if not choosers.index.is_monotonic_increasing:
@@ -820,11 +814,6 @@ def run_od_logsums(
820814
dest_id_col = model_settings.DEST_COL_NAME
821815
tour_od_id_col = get_od_id_col(origin_id_col, dest_id_col)
822816

823-
# FIXME - MEMORY HACK - only include columns actually used in spec
824-
tours_merged_df = logsum.filter_chooser_columns(
825-
tours_merged_df, logsum_settings, model_settings
826-
)
827-
828817
# merge ods into choosers table
829818
choosers = od_sample.join(tours_merged_df, how="left")
830819
choosers[tour_od_id_col] = (
@@ -1000,13 +989,6 @@ def run_od_simulate(
1000989
# merge persons into tours
1001990
choosers = tours
1002991

1003-
# FIXME - MEMORY HACK - only include columns actually used in spec
1004-
chooser_columns = model_settings.SIMULATE_CHOOSER_COLUMNS
1005-
# Drop this when PR #1017 is merged
1006-
if ("household_id" not in chooser_columns) and ("household_id" in choosers.columns):
1007-
chooser_columns = chooser_columns + ["household_id"]
1008-
choosers = choosers[chooser_columns]
1009-
1010992
# interaction_sample requires that choosers.index.is_monotonic_increasing
1011993
if not choosers.index.is_monotonic_increasing:
1012994
logger.debug(

activitysim/abm/models/util/tour_scheduling.py

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from activitysim.abm.models.util import vectorize_tour_scheduling as vts
1010
from activitysim.core import config, estimation, expressions, simulate, workflow
1111

12-
from .vectorize_tour_scheduling import TourModeComponentSettings, TourSchedulingSettings
12+
from .vectorize_tour_scheduling import TourSchedulingSettings
1313

1414
logger = logging.getLogger(__name__)
1515

@@ -24,30 +24,6 @@ def run_tour_scheduling(
2424
trace_label: str,
2525
):
2626

27-
if model_settings.LOGSUM_SETTINGS:
28-
logsum_settings = TourModeComponentSettings.read_settings_file(
29-
state.filesystem,
30-
str(model_settings.LOGSUM_SETTINGS),
31-
mandatory=False,
32-
)
33-
logsum_columns = logsum_settings.LOGSUM_CHOOSER_COLUMNS
34-
else:
35-
logsum_columns = []
36-
37-
# - filter chooser columns for both logsums and simulate
38-
model_columns = model_settings.SIMULATE_CHOOSER_COLUMNS
39-
chooser_columns = logsum_columns + [
40-
c for c in model_columns if c not in logsum_columns
41-
]
42-
43-
# Drop this when PR #1017 is merged
44-
if ("household_id" not in chooser_columns) and (
45-
"household_id" in persons_merged.columns
46-
):
47-
chooser_columns = chooser_columns + ["household_id"]
48-
49-
persons_merged = expressions.filter_chooser_columns(persons_merged, chooser_columns)
50-
5127
timetable = state.get_injectable("timetable")
5228

5329
# - run preprocessor to annotate choosers

activitysim/abm/models/util/vectorize_tour_scheduling.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
from __future__ import annotations
44

55
import logging
6+
import warnings
67
from collections import OrderedDict
78
from pathlib import Path
89
from typing import Any
910

1011
import numpy as np
1112
import pandas as pd
13+
from pydantic import field_validator
1214

1315
from activitysim.abm.models.tour_mode_choice import TourModeComponentSettings
1416
from activitysim.core import chunk, config, expressions, los, simulate
@@ -43,7 +45,26 @@ class TourSchedulingSettings(LogitComponentSettings, extra="forbid"):
4345
it is assumed to be an unsegmented preprocessor. Otherwise, the dict keys
4446
give the segements.
4547
"""
46-
SIMULATE_CHOOSER_COLUMNS: list[str] | None = None
48+
SIMULATE_CHOOSER_COLUMNS: Any | None = None
49+
"""Was used to help reduce the memory needed for the model.
50+
51+
This setting is now obsolete and does nothing. Its functionality has been
52+
replaced by :func:`activitysim.core.util.drop_unused_columns`.
53+
54+
.. deprecated:: 1.4
55+
"""
56+
57+
@field_validator("SIMULATE_CHOOSER_COLUMNS", mode="before")
58+
@classmethod
59+
def _deprecate_simulate_chooser_columns(cls, value):
60+
if value is not None:
61+
warnings.warn(
62+
"SIMULATE_CHOOSER_COLUMNS is deprecated and no longer used, "
63+
"unused columns are now dropped automatically",
64+
DeprecationWarning,
65+
stacklevel=2,
66+
)
67+
return None
4768

4869
SPEC_SEGMENTS: dict[str, LogitComponentSettings] = {}
4970

activitysim/abm/test/test_misc/test_location_choice_sampling.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ def fake_choose_maz_for_taz(
9393
(),
9494
{
9595
"ALT_DEST_COL_NAME": "zone_id",
96-
"SIMULATE_CHOOSER_COLUMNS": [location_choice.HOME_MAZ],
9796
},
9897
)()
9998
persons_merged = pd.DataFrame(
@@ -222,7 +221,6 @@ def fake_choose_maz_for_taz(
222221
(),
223222
{
224223
"ALT_DEST_COL_NAME": "zone_id",
225-
"SIMULATE_CHOOSER_COLUMNS": [location_choice.HOME_MAZ],
226224
},
227225
)()
228226
persons_merged = pd.DataFrame(
@@ -327,7 +325,6 @@ def fake_location_sample(
327325
(),
328326
{
329327
"ALT_DEST_COL_NAME": "zone_id",
330-
"SIMULATE_CHOOSER_COLUMNS": [location_choice.HOME_MAZ],
331328
},
332329
)()
333330
persons_merged = pd.DataFrame(

activitysim/abm/test/test_misc/test_shadow_pricing_simulate.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,6 @@ def state(
122122
choice_sizes[col] = 0
123123

124124
school_location_settings = """
125-
SIMULATE_CHOOSER_COLUMNS:
126-
- home_zone_id
127-
- school_segment
128-
- household_id
129-
- is_student
130-
- age_0_to_5
131-
- age_6_to_12
132-
- pemploy
133125
CHOOSER_ORIG_COL_NAME: home_zone_id
134126
ALT_DEST_COL_NAME: alt_dest
135127
SAMPLE_SIZE: 30

0 commit comments

Comments
 (0)