From 9aec46f4fa246367355b9284a21936a5e41f7682 Mon Sep 17 00:00:00 2001 From: Matt Richards Date: Tue, 10 Mar 2026 20:52:55 +1100 Subject: [PATCH 1/2] ENH: add trip scheduling choice explicit chunking --- .../abm/models/trip_scheduling_choice.py | 10 +++++++-- .../test_misc/test_trip_scheduling_choice.py | 22 +++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/activitysim/abm/models/trip_scheduling_choice.py b/activitysim/abm/models/trip_scheduling_choice.py index 81d908ef1b..0b73cd6ccb 100644 --- a/activitysim/abm/models/trip_scheduling_choice.py +++ b/activitysim/abm/models/trip_scheduling_choice.py @@ -276,7 +276,9 @@ def run_trip_scheduling_choice( choosers, chunk_trace_label, chunk_sizer, - ) in chunk.adaptive_chunked_choosers(state, indirect_tours, trace_label): + ) in chunk.adaptive_chunked_choosers( + state, indirect_tours, trace_label, explicit_chunk_size=model_settings.explicit_chunk + ): # Sort the choosers and get the schedule alternatives choosers = choosers.sort_index() schedules = generate_schedule_alternatives(choosers).sort_index() @@ -350,7 +352,11 @@ class TripSchedulingChoiceSettings(LogitComponentSettings, extra="forbid"): Settings for the `trip_scheduling_choice` component. """ - pass + explicit_chunk: float = 0 + """ + If > 0, use this chunk size instead of adaptive chunking. + If less than 1, use this fraction of the total number of rows. + """ @workflow.step diff --git a/activitysim/abm/test/test_misc/test_trip_scheduling_choice.py b/activitysim/abm/test/test_misc/test_trip_scheduling_choice.py index 6823a5b123..6db004b438 100644 --- a/activitysim/abm/test/test_misc/test_trip_scheduling_choice.py +++ b/activitysim/abm/test/test_misc/test_trip_scheduling_choice.py @@ -4,6 +4,7 @@ import os from pathlib import Path +from pandas.testing import assert_frame_equal from activitysim.abm.models import trip_scheduling_choice as tsc from activitysim.abm.tables.skims import skim_dict @@ -285,3 +286,24 @@ def test_run_trip_scheduling_choice(model_spec, tours, skims, locals_dict): # check that tours with no inbound stops have zero inbound duration assert out_tours[tsc.IB_DURATION].mask(in_tours[tsc.HAS_IB_STOPS], 0).sum() == 0 + + # confirm explicit chunking is supported and doesn't affect results + model_settings_explicit_chunk = tsc.TripSchedulingChoiceSettings( + **{ + "SPEC": "placeholder.csv", + "compute_settings": { + "protect_columns": ["origin", "destination", "schedule_id"] + }, + } + ) + out_tours_chunked = tsc.run_trip_scheduling_choice( + state, + model_spec, + tours, + skims, + locals_dict, + trace_label="PyTest Trip Scheduling", + model_settings=model_settings_explicit_chunk, + ) + assert_frame_equal(out_tours, out_tours_chunked) + From 74f787998523cb581199a9f4ca3501659fc26d0f Mon Sep 17 00:00:00 2001 From: Jeffrey Newman Date: Thu, 16 Jul 2026 09:04:27 -0400 Subject: [PATCH 2/2] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- .../abm/test/test_misc/test_trip_scheduling_choice.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/activitysim/abm/test/test_misc/test_trip_scheduling_choice.py b/activitysim/abm/test/test_misc/test_trip_scheduling_choice.py index 6db004b438..bc51a74e21 100644 --- a/activitysim/abm/test/test_misc/test_trip_scheduling_choice.py +++ b/activitysim/abm/test/test_misc/test_trip_scheduling_choice.py @@ -288,9 +288,12 @@ def test_run_trip_scheduling_choice(model_spec, tours, skims, locals_dict): assert out_tours[tsc.IB_DURATION].mask(in_tours[tsc.HAS_IB_STOPS], 0).sum() == 0 # confirm explicit chunking is supported and doesn't affect results + state.settings.chunk_training_mode = "explicit" + model_settings_explicit_chunk = tsc.TripSchedulingChoiceSettings( **{ "SPEC": "placeholder.csv", + "explicit_chunk": 2, "compute_settings": { "protect_columns": ["origin", "destination", "schedule_id"] }, @@ -299,7 +302,7 @@ def test_run_trip_scheduling_choice(model_spec, tours, skims, locals_dict): out_tours_chunked = tsc.run_trip_scheduling_choice( state, model_spec, - tours, + in_tours.copy(deep=True), skims, locals_dict, trace_label="PyTest Trip Scheduling",