Skip to content

Commit

Permalink
Moving quadratic repn visitor to instance attribute on nonlinear to p…
Browse files Browse the repository at this point in the history
…wl transformation
  • Loading branch information
emma58 committed Aug 19, 2024
1 parent 5bda911 commit 804ad04
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions pyomo/contrib/piecewise/transform/nonlinear_to_pwl.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,6 @@ class DomainPartitioningMethod(enum.IntEnum):
LINEAR_MODEL_TREE_RANDOM = 4


# This should be safe to use many times; declare it globally
_quadratic_repn_visitor = QuadraticRepnVisitor(
subexpression_cache={}, var_map={}, var_order={}, sorter=None
)


class _NonlinearToPWLTransformationData(AutoSlots.Mixin):
__slots__ = (
'transformed_component',
Expand Down Expand Up @@ -502,6 +496,9 @@ def __init__(self):
}
self._transformation_blocks = {}
self._transformation_block_set = ComponentSet()
self._quadratic_repn_visitor = QuadraticRepnVisitor(
subexpression_cache={}, var_map={}, var_order={}, sorter=None
)

def _apply_to(self, instance, **kwds):
try:
Expand Down Expand Up @@ -630,7 +627,7 @@ def _get_bounds_list(self, var_list, obj):
return bounds

def _needs_approximating(self, expr, approximate_quadratic):
repn = _quadratic_repn_visitor.walk_expression(expr)
repn = self._quadratic_repn_visitor.walk_expression(expr)
if repn.nonlinear is None:
if repn.quadratic is None:
# Linear constraint. Always skip.
Expand Down

0 comments on commit 804ad04

Please sign in to comment.