-
Notifications
You must be signed in to change notification settings - Fork 541
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
base: main
Are you sure you want to change the base?
Conversation
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 |
@jas-yao is this ready for review or should we wait for the TODO's in the description to be completed? |
Hi @blnicho, I will need to finish some of the TODOs before this will be ready for review. |
@jas-yao I'm going to convert this to a draft until it is ready for review. |
… into pyros-uncertaintyset-validation
@shermanjasonaf, @blnicho, @jsiirola I have completed the TODOs and think this PR should be ready for review now. |
Fixes: #2724, #3508
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
methodsTODO
_compute_parameter_bounds
validate_array
to allvalidate
methodstest_validate
tests into separate tests for each validation check_validate
method forPolyhedralSet
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: