From a7f8544b0cbc913aef950e4f13441ff1f0555958 Mon Sep 17 00:00:00 2001 From: Sijia Wang Date: Fri, 19 Apr 2024 10:41:10 -0400 Subject: [PATCH] allow skip dropping by component --- activitysim/abm/models/atwork_subtour_frequency.py | 1 + activitysim/abm/models/auto_ownership.py | 1 + activitysim/abm/models/cdap.py | 1 + activitysim/abm/models/free_parking.py | 1 + activitysim/abm/models/joint_tour_composition.py | 1 + activitysim/abm/models/joint_tour_frequency.py | 1 + .../abm/models/joint_tour_frequency_composition.py | 1 + activitysim/abm/models/location_choice.py | 2 ++ activitysim/abm/models/mandatory_tour_frequency.py | 1 + activitysim/abm/models/non_mandatory_tour_frequency.py | 1 + activitysim/abm/models/parking_location_choice.py | 1 + activitysim/abm/models/school_escorting.py | 1 + activitysim/abm/models/stop_frequency.py | 1 + activitysim/abm/models/telecommute_frequency.py | 1 + .../abm/models/tour_scheduling_probabilistic.py | 2 ++ activitysim/abm/models/transit_pass_ownership.py | 1 + activitysim/abm/models/transit_pass_subsidy.py | 1 + activitysim/abm/models/trip_destination.py | 3 +++ activitysim/abm/models/trip_matrices.py | 3 +++ activitysim/abm/models/trip_mode_choice.py | 1 + activitysim/abm/models/trip_purpose.py | 1 + activitysim/abm/models/trip_purpose_and_destination.py | 2 ++ activitysim/abm/models/trip_scheduling.py | 2 ++ activitysim/abm/models/trip_scheduling_choice.py | 2 ++ activitysim/abm/models/util/logsums.py | 1 + activitysim/abm/models/util/mode.py | 3 +++ activitysim/abm/models/util/tour_destination.py | 2 ++ activitysim/abm/models/util/tour_od.py | 2 ++ .../abm/models/util/vectorize_tour_scheduling.py | 2 ++ activitysim/abm/models/vehicle_allocation.py | 1 + activitysim/abm/models/vehicle_type_choice.py | 1 + activitysim/abm/models/work_from_home.py | 1 + activitysim/core/configuration/logit.py | 8 ++++++++ activitysim/core/interaction_sample.py | 5 ++++- activitysim/core/interaction_sample_simulate.py | 5 ++++- activitysim/core/interaction_simulate.py | 5 ++++- activitysim/core/simulate.py | 10 ++++++++-- 37 files changed, 74 insertions(+), 5 deletions(-) diff --git a/activitysim/abm/models/atwork_subtour_frequency.py b/activitysim/abm/models/atwork_subtour_frequency.py index f9cae3821..67b7413a4 100644 --- a/activitysim/abm/models/atwork_subtour_frequency.py +++ b/activitysim/abm/models/atwork_subtour_frequency.py @@ -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", diff --git a/activitysim/abm/models/auto_ownership.py b/activitysim/abm/models/auto_ownership.py index c99344566..924f6568c 100644 --- a/activitysim/abm/models/auto_ownership.py +++ b/activitysim/abm/models/auto_ownership.py @@ -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", diff --git a/activitysim/abm/models/cdap.py b/activitysim/abm/models/cdap.py index 7eb082e4d..d54677622 100644 --- a/activitysim/abm/models/cdap.py +++ b/activitysim/abm/models/cdap.py @@ -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 diff --git a/activitysim/abm/models/free_parking.py b/activitysim/abm/models/free_parking.py index 97b70ade3..562642687 100644 --- a/activitysim/abm/models/free_parking.py +++ b/activitysim/abm/models/free_parking.py @@ -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", diff --git a/activitysim/abm/models/joint_tour_composition.py b/activitysim/abm/models/joint_tour_composition.py index ab57298e0..600092d03 100644 --- a/activitysim/abm/models/joint_tour_composition.py +++ b/activitysim/abm/models/joint_tour_composition.py @@ -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", diff --git a/activitysim/abm/models/joint_tour_frequency.py b/activitysim/abm/models/joint_tour_frequency.py index 93a8aa475..c926aaeb6 100644 --- a/activitysim/abm/models/joint_tour_frequency.py +++ b/activitysim/abm/models/joint_tour_frequency.py @@ -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", diff --git a/activitysim/abm/models/joint_tour_frequency_composition.py b/activitysim/abm/models/joint_tour_frequency_composition.py index be52c900a..1a1ae688d 100644 --- a/activitysim/abm/models/joint_tour_frequency_composition.py +++ b/activitysim/abm/models/joint_tour_frequency_composition.py @@ -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, diff --git a/activitysim/abm/models/location_choice.py b/activitysim/abm/models/location_choice.py index 3017235f6..cbead87aa 100644 --- a/activitysim/abm/models/location_choice.py +++ b/activitysim/abm/models/location_choice.py @@ -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, @@ -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, diff --git a/activitysim/abm/models/mandatory_tour_frequency.py b/activitysim/abm/models/mandatory_tour_frequency.py index a80b82904..5fbac1233 100644 --- a/activitysim/abm/models/mandatory_tour_frequency.py +++ b/activitysim/abm/models/mandatory_tour_frequency.py @@ -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", diff --git a/activitysim/abm/models/non_mandatory_tour_frequency.py b/activitysim/abm/models/non_mandatory_tour_frequency.py index 972c4b3dc..97ac64ccb 100644 --- a/activitysim/abm/models/non_mandatory_tour_frequency.py +++ b/activitysim/abm/models/non_mandatory_tour_frequency.py @@ -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, diff --git a/activitysim/abm/models/parking_location_choice.py b/activitysim/abm/models/parking_location_choice.py index 2c9b5097c..a82cfbf2b 100644 --- a/activitysim/abm/models/parking_location_choice.py +++ b/activitysim/abm/models/parking_location_choice.py @@ -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, diff --git a/activitysim/abm/models/school_escorting.py b/activitysim/abm/models/school_escorting.py index b3aaf2b60..acb61a130 100644 --- a/activitysim/abm/models/school_escorting.py +++ b/activitysim/abm/models/school_escorting.py @@ -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, diff --git a/activitysim/abm/models/stop_frequency.py b/activitysim/abm/models/stop_frequency.py index 4513c2477..9f86c0c6d 100644 --- a/activitysim/abm/models/stop_frequency.py +++ b/activitysim/abm/models/stop_frequency.py @@ -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", diff --git a/activitysim/abm/models/telecommute_frequency.py b/activitysim/abm/models/telecommute_frequency.py index 19bd850f8..35f759905 100755 --- a/activitysim/abm/models/telecommute_frequency.py +++ b/activitysim/abm/models/telecommute_frequency.py @@ -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", diff --git a/activitysim/abm/models/tour_scheduling_probabilistic.py b/activitysim/abm/models/tour_scheduling_probabilistic.py index 324db4566..58d574f6c 100644 --- a/activitysim/abm/models/tour_scheduling_probabilistic.py +++ b/activitysim/abm/models/tour_scheduling_probabilistic.py @@ -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( diff --git a/activitysim/abm/models/transit_pass_ownership.py b/activitysim/abm/models/transit_pass_ownership.py index 48e01c47d..cfed9c266 100644 --- a/activitysim/abm/models/transit_pass_ownership.py +++ b/activitysim/abm/models/transit_pass_ownership.py @@ -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", diff --git a/activitysim/abm/models/transit_pass_subsidy.py b/activitysim/abm/models/transit_pass_subsidy.py index 7d1f320e2..2fa6ac83f 100644 --- a/activitysim/abm/models/transit_pass_subsidy.py +++ b/activitysim/abm/models/transit_pass_subsidy.py @@ -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", diff --git a/activitysim/abm/models/trip_destination.py b/activitysim/abm/models/trip_destination.py index 6dea50980..1b4b56bda 100644 --- a/activitysim/abm/models/trip_destination.py +++ b/activitysim/abm/models/trip_destination.py @@ -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, @@ -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, @@ -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, diff --git a/activitysim/abm/models/trip_matrices.py b/activitysim/abm/models/trip_matrices.py index 12c2e4f6a..eb59495b7 100644 --- a/activitysim/abm/models/trip_matrices.py +++ b/activitysim/abm/models/trip_matrices.py @@ -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__) @@ -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: diff --git a/activitysim/abm/models/trip_mode_choice.py b/activitysim/abm/models/trip_mode_choice.py index b9091522c..d91473be8 100644 --- a/activitysim/abm/models/trip_mode_choice.py +++ b/activitysim/abm/models/trip_mode_choice.py @@ -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, diff --git a/activitysim/abm/models/trip_purpose.py b/activitysim/abm/models/trip_purpose.py index 5f208f514..909a2a10a 100644 --- a/activitysim/abm/models/trip_purpose.py +++ b/activitysim/abm/models/trip_purpose.py @@ -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( diff --git a/activitysim/abm/models/trip_purpose_and_destination.py b/activitysim/abm/models/trip_purpose_and_destination.py index 1c91f19bf..7252c0319 100644 --- a/activitysim/abm/models/trip_purpose_and_destination.py +++ b/activitysim/abm/models/trip_purpose_and_destination.py @@ -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( diff --git a/activitysim/abm/models/trip_scheduling.py b/activitysim/abm/models/trip_scheduling.py index fa69567ec..011071f94 100644 --- a/activitysim/abm/models/trip_scheduling.py +++ b/activitysim/abm/models/trip_scheduling.py @@ -458,6 +458,8 @@ class TripSchedulingSettings(PydanticReadable): CONSTANTS: dict[str, Any] = {} + drop_unused_columns: bool = True + @workflow.step(copy_tables=False) def trip_scheduling( diff --git a/activitysim/abm/models/trip_scheduling_choice.py b/activitysim/abm/models/trip_scheduling_choice.py index d6f6d5886..6f2057e8e 100644 --- a/activitysim/abm/models/trip_scheduling_choice.py +++ b/activitysim/abm/models/trip_scheduling_choice.py @@ -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( diff --git a/activitysim/abm/models/util/logsums.py b/activitysim/abm/models/util/logsums.py index 328957965..2735f9450 100644 --- a/activitysim/abm/models/util/logsums.py +++ b/activitysim/abm/models/util/logsums.py @@ -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, diff --git a/activitysim/abm/models/util/mode.py b/activitysim/abm/models/util/mode.py index b6e6bbb23..ffccd2b9b 100644 --- a/activitysim/abm/models/util/mode.py +++ b/activitysim/abm/models/util/mode.py @@ -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, @@ -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, @@ -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, diff --git a/activitysim/abm/models/util/tour_destination.py b/activitysim/abm/models/util/tour_destination.py index fbc8113e2..c5d7fa70d 100644 --- a/activitysim/abm/models/util/tour_destination.py +++ b/activitysim/abm/models/util/tour_destination.py @@ -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, @@ -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, ) diff --git a/activitysim/abm/models/util/tour_od.py b/activitysim/abm/models/util/tour_od.py index 22ea4a310..c5c849228 100644 --- a/activitysim/abm/models/util/tour_od.py +++ b/activitysim/abm/models/util/tour_od.py @@ -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, @@ -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, diff --git a/activitysim/abm/models/util/vectorize_tour_scheduling.py b/activitysim/abm/models/util/vectorize_tour_scheduling.py index 17425d75b..fd18faa30 100644 --- a/activitysim/abm/models/util/vectorize_tour_scheduling.py +++ b/activitysim/abm/models/util/vectorize_tour_scheduling.py @@ -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, @@ -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, diff --git a/activitysim/abm/models/vehicle_allocation.py b/activitysim/abm/models/vehicle_allocation.py index a341493ff..7c5f8d1df 100644 --- a/activitysim/abm/models/vehicle_allocation.py +++ b/activitysim/abm/models/vehicle_allocation.py @@ -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, diff --git a/activitysim/abm/models/vehicle_type_choice.py b/activitysim/abm/models/vehicle_type_choice.py index 813652459..95a44a736 100644 --- a/activitysim/abm/models/vehicle_type_choice.py +++ b/activitysim/abm/models/vehicle_type_choice.py @@ -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, diff --git a/activitysim/abm/models/work_from_home.py b/activitysim/abm/models/work_from_home.py index 234302b70..8cd7e0827 100755 --- a/activitysim/abm/models/work_from_home.py +++ b/activitysim/abm/models/work_from_home.py @@ -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", diff --git a/activitysim/core/configuration/logit.py b/activitysim/core/configuration/logit.py index a7f507aeb..a828c4226 100644 --- a/activitysim/core/configuration/logit.py +++ b/activitysim/core/configuration/logit.py @@ -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): """ diff --git a/activitysim/core/interaction_sample.py b/activitysim/core/interaction_sample.py index 33f498029..d4cb06a1e 100644 --- a/activitysim/core/interaction_sample.py +++ b/activitysim/core/interaction_sample.py @@ -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, @@ -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, @@ -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, @@ -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, diff --git a/activitysim/core/interaction_sample_simulate.py b/activitysim/core/interaction_sample_simulate.py index bee7c79a7..1b17a56f5 100644 --- a/activitysim/core/interaction_sample_simulate.py +++ b/activitysim/core/interaction_sample_simulate.py @@ -28,6 +28,7 @@ def _interaction_sample_simulate( trace_label, trace_choice_name, estimator, + drop_unused_columns, skip_choice=False, *, chunk_sizer: chunk.ChunkSizer, @@ -140,7 +141,7 @@ def _interaction_sample_simulate( # 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 (estimator is None) and drop_unused_columns: choosers = util.drop_unused_chooser_columns( choosers, @@ -379,6 +380,7 @@ def interaction_sample_simulate( alternatives, spec, choice_column, + drop_unused_columns, allow_zero_probs=False, zero_prob_choice_val=None, log_alt_losers=False, @@ -478,6 +480,7 @@ def interaction_sample_simulate( chunk_trace_label, trace_choice_name, estimator, + drop_unused_columns, skip_choice, chunk_sizer=chunk_sizer, ) diff --git a/activitysim/core/interaction_simulate.py b/activitysim/core/interaction_simulate.py index dedc6759f..782777091 100644 --- a/activitysim/core/interaction_simulate.py +++ b/activitysim/core/interaction_simulate.py @@ -599,6 +599,7 @@ def _interaction_simulate( choosers: pd.DataFrame, alternatives: pd.DataFrame, spec: pd.DataFrame, + drop_unused_columns, skims=None, locals_d: Mapping = None, sample_size=None, @@ -701,7 +702,7 @@ def _interaction_simulate( # check if tracing is enabled and if we have trace targets # if not estimation mode, drop unused columns - if (not have_trace_targets) and (estimator is None): + if (not have_trace_targets) and (estimator is None) and drop_unused_columns: choosers = util.drop_unused_chooser_columns( choosers, @@ -899,6 +900,7 @@ def interaction_simulate( choosers, alternatives, spec, + drop_unused_columns, log_alt_losers=False, skims=None, locals_d=None, @@ -976,6 +978,7 @@ def interaction_simulate( chooser_chunk, alternatives, spec, + drop_unused_columns, skims=skims, locals_d=locals_d, sample_size=sample_size, diff --git a/activitysim/core/simulate.py b/activitysim/core/simulate.py index db67687c6..48a73dc12 100644 --- a/activitysim/core/simulate.py +++ b/activitysim/core/simulate.py @@ -1454,6 +1454,7 @@ def _simple_simulate( choosers, spec, nest_spec, + drop_unused_choosers_columns, skims=None, locals_d=None, custom_chooser: CustomChooser_T = None, @@ -1521,7 +1522,7 @@ def _simple_simulate( # if tracing is not enabled, drop unused columns # if not estimation mode, drop unused columns - if (not have_trace_targets) and (estimator is None): + if (not have_trace_targets) and (estimator is None) and drop_unused_choosers_columns: # drop unused variables in chooser table choosers = util.drop_unused_chooser_columns( choosers, @@ -1590,6 +1591,7 @@ def simple_simulate( choosers, spec, nest_spec, + drop_unused_columns, skims=None, locals_d=None, custom_chooser=None, @@ -1623,6 +1625,7 @@ def simple_simulate( chooser_chunk, spec, nest_spec, + drop_unused_columns, skims=skims, locals_d=locals_d, custom_chooser=custom_chooser, @@ -1917,6 +1920,7 @@ def _simple_simulate_logsums( choosers, spec, nest_spec, + drop_unused_columns, skims=None, locals_d=None, trace_label=None, @@ -1939,7 +1943,7 @@ def _simple_simulate_logsums( have_trace_targets = state.tracing.has_trace_targets(choosers) # if tracing is not enabled, drop unused columns - if not have_trace_targets: + if (not have_trace_targets) and drop_unused_columns: # drop unused variables in chooser table choosers = util.drop_unused_chooser_columns( choosers, @@ -1978,6 +1982,7 @@ def simple_simulate_logsums( choosers, spec, nest_spec, + drop_unused_columns, skims=None, locals_d=None, chunk_size=0, @@ -2011,6 +2016,7 @@ def simple_simulate_logsums( chooser_chunk, spec, nest_spec, + drop_unused_columns, skims, locals_d, chunk_trace_label,