Skip to content

Commit

Permalink
protect_columns for all simulations (choosers, alts, simple simulat…
Browse files Browse the repository at this point in the history
…e, interaction simulate, etc) (#871)

* protect columns in all simulate

* enabling compute settings for trip scheduling choice

* move hardcoded protect columns to settings

* allow protect columns in parking location choice
  • Loading branch information
i-am-sijia authored May 21, 2024
1 parent 564c476 commit f31bfe5
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 6 deletions.
14 changes: 12 additions & 2 deletions activitysim/abm/models/parking_location_choice.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,19 @@ def choose_parking_location(
locals_dict["PARKING"] = skims["op_skims"].dest_key

spec = get_spec_for_segment(state, model_settings, segment_name)
trips = drop_unused_columns(trips, spec, locals_dict, custom_chooser=None)
trips = drop_unused_columns(
trips,
spec,
locals_dict,
custom_chooser=None,
additional_columns=model_settings.compute_settings.protect_columns,
)
alternatives = drop_unused_columns(
alternatives, spec, locals_dict, custom_chooser=None
alternatives,
spec,
locals_dict,
custom_chooser=None,
additional_columns=model_settings.compute_settings.protect_columns,
)

destination_sample = logit.interaction_dataset(
Expand Down
19 changes: 17 additions & 2 deletions activitysim/abm/models/trip_scheduling_choice.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
get_time_windows,
)
from activitysim.core import chunk, expressions, simulate, tracing, workflow
from activitysim.core.configuration.base import PreprocessorSettings, PydanticReadable
from activitysim.core.configuration.base import (
ComputeSettings,
PreprocessorSettings,
PydanticReadable,
)
from activitysim.core.interaction_sample_simulate import _interaction_sample_simulate
from activitysim.core.skim_dataset import SkimDataset
from activitysim.core.skim_dictionary import SkimDict
Expand Down Expand Up @@ -223,6 +227,7 @@ def run_trip_scheduling_choice(
skims,
locals_dict: Mapping,
trace_label: str,
model_settings: TripSchedulingChoiceSettings,
):
NUM_TOUR_LEGS = 3
trace_label = tracing.extend_trace_label(trace_label, "interaction_sample_simulate")
Expand Down Expand Up @@ -296,6 +301,7 @@ def run_trip_scheduling_choice(
trace_choice_name="trip_schedule_stage_1",
estimator=None,
chunk_sizer=chunk_sizer,
compute_settings=model_settings.compute_settings,
)

assert len(choices.index) == len(choosers.index)
Expand Down Expand Up @@ -338,6 +344,9 @@ class TripSchedulingChoiceSettings(PydanticReadable, extra="forbid"):
SPECIFICATION: str
"""file name of specification file"""

compute_settings: ComputeSettings = ComputeSettings()
"""Compute settings for this component."""


@workflow.step
def trip_scheduling_choice(
Expand Down Expand Up @@ -419,7 +428,13 @@ def trip_scheduling_choice(
)

tours_df = run_trip_scheduling_choice(
state, spec, tours_df, skims, locals_dict, trace_label
state,
spec,
tours_df,
skims,
locals_dict,
trace_label,
model_settings,
)

state.add_table("tours", tours_df)
1 change: 1 addition & 0 deletions activitysim/core/configuration/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ def subcomponent_settings(self, subcomponent: str) -> ComputeSettings:
use_numexpr=self.use_numexpr,
use_numba=self.use_numba,
drop_unused_columns=self.drop_unused_columns,
protect_columns=self.protect_columns,
)


Expand Down
3 changes: 2 additions & 1 deletion activitysim/core/interaction_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ def _interaction_sample(
locals_d,
custom_chooser=None,
sharrow_enabled=sharrow_enabled,
additional_columns=compute_settings.protect_columns,
)

alternatives = util.drop_unused_columns(
Expand All @@ -265,7 +266,7 @@ def _interaction_sample(
locals_d,
custom_chooser=None,
sharrow_enabled=sharrow_enabled,
additional_columns=["tdd", "origin_destination"],
additional_columns=["tdd"] + compute_settings.protect_columns,
)

if sharrow_enabled:
Expand Down
3 changes: 2 additions & 1 deletion activitysim/core/interaction_sample_simulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ def _interaction_sample_simulate(
locals_d,
custom_chooser=None,
sharrow_enabled=sharrow_enabled,
additional_columns=compute_settings.protect_columns,
)

alternatives = util.drop_unused_columns(
Expand All @@ -166,7 +167,7 @@ def _interaction_sample_simulate(
locals_d,
custom_chooser=None,
sharrow_enabled=sharrow_enabled,
additional_columns=["tdd", "origin_destination"],
additional_columns=["tdd"] + compute_settings.protect_columns,
)

interaction_df = alternatives.join(choosers, how="left", rsuffix="_chooser")
Expand Down
1 change: 1 addition & 0 deletions activitysim/core/interaction_simulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,7 @@ def _interaction_simulate(
locals_d,
custom_chooser=None,
sharrow_enabled=sharrow_enabled,
additional_columns=compute_settings.protect_columns,
)

if (
Expand Down
1 change: 1 addition & 0 deletions activitysim/core/simulate.py
Original file line number Diff line number Diff line change
Expand Up @@ -1989,6 +1989,7 @@ def _simple_simulate_logsums(
locals_d,
custom_chooser=None,
sharrow_enabled=state.settings.sharrow,
additional_columns=compute_settings.protect_columns,
)

if nest_spec is None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,7 @@ SEGMENTS:

LOGSUM_SETTINGS: tour_mode_choice
LOGSUM_PREPROCESSOR: preprocessor

compute_settings:
protect_columns:
- origin_destination

0 comments on commit f31bfe5

Please sign in to comment.