Repository navigation
Description
explicit_chunk does not limit memory in park_and_ride_lot_choice when it is run for location choice logsums, which can result in out of memory in workplace_location with large amount workers.
Describe the bug
When include_pnr_for_logsums: True is set in the tour mode choice settings, the location choice models (e.g. workplace_location) run the park-and-ride lot choice model while computing logsums. run_park_and_ride_lot_choice is called once with the whole logsum chooser table, which has one row per (person, sampled destination) pair joined to the persons table. For a large region this is millions of rows per process.
Before interaction_simulate is called, run_park_and_ride_lot_choice makes several full copies of that table:
choosers.reset_index(drop=False)when the chooser index is not unique (always the case for logsums, since each person has several sampled destinations),filter_chooser_to_transit_accessible_destinations(boolean mask copy),logsums.setup_skimsand the chooserpreprocessor(adds columns),- the optional
CHOOSER_FILTER_EXPR.query()(another copy).
The component's explicit_chunk setting is only passed on to interaction_simulate, so it only limits the memory used by the final utility evaluation, after the memory for the steps above has already been used. Setting explicit_chunk to a smaller value, or changing num_processes, therefore does not prevent the failure. The failure only moves between the preprocessor and eval_interaction_utils, depending on how much memory is left when each step runs.
To Reproduce
- In
tour_mode_choice.yamlsetinclude_pnr_for_logsums: True. Use a location choice model with logsums (e.g.workplace_location.yamlwithLOGSUM_SETTINGS: tour_mode_choice.yaml) and a large number of persons. - Use multiprocessing with
chunk_training_mode: explicit, and setexplicit_chunkinpark_and_ride_lot_choice.yaml(any value, e.g.200000or20000) or leave it unset. - Run on a machine with 256 GB of memory (large region, about 1.2 million persons in the largest
workplace_locationsegment,SAMPLE_SIZE: 30, about 22 park-and-ride lots). - The run is killed by the operating system in the largest segment of
workplace_location. With 6 processes the main process reports:
WARNING - activitysim.core.mp_tasks - process mp_households_4 failed with exitcode -9
mp_tasks - MainProcess - fail_fast terminating remaining running processes
The last lines in the sub-process logs are, with park-and-ride explicit_chunk set:
DEBUG - activitysim.core.flow - 73348 chooser rows on workplace_location.i1.logsums.work_veryhigh.compute_logsums.pnr_lot_choice.interaction_simulate.interaction_simulate.eval_interaction_utils
and, with park-and-ride explicit_chunk unset:
DEBUG - activitysim.core.assign - workplace_location.i1.logsums.work_veryhigh.compute_logsums.pnr_lot_choice.preprocessor.park_and_ride_lot_choice_preprocessor.csv.assign_variables tour_type = df.tour_type if 'tour_type' in df.columns else tour_type_imputed
Peak system memory (all processes) in the logs follows the number of logsum rows, not the chunk settings:
| Segment | Logsum rows (all processes) | Peak memory |
|---|---|---|
| work_lowmed | ~6.9 M | 78 GB |
| work_high | ~21.7 M | 180 GB |
| work_veryhigh | ~32.4 M | over 251 GB (killed) |
This fits about 30 GB of base memory plus about 6.9 KB per row. In the failing runs memory grew from about 50 GB to about 250 GB in about 35 seconds, before the first park-and-ride interaction_simulate chunk was logged. The park-and-ride interaction itself is small (about 22 lots), the failing chunk had between 73 thousand and 550 thousand interaction rows.
Expected behavior
The memory used by run_park_and_ride_lot_choice should be limited by the component's explicit_chunk setting, for all the steps in the component and not only for interaction_simulate, and the results should not change.
Screenshots
Not applicable.
Additional context
run_park_and_ride_lot_choiceis also used by tour mode choice, tour scheduling logsums, at-work subtour mode choice, the disaggregate accessibility model and the kiss-and-ride and TNC-and-ride lot choice models. A fix inrun_park_and_ride_lot_choiceapplies to all of them.- Lowering
SAMPLE_SIZEfor the location choice model also lowers memory (rows scale withSAMPLE_SIZE), but it changes the model (different sampled alternatives and random draws), so it is not a fix for production runs. - The park-and-ride random draws depend on the (unique) chooser index and not on which other choosers are processed together, so the lot choice can be run in slices of choosers without changing the choices, as long as the unique index is created once for the whole table.
Activity
bwentl commentedon Nov 20, 2026
I finished running my test with the new branch proposed by @jpn-- PR #1110
@dhensle - Overall things look good, but I would like to still look into memory peak at park and ride model(s) before we close this issue.
Overall, the memory reduction is quite substantial even without park and ride chunking, and the issue of previous memory peaks in models such as workplace location has completely went away. No changes to config, just swapping the ActivitySim branch.
I am seeing jump on memory use in kiss and ride, tnc and ride, and park and ride. The memory curve looks weird for those three models, and it is not super clear to me why it looks that way. Since park-and-ride and related models is now the memory bottleneck.
perfprofile_1119_memmiser.html
dhensle commentedon Nov 20, 2026
Yeah, great improvement! The knr and tncnr models are currently extensions for the TransLink model. I will take a look at them and see if there's some changes that need to be included in those models.