Skip to content

Adding ParameterizedLinearRepn and corresponding walker#3268

Merged
emma58 merged 49 commits intoPyomo:mainfrom
emma58:linear-walker-wrt
Jul 9, 2024
Merged

Adding ParameterizedLinearRepn and corresponding walker#3268
emma58 merged 49 commits intoPyomo:mainfrom
emma58:linear-walker-wrt

Conversation

@emma58
Copy link
Copy Markdown
Contributor

@emma58 emma58 commented May 21, 2024

Fixes # .

Summary/Motivation:

With eventual bilevel programming applications in mind, this PR adds a ParameterizedLinearRepn object that has the same structure as LinearRepn but allows for an argument wrt to specify a list of Vars that will be treated as data for the purposes of creating the repn.

Changes proposed in this PR:

  • Adds ParameterizedLinearRepn component that inherits from LinearRepn but has to re-implement everything that assumes that constants and coefficients are numbers rather than expressions.
  • Adds ParameterizedLinearRepnVisitor that inherits from LinearRepnVisitor but adds a "pseudo-constant" expression type and new exitNode handlers for psuedo-constants (i.e., Pyomo expressions that we are treating as constant mathematically)
  • Adds handling for nan in assertExpressionsEqual

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.

emma58 added 30 commits April 8, 2024 16:48
…espect to specified variables, treating others as data
…dle expressions so that I don't kill performance
…nstants' that are actually Pyomo expressions
…ars regardless of if they are parameters or Vars from the perspective of the walker
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.

Overall this looks good! Just a few questions...

Comment on lines +237 to +240
if places is None:
test.assertEqual(_a, _b)
else:
test.assertAlmostEqual(_a, _b, places=places)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Instead of this, should we just have places default to the default value in assertAlmostEqual?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There are a few tests in contrib.piecewise where I had to reduce it because of numerical stuff. So that's why there's an argument for it.

Comment on lines +237 to +238
def _handle_product_constant_constant(visitor, node, arg1, arg2):
return _CONSTANT, arg1[1] * arg2[1]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why did you need to override this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Because I didn't include the deprecation path for 0 * nan. I'll add a comment because it can get un-overridden when that deprecation path goes away.

@emma58 emma58 requested a review from jsiirola June 25, 2024 19:14
@codecov
Copy link
Copy Markdown

codecov bot commented Jul 9, 2024

Codecov Report

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

Project coverage is 88.48%. Comparing base (53d5cad) to head (3235f92).
Report is 912 commits behind head on main.

Files with missing lines Patch % Lines
pyomo/core/expr/compare.py 90.00% 1 Missing ⚠️
pyomo/repn/parameterized_linear.py 99.49% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3268      +/-   ##
==========================================
+ Coverage   86.46%   88.48%   +2.02%     
==========================================
  Files         801      868      +67     
  Lines       96758    98423    +1665     
==========================================
+ Hits        83661    87091    +3430     
+ Misses      13097    11332    -1765     
Flag Coverage Δ
linux 86.30% <99.16%> (+0.02%) ⬆️
osx 75.61% <99.16%> (+0.05%) ⬆️
other 86.49% <99.16%> (+0.03%) ⬆️
win 83.80% <99.16%> (+0.03%) ⬆️

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.

@emma58 emma58 merged commit b50cfac into Pyomo:main Jul 9, 2024
@emma58 emma58 deleted the linear-walker-wrt branch July 9, 2024 19:30
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