Skip to content

Commit e58c5cb

Browse files
weinbe58Copilot
andauthored
Bug Fixes. (#58)
* adding hash function for layout * fixing bugs in Fold and hashing of layout * copilot suggestion * Adding test * Update src/bloqade/shuttle/arch.py Co-authored-by: Copilot <[email protected]> * adding some basic tests * run linter --------- Co-authored-by: Copilot <[email protected]>
1 parent 468d349 commit e58c5cb

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

src/bloqade/shuttle/arch.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ class Layout:
1414
fillable: set[str]
1515
""" The set of trap names that are fillable by the sorter. """
1616

17+
def __hash__(self):
18+
return hash((frozenset(self.static_traps.items()), frozenset(self.fillable)))
19+
20+
def __eq__(self, other):
21+
if not isinstance(other, Layout):
22+
return NotImplemented
23+
return (
24+
self.static_traps == other.static_traps and self.fillable == other.fillable
25+
)
26+
1727
@staticmethod
1828
def _plot_zone(zone: Grid, ax, name: str, **plot_options):
1929
from matplotlib.axes import Axes # type: ignore

src/bloqade/shuttle/passes/fold.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def unsafe_run(self, mt: Method) -> RewriteResult:
3939
Call2Invoke(),
4040
InlineGetField(),
4141
InlineGetItem(),
42+
ilist.rewrite.InlineGetItem(),
4243
DeadCodeElimination(),
4344
CommonSubexpressionElimination(),
4445
)

test/unit/test_arch.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from bloqade.geometry.dialects.grid import Grid
2+
3+
from bloqade.shuttle.arch import Layout
4+
5+
6+
def test_layout():
7+
8+
layout = Layout({"test": Grid.from_positions(range(16), range(16))}, {"test"})
9+
10+
assert hash(layout) == hash(
11+
(frozenset(layout.static_traps.items()), frozenset(layout.fillable))
12+
)
13+
assert layout == Layout(
14+
{"test": Grid.from_positions(range(16), range(16))}, {"test"}
15+
)
16+
assert layout != 1

0 commit comments

Comments
 (0)