Skip to content

Commit

Permalink
Provide implicit filter callback argument mapping for scalar Sets
Browse files Browse the repository at this point in the history
  • Loading branch information
jsiirola committed Aug 12, 2024
1 parent 4d825f6 commit 9506873
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions pyomo/core/base/set.py
Original file line number Diff line number Diff line change
Expand Up @@ -2246,19 +2246,6 @@ def __init__(self, *args, **kwds):

IndexedComponent.__init__(self, *args, **kwds)

if (
self._validate.__class__ is ParameterizedIndexedCallInitializer
and not self.parent_component().is_indexed()
):
# TBD [JDS: 8/2024]: should we deprecate the "expanded
# tuple" version of the validate callback for scalar sets?
# It is widely used and we can (reasonably reliably) map to
# the expected behavior.
orig_fcn = self._validate._fcn
self._validate = ParameterizedScalarCallInitializer(
lambda m, v: orig_fcn(m, *v), True
)

# HACK to make the "counted call" syntax work. We wait until
# after the base class is set up so that is_indexed() is
# reliable.
Expand All @@ -2277,6 +2264,26 @@ def __init__(self, *args, **kwds):
if self._init_dimen.constant():
self._dimen = self._init_dimen(self.parent_block(), None)

if self._validate.__class__ is ParameterizedIndexedCallInitializer:
# TBD [JDS: 8/2024]: should we deprecate the "expanded
# tuple" version of the validate callback for scalar sets?
# It is widely used and we can (reasonably reliably) map to
# the expected behavior...
orig_fcn = self._validate._fcn
self._validate = ParameterizedScalarCallInitializer(
lambda m, v: orig_fcn(m, *v), True
)

if self._filter.__class__ is ParameterizedIndexedCallInitializer:
# TBD [JDS: 8/2024]: should we deprecate the "expanded
# tuple" version of the filter callback for scalar sets?
# It is widely used and we can (reasonably reliably) map to
# the expected behavior...
orig_fcn = self._filter._fcn
self._filter = ParameterizedScalarCallInitializer(
lambda m, v: orig_fcn(m, *v), True
)

@deprecated(
"check_values() is deprecated: Sets only contain valid members", version='5.7'
)
Expand Down

0 comments on commit 9506873

Please sign in to comment.