-
Notifications
You must be signed in to change notification settings - Fork 529
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
Multiple dispatch for relational expression generation #3483
base: main
Are you sure you want to change the base?
Conversation
(Do not attempt to squeeze this into the release) |
pyomo/core/expr/relational_expr.py
Outdated
_lt_dispatcher = collections.defaultdict(lambda: _register_new_lt_handler) | ||
_lt_type_handler_mapping = _binary_op_dispatcher_type_mapping( | ||
_lt_dispatcher, | ||
{ | ||
(ARG_TYPE.NATIVE, ARG_TYPE.NATIVE): _lt_native, | ||
(ARG_TYPE.NATIVE, ARG_TYPE.PARAM): _lt_any_param, | ||
(ARG_TYPE.NATIVE, ARG_TYPE.OTHER): _lt_expr, | ||
(ARG_TYPE.NATIVE, ARG_TYPE.INEQUALITY): _lt_expr_ineq, | ||
(ARG_TYPE.NATIVE, ARG_TYPE.INVALID_RELATIONAL): _lt_invalid, | ||
(ARG_TYPE.PARAM, ARG_TYPE.NATIVE): _lt_param_any, | ||
(ARG_TYPE.PARAM, ARG_TYPE.PARAM): _lt_param, | ||
(ARG_TYPE.PARAM, ARG_TYPE.OTHER): _lt_param_any, | ||
(ARG_TYPE.PARAM, ARG_TYPE.INEQUALITY): _lt_param_ineq, | ||
(ARG_TYPE.PARAM, ARG_TYPE.INVALID_RELATIONAL): _lt_invalid, | ||
(ARG_TYPE.OTHER, ARG_TYPE.NATIVE): _lt_expr, | ||
(ARG_TYPE.OTHER, ARG_TYPE.PARAM): _lt_any_param, | ||
(ARG_TYPE.OTHER, ARG_TYPE.OTHER): _lt_expr, | ||
(ARG_TYPE.OTHER, ARG_TYPE.INEQUALITY): _lt_expr_ineq, | ||
(ARG_TYPE.OTHER, ARG_TYPE.INVALID_RELATIONAL): _lt_invalid, | ||
(ARG_TYPE.INEQUALITY, ARG_TYPE.NATIVE): _lt_ineq_expr, | ||
(ARG_TYPE.INEQUALITY, ARG_TYPE.PARAM): _lt_ineq_param, | ||
(ARG_TYPE.INEQUALITY, ARG_TYPE.OTHER): _lt_ineq_expr, | ||
(ARG_TYPE.INEQUALITY, ARG_TYPE.INEQUALITY): _lt_invalid, | ||
(ARG_TYPE.INEQUALITY, ARG_TYPE.INVALID_RELATIONAL): _lt_invalid, | ||
(ARG_TYPE.INVALID_RELATIONAL, ARG_TYPE.NATIVE): _lt_invalid, | ||
(ARG_TYPE.INVALID_RELATIONAL, ARG_TYPE.PARAM): _lt_invalid, | ||
(ARG_TYPE.INVALID_RELATIONAL, ARG_TYPE.OTHER): _lt_invalid, | ||
(ARG_TYPE.INVALID_RELATIONAL, ARG_TYPE.INEQUALITY): _lt_invalid, | ||
(ARG_TYPE.INVALID_RELATIONAL, ARG_TYPE.INVALID_RELATIONAL): _lt_invalid, | ||
}, | ||
ARG_TYPE, | ||
) |
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 don't know if there is a "better" way to do this, but there are three versions of this map that are all "almost" the same, and it makes my little "minimize repeat code" heart sad.
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.
Sorry for the long-delayed review... This is really pretty! A few questions, but otherwise it looks good.
class RELATIONAL_ARG_TYPE(enums.IntEnum, metaclass=enums.ExtendedEnumType): | ||
__base_enum__ = NUMERIC_ARG_TYPE | ||
|
||
INEQUALITY = 100 | ||
INVALID_RELATIONAL = 101 |
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.
Should this have equality in it? Why doesn't it?
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.
This is the list of argument types for relational expressions. As an Equality expression is not allowed to be the argument for another numeric / relational expression, we will never need to do special dispatch for it (it will fall back on getting mapped to INVALID).
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3483 +/- ##
==========================================
- Coverage 88.69% 88.68% -0.01%
==========================================
Files 888 888
Lines 101886 101976 +90
==========================================
+ Hits 90365 90439 +74
- Misses 11521 11537 +16
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…ional-multiple-dispatch
Fixes # .
Summary/Motivation:
NOTE: This PR includes #3551; review / merge that PR first.
This is a continuation of the work moving Pyomo expression generation to use multiple dispatch for more efficient / standardized argument processing. This migrates the relational expression generation. Overall, it provides more standardized and efficient argument processing. Overall performance on the performance test suite is improved (in particular, a 3.5% improvement in create_instance:
Changes proposed in this PR:
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: