Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion pyomo/contrib/fbbt/expression_bounds_walker.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,18 @@ def _handle_AbsExpression(visitor, node, arg):
return interval_abs(*arg)


def _handle_unsupported_unary_function(visitor, node, arg):
logger.warning(
f"Unsupported unary function '{node.getname()}' found while walking "
"expression tree; returning (-inf, inf) for the expression bounds."
)
return -inf, inf


def _handle_UnaryFunctionExpression(visitor, node, arg):
return _unary_function_dispatcher[node.getname()](visitor, node, arg)
return _unary_function_dispatcher.get(
node.getname(), _handle_unsupported_unary_function
)(visitor, node, arg)


def _handle_named_expression(visitor, node, arg):
Expand Down
22 changes: 22 additions & 0 deletions pyomo/contrib/fbbt/tests/test_expression_bounds_walker.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@
acos,
atan,
sqrt,
sinh,
cosh,
tanh,
asinh,
acosh,
atanh,
ceil,
floor,
inequality,
Expr_if,
Any,
Expand Down Expand Up @@ -201,6 +209,20 @@ def test_abs_bounds(self):
self.assertEqual(lb, 0)
self.assertEqual(ub, 4)

def test_unsupported_unary_function_bounds(self):
m = self.make_model()
visitor = ExpressionBoundsVisitor()
for func in (sinh, cosh, tanh, asinh, acosh, atanh, ceil, floor):
expr = func(m.x)
with LoggingIntercept() as LOG:
self.assertEqual(visitor.walk_expression(expr), (-inf, inf))
self.assertEqual(
LOG.getvalue(),
f"Unsupported unary function '{expr.getname()}' found while "
"walking expression tree; returning (-inf, inf) for the "
"expression bounds.\n",
)

def test_leaf_bounds_cached(self):
m = self.make_model()
visitor = ExpressionBoundsVisitor()
Expand Down
Loading