pyomo icon indicating copy to clipboard operation
pyomo copied to clipboard

[PEP] Remove ConstraintData.equality

Open jsiirola opened this issue 3 years ago • 2 comments

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":

  1. Was the Constraint initialized with an EqualityExpression object (as opposed to an InequalityExpression or RangedExpression)?
  2. Does the ConstraintData represent a "structural equality"; that is (1) plus RangedExpression where the upper and lower bounds are symbolically equal?
  3. Does the ConstraintData represent a "numerical equality"; that is (1) plus RangedExpression where the upper and lower bounds are have equal value()?

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

jsiirola avatar Aug 24 '21 22:08 jsiirola

This seems reasonable to me. I like clarity.

michaelbynum avatar Aug 25 '21 12:08 michaelbynum

I support this change.

blnicho avatar Aug 25 '21 18:08 blnicho