Skip to content

Make global constants available to interaction-based model expressions - #1095

Draft
jpn-- with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-global-constants-availability
Draft

Make global constants available to interaction-based model expressions#1095
jpn-- with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-global-constants-availability

Conversation

Copilot AI commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Constants defined in constants.yaml were unavailable in location choice, destination choice, and tour scheduling specs. Those models evaluate utilities via interaction_simulate.eval_interaction_utilities(), which used only the caller-supplied locals_d, unlike simulate.eval_utilities() / assign.local_utilities() which already merge in the global constants.

Changes

  • activitysim/core/interaction_simulate.py: seed the evaluation locals with state.get_global_constants() before applying the caller's locals_d, so model-supplied locals (model CONSTANTS, skims, df) still win on name collisions. Because this is the single entry point used by interaction_sample, interaction_simulate, and interaction_sample_simulate, it covers all the affected models, in both the sharrow and non-sharrow paths.
# avoid altering caller's passed-in locals_d parameter (they may be looping)
# global constants are always available, but can be overridden by locals_d
locals_d = {**state.get_global_constants(), **(locals_d or {})}
  • activitysim/core/test/test_interaction_simulate.py: tests that a constant from constants.yaml resolves in an interaction spec expression, and that locals_d takes precedence over a same-named global constant.

With this, a spec expression such as distance_km * KM_TO_MILE resolves in destination/location choice and tour scheduling specs using a single system-wide constant.

Note

Constants now shadow chooser columns of the same name in interaction specs (resolvers precede DataFrame columns in fast_eval). This matches existing behavior in simulate.eval_utilities, but is worth a look during review.

Copilot AI linked an issue Jul 30, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Fix global constants not available in all models Make global constants available to interaction-based model expressions Jul 30, 2026
Copilot finished work on behalf of jpn-- July 30, 2026 21:14
Copilot AI requested a review from jpn-- July 30, 2026 21:14
@jpn--

jpn-- commented Jul 30, 2026

Copy link
Copy Markdown
Member

@copilot your PR is failing the checks. Run the pre-commit checks on your code, do not attempt to fix black formatting errors without actually calling black to fix them.

Copilot finished work on behalf of jpn-- July 30, 2026 21:44
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.

Global constants not available in all models

2 participants