Draft
Make global constants available to interaction-based model expressions#1095
Conversation
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
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Constants defined in
constants.yamlwere unavailable in location choice, destination choice, and tour scheduling specs. Those models evaluate utilities viainteraction_simulate.eval_interaction_utilities(), which used only the caller-suppliedlocals_d, unlikesimulate.eval_utilities()/assign.local_utilities()which already merge in the global constants.Changes
activitysim/core/interaction_simulate.py: seed the evaluation locals withstate.get_global_constants()before applying the caller'slocals_d, so model-supplied locals (modelCONSTANTS, skims,df) still win on name collisions. Because this is the single entry point used byinteraction_sample,interaction_simulate, andinteraction_sample_simulate, it covers all the affected models, in both the sharrow and non-sharrow paths.activitysim/core/test/test_interaction_simulate.py: tests that a constant fromconstants.yamlresolves in an interaction spec expression, and thatlocals_dtakes precedence over a same-named global constant.With this, a spec expression such as
distance_km * KM_TO_MILEresolves 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 insimulate.eval_utilities, but is worth a look during review.