1"""High-level Python wrapper for dependency pruning operations.
3This module wraps the bound C++ ``DependencyPruner`` adapter. It provides a
4small Python-friendly façade for detaching and reattaching dependent blocks or
5individual dependent parameters from their upstream dependencies.
7The Hyperiso core must be initialized before using this wrapper, typically via
8``HyperisoMaster.init(...)``, because the underlying C++ adapter delegates to
9``Parameters::GetInstance(...)``.
12 >>> pruner = DependencyPruner()
13 >>> pruner.detach_block(ParameterType.SM, "EW")
14 >>> pruner.reattach_block(ParameterType.SM, "EW")
19from pyhyperiso.phyperiso.pyhyperiso.core
import DependencyPruner
as _CppDependencyPruner
24 """Detach and reattach dependency links in the Hyperiso parameter graph.
26 ``DependencyPruner`` is a Python façade over the C++ adapter with the same
27 name. It can operate at two levels:
29 - block level, through :meth:`detach_block` and :meth:`reattach_block`,
30 - parameter level, through :meth:`detach_parameter` and
31 :meth:`reattach_parameter`.
34 cpp_obj: Optional already-bound C++ ``DependencyPruner`` instance. When
35 omitted, a fresh C++ adapter is created.
38 def __init__(self, cpp_obj: _CppDependencyPruner |
None =
None):
39 """Create a Python wrapper around the C++ ``DependencyPruner``."""
40 self.
_cpp_obj = cpp_obj
if cpp_obj
is not None else _CppDependencyPruner()
44 """Convert a Python block-name-like object to the string expected by pybind.
47 block_name: Block name, usually a ``str``. Objects implementing
48 ``__str__`` are also accepted.
51 str: Block name passed to the C++ binding, where it is converted to
54 return str(block_name)
58 """Return the bound C++ ``LhaID`` object for a Python LHA id wrapper.
61 id_: Either a bound C++ ``LhaID`` object or a Python wrapper exposing
65 Any: Object forwarded to the pybind layer.
67 return id_.to_cpp()
if hasattr(id_,
"to_cpp")
else id_
69 def detach_block(self, parameter_type: ParameterType, block_name: Any) ->
None:
70 """Detach a dependent block from its upstream source blocks.
72 After detachment, updates of upstream blocks no longer propagate through
73 this dependency link until the block is reattached.
76 parameter_type: Parameter namespace containing the block, e.g.
78 block_name: Name of the dependent block to detach.
83 """Reattach a previously detached dependent block to its sources.
86 parameter_type: Parameter namespace containing the block, e.g.
88 block_name: Name of the dependent block to reattach.
92 def detach_parameter(self, parameter_type: ParameterType, block_name: Any, id_: Any) ->
None:
93 """Detach a dependent parameter from its upstream source parameters.
96 parameter_type: Parameter namespace containing the parameter.
97 block_name: Name of the block containing the parameter.
98 id_: LHA identifier of the dependent parameter. This may be a bound
99 C++ ``LhaID`` or a Python wrapper exposing ``to_cpp()``.
102 parameter_type.value,
108 """Reattach a previously detached dependent parameter to its sources.
111 parameter_type: Parameter namespace containing the parameter.
112 block_name: Name of the block containing the parameter.
113 id_: LHA identifier of the dependent parameter. This may be a bound
114 C++ ``LhaID`` or a Python wrapper exposing ``to_cpp()``.
117 parameter_type.value,
122 def detach_param(self, parameter_type: ParameterType, block_name: Any, id_: Any) ->
None:
123 """Alias for :meth:`detach_parameter`.
126 parameter_type: Parameter namespace containing the parameter.
127 block_name: Name of the block containing the parameter.
128 id_: LHA identifier of the dependent parameter.
132 def reattach_param(self, parameter_type: Any, block_name: Any, id_: Any) ->
None:
133 """Alias for :meth:`reattach_parameter`.
136 parameter_type: Parameter namespace containing the parameter.
137 block_name: Name of the block containing the parameter.
138 id_: LHA identifier of the dependent parameter.
144 """Bound C++ ``DependencyPruner`` instance used by this wrapper."""
148__all__ = [
"DependencyPruner"]
None detach_param(self, ParameterType parameter_type, Any block_name, Any id_)
Any _to_cpp_lha_id(Any id_)
None reattach_param(self, Any parameter_type, Any block_name, Any id_)
__init__(self, _CppDependencyPruner|None cpp_obj=None)
_CppDependencyPruner cpp_obj(self)
None reattach_block(self, Any parameter_type, Any block_name)
None reattach_parameter(self, ParameterType parameter_type, Any block_name, Any id_)
None detach_block(self, ParameterType parameter_type, Any block_name)
str _normalize_block_name(Any block_name)
None detach_parameter(self, ParameterType parameter_type, Any block_name, Any id_)