Skip to content

Commit 285d939

Browse files
weinbe58Copilot
andauthored
Fixing bug with Hashing (#17)
* fixing hashing bug * Apply suggestions from code review Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Copilot <[email protected]>
1 parent f5e6182 commit 285d939

File tree

1 file changed

+14
-2
lines changed
  • src/bloqade/geometry/dialects/grid

1 file changed

+14
-2
lines changed

src/bloqade/geometry/dialects/grid/types.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,16 @@ def __getitem__(self, indices):
202202
return self.get_view(x_indices=x_indices, y_indices=y_indices)
203203

204204
def __hash__(self) -> int:
205-
return id(self)
205+
return hash((self.x_spacing, self.y_spacing, self.x_init, self.y_init))
206+
207+
def __eq__(self, other: Any) -> bool:
208+
return (
209+
isinstance(other, Grid)
210+
and self.x_spacing == other.x_spacing
211+
and self.y_spacing == other.y_spacing
212+
and self.x_init == other.x_init
213+
and self.y_init == other.y_init
214+
)
206215

207216
def print_impl(self, printer: Printer) -> None:
208217
printer.plain_print("Grid(")
@@ -309,7 +318,10 @@ def get_view(
309318
)
310319

311320
def __hash__(self):
312-
return id(self)
321+
return super().__hash__()
322+
323+
def __eq__(self, other: Any) -> bool:
324+
return super().__eq__(other)
313325

314326
def __repr__(self):
315327
return super().__repr__()

0 commit comments

Comments
 (0)