Skip to content

Improvements to Pyomo component iteration#2829

Merged
blnicho merged 37 commits intoPyomo:mainfrom
jsiirola:iter-improvements
May 23, 2023
Merged

Improvements to Pyomo component iteration#2829
blnicho merged 37 commits intoPyomo:mainfrom
jsiirola:iter-improvements

Conversation

@jsiirola
Copy link
Copy Markdown
Member

Fixes # .

Summary/Motivation:

This PR cleans up how component iteration is implemented for Pyomo Components. In particular, it:

  • standardizes the meaning of .keys(sort=True) / .values(sort=True) / .items(sort=True) to be consistent with methods like component_data_objects(sort=True).
  • it reduces the amount of sorting done when walking "normal" Pyomo models (that use ordered sets)
  • it greatly simplifies the implementation of the Block DFS and BFS walkers
  • it converts 1-off flag classes to use standard Enums, and moves those enums to a new module to make importingg them without creating circular imports easier
  • it makes sorted iterators significantly more efficient for References
  • all Sets now support reversed()

Changes proposed in this PR:

  • (see above)

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.

jsiirola added a commit to jsiirola/pyomo that referenced this pull request May 15, 2023
@codecov
Copy link
Copy Markdown

codecov bot commented May 15, 2023

Codecov Report

Patch coverage: 98.82% and project coverage change: +0.02 🎉

Comparison is base (47deef1) 87.18% compared to head (47d8696) 87.21%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2829      +/-   ##
==========================================
+ Coverage   87.18%   87.21%   +0.02%     
==========================================
  Files         765      768       +3     
  Lines       88471    89952    +1481     
==========================================
+ Hits        77134    78449    +1315     
- Misses      11337    11503     +166     
Flag Coverage Δ
linux 84.31% <98.82%> (+0.06%) ⬆️
osx 74.01% <98.82%> (+0.10%) ⬆️
other 84.48% <98.43%> (+0.06%) ⬆️
win 81.86% <98.82%> (+0.07%) ⬆️

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

Impacted Files Coverage Δ
pyomo/core/base/param.py 81.69% <ø> (ø)
pyomo/repn/beta/matrix.py 74.17% <66.66%> (-0.14%) ⬇️
pyomo/core/base/indexed_component.py 91.21% <97.95%> (+0.72%) ⬆️
...rib/cp/transform/logical_to_disjunctive_program.py 96.61% <100.00%> (+0.05%) ⬆️
pyomo/core/base/__init__.py 100.00% <100.00%> (ø)
pyomo/core/base/block.py 92.40% <100.00%> (+0.95%) ⬆️
pyomo/core/base/enums.py 100.00% <100.00%> (ø)
pyomo/core/base/global_set.py 97.97% <100.00%> (+6.31%) ⬆️
pyomo/core/base/indexed_component_slice.py 97.15% <100.00%> (+0.06%) ⬆️
pyomo/core/base/reference.py 98.64% <100.00%> (+1.04%) ⬆️
... and 2 more

... and 14 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@blnicho blnicho self-requested a review May 16, 2023 18:42

def __delitem__(self):
raise NotImplementedError

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If it's not too much hassle, maybe add tests for these new methods?

@blnicho blnicho merged commit f471a97 into Pyomo:main May 23, 2023
@jsiirola jsiirola deleted the iter-improvements branch May 23, 2023 15:26
jsiirola added a commit to jsiirola/pyomo that referenced this pull request May 23, 2023
jsiirola added a commit to jsiirola/pyomo that referenced this pull request May 26, 2023
blnicho added a commit that referenced this pull request May 26, 2023
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