1"""Python wrappers for C++ parameters."""
3from __future__
import annotations
6from typing
import List, Optional, Tuple, Union
8from pyhyperiso.phyperiso.pyhyperiso.core
import DependentParameter
as _CppDependentParameter
9from pyhyperiso.phyperiso.pyhyperiso.core
import Parameter
as _CppParameter
10from pyhyperiso.phyperiso.pyhyperiso.core
import ParameterMode
as _CppParameterMode
12from pyhyperiso.core.Math.Scalar
import Scalar, _to_scalar
16 """Update mode used by shiftable C++ parameters.
19 FIXED: The parameter value is fixed to its expected value.
20 SHIFTABLE: The parameter can be shifted through the C++ shift machinery.
23 FIXED = _CppParameterMode.FIXED
24 SHIFTABLE = _CppParameterMode.SHIFTABLE
28 """Python wrapper around the C++ ``Parameter`` object.
30 Parameters store a central value and statistical/systematic uncertainties.
31 They may also carry optional metadata such as a scale or bin range. Numeric
32 inputs are converted to the package ``Scalar`` type before crossing the
36 pid: Parameter identifier.
37 expected: Central value.
38 stat: Statistical uncertainty.
39 syst: Systematic uncertainty.
40 scale: Optional scale metadata.
41 bin: Optional bin metadata forwarded to the C++ object.
44 >>> pid = ParamId(type=ParameterType.SM, block="MASS", code=25)
45 >>> p = Parameter(pid, expected=125.0, stat=0.1, syst=0.2)
53 expected: Union[float, complex, Scalar],
54 stat: Union[float, complex, Scalar],
55 syst: Union[float, complex, Scalar],
56 scale: Optional[float] =
None,
57 bin: Optional[List] =
None,
61 _to_scalar(expected)._cpp_obj,
62 _to_scalar(stat)._cpp_obj,
63 _to_scalar(syst)._cpp_obj,
72 """Current parameter value after any active shift."""
73 return Scalar.from_cpp(self.
_cpp_obj.get_val())
76 def std(self) -> Tuple[Scalar, Scalar]:
77 """Statistical and systematic uncertainties as ``(stat, syst)``."""
79 return Scalar.from_cpp(stat), Scalar.from_cpp(syst)
83 """Combined uncertainty according to the C++ parameter rules."""
84 return Scalar.from_cpp(self.
_cpp_obj.get_combined_std())
87 def pid(self) -> ParamId:
88 """Identifier of this parameter."""
89 return ParamId.from_cpp(self.
_cpp_obj.get_id())
91 def set_expected(self, val: Union[float, complex, Scalar]) ->
None:
92 """Set the central value.
95 val: New expected value.
101 stat: Union[float, complex, Scalar],
102 syst: Union[float, complex, Scalar],
104 """Set statistical and systematic uncertainties.
107 stat: Statistical uncertainty.
108 syst: Systematic uncertainty.
110 self.
_cpp_obj.
set_std(_to_scalar(stat)._cpp_obj, _to_scalar(syst)._cpp_obj)
112 def set_shift(self, shift: Union[float, complex, Scalar]) ->
None:
113 """Set the active shift value for a shiftable parameter.
116 shift: Shift value forwarded to C++.
121 """Set whether the parameter is fixed or shiftable.
124 mode: New parameter mode.
129 """Return a readable representation for debugging."""
131 f
"<Parameter pid={self.pid}, value={self.value}, "
132 f
"std={self.std}, combined_std={self.combined_std}>"
137 """Wrap an existing bound C++ ``Parameter``.
140 cpp_obj: Bound C++ parameter instance.
143 Python wrapper sharing the provided C++ object.
145 param = Parameter.__new__(Parameter)
146 param._cpp_obj = cpp_obj
151 """Python wrapper around a C++ ``DependentParameter``.
153 Dependent parameters can update their value from other parameters, and can
154 be frozen to avoid repeated recomputation in workflows that scan many
158 def __init__(self, cpp_obj: _CppDependentParameter) ->
None:
159 """Wrap an existing C++ dependent parameter."""
163 """Return whether this parameter depends on ``pid``."""
167 """Initialize the underlying dependent parameter."""
171 """Recompute the parameter value from its dependencies."""
175 """Freeze updates for the dependent parameter."""
179 """Re-enable updates for the dependent parameter."""
183__all__ = [
"Parameter",
"ParameterMode",
"PyDependentParameter"]
Scalar combined_std(self)
"Parameter" from_cpp(cpp_obj)
None set_expected(self, Union[float, complex, Scalar] val)
None set_mode(self, ParameterMode mode)
None set_std(self, Union[float, complex, Scalar] stat, Union[float, complex, Scalar] syst)
None __init__(self, ParamId pid, Union[float, complex, Scalar] expected, Union[float, complex, Scalar] stat, Union[float, complex, Scalar] syst, Optional[float] scale=None, Optional[List] bin=None)
None set_shift(self, Union[float, complex, Scalar] shift)
None __init__(self, _CppDependentParameter cpp_obj)
bool depends_on(self, ParamId pid)
Hash specialization for SymbolId<Tag>.