Adding ParameterizedLinearRepn and corresponding walker#3268
Adding ParameterizedLinearRepn and corresponding walker#3268emma58 merged 49 commits intoPyomo:mainfrom
Conversation
…espect to specified variables, treating others as data
…onstant and multiplier are numeric types
…dle expressions so that I don't kill performance
…nstants' that are actually Pyomo expressions
… whole conundrum about fixed variables
…g the meaning of the 'wrt' argument
…ars regardless of if they are parameters or Vars from the perspective of the walker
… all tests passing
… in walker_exitNode
…resentation to not be the same as LinearRepn
jsiirola
left a comment
There was a problem hiding this comment.
Overall this looks good! Just a few questions...
| if places is None: | ||
| test.assertEqual(_a, _b) | ||
| else: | ||
| test.assertAlmostEqual(_a, _b, places=places) |
There was a problem hiding this comment.
Instead of this, should we just have places default to the default value in assertAlmostEqual?
There was a problem hiding this comment.
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.
| def _handle_product_constant_constant(visitor, node, arg1, arg2): | ||
| return _CONSTANT, arg1[1] * arg2[1] |
There was a problem hiding this comment.
Why did you need to override this?
There was a problem hiding this comment.
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.
Codecov ReportAttention: Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Fixes # .
Summary/Motivation:
With eventual bilevel programming applications in mind, this PR adds a
ParameterizedLinearRepnobject that has the same structure asLinearRepnbut allows for an argumentwrtto specify a list of Vars that will be treated as data for the purposes of creating the repn.Changes proposed in this PR:
ParameterizedLinearRepncomponent that inherits fromLinearRepnbut has to re-implement everything that assumes that constants and coefficients are numbers rather than expressions.ParameterizedLinearRepnVisitorthat inherits fromLinearRepnVisitorbut adds a "pseudo-constant" expression type and new exitNode handlers for psuedo-constants (i.e., Pyomo expressions that we are treating as constant mathematically)assertExpressionsEqualLegal Acknowledgement
By contributing to this software project, I have read the contribution guide and agree to the following terms and conditions for my contribution: