Skip to content

Add ParameterizedQuadraticRepn and corresponding expression walker#3324

Merged
blnicho merged 35 commits intoPyomo:mainfrom
shermanjasonaf:quadratic-walker-wrt
Aug 20, 2024
Merged

Add ParameterizedQuadraticRepn and corresponding expression walker#3324
blnicho merged 35 commits intoPyomo:mainfrom
shermanjasonaf:quadratic-walker-wrt

Conversation

@shermanjasonaf
Copy link
Copy Markdown
Contributor

@shermanjasonaf shermanjasonaf commented Jul 17, 2024

Summary/Motivation:

With upcoming changes to the preprocessing subroutine of the contributed PyROS solver, and, in particular, the preprocessor's coefficient matching step, which requires analyzing expression trees in terms of selected variables only, this PR adds a ParameterizedQuadraticRepn object that has the same structure as the existing QuadraticRepn (of #2823), and an accompanying expression walker that extends the behavior of the QuadraticRepnVisitor and ParameterizedLinearRepnVisitor (of #3268) to allow for collection of quadratic/bilinear terms with potentially variable coefficient expressions. As with the ParameterizedLinearRepnVisitor, variables to be treated as data are specified through the wrt argument to the ParameterizedQuadraticRepnVisitor constructor.

Changes proposed in this PR:

  • Add ParameterizedQuadraticRepn class that inherits from QuadraticRepn but re-implements all methods/attributes that assume that constants and coefficients are numbers rather than expressions.
  • Add ParameterizedQuadraticRepnVisitor that inherits from ParameterizedLinearRepnVisitor and features:
    • redefined exitNode handlers for products of linear expressions and products of quadratic/nonlinear expressions
    • a redefined finalizeResult method
    • expansion of nonlinear products by default

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 Jul 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.55%. Comparing base (b480497) to head (7ab6270).
Report is 30 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3324      +/-   ##
==========================================
+ Coverage   88.52%   88.55%   +0.03%     
==========================================
  Files         868      869       +1     
  Lines       98436    98687     +251     
==========================================
+ Hits        87144    87396     +252     
+ Misses      11292    11291       -1     
Flag Coverage Δ
linux 86.08% <100.00%> (+0.04%) ⬆️
osx 75.73% <100.00%> (+0.06%) ⬆️
other 86.58% <100.00%> (+0.03%) ⬆️
win 83.89% <100.00%> (+0.04%) ⬆️

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 jsiirola July 23, 2024 19:07
Copy link
Copy Markdown
Member

@jsiirola jsiirola left a comment

Choose a reason for hiding this comment

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

This has a huge amount of repeated code (from a mix of parameterized_linear and quadratic. In the future we should refactor the walkers so that we can make better use of mixins or more general methods to clean this up.

@blnicho blnicho merged commit 40ad402 into Pyomo:main Aug 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects

Development

Successfully merging this pull request may close these issues.

5 participants