Hyperiso 1.0.3
Modular flavour-physics calculations, Wilson coefficients and statistical inference
Loading...
Searching...
No Matches
Configs.py
Go to the documentation of this file.
1"""Python configuration objects converted to native HyperIso structures."""
2
3from dataclasses import dataclass, field
4from typing import Set, Union
5
6from pyhyperiso.phyperiso.pyhyperiso.common import (
7 WilsonBuildConfig as _CppWilsonBuildConfig,
8 WilsonRequest as _CppWilsonRequest,
9 AlphasConfig as _CppAlphasConfig,
10 MassConfig as _CppMassConfig,
11)
12from pyhyperiso.core.Common.Mapper import GroupMapper, WCoefMapper
13from pyhyperiso.core.Common.SymbolId import WGroupId, WCoefId
15 QCDOrder,
16 WGroup,
17 WCoeff,
18 ContributionType,
19 ScaleType,
20 MassType,
21 WilsonBasis,
22)
23
24WilsonGroupLike = Union[WGroup, WGroupId, str]
25WilsonCoefLike = Union[WCoeff, WCoefId, str]
26
27
28def _cpp_group_id(group: WilsonGroupLike):
29 """Convert a group enum/string/id to the bound C++ ``WGroupId``."""
30 if isinstance(group, WGroupId):
31 return group._to_cpp()
32 return GroupMapper.id_of(group)._to_cpp()
33
34
35def _cpp_coef_id(coef: WilsonCoefLike):
36 """Convert a coefficient enum/string/id to the bound C++ ``WCoefId``."""
37 if isinstance(coef, WCoefId):
38 return coef._to_cpp()
39 return WCoefMapper.id_of(coef)._to_cpp()
40
41
42@dataclass
44 """Configuration for building Wilson coefficient groups.
45
46 The C++ layer stores groups as dynamic ``WGroupId`` values. Python accepts
47 legacy :class:`WGroup` enums, strings/aliases, or :class:`WGroupId` objects.
48
49 Args:
50 groups: Wilson groups to build. Examples: ``WGroup.B``,
51 ``"BCoefficients"`` or ``GroupMapper.id_of("DEV_GROUP")``.
52 matching_scale: Matching scale in GeV.
53 hadronic_scale: Hadronic/running scale in GeV.
54 order: Maximum QCD order requested for matching/running.
55 """
56
57 groups: Set[WilsonGroupLike] = field(default_factory=set)
58 matching_scale: float = 81.0
59 hadronic_scale: float = 4.8
60 order: QCDOrder = QCDOrder.LO
61
62 def to_cpp(self) -> _CppWilsonBuildConfig:
63 """Convert this Python config to the bound C++ config object."""
64 cpp = _CppWilsonBuildConfig()
65 cpp.groups = {_cpp_group_id(g) for g in self.groups}
66 cpp.matching_scale = float(self.matching_scale)
67 cpp.hadronic_scale = float(self.hadronic_scale)
68 cpp.order = self.order.value
69 return cpp
70
71
72@dataclass
74 """Request for one Wilson coefficient.
75
76 ``group`` and ``coefficient`` accept both legacy enums and dynamic ids. This
77 means the same wrapper can query builtin Wilson coefficients and custom
78 lambda-backed coefficients.
79 """
80
81 group: WilsonGroupLike
82 coefficient: WilsonCoefLike
83 order: QCDOrder = QCDOrder.LO
84 contribution: ContributionType = ContributionType.TOTAL
85 scale_type: ScaleType = ScaleType.HADRONIC
86 wilson_basis: WilsonBasis = WilsonBasis.STANDARD
87 sum_qcd_orders: bool = False
88
89 def to_cpp(self) -> _CppWilsonRequest:
90 """Convert this request to the bound C++ ``WilsonRequest``."""
91 return _CppWilsonRequest(
92 _cpp_group_id(self.groupgroup),
93 _cpp_coef_id(self.coefficientcoefficient),
94 self.orderorder.value,
95 self.contributioncontribution.value,
96 self.scale_type.value,
98 )
99
101 """Return keyword arguments suitable for matching-scale getters."""
102 return {
103 "group": self.groupgroup,
104 "coeff": self.coefficientcoefficient,
105 "order": self.orderorder,
106 "cont_type": self.contributioncontribution,
107 }
108
110 """Return keyword arguments suitable for running-scale getters."""
111 return {
112 "group": self.groupgroup,
113 "coeff": self.coefficientcoefficient,
114 "order": self.orderorder,
115 "cont_type": self.contributioncontribution,
117 }
118
119
120@dataclass
122 """Configuration for evaluating the strong coupling constant ``alpha_s``."""
123
124 scale: float
125 m_b_type: MassType = field(default=MassType.POLE)
126 m_t_type: MassType = field(default=MassType.POLE)
127
128 def to_cpp(self) -> _CppAlphasConfig:
129 """Convert this Python config to the bound C++ config object."""
130 return _CppAlphasConfig(self.scalescale, self.m_b_type.value, self.m_t_type.value)
131
132
133@dataclass
135 """Configuration for computing a particle mass at a given scale."""
136
137 pdg_id: int = field(default=6)
138
139 def to_cpp(self) -> _CppMassConfig:
140 """Convert this Python config to the bound C++ config object."""
141 return _CppMassConfig(self.pdg_idpdg_id, self.scalescalescale, self.m_b_type.value, self.m_t_type.value)
142
143
144__all__ = [
145 "WilsonBuildConfig",
146 "WilsonRequest",
147 "AlphasConfig",
148 "MassConfig",
149 "WilsonGroupLike",
150 "WilsonCoefLike",
151 "_cpp_group_id",
152 "_cpp_coef_id",
153]
static IdOf< WGroupTag > id_of(std::string_view s)
Resolves a string into an IdOf<Tag> via the registry.