Skip to content

Commit 8dc8ca4

Browse files
committed
Support explicit_chunk for mode-choice components
Location, destination, and scheduling components already honor the `explicit_chunk` setting (a fixed chunk size, used when chunk_training_mode: explicit), but mode-choice components did not: the setting was never plumbed from the component settings into simple_simulate's chunk loop. This wires it through: add `explicit_chunk` to TemplatedLogitComponentSettings (the base for mode-choice settings), and pass it via mode_choice_simulate -> simple_simulate -> adaptive_chunked_choosers. Defaults to 0 (unchanged behavior). This lets tour_mode_choice and trip_mode_choice run with a fixed, bounded per-chunk memory footprint, which is what makes large samples fit on memory-constrained machines under chunk_training_mode: explicit.
1 parent aa1a3ff commit 8dc8ca4

4 files changed

Lines changed: 16 additions & 1 deletion

File tree

‎activitysim/abm/models/trip_mode_choice.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ def trip_mode_choice(
228228
trace_choice_name="trip_mode_choice",
229229
estimator=estimator,
230230
compute_settings=model_settings.compute_settings,
231+
explicit_chunk_size=model_settings.explicit_chunk,
231232
)
232233

233234
if state.settings.trace_hh_id:

‎activitysim/abm/models/util/mode.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def mode_choice_simulate(
3636
trace_column_names=None,
3737
estimator: Optional[Estimator] = None,
3838
compute_settings: ComputeSettings | None = None,
39+
explicit_chunk_size: float = 0,
3940
):
4041
"""
4142
common method for both tour_mode_choice and trip_mode_choice
@@ -74,6 +75,7 @@ def mode_choice_simulate(
7475
estimator=estimator,
7576
trace_column_names=trace_column_names,
7677
compute_settings=compute_settings,
78+
explicit_chunk_size=explicit_chunk_size,
7779
)
7880

7981
# for consistency, always return dataframe, whether or not logsums were requested
@@ -176,6 +178,7 @@ def run_tour_mode_choice_simulate(
176178
trace_column_names=trace_column_names,
177179
estimator=estimator,
178180
compute_settings=model_settings.compute_settings,
181+
explicit_chunk_size=model_settings.explicit_chunk,
179182
)
180183

181184
return choices

‎activitysim/core/configuration/logit.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,14 @@ class TemplatedLogitComponentSettings(LogitComponentSettings, extra="forbid"):
200200
segment-specific names.
201201
"""
202202

203+
explicit_chunk: float = 0
204+
"""
205+
If > 0, use this fixed chunk size (number of chooser rows) instead of adaptive
206+
chunking. If less than 1, use this fraction of the total number of rows. Plumbed
207+
through mode_choice_simulate -> simple_simulate so mode-choice models can be chunked
208+
(default 0 = unchanged chunkless/adaptive behavior).
209+
"""
210+
203211

204212
class LocationComponentSettings(BaseLogitComponentSettings):
205213
"""

‎activitysim/core/simulate.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1719,6 +1719,7 @@ def simple_simulate(
17191719
trace_choice_name=None,
17201720
trace_column_names=None,
17211721
compute_settings: ComputeSettings | None = None,
1722+
explicit_chunk_size: float = 0,
17221723
):
17231724
"""
17241725
Run an MNL or NL simulation for when the model spec does not involve alternative
@@ -1737,7 +1738,9 @@ def simple_simulate(
17371738
chooser_chunk,
17381739
chunk_trace_label,
17391740
chunk_sizer,
1740-
) in chunk.adaptive_chunked_choosers(state, choosers, trace_label):
1741+
) in chunk.adaptive_chunked_choosers(
1742+
state, choosers, trace_label, explicit_chunk_size=explicit_chunk_size
1743+
):
17411744
choices = _simple_simulate(
17421745
state,
17431746
chooser_chunk,

0 commit comments

Comments
 (0)