-
Notifications
You must be signed in to change notification settings - Fork 535
Update PyROS Uncertainty Set Validation Methods #3558
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
Open
jas-yao
wants to merge
35
commits into
Pyomo:main
Choose a base branch
from
jas-yao:pyros-uncertaintyset-validation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,005
−447
Conversation
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
Thanks for all the feedback and suggestions @jsiirola ! """Reproducing FBBT error."""
from pyomo.contrib.pyros.uncertainty_sets import PolyhedralSet
from pyomo.contrib.fbbt.fbbt import fbbt
# create a polyhedral uncertainty set that is not bounded
lhs_coefficients_mat = [[1, 2, 3], [4, 5, 6]]
rhs_vec = [1, 3]
pset = PolyhedralSet(lhs_coefficients_mat, rhs_vec)
# create pyomo model and pprint
bounding_model = pset._create_bounding_model()
bounding_model.pprint()
# try to use fbbt and pprint results
fbbt(bounding_model)
bounding_model.pprint() with traceback Traceback (most recent call last):
File "<string>", line 17, in __PYTHON_EL_eval
File "/Users/yletian/Documents/projects/pyomo/pyomo/contrib/pyros/temp_fbbt_error.py", line 15, in <module>
fbbt(bounding_model)
~~~~^^^^^^^^^^^^^^^^
File "/Users/yletian/Documents/projects/pyomo/pyomo/contrib/fbbt/fbbt.py", line 1543, in fbbt
_new_var_bounds = _fbbt_block(comp, config)
File "/Users/yletian/Documents/projects/pyomo/pyomo/contrib/fbbt/fbbt.py", line 1429, in _fbbt_block
_new_var_bounds = _fbbt_con(c, config)
File "/Users/yletian/Documents/projects/pyomo/pyomo/contrib/fbbt/fbbt.py", line 1334, in _fbbt_con
visitorA.walk_expression(con.expr)
~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
File "/Users/yletian/Documents/projects/pyomo/pyomo/core/expr/visitor.py", line 276, in walk_expression
result = self._process_node(root, RECURSION_LIMIT)
File "/Users/yletian/Documents/projects/pyomo/pyomo/core/expr/visitor.py", line 472, in _process_node_bx
tmp = self.beforeChild(node, child, child_idx)
File "/Users/yletian/Documents/projects/pyomo/pyomo/contrib/fbbt/fbbt.py", line 1160, in beforeChild
return _before_child_handlers[child.__class__](self, child)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
File "/Users/yletian/Documents/projects/pyomo/pyomo/contrib/fbbt/fbbt.py", line 1108, in _register_new_before_child_handler
if child.is_variable_type():
^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'numpy.int64' object has no attribute 'is_variable_type' This was fixed with your suggested changes: @@ -19,7 +19,7 @@ from pyomo.core.expr.visitor import (
identify_variables,
StreamBasedExpressionVisitor,
)
-from pyomo.core.expr.numvalue import nonpyomo_leaf_types, value
+from pyomo.common.numeric_types import nonpyomo_leaf_types, native_numeric_types, value
from pyomo.core.expr.numvalue import is_fixed
import pyomo.contrib.fbbt.interval as interval
import math
@@ -1105,7 +1105,9 @@ def _before_external_function(visitor, child):
def _register_new_before_child_handler(visitor, child):
handlers = _before_child_handlers
child_type = child.__class__
- if child.is_variable_type():
+ if child_type in native_numeric_types:
+ handlers[child_type] = _before_constant
+ elif child.is_variable_type():
handlers[child_type] = _before_var
elif not child.is_potentially_variable():
handlers[child_type] = _before_NPV With this fix, I'll take a closer look into possibly replacing the 2N bounding problems of |
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.
Summary/Motivation:
This PR provides updates to PyROS uncertainty set validation methods and related tests.
Here, a
validate
method replaces theis_valid
method (which solves 2N bounding problems to check for set boundedness) in all uncertainty sets, with each set having its own customvalidate
method that efficiently checks set-specific attributes and raises informative exceptions if any issues are found.Changes proposed in this PR:
is_bounded
andis_nonempty
methods in baseUncertaintySet
class_solve_feasibility
method in baseUncertaintySet
classis_valid
withvalidate
method that runsis_bounded
andis_nonempty
in the baseUncertaintySet
classvalidate
in subclass uncertainty sets to check set-specific attributesvalidate
methodis_bounded
,is_nonempty
,_solve_feasibility
, andvalidate
methodsLegal Acknowledgement
By contributing to this software project, I have read the contribution guide and agree to the following terms and conditions for my contribution: