Numpy expression integration (part 1)#2027
Merged
michaelbynum merged 12 commits intoPyomo:mainfrom Jun 28, 2021
Merged
Conversation
Codecov Report
@@ Coverage Diff @@
## main #2027 +/- ##
==========================================
+ Coverage 82.71% 82.74% +0.03%
==========================================
Files 592 592
Lines 73355 73522 +167
==========================================
+ Hits 60675 60837 +162
- Misses 12680 12685 +5
Continue to review full report at Codecov.
|
Contributor
michaelbynum
left a comment
There was a problem hiding this comment.
Overall, this looks great. I had one suggestion for the tests.
| m.x = Var() | ||
| e = np.float64(5) * m.x | ||
| self.assertIs(type(e), MonomialTermExpression) | ||
| self.assertEqual(str(e), "5.0*x") |
Contributor
There was a problem hiding this comment.
I would recommend using the compare_expressions function from pyomo/core/expr/compare.py throughout these tests.
michaelbynum
approved these changes
Jun 28, 2021
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #685, fixes #31
Summary/Motivation:
This is the initial step toward integrating numpy with the Pyomo expression system. This provides basic support for generating Pyomo expressions contained in NumPy ndarrays.
It is by no means complete (there will be at least 3 more parts to finish the integration), but I felt breaking this up into chunks will make it easier to review. However, this PR will support the following example:
Please note that this implementation is NOT intended to be "numpy-fast": we still generate the same expanded Pyomo expression trees that we always have. However, this is intended to lay the groundwork for a fast "matrix-based" expression system later.
Changes proposed in this PR:
IndexedComponentsintondarrayobjectsndarrayinInitializer()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: