Skip to content

Commit 5e4eae8

Browse files
authored
Adding gate metadata to spec + special field for non-static traps (#66)
1 parent d45127d commit 5e4eae8

File tree

9 files changed

+74
-17
lines changed

9 files changed

+74
-17
lines changed

demo/log_depth_ghz.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,12 @@ def run_ghz():
149149
static_traps={
150150
"mem": mem,
151151
},
152+
special_grid={
153+
"gate": gate,
154+
},
152155
fillable=set(["mem"]),
156+
has_cz=set(["gate"]),
157+
has_local=set(["mem"]),
153158
)
154159
)
155160

src/bloqade/shuttle/arch.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,27 @@ class Layout:
1212
"""Abstract base class for layout."""
1313

1414
fillable: set[str]
15-
""" The set of trap names that are fillable by the sorter. """
15+
"""The set of trap names that are fillable by the sorter."""
16+
17+
has_cz: set[str]
18+
"""The set of trap names that can have a CZ gates applied."""
19+
20+
has_local: set[str]
21+
"""The set of trap names that can have local single qubit gates applied."""
22+
23+
special_grid: dict[str, Grid] = field(default_factory=dict, kw_only=True)
24+
"""Set of special grid values that are not static traps, but can be used for specific purposes."""
1625

1726
def __hash__(self):
18-
return hash((frozenset(self.static_traps.items()), frozenset(self.fillable)))
27+
return hash(
28+
(
29+
frozenset(self.static_traps.items()),
30+
frozenset(self.fillable),
31+
frozenset(self.has_cz),
32+
frozenset(self.has_local),
33+
frozenset(self.special_grid.items()),
34+
)
35+
)
1936

2037
def __eq__(self, other):
2138
if not isinstance(other, Layout):
@@ -81,7 +98,12 @@ def _default_layout():
8198
range(16),
8299
).scale(10.0, 10.0)
83100

84-
return Layout(static_traps={"traps": zone}, fillable={"traps"})
101+
return Layout(
102+
static_traps={"traps": zone},
103+
fillable={"traps"},
104+
has_cz={"traps"},
105+
has_local={"traps"},
106+
)
85107

86108

87109
@dataclass(frozen=True)

src/bloqade/shuttle/stdlib/layouts/single_col_zone.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ def get_spec(num_x: int, num_y: int, spacing: float = 10.0) -> spec.ArchSpec:
2727

2828
return spec.ArchSpec(
2929
layout=spec.Layout(
30-
static_traps={"traps": grid.Grid(x_spacing, y_spacing, 0.0, 0.0)},
31-
fillable=set(["traps"]),
30+
{"traps": grid.Grid(x_spacing, y_spacing, 0.0, 0.0)},
31+
set(["traps"]),
32+
set(["traps"]),
33+
set(["traps"]),
3234
)
3335
)
3436

src/bloqade/shuttle/stdlib/layouts/two_col_zone.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ def get_spec(
3131

3232
return spec.ArchSpec(
3333
layout=spec.Layout(
34-
static_traps={"traps": grid.Grid(x_spacing, y_spacing, 0.0, 0.0)},
35-
fillable=set(["traps"]),
34+
{"traps": grid.Grid(x_spacing, y_spacing, 0.0, 0.0)},
35+
set(["traps"]),
36+
set(["traps"]),
37+
set(["traps"]),
3638
)
3739
)
3840

src/bloqade/shuttle/stdlib/spec.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,7 @@ def single_zone_spec(num_x: int, num_y: int, spacing: float = 10.0) -> spec.Arch
3333
layout=spec.Layout(
3434
static_traps={"traps": grid.Grid(x_spacing, y_spacing, 0.0, 0.0)},
3535
fillable=set(["traps"]),
36+
has_cz=set(["traps"]),
37+
has_local=set(["traps"]),
3638
)
3739
)

test/analysis/test_zone.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ def default_spec():
1919
spec.Layout(
2020
static_traps={"test": grid.Grid.from_positions([0, 1, 2], [0, 1, 2])},
2121
fillable=set(["test"]),
22+
has_cz=set(["test"]),
23+
has_local=set(["test"]),
2224
)
2325
)
2426

test/passes/test_inject_spec.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,20 @@
55
from bloqade.shuttle.prelude import move
66

77

8+
def get_spec(slm_grid: grid.Grid) -> spec.ArchSpec:
9+
return spec.ArchSpec(
10+
layout=spec.Layout(
11+
{"slm": slm_grid},
12+
fillable=set(["slm"]),
13+
has_cz=set(["slm"]),
14+
has_local=set(["slm"]),
15+
)
16+
)
17+
18+
819
def test_inject_spec():
920
slm_grid = grid.Grid.from_positions([1, 2, 3], [4, 5, 6])
10-
test_spec = spec.ArchSpec(
11-
layout=spec.Layout({"slm": slm_grid}, fillable=set(["slm"]))
12-
)
21+
test_spec = get_spec(slm_grid)
1322

1423
@move(arch_spec=test_spec)
1524
def test():
@@ -21,11 +30,8 @@ def test():
2130

2231

2332
def test_inject_spac_callgraph():
24-
2533
slm_grid = grid.Grid.from_positions([1, 2, 3], [4, 5, 6])
26-
test_spec = spec.ArchSpec(
27-
layout=spec.Layout({"slm": slm_grid}, fillable=set(["slm"]))
28-
)
34+
test_spec = get_spec(slm_grid)
2935

3036
@move
3137
def subroutine(depth: int):

test/stdlib/test_spec.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ def test_single_zone_spec():
1818
)
1919
},
2020
fillable=set(["traps"]),
21+
has_cz=set(["traps"]),
22+
has_local=set(["traps"]),
2123
)
2224
)
2325

test/unit/test_arch.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,26 @@
55

66
def test_layout():
77

8-
layout = Layout({"test": Grid.from_positions(range(16), range(16))}, {"test"})
8+
layout = Layout(
9+
{"test": Grid.from_positions(range(16), range(16))},
10+
{"test"},
11+
{"test"},
12+
{"test"},
13+
)
914

1015
assert hash(layout) == hash(
11-
(frozenset(layout.static_traps.items()), frozenset(layout.fillable))
16+
(
17+
frozenset(layout.static_traps.items()),
18+
frozenset(layout.fillable),
19+
frozenset(layout.has_cz),
20+
frozenset(layout.has_local),
21+
frozenset(layout.special_grid.items()),
22+
)
1223
)
1324
assert layout == Layout(
14-
{"test": Grid.from_positions(range(16), range(16))}, {"test"}
25+
{"test": Grid.from_positions(range(16), range(16))},
26+
{"test"},
27+
{"test"},
28+
{"test"},
1529
)
1630
assert layout != 1

0 commit comments

Comments
 (0)