Repository navigation
Conversation
ExpressionBoundsVisitor looked up unary function handlers with a plain dict index, so sinh, cosh, tanh, asinh, acosh, atanh, ceil and floor raised KeyError from compute_bounds_on_expr. Fall back to (-inf, inf) with a warning, as the walker already does for unexpected node types.
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
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.
Fixes #4125 .
Summary/Motivation:
compute_bounds_on_expr(ExpressionBoundsVisitor) raisesKeyErrorfor any expression that contains a unary function without an entry in_unary_function_dispatcher. Of the 18 intrinsic functions Pyomo provides, 8 are missing:sinh,cosh,tanh,asinh,acosh,atanh,ceilandfloor. As reported in #4125, this breaks IDAESDiagnosticsToolbox.report_structural_issues()on models that usetanh.The walker already returns
(-inf, inf)with a warning for expression node types it does not recognize (ExpressionBoundsExitNodeDispatcher.unexpected_expression_type), and the FBBT leaf-to-root map (_unary_leaf_to_root_map) returns(-inf, inf)for these function names. This PR applies the same fallback to unary functions that have no handler.Changes proposed in this PR:
pyomo/contrib/fbbt/expression_bounds_walker.py: look up the unary function handler withdict.getand fall back to a handler that logs a warning and returns(-inf, inf)._unary_function_dispatcherstays a plain dict, so a handler registered at runtime (like the workaround in ExpressionBoundsVisitor / compute_bounds_on_expr raises KeyError for hyperbolic functions (tanh, sinh, cosh, ...) #4125) still takes precedence.pyomo/contrib/fbbt/tests/test_expression_bounds_walker.py: addtest_unsupported_unary_function_bounds, which walks each of the 8 functions and checks the bounds and the warning. It fails onmainwithKeyError: 'sinh'and passes with this change.AI-Use Disclosure
or
AI tools contributed to the development of this PR
Review process (select ONE):
Notes for reviewers (optional):
unexpected_expression_typein the same walker. The FBBT leaf-to-root map returns(-inf, inf)for these names without a warning. If you would rather keep the walker silent here, the warning can be dropped.tanh,sinh,asinh, ...) would need new functions ininterval.pyand handlers in both FBBT and this walker. This PR only removes theKeyError.pyomo/contrib/fbbt/testsgives 73 passed and 28 skipped (72 passed and 28 skipped onmain). Together with the other users of the walker (pyomo/gdp/tests/test_bigm.py,pyomo/gdp/tests/test_mbigm.py,pyomo/contrib/piecewise/testsandpyomo/contrib/alternative_solutions/tests/test_shifted_lp.py) it gives 319 passed and 97 skipped.black --checkandtypospass on the two files. The reproducer from ExpressionBoundsVisitor / compute_bounds_on_expr raises KeyError for hyperbolic functions (tanh, sinh, cosh, ...) #4125 now prints(None, None)with the warning for all 8 functions instead ofKeyError.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: