Hyperiso 1.0.3
Modular flavour-physics calculations, Wilson coefficients and statistical inference
Loading...
Searching...
No Matches
SymbolId.py
Go to the documentation of this file.
1"""Symbolic identifiers used by dynamic mappers and registries."""
2
3from dataclasses import dataclass
4from pyhyperiso.phyperiso.pyhyperiso.common import _CppObservableId
5from pyhyperiso.phyperiso.pyhyperiso.common import _CppDecayId
6from pyhyperiso.phyperiso.pyhyperiso.common import _CppWGroupId
7from pyhyperiso.phyperiso.pyhyperiso.common import _CppWCoefId
8
9
10@dataclass(frozen=True)
12 """Small Python wrapper around Hyperiso's dynamic symbol identifiers.
13
14 Dynamic identifiers are string-backed, strongly typed C++ ids. They allow
15 runtime observables, decays, Wilson groups and Wilson coefficients to live
16 next to the legacy static enums without forcing a conversion back to an enum.
17 """
18
19 _name: str
20 _cpp_type = None
21
22 def __str__(self) -> str:
23 return self._name_name
24
25 @property
26 def name(self) -> str:
27 """Canonical name stored by the C++ id."""
28 return self._name_name
29
30 def _to_cpp(self):
31 """Return the bound C++ id object."""
32 return self._cpp_type(self._name_name)
33
34 def to_cpp(self):
35 """Public alias for :meth:`_to_cpp`."""
36 return self._to_cpp()
37
38
40 """Dynamic id for builtin or runtime observables."""
41
42 _cpp_type = _CppObservableId
43
44
46 """Dynamic id for builtin or runtime decays."""
47
48 _cpp_type = _CppDecayId
49
50
52 """Dynamic id for builtin or runtime Wilson groups."""
53
54 _cpp_type = _CppWGroupId
55
56
58 """Dynamic id for builtin or runtime Wilson coefficients."""
59
60 _cpp_type = _CppWCoefId
61
62
63def _unwrap_optional(x, what="value"):
64 if x is None:
65 raise KeyError(f"{what} not found")
66 return x