Skip to content

Support a reusable 'var_cache' within the IdentifyVariableVisitor#3966

Open
jsiirola wants to merge 5 commits into
Pyomo:mainfrom
jsiirola:identify_vars_seen_cache
Open

Support a reusable 'var_cache' within the IdentifyVariableVisitor#3966
jsiirola wants to merge 5 commits into
Pyomo:mainfrom
jsiirola:identify_vars_seen_cache

Conversation

@jsiirola
Copy link
Copy Markdown
Member

@jsiirola jsiirola commented May 29, 2026

Fixes # .

Summary/Motivation:

This implements a minor performance improvement when we want to collect all the variables used by a model. The previous implementation ended up using two "seen" caches: one within the IdentifyVariableVisitor, and the other in the get_var_from_components() utility. This allows a client to instantiate an IdentifyVariableVisitor with a persistent "seen" cache, thereby eliminating the redundant caches.

This implementation is fully backwards compatible with the previous IdentifyVariableViaitor / identify_variables implementation.

Changes proposed in this PR:

  • Support a persistent "seen" cache within the IdentifyVariableVisitor
  • Update get_vars_from_components to use a single persistent "seen" cache
  • Add a get_vars() utility that is an alias for get_vars_from_components(ctype=(Constraint, Objective))
  • Test the new behavior

AI-Use Disclosure

  • AI tools were NOT used during the preparation of this PR

or

  • AI tools contributed to the development of this PR

    • AI tools generated documentation (including the PR description/comments, code comments, and/or Sphinx documentation)
    • AI tools generated tests (baselines, examples, and/or code)
    • AI tools generated code (apart from tests)

    Review process (select ONE):

    • Rewritten: All AI-generated content was rewritten by me before being committed.
    • Reviewed/verified: I retained AI-generated content and verified it before committing. Verification included (as applicable):
      • Ran the code and fixed issues
      • Added and ran tests
      • Checked correctness/logic of code and tests
      • Checked for alignment with the contribution guide
      • Considered security implications
    • As-is: AI-generated content was commited directly to the repository

Notes for reviewers (optional):

Legal Acknowledgement

By contributing to this software project, I have read the contribution guide and agree to the following terms and conditions for my contribution:

  1. I agree my contributions are submitted under the BSD license.
  2. I represent I am authorized to make the contributions and grant the license. If my employer has rights to intellectual property that includes these contributions, I represent that I have received permission to make contributions and grant the required license on behalf of that employer.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 29, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.12%. Comparing base (3603b1e) to head (33064ab).
⚠️ Report is 6 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3966   +/-   ##
=======================================
  Coverage   90.11%   90.12%           
=======================================
  Files         909      909           
  Lines      108580   108641   +61     
=======================================
+ Hits        97847    97912   +65     
+ Misses      10733    10729    -4     
Flag Coverage Δ
builders 29.10% <23.80%> (+<0.01%) ⬆️
default 86.11% <100.00%> (?)
expensive 35.13% <95.23%> (?)
linux 87.63% <100.00%> (-1.99%) ⬇️
linux_other 87.63% <100.00%> (+<0.01%) ⬆️
oldsolvers 28.04% <23.80%> (+<0.01%) ⬆️
osx 83.05% <100.00%> (+<0.01%) ⬆️
win 85.37% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jsiirola jsiirola changed the title Support a reusable 'seen' cache within the IdentifyVariableVisitor Support a reusable 'var_cache' within the IdentifyVariableVisitor May 29, 2026
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.

1 participant