Skip to content

Commit

Permalink
adding cached_property for _hash_value
Browse files Browse the repository at this point in the history
  • Loading branch information
weinbe58 committed Oct 2, 2023
1 parent a468042 commit 91f2ca5
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/bloqade/ir/control/field.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from functools import cached_property
from ..scalar import Scalar, cast
from ..tree_print import Printer
from .waveform import Waveform
Expand Down Expand Up @@ -107,8 +108,12 @@ class AssignedRunTimeVector(SpatialModulation):
name: str
value: List[Decimal]

@cached_property
def _hash_value(self):
return hash(self.name) ^ hash(tuple(self.value)) ^ hash(self.__class__)

def __hash__(self) -> int:
return hash(self.name) ^ hash(self.__class__) ^ hash(tuple(self.value))
return self._hash_value

def print_node(self):
return "AssgiendRunTimeVector"
Expand Down Expand Up @@ -143,9 +148,13 @@ def __init__(self, pairs):
value[k] = cast(v)
self.value = value

def __hash__(self) -> int:
@cached_property
def _hash_value(self) -> int:
return hash(frozenset(self.value.items())) ^ hash(self.__class__)

def __hash__(self) -> int:
return self._hash_value

def _get_data(self, **assignments):
names = []
scls = []
Expand Down Expand Up @@ -209,9 +218,13 @@ class Field(FieldExpr):

drives: Dict[SpatialModulation, Waveform]

def __hash__(self) -> int:
@cached_property
def _hash_value(self):
return hash(frozenset(self.drives.items())) ^ hash(self.__class__)

def __hash__(self) -> int:
return self._hash_value

def canoncialize(self) -> "Field":
reversed_dirves = {}

Expand Down

0 comments on commit 91f2ca5

Please sign in to comment.