-
Notifications
You must be signed in to change notification settings - Fork 526
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
Add is_reference API #1740
Add is_reference API #1740
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1740 +/- ##
==========================================
+ Coverage 72.76% 74.96% +2.20%
==========================================
Files 629 638 +9
Lines 91423 91845 +422
==========================================
+ Hits 66522 68855 +2333
+ Misses 24901 22990 -1911
Continue to review full report at Codecov.
|
As @jsiirola has pointed out, I've changed the method name here to reflect this and have added some tests. |
I like this a lot. |
@carldlaird @michaelbynum @andrewlee94 We are trying to come up with the name for the method to test if an object owns its own data. Any suggestions on an |
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.
One minor question, otherwise this looks fine.
pyomo/core/base/indexed_component.py
Outdated
@@ -258,6 +258,10 @@ def is_indexed(self): | |||
"""Return true if this component is indexed""" | |||
return self._index is not UnindexedComponent_set | |||
|
|||
def is_reference(self): | |||
""" Return True if this component is a reference. """ |
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.
Should we expand this description to include the idea of a reference "not owning" it's data objects?
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.
I think that's a good idea. Have updated.
Addresses #1640 .
Summary/Motivation:
Several users have noticed that there is no officially supported way to distinguish a component that was created by the
Reference
function. However, it is very useful to be able to make this distinction. Also, in some cases, it is useful to get the object(slice)from which a reference was created.This PR addresses the first point by adding an
is_reference
owns_data
method toPyomoObject
, and the second by tacking on areferent
attribute to the component returned by theReference
function.Changes proposed in this PR:
owns_data
method toPyomoObject
andIndexedComponent
referent
attribute to component returned byReference
owns_data
to address a hiccup inIndexedComponent
that causes iteration over references-to-references to be incredibly slow.One intent of this PR is to provide a concrete talking point for the proposals in #1640.
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: