|
| 1 | +from functools import cached_property |
1 | 2 | from ..scalar import Scalar, cast
|
2 | 3 | from ..tree_print import Printer
|
3 | 4 | from .waveform import Waveform
|
@@ -107,8 +108,12 @@ class AssignedRunTimeVector(SpatialModulation):
|
107 | 108 | name: str
|
108 | 109 | value: List[Decimal]
|
109 | 110 |
|
| 111 | + @cached_property |
| 112 | + def _hash_value(self): |
| 113 | + return hash(self.name) ^ hash(tuple(self.value)) ^ hash(self.__class__) |
| 114 | + |
110 | 115 | def __hash__(self) -> int:
|
111 |
| - return hash(self.name) ^ hash(self.__class__) ^ hash(tuple(self.value)) |
| 116 | + return self._hash_value |
112 | 117 |
|
113 | 118 | def print_node(self):
|
114 | 119 | return "AssgiendRunTimeVector"
|
@@ -143,9 +148,13 @@ def __init__(self, pairs):
|
143 | 148 | value[k] = cast(v)
|
144 | 149 | self.value = value
|
145 | 150 |
|
146 |
| - def __hash__(self) -> int: |
| 151 | + @cached_property |
| 152 | + def _hash_value(self) -> int: |
147 | 153 | return hash(frozenset(self.value.items())) ^ hash(self.__class__)
|
148 | 154 |
|
| 155 | + def __hash__(self) -> int: |
| 156 | + return self._hash_value |
| 157 | + |
149 | 158 | def _get_data(self, **assignments):
|
150 | 159 | names = []
|
151 | 160 | scls = []
|
@@ -209,9 +218,13 @@ class Field(FieldExpr):
|
209 | 218 |
|
210 | 219 | drives: Dict[SpatialModulation, Waveform]
|
211 | 220 |
|
212 |
| - def __hash__(self) -> int: |
| 221 | + @cached_property |
| 222 | + def _hash_value(self): |
213 | 223 | return hash(frozenset(self.drives.items())) ^ hash(self.__class__)
|
214 | 224 |
|
| 225 | + def __hash__(self) -> int: |
| 226 | + return self._hash_value |
| 227 | + |
215 | 228 | def canoncialize(self) -> "Field":
|
216 | 229 | reversed_dirves = {}
|
217 | 230 |
|
|
0 commit comments