Skip to content

Commit 91f2ca5

Browse files
committed
adding cached_property for _hash_value
1 parent a468042 commit 91f2ca5

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/bloqade/ir/control/field.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from functools import cached_property
12
from ..scalar import Scalar, cast
23
from ..tree_print import Printer
34
from .waveform import Waveform
@@ -107,8 +108,12 @@ class AssignedRunTimeVector(SpatialModulation):
107108
name: str
108109
value: List[Decimal]
109110

111+
@cached_property
112+
def _hash_value(self):
113+
return hash(self.name) ^ hash(tuple(self.value)) ^ hash(self.__class__)
114+
110115
def __hash__(self) -> int:
111-
return hash(self.name) ^ hash(self.__class__) ^ hash(tuple(self.value))
116+
return self._hash_value
112117

113118
def print_node(self):
114119
return "AssgiendRunTimeVector"
@@ -143,9 +148,13 @@ def __init__(self, pairs):
143148
value[k] = cast(v)
144149
self.value = value
145150

146-
def __hash__(self) -> int:
151+
@cached_property
152+
def _hash_value(self) -> int:
147153
return hash(frozenset(self.value.items())) ^ hash(self.__class__)
148154

155+
def __hash__(self) -> int:
156+
return self._hash_value
157+
149158
def _get_data(self, **assignments):
150159
names = []
151160
scls = []
@@ -209,9 +218,13 @@ class Field(FieldExpr):
209218

210219
drives: Dict[SpatialModulation, Waveform]
211220

212-
def __hash__(self) -> int:
221+
@cached_property
222+
def _hash_value(self):
213223
return hash(frozenset(self.drives.items())) ^ hash(self.__class__)
214224

225+
def __hash__(self) -> int:
226+
return self._hash_value
227+
215228
def canoncialize(self) -> "Field":
216229
reversed_dirves = {}
217230

0 commit comments

Comments
 (0)