Skip to content

Simplify expressions generated by TemplateSumExpression #3196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Apr 2, 2024

Conversation

jsiirola
Copy link
Member

Fixes # .

Summary/Motivation:

This PR improves the automatic generation / simplification of expressions generated from TemplateSumExpression. In particular it:

  • uses the mutable_expression context manager to generate the sum expression (so that expression simplification can occur)
  • updates the mutable expression handlers to simplify sequential native numeric type terms into a single term
  • updates the TemplateSumExpression resolver to return 0 or a single term instead of a sum expression when appropriate

This generates more natural (and flatter) sum expressions.

Changes proposed in this PR:

  • collapse sequential native constants in the mutable expression context
  • use the mutable expression context manager to resolve TemplateSumExpression objects

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.

Copy link

codecov bot commented Mar 14, 2024

Codecov Report

Attention: Patch coverage is 93.10345% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 88.39%. Comparing base (cd9d6ce) to head (ba105ea).

Files Patch % Lines
pyomo/core/expr/numeric_expr.py 93.33% 1 Missing ⚠️
pyomo/core/expr/template_expr.py 92.30% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3196      +/-   ##
==========================================
- Coverage   88.40%   88.39%   -0.02%     
==========================================
  Files         846      846              
  Lines       95131    95139       +8     
==========================================
- Hits        84099    84096       -3     
- Misses      11032    11043      +11     
Flag Coverage Δ
linux 86.33% <93.10%> (-0.01%) ⬇️
osx 76.17% <93.10%> (-0.01%) ⬇️
other 86.52% <93.10%> (-0.02%) ⬇️
win 83.82% <93.10%> (-0.02%) ⬇️

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.

@blnicho blnicho requested a review from emma58 March 26, 2024 18:45
@blnicho blnicho merged commit cc33f35 into Pyomo:main Apr 2, 2024
33 checks passed
@jsiirola jsiirola deleted the simplify-linear-expression branch April 4, 2024 04:46
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.

4 participants