File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -565,18 +565,25 @@ def _interaction_sample(
565565 if compute_settings is None :
566566 compute_settings = ComputeSettings ()
567567
568- # drop variables before the interaction dataframe is created
568+ # drop variables before the interaction dataframe is created, otherwise the
569+ # cross join of choosers and alternatives can blow up memory usage
570+ if compute_settings .drop_unused_columns :
571+ # when tracing, the unpruned choosers and alternatives have already been
572+ # written out above, so here we only need to preserve the columns used to
573+ # identify the traced rows in the interaction dataframe
574+ trace_columns = (
575+ ["person_id" , "proto_person_id" , "proto_household_id" ]
576+ if have_trace_targets
577+ else []
578+ )
569579
570- # check if tracing is enabled and if we have trace targets
571- # if not estimation mode, drop unused columns
572- if (not have_trace_targets ) and (compute_settings .drop_unused_columns ):
573580 choosers = util .drop_unused_columns (
574581 choosers ,
575582 spec ,
576583 locals_d ,
577584 custom_chooser = None ,
578585 sharrow_enabled = sharrow_enabled ,
579- additional_columns = compute_settings .protect_columns ,
586+ additional_columns = trace_columns + compute_settings .protect_columns ,
580587 )
581588
582589 alternatives = util .drop_unused_columns (
Original file line number Diff line number Diff line change @@ -31,6 +31,13 @@ Users should remove these settings from their configuration files. Nothing else
3131needs to be done to take advantage of this change; unused columns continue to be
3232dropped automatically.
3333
34+ Relatedly, ` interaction_sample ` (used for destination sampling) previously
35+ skipped dropping unused columns entirely when a run had trace targets, which
36+ could result in very large interaction dataframes for traced runs. Unused
37+ columns are now dropped in that case as well, retaining only the columns needed
38+ to identify the traced rows. The complete chooser and alternatives tables are
39+ still written to the trace output before the columns are dropped.
40+
3441### Changed Default for Sharrow "Fastmath" Optimization
3542
3643The default setting for the "fastmath" optimization in sharrow has been changed
You can’t perform that action at this time.
0 commit comments