-
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
Integrate new Set rewrite into Pyomo #1319
Conversation
Move to a more aggressive approach for immediately constructing Sets when the data is already present / defined.
We map 1-tuple indexes to scalars. Set.get() allows consumers like IndexedComponent to both test membership and retrieve the mapped value, so that the _data dictionary can match the underlying Set.
...including concrete, virtual, value and check_values()
This restores legacy functionality whereby dimensioned Set objects can be initialized from flat lists (necessary for DAT file input).
This updates Set methods so that they better match the behavior in the Python set methods they are copying.
Adding additional cases for backwards compatibility with the previous RangeSet implementation.
Constructing an abstract component that us using the class name as the component name should update the component name to the concrete version of the class.
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.
Overall, this looks great. I do have a few minor comments/questions.
Just merged this with my dae-tools branch and discovered a bug. When creating a from pyomo.environ import *
from pyomo.dae import *
m = ConcreteModel()
m.time = ContinuousSet(bounds=(0,1))
m.set1 = Set(initialize=['a','b','c'])
disc = TransformationFactory('dae.collocation')
disc.apply_to(m, wrt=m.time, nfe=2, ncp=2, scheme='LAGRANGE-RADAU')
op = m.time * m.set1
print(m.time._fe) displaying |
This also seems to happen when expanding arcs. |
@Robbybp ContinuousSet should be fixed now (including a test to catch this case in the future). Thanks! |
Yep, the code that led to me finding this works now, thanks for fixing |
Hoping to get around to looking over this PR this week.
… On Mar 10, 2020, at 2:45 PM, Robert Parker ***@***.***> wrote:
@Robbybp ContinuousSet should be fixed now (including a test to catch this case in the future). Thanks!
Yep, the code that led to me finding this works now, thanks for fixing
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
@blnicho, I think I addressed all your comments except for updating the |
examples/kernel/variables.py
Outdated
@@ -1,14 +1,15 @@ | |||
import pyomo.kernel as pmo | |||
import pyomo.environ as pe |
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'm hoping to keep pyomo.kernel as self contained as possible until the two modeling layers are compatible. Is this import necessary?
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.
Unfortunately, for this example., yes: Reals
is a proper Pyomo Set. The alternative was to change all the Reals
in the example to RealSet
from kernel, and I wasn't exactly clear as to what you were trying to highlight in the example.
return False | ||
|
||
|
||
class BinarySet(object): |
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 BinarySet, BooleanSet objects don't seem to serve a purpose in kernel.
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 agree, but I think I ran into examples that used BinarySet and BooleanSet from kernel. Regardless, I left them in for backwards compatibility. If we can later confirm that they are not necessary (and no one is using them), then we can delete.
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'm fairly certain this these are not needed in kernel. Binary, yes. BinarySet, no.
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.
BooleanSet is used in pyomo/core/tests/unit/kernel/test_variable.py
(and historically BooleanSet
and BinarySet
have been the same class), but it was not imported into pyomo.kernel
.
Part of my refactoring was so that kernel
proper only needs RealSet
and IntegerSet
, and can infer Binary from a standard get_interval()
method. Longer term, I would like to standardize on BinarySet
where needed so that we can re-purpose BooleanSet
to be a proper Boolean (i.e., True/False, and not 0/1) set.
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.
Thanks, @ghackebeil. Some responses below.
Do you see any concerns with Pyomo now having two implementations of RealSet
and IntegerSet
(one for core/kernel and one for core/base)? When Reals/Integers/etc got moved to be proper Set objects, this meant that we needed to support the RealSet / IntegerSet objects in both frameworks (at least for backwards compatibility).
examples/kernel/variables.py
Outdated
@@ -1,14 +1,15 @@ | |||
import pyomo.kernel as pmo | |||
import pyomo.environ as pe |
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.
Unfortunately, for this example., yes: Reals
is a proper Pyomo Set. The alternative was to change all the Reals
in the example to RealSet
from kernel, and I wasn't exactly clear as to what you were trying to highlight in the example.
return False | ||
|
||
|
||
class BinarySet(object): |
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 agree, but I think I ran into examples that used BinarySet and BooleanSet from kernel. Regardless, I left them in for backwards compatibility. If we can later confirm that they are not necessary (and no one is using them), then we can delete.
This restores global set (Reals, etc) imports for kernel users through the pyomo.kernel environment. Reverting changes to the kernel variables documentation and example.
Fixes #N/A
Summary/Motivation:
This integrates the set rewrite (#1111 / #326) into all of Pyomo.
Changes proposed in this PR:
indices
,contains_indices
methods to initializer objectscore.kernal.set_tyes
tocore.base.set
. Stubs (sufficient for kernel's needs) were reimplemented in Kernel.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: