pyomo
pyomo copied to clipboard
[PEP] Remove ConstraintData.equality
Summary
Deprecate the ConstraintData.equality
property.
Rationale
#2093 and #2097 highlighted confusion as to the meaning of ConstraintData.equality
. There are (at least) 3 interpreatations of "equality":
- Was the Constraint initialized with an
EqualityExpression
object (as opposed to anInequalityExpression
orRangedExpression
)? - Does the
ConstraintData
represent a "structural equality"; that is (1) plusRangedExpression
where the upper and lower bounds are symbolically equal? - Does the
ConstraintData
represent a "numerical equality"; that is (1) plusRangedExpression
where the upper and lower bounds are have equalvalue()
?
Looking through the code base, there is not real consistency ... some places assume equality
means case (1) (primarily transformations), and others (primarily writers) assume something closer to (3). As this is confusing (and not something easily rectified), this PEP proposes:
- restore the current definition of
equality
to interpretation (1) (i.e., restore it to very close to the Pyomo 5.7 meaning) - deprecate the
equality
property altogether.
Removal of equality
is no longer a significant burden to the end-user, as ConstraintData objects now preserve the original expression returned from the rule. As a result, interpretation (1) can be implemented as:
equality = isinstance(con.expr, EqualityExpression)
and interpretation (3) is:
equality = con.lb is not None and con.lb == con.ub
This seems reasonable to me. I like clarity.
I support this change.