rule_wrapper
(function from pyomo.core.base.indexed_component)
- pyomo.core.base.indexed_component.rule_wrapper(rule, wrapping_fcn, positional_arg_map=None, map_types=None)[source]
Wrap a rule with another function
This utility method provides a way to wrap a function (rule) with another function while preserving the original function signature. This is important for rules, as the
Initializer()argument processor relies on knowing the number of positional arguments.- Parameters:
rule (function) – The original rule being wrapped
wrapping_fcn (function or Dict) – The wrapping function. The wrapping_fcn will be called with
(rule, *args, **kwargs). For convenience, if a dict is passed as the wrapping_fcn, then the result ofrule_result_substituter(wrapping_fcn)()is used as the wrapping function.positional_arg_map (iterable[int]) – An iterable of indices of rule positional arguments to expose in the wrapped function signature. For example, positional_arg_map=(2, 0) and rule=fcn(a, b, c) would produce a wrapped function with a signature wrapper_function(c, a)