-
Notifications
You must be signed in to change notification settings - Fork 562
Adding support for abs in numeric differentiation #2232
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
Conversation
pyomo/core/tests/unit/test_derivs.py
Outdated
| m = pyo.ConcreteModel() | ||
| m.x = pyo.Var(initialize=2.0) | ||
| e = 2 * abs(m.x) | ||
| with self.assertRaises(DifferentiationException): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, I prefer assertRaisesRegex() so that we check that the correct message is being raised (I have run across bugs where we thought we were testing that Pyomo correctly handled an exception only to find that there was a bug that happened to raise the same exception).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Fixed.
Codecov Report
@@ Coverage Diff @@
## main #2232 +/- ##
==========================================
- Coverage 82.77% 82.73% -0.04%
==========================================
Files 607 607
Lines 76842 76903 +61
==========================================
+ Hits 63604 63629 +25
- Misses 13238 13274 +36
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
pyomo/core/tests/unit/test_derivs.py
Outdated
| m.x = pyo.Var(initialize=2.0) | ||
| e = 2 * abs(m.x) | ||
| with self.assertRaises(DifferentiationException): | ||
| with self.assertRaisesRegexp(DifferentiationException, 'Cannot perform symbolic differentiation of abs\(x\)'): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reference string needs to be declared as a raw string to avoid errors in recent Python versions. (I will fix that shortly)
Summary/Motivation:
This PR adds support for
absin Pyomo's numeric differentiation. Attempting symbolic differentiation on anabsexpression with a non-constant argument will still raise an exception.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: