Skip to content

Conversation

@dhensle
Copy link
Contributor

@dhensle dhensle commented Oct 21, 2025

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

  • Updated the trip scheduling and departure choice configuration files to use SPEC instead of SPECIFICATION, standardized preprocessor settings, and added compute_settings and protect_columns for 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]
  • Refactored the TripSchedulingChoiceSettings class to inherit from LogitComponentSettings and 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

Testing Enhancements

Prototype and Test Configuration Updates

  • Added new and updated test configuration files for network level-of-service and time period settings, improving test coverage for different scenarios. (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]
  • Updated prototype settings to sample households, disable parking location, and enable multiprocessing for more flexible and efficient runs. (activitysim/examples/prototype_arc/configs/settings.yaml, [1] [2]

Miscellaneous

  • Removed unnecessary .gitignore entries 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]

@dhensle dhensle marked this pull request as ready for review October 30, 2025 03:32
@jpn-- jpn-- requested review from Copilot and jpn-- October 30, 2025 16:11
Copy link
Contributor

Copilot AI left a 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 TripSchedulingChoiceSettings to inherit from LogitComponentSettings instead of defining fields manually
  • Updates configuration files to use standardized field names (SPEC instead of SPECIFICATION, preprocessor instead of PREPROCESSOR)
  • Un-comments and updates trip scheduling and departure choice tests to be functional again
  • Adds new test configuration files and fixtures
  • Removes placeholder .gitignore files 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
Copy link

Copilot AI Oct 30, 2025

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.

Suggested change
SPECIFICATION: trip_departure_choice.csv
SPEC: trip_departure_choice.csv

Copilot uses AI. Check for mistakes.
#COEFFICIENTS: trip_departure_choice_coeff.csv


PREPROCESSOR:
Copy link

Copilot AI Oct 30, 2025

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.

Suggested change
PREPROCESSOR:
preprocessor:

Copilot uses AI. Check for mistakes.
Comment on lines +122 to +123
A pytest fixture that returns the data folder location.
:return: folder location for any necessary data to initialize the tests
Copy link

Copilot AI Oct 30, 2025

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.

Suggested change
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")

Copilot uses AI. Check for mistakes.
assert len(departures) == len(trips)
pd.testing.assert_index_equal(departures.index, trips.index)

departures = pd.concat([trips, departures], axis=1)
Copy link

Copilot AI Oct 30, 2025

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.

Suggested change
departures = pd.concat([trips, departures], axis=1)
# Removed unused assignment to departures

Copilot uses AI. Check for mistakes.
Comment on lines +12 to +14
from .setup_utils import setup_dirs


Copy link

Copilot AI Oct 30, 2025

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.

Suggested change
from .setup_utils import setup_dirs

Copilot uses AI. Check for mistakes.
Copy link
Member

@jpn-- jpn-- left a 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)
Copy link
Member

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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:
Copy link
Member

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
Copy link
Member

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:
Copy link
Member

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]
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants