-
Notifications
You must be signed in to change notification settings - Fork 117
Trip Scheduling Choice -- Same Results Single Process and Multi-Process #1005
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
single process run with
…ctivitysim into trip_scheduling_rng_fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR makes several updates to the trip scheduling and departure choice models and their test configurations:
- Migrates
TripSchedulingChoiceSettingsto inherit fromLogitComponentSettingsinstead of defining fields manually - Updates configuration files to use standardized field names (
SPECinstead ofSPECIFICATION,preprocessorinstead ofPREPROCESSOR) - Un-comments and updates trip scheduling and departure choice tests to be functional again
- Adds new test configuration files and fixtures
- Removes placeholder
.gitignorefiles from output directories - Adds a new simulation script and test configuration for the prototype_arc example
Reviewed Changes
Copilot reviewed 12 out of 14 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| activitysim/examples/prototype_arc/test/simulation.py | Adds a command-line script to run simulations via ActivitySim's CLI |
| activitysim/examples/prototype_arc/test/output/trace/.gitignore | Removes .gitignore for trace output directory |
| activitysim/examples/prototype_arc/test/output/cache/.gitignore | Removes .gitignore for cache output directory |
| activitysim/examples/prototype_arc/test/output/.gitignore | Removes .gitignore for main output directory |
| activitysim/examples/prototype_arc/configs/trip_scheduling_choice.yaml | Updates to use standard field names and adds compute_settings with protect_columns |
| activitysim/examples/prototype_arc/configs/settings.yaml | Adds test configuration settings including sample size, model settings check flag, and multiprocessing settings |
| activitysim/abm/test/test_misc/test_trip_scheduling_choice.py | Un-comments and updates tests with proper imports and fixtures, including state initialization |
| activitysim/abm/test/test_misc/test_trip_departure_choice.py | Un-comments and updates tests with state initialization and model settings loading |
| activitysim/abm/test/test_misc/configs_test_misc/trip_scheduling_choice.yaml | Adds test configuration file with standardized field names |
| activitysim/abm/test/test_misc/configs_test_misc/trip_departure_choice.yaml | Adds test configuration file using legacy field names |
| activitysim/abm/test/test_misc/configs_test_misc/settings_60_min.yaml | Adds skim settings configuration for 60-minute time periods |
| activitysim/abm/test/test_misc/configs_test_misc/network_los.yaml | Adds network level-of-service configuration |
| activitysim/abm/models/trip_scheduling_choice.py | Refactors TripSchedulingChoiceSettings to inherit from LogitComponentSettings, adds line to sort schedule alternatives |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # - start_period | ||
| # - end_period | ||
|
|
||
| SPECIFICATION: trip_departure_choice.csv |
Copilot
AI
Oct 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The configuration uses the deprecated field name 'SPECIFICATION' instead of 'SPEC'. The TripSchedulingChoiceSettings in trip_scheduling_choice.yaml uses 'SPEC' (the standardized field name), and this should be consistent. Consider updating to 'SPEC' to match the pattern used in LogitComponentSettings.
| SPECIFICATION: trip_departure_choice.csv | |
| SPEC: trip_departure_choice.csv |
| #COEFFICIENTS: trip_departure_choice_coeff.csv | ||
|
|
||
|
|
||
| PREPROCESSOR: |
Copilot
AI
Oct 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The configuration uses the deprecated field name 'PREPROCESSOR' (uppercase) instead of 'preprocessor' (lowercase). The trip_scheduling_choice.yaml file in the same directory uses 'preprocessor', and this inconsistency should be resolved. Consider updating to 'preprocessor' to match the standardized naming convention.
| PREPROCESSOR: | |
| preprocessor: |
| A pytest fixture that returns the data folder location. | ||
| :return: folder location for any necessary data to initialize the tests |
Copilot
AI
Oct 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docstring incorrectly states that this fixture 'returns the data folder location', but it actually returns the module name string 'summarize'. The docstring should be updated to accurately describe what the fixture returns and its purpose.
| A pytest fixture that returns the data folder location. | |
| :return: folder location for any necessary data to initialize the tests | |
| A pytest fixture that returns the module name string used in the test setup. | |
| :return: module name string ("summarize") |
| assert len(departures) == len(trips) | ||
| pd.testing.assert_index_equal(departures.index, trips.index) | ||
|
|
||
| departures = pd.concat([trips, departures], axis=1) |
Copilot
AI
Oct 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Variable departures is not used.
| departures = pd.concat([trips, departures], axis=1) | |
| # Removed unused assignment to departures |
| from .setup_utils import setup_dirs | ||
|
|
||
|
|
Copilot
AI
Oct 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Import of 'setup_dirs' is not used.
| from .setup_utils import setup_dirs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some changes...
|
|
||
| schedules = pd.concat([no_stops, one_way, two_way], sort=True) | ||
| schedules[SCHEDULE_ID] = np.arange(1, schedules.shape[0] + 1) | ||
| schedules.sort_values(by=["tour_id", SCHEDULE_ID], inplace=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is the actual "fix" for the non-reproducibility problem... let's put a comment noting that for posterity.
|
|
||
| schedules = pd.concat([no_stops, one_way, two_way], sort=True) | ||
| schedules[SCHEDULE_ID] = np.arange(1, schedules.shape[0] + 1) | ||
| schedules.sort_values(by=["tour_id", SCHEDULE_ID], inplace=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| schedules.sort_values(by=["tour_id", SCHEDULE_ID], inplace=True) | |
| # sort by tour id and schedule id to ensure reproducible random results are actually | |
| # stable and reproducible between single and multi-process model runs. | |
| schedules.sort_values(by=["tour_id", SCHEDULE_ID], inplace=True) |
| @@ -0,0 +1,20 @@ | |||
| #METADATA: | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's "METADATA" for here? Seems like nothing, since it's commented out? We should not add new code/tests with commented out old code.
| # - end_period | ||
|
|
||
| SPECIFICATION: trip_departure_choice.csv | ||
| #COEFFICIENTS: trip_departure_choice_coeff.csv |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete?
| @@ -0,0 +1,28 @@ | |||
| #METADATA: | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should have no extra commented out lines unless it's obvious why
|
|
||
| @pytest.fixture(scope="module") | ||
| def trips(): | ||
| outbound_array = [True, True, False, False, False, True, True, False, False, True] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason why this one single array is written as a variable instead of as a literal in the DF definition below? If so, note why. If not, make it consistent to avoid confusion.
Fix for #891
This pull request introduces several improvements and refactors to the trip scheduling and departure choice components, settings, and configuration files in the ActivitySim ABM prototype and test suite. The main changes include updating configuration schemas for consistency, refactoring settings classes for better inheritance and maintainability, improving sorting and spec reading logic, and enhancing test coverage and utility functions.
Configuration and Settings Refactoring
SPECinstead ofSPECIFICATION, standardized preprocessor settings, and addedcompute_settingsandprotect_columnsfor consistency and clarity. (activitysim/examples/prototype_arc/configs/trip_scheduling_choice.yaml,activitysim/abm/test/test_misc/configs_test_misc/trip_scheduling_choice.yaml,activitysim/abm/test/test_misc/configs_test_misc/trip_departure_choice.yaml, [1] [2] [3]TripSchedulingChoiceSettingsclass to inherit fromLogitComponentSettingsand removed redundant fields, streamlining the settings schema for trip scheduling choice. (activitysim/abm/models/trip_scheduling_choice.py, activitysim/abm/models/trip_scheduling_choice.pyL347-R352)Logic and Code Improvements
tour_idandSCHEDULE_IDin the schedule generation function to ensure deterministic and organized output. (activitysim/abm/models/trip_scheduling_choice.py, activitysim/abm/models/trip_scheduling_choice.pyR85) (This was the actual fix to Reproducible random does not work in trip scheduling choice #891)SPECIFICATIONtoSPECin the segment spec reading function for consistency with configuration changes. (activitysim/abm/models/trip_scheduling_choice.py, activitysim/abm/models/trip_scheduling_choice.pyL210-R212)Testing Enhancements
activitysim/abm/test/test_misc/test_trip_departure_choice.py, activitysim/abm/test/test_misc/test_trip_departure_choice.pyL1-R177)Prototype and Test Configuration Updates
activitysim/abm/test/test_misc/configs_test_misc/network_los.yaml, [1];activitysim/abm/test/test_misc/configs_test_misc/settings_60_min.yaml, [2]activitysim/examples/prototype_arc/configs/settings.yaml, [1] [2]Miscellaneous
.gitignoreentries in test output directories for cleaner repository management. (activitysim/examples/prototype_arc/test/output/.gitignore, [1];activitysim/examples/prototype_arc/test/output/cache/.gitignore, [2];activitysim/examples/prototype_arc/test/output/trace/.gitignore, [3]