Skip to content

Commit

Permalink
allow skip dropping by component
Browse files Browse the repository at this point in the history
  • Loading branch information
i-am-sijia committed Apr 19, 2024
1 parent 93031bd commit a7f8544
Show file tree
Hide file tree
Showing 37 changed files with 74 additions and 5 deletions.
1 change: 1 addition & 0 deletions activitysim/abm/models/atwork_subtour_frequency.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ def atwork_subtour_frequency(
choosers=work_tours,
spec=model_spec,
nest_spec=nest_spec,
drop_unused_columns=model_settings.drop_unused_columns,
locals_d=constants,
trace_label=trace_label,
trace_choice_name="atwork_subtour_frequency",
Expand Down
1 change: 1 addition & 0 deletions activitysim/abm/models/auto_ownership.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def auto_ownership_simulate(
choosers=choosers,
spec=model_spec,
nest_spec=nest_spec,
drop_unused_columns=model_settings.drop_unused_columns,
locals_d=constants,
trace_label=trace_label,
trace_choice_name="auto_ownership",
Expand Down
1 change: 1 addition & 0 deletions activitysim/abm/models/cdap.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class CdapSettings(PydanticReadable, extra="forbid"):
annotate_households: PreprocessorSettings | None = None
COEFFICIENTS: Path
CONSTANTS: dict[str, Any] = {}
drop_unused_columns: bool = True


@workflow.step
Expand Down
1 change: 1 addition & 0 deletions activitysim/abm/models/free_parking.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def free_parking(
choosers=choosers,
spec=model_spec,
nest_spec=nest_spec,
drop_unused_columns=model_settings.drop_unused_columns,
locals_d=constants,
trace_label=trace_label,
trace_choice_name="free_parking_at_work",
Expand Down
1 change: 1 addition & 0 deletions activitysim/abm/models/joint_tour_composition.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def joint_tour_composition(
choosers=joint_tours_merged,
spec=model_spec,
nest_spec=nest_spec,
drop_unused_columns=model_settings.drop_unused_columns,
locals_d=constants,
trace_label=trace_label,
trace_choice_name="composition",
Expand Down
1 change: 1 addition & 0 deletions activitysim/abm/models/joint_tour_frequency.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ def joint_tour_frequency(
choosers=multi_person_households,
spec=model_spec,
nest_spec=nest_spec,
drop_unused_columns=model_settings.drop_unused_columns,
locals_d=constants,
trace_label=trace_label,
trace_choice_name="joint_tour_frequency",
Expand Down
1 change: 1 addition & 0 deletions activitysim/abm/models/joint_tour_frequency_composition.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ def joint_tour_frequency_composition(
choosers=choosers,
alternatives=alts,
spec=model_spec,
drop_unused_columns=model_settings.drop_unused_columns,
locals_d=constants,
trace_label=trace_label,
trace_choice_name=trace_label,
Expand Down
2 changes: 2 additions & 0 deletions activitysim/abm/models/location_choice.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ def _location_sample(
spec=spec,
sample_size=sample_size,
alt_col_name=alt_dest_col_name,
drop_unused_columns=model_settings.drop_unused_columns,
log_alt_losers=log_alt_losers,
skims=skims,
locals_d=locals_d,
Expand Down Expand Up @@ -686,6 +687,7 @@ def run_location_simulate(
alternatives,
spec=spec,
choice_column=alt_dest_col_name,
drop_unused_columns=model_settings.drop_unused_columns,
log_alt_losers=log_alt_losers,
want_logsums=want_logsums,
skims=skims,
Expand Down
1 change: 1 addition & 0 deletions activitysim/abm/models/mandatory_tour_frequency.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ def mandatory_tour_frequency(
choosers=choosers,
spec=model_spec,
nest_spec=nest_spec,
drop_unused_columns=model_settings.drop_unused_columns,
locals_d=constants,
trace_label=trace_label,
trace_choice_name="mandatory_tour_frequency",
Expand Down
1 change: 1 addition & 0 deletions activitysim/abm/models/non_mandatory_tour_frequency.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ def non_mandatory_tour_frequency(
chooser_segment,
alternatives,
spec=segment_spec,
drop_unused_columns=model_settings.drop_unused_columns,
log_alt_losers=log_alt_losers,
locals_d=constants,
trace_label="non_mandatory_tour_frequency.%s" % segment_name,
Expand Down
1 change: 1 addition & 0 deletions activitysim/abm/models/parking_location_choice.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ def parking_destination_simulate(
choosers=trips,
alternatives=destination_sample,
spec=spec,
drop_unused_columns=model_settings.drop_unused_columns,
choice_column=alt_dest_col_name,
want_logsums=False,
allow_zero_probs=True,
Expand Down
1 change: 1 addition & 0 deletions activitysim/abm/models/school_escorting.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,7 @@ def school_escorting(
choosers=choosers,
alternatives=alts,
spec=model_spec,
drop_unused_columns=model_settings.drop_unused_columns,
log_alt_losers=log_alt_losers,
locals_d=locals_dict,
trace_label=stage_trace_label,
Expand Down
1 change: 1 addition & 0 deletions activitysim/abm/models/stop_frequency.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ def stop_frequency(
choosers=chooser_segment,
spec=segment_spec,
nest_spec=nest_spec,
drop_unused_columns=model_settings.drop_unused_columns,
locals_d=constants,
trace_label=tracing.extend_trace_label(trace_label, segment_name),
trace_choice_name="stops",
Expand Down
1 change: 1 addition & 0 deletions activitysim/abm/models/telecommute_frequency.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def telecommute_frequency(
choosers=choosers,
spec=model_spec,
nest_spec=nest_spec,
drop_unused_columns=model_settings.drop_unused_columns,
locals_d=constants,
trace_label=trace_label,
trace_choice_name="telecommute_frequency",
Expand Down
2 changes: 2 additions & 0 deletions activitysim/abm/models/tour_scheduling_probabilistic.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ class TourSchedulingProbabilisticSettings(PydanticReadable):
PROBS_JOIN_COLS: list[str] | None = None
"""List of columns"""

drop_unused_columns: bool = True


@workflow.step
def tour_scheduling_probabilistic(
Expand Down
1 change: 1 addition & 0 deletions activitysim/abm/models/transit_pass_ownership.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def transit_pass_ownership(
choosers=choosers,
spec=model_spec,
nest_spec=nest_spec,
drop_unused_columns=model_settings.drop_unused_columns,
locals_d=constants,
trace_label=trace_label,
trace_choice_name="transit_pass_ownership",
Expand Down
1 change: 1 addition & 0 deletions activitysim/abm/models/transit_pass_subsidy.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def transit_pass_subsidy(
choosers=choosers,
spec=model_spec,
nest_spec=nest_spec,
drop_unused_columns=model_settings.drop_unused_columns,
locals_d=constants,
trace_label=trace_label,
trace_choice_name="transit_pass_subsidy",
Expand Down
3 changes: 3 additions & 0 deletions activitysim/abm/models/trip_destination.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ def _destination_sample(
alternatives=alternatives,
sample_size=sample_size,
alt_col_name=alt_dest_col_name,
drop_unused_columns=model_settings.drop_unused_columns,
log_alt_losers=log_alt_losers,
allow_zero_probs=True,
spec=spec,
Expand Down Expand Up @@ -713,6 +714,7 @@ def compute_ood_logsums(
choosers,
logsum_spec,
nest_spec,
drop_unused_columns=logsum_settings.get("drop_unused_columns", True),
skims=od_skims,
locals_d=locals_dict,
chunk_size=chunk_size,
Expand Down Expand Up @@ -937,6 +939,7 @@ def trip_destination_simulate(
choosers=trips,
alternatives=destination_sample,
spec=spec,
drop_unused_columns=model_settings.drop_unused_columns,
choice_column=alt_dest_col_name,
log_alt_losers=log_alt_losers,
want_logsums=want_logsums,
Expand Down
3 changes: 3 additions & 0 deletions activitysim/abm/models/trip_matrices.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from activitysim.core import config, expressions, los, workflow
from activitysim.core.configuration.base import PreprocessorSettings, PydanticReadable
from activitysim.core.configuration.logit import LogitComponentSettings
from activitysim.core.util import drop_unused_chooser_columns

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -87,6 +88,8 @@ def write_trip_matrices(
model_settings_file_name,
)

annotate_trips_spec = model_settings.preprocessor

trips_df = annotate_trips(state, trips, network_los, model_settings)

if model_settings.SAVE_TRIPS_TABLE:
Expand Down
1 change: 1 addition & 0 deletions activitysim/abm/models/trip_mode_choice.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ def trip_mode_choice(
nest_spec=simulate.eval_nest_coefficients(
nest_spec, coefficients, segment_trace_label
),
drop_unused_columns=model_settings.drop_unused_columns,
skims=skims,
locals_d=locals_dict,
mode_column_name=mode_column_name,
Expand Down
1 change: 1 addition & 0 deletions activitysim/abm/models/trip_purpose.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ class TripPurposeSettings(PydanticReadable):
preprocessor: PreprocessorSettings | None = None
use_depart_time: bool = True
CONSTANTS: dict[str, Any] = {}
drop_unused_columns: bool = True


def run_trip_purpose(
Expand Down
2 changes: 2 additions & 0 deletions activitysim/abm/models/trip_purpose_and_destination.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class TripPurposeAndDestinationSettings(PydanticReadable):
MAX_ITERATIONS: int = 5
"""Setting for the maximum iterations"""

drop_unused_columns: bool = True


@workflow.step
def trip_purpose_and_destination(
Expand Down
2 changes: 2 additions & 0 deletions activitysim/abm/models/trip_scheduling.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,8 @@ class TripSchedulingSettings(PydanticReadable):

CONSTANTS: dict[str, Any] = {}

drop_unused_columns: bool = True


@workflow.step(copy_tables=False)
def trip_scheduling(
Expand Down
2 changes: 2 additions & 0 deletions activitysim/abm/models/trip_scheduling_choice.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,8 @@ class TripSchedulingChoiceSettings(PydanticReadable, extra="forbid"):
SPECIFICATION: str
"""file name of specification file"""

drop_unused_columns: bool = True


@workflow.step
def trip_scheduling_choice(
Expand Down
1 change: 1 addition & 0 deletions activitysim/abm/models/util/logsums.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ def compute_location_choice_logsums(
choosers,
logsum_spec,
nest_spec,
drop_unused_columns=model_settings.drop_unused_columns,
skims=skims,
locals_d=locals_dict,
chunk_size=chunk_size,
Expand Down
3 changes: 3 additions & 0 deletions activitysim/abm/models/util/mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def mode_choice_simulate(
choosers: pd.DataFrame,
spec: pd.DataFrame,
nest_spec,
drop_unused_columns,
skims,
locals_d,
mode_column_name,
Expand Down Expand Up @@ -63,6 +64,7 @@ def mode_choice_simulate(
choosers=choosers,
spec=spec,
nest_spec=nest_spec,
drop_unused_columns=drop_unused_columns,
skims=skims,
locals_d=locals_d,
want_logsums=want_logsums,
Expand Down Expand Up @@ -162,6 +164,7 @@ def run_tour_mode_choice_simulate(
choosers=choosers,
spec=spec,
nest_spec=nest_spec,
drop_unused_columns=model_settings.drop_unused_columns,
skims=skims,
locals_d=locals_dict,
mode_column_name=mode_column_name,
Expand Down
2 changes: 2 additions & 0 deletions activitysim/abm/models/util/tour_destination.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ def _destination_sample(
alternatives=destination_size_terms,
sample_size=sample_size,
alt_col_name=alt_dest_col_name,
drop_unused_columns=model_settings.drop_unused_columns,
log_alt_losers=log_alt_losers,
spec=model_spec,
skims=skims,
Expand Down Expand Up @@ -776,6 +777,7 @@ def run_destination_simulate(
trace_label=trace_label,
trace_choice_name="destination",
estimator=estimator,
drop_unused_columns=model_settings.drop_unused_columns,
skip_choice=skip_choice,
)

Expand Down
2 changes: 2 additions & 0 deletions activitysim/abm/models/util/tour_od.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ def _od_sample(
sample_size=sample_size,
alt_col_name=alt_col_name,
spec=model_spec,
drop_unused_columns=model_settings.drop_unused_columns,
skims=skims,
locals_d=locals_d,
chunk_size=chunk_size,
Expand Down Expand Up @@ -1046,6 +1047,7 @@ def run_od_simulate(
choosers,
od_sample,
spec=model_spec,
drop_unused_columns=model_settings.drop_unused_columns,
choice_column=alt_od_col_name,
want_logsums=want_logsums,
skims=skims,
Expand Down
2 changes: 2 additions & 0 deletions activitysim/abm/models/util/vectorize_tour_scheduling.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ def _compute_logsums(
choosers,
logsum_spec,
nest_spec,
drop_unused_columns=logsum_settings.drop_unused_columns,
skims=skims,
locals_d=locals_dict,
chunk_size=0,
Expand Down Expand Up @@ -856,6 +857,7 @@ def _schedule_tours(
alt_tdd,
spec,
choice_column=choice_column,
drop_unused_columns=model_settings.drop_unused_columns,
log_alt_losers=log_alt_losers,
locals_d=locals_d,
chunk_size=0,
Expand Down
1 change: 1 addition & 0 deletions activitysim/abm/models/vehicle_allocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ def vehicle_allocation(
choosers=choosers,
spec=model_spec,
nest_spec=nest_spec,
drop_unused_columns=model_settings.drop_unused_columns,
skims=skims,
locals_d=locals_dict,
trace_label=trace_label,
Expand Down
1 change: 1 addition & 0 deletions activitysim/abm/models/vehicle_type_choice.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ def iterate_vehicle_type_choice(
choosers=choosers,
alternatives=alts_wide,
spec=model_spec,
drop_unused_columns=model_settings.drop_unused_columns,
log_alt_losers=log_alt_losers,
locals_d=locals_dict,
trace_label=trace_label,
Expand Down
1 change: 1 addition & 0 deletions activitysim/abm/models/work_from_home.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ def work_from_home(
choosers=choosers,
spec=model_spec,
nest_spec=nest_spec,
drop_unused_columns=model_settings.drop_unused_columns,
locals_d=constants,
trace_label=trace_label,
trace_choice_name="work_from_home",
Expand Down
8 changes: 8 additions & 0 deletions activitysim/core/configuration/logit.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ class BaseLogitComponentSettings(PydanticReadable):
sharrow_skip: bool = False
"""Skip sharrow when evaluating this component."""

drop_unused_columns: bool = True
"""Drop unused columns in choosers table when evaluating this component.
Default to dropping used columns for memory efficiency.
However, user can set this to False to keep all columns in choosers table.
This setting is component specific.
"""


class LogitComponentSettings(BaseLogitComponentSettings):
"""
Expand Down
5 changes: 4 additions & 1 deletion activitysim/core/interaction_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ def _interaction_sample(
spec,
sample_size,
alt_col_name,
drop_unused_columns,
allow_zero_probs=False,
log_alt_losers=False,
skims=None,
Expand Down Expand Up @@ -237,7 +238,7 @@ def _interaction_sample(

# check if tracing is enabled and if we have trace targets
# if not estimation mode, drop unused columns
if not have_trace_targets:
if (not have_trace_targets) and drop_unused_columns:

choosers = util.drop_unused_chooser_columns(
choosers,
Expand Down Expand Up @@ -529,6 +530,7 @@ def interaction_sample(
spec: pd.DataFrame,
sample_size: int,
alt_col_name: str,
drop_unused_columns: bool,
allow_zero_probs: bool = False,
log_alt_losers: bool = False,
skims: SkimWrapper | DatasetWrapper | None = None,
Expand Down Expand Up @@ -625,6 +627,7 @@ def interaction_sample(
spec=spec,
sample_size=sample_size,
alt_col_name=alt_col_name,
drop_unused_columns=drop_unused_columns,
allow_zero_probs=allow_zero_probs,
log_alt_losers=log_alt_losers,
skims=skims,
Expand Down
Loading

0 comments on commit a7f8544

Please sign in to comment.