Skip to content
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

QuadraticRepnVisitor: Improve nonlinear expression expansion #2997

Merged
merged 4 commits into from
Sep 19, 2023

Conversation

jsiirola
Copy link
Member

@jsiirola jsiirola commented Sep 18, 2023

Fixes #2275 .

Summary/Motivation:

This resolves some issues in the QuadraticRepnVisitor nonlinear term expansion logic. In particular, it needed specialized handlers for LINEAR * GENERAL and GENERAL * GENERAL so that nonlinear terms are correctly expanded when expand_nonlinear_products is True.

Changes proposed in this PR:

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

codecov bot commented Sep 18, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.22% 🎉

Comparison is base (c471729) 87.85% compared to head (0992622) 88.08%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2997      +/-   ##
==========================================
+ Coverage   87.85%   88.08%   +0.22%     
==========================================
  Files         769      769              
  Lines       89497    89496       -1     
==========================================
+ Hits        78632    78835     +203     
+ Misses      10865    10661     -204     
Flag Coverage Δ
linux 85.19% <100.00%> (+1.45%) ⬆️
osx 74.99% <100.00%> (+<0.01%) ⬆️
other 85.36% <100.00%> (+1.45%) ⬆️
win 82.43% <100.00%> (+0.04%) ⬆️

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

Files Changed Coverage Δ
pyomo/repn/quadratic.py 93.08% <100.00%> (+2.07%) ⬆️

... and 6 files with indirect coverage changes

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

@@ -294,6 +293,9 @@ def _handle_product_nonlinear(visitor, node, arg1, arg2):
(_QUADRATIC, _GENERAL): _handle_product_nonlinear,
# Replace handler from the linear walker
(_LINEAR, _LINEAR): _handle_product_linear_linear,
(_GENERAL, _GENERAL): _handle_product_nonlinear,
Copy link
Contributor

Choose a reason for hiding this comment

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

Just so I understand - _GENERAL implies nonlinear, correct?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes.

Copy link
Member Author

Choose a reason for hiding this comment

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

...I used "GENERAL" as a shorthand for "General nonlinear", because just using "NONLINEAR" would have been confusing with QUADRATIC.

Copy link
Contributor

@michaelbynum michaelbynum left a comment

Choose a reason for hiding this comment

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

Looks good.

Unrelated - what is the default for expand_nonlinear_products?

@jsiirola
Copy link
Member Author

@michaelbynum: The default is currently False (because it is not needed for the LP writer), but I was thinking about it this morning, and I was going to propose (either here or at the Dev call) that we change the default to True, and then the LP writer could set it explicitly to False.

@michaelbynum
Copy link
Contributor

@michaelbynum: The default is currently False (because it is not needed for the LP writer), but I was thinking about it this morning, and I was going to propose (either here or at the Dev call) that we change the default to True, and then the LP writer could set it explicitly to False.

I like that proposal. The expansion is very powerful, and I don't think we should "hide" that functionality (I realize it is not really hidden, but, hopefully, you get my point).

@blnicho blnicho merged commit 1f9b35f into Pyomo:main Sep 19, 2023
33 checks passed
@jsiirola jsiirola deleted the quad-expansion-issue-2275 branch September 22, 2023 20:25
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.

Extract linear/quadratic/nonlinear terms from nonlinear expressions
4 participants