Skip to content

Commit 4d70c13

Browse files
authored
fixing bug related to permutation of position order in bloqade-geometry (#53)
1 parent 83f11cb commit 4d70c13

File tree

5 files changed

+60
-46
lines changed

5 files changed

+60
-46
lines changed

src/bloqade/lanes/analysis/atom/impl.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,7 @@ def noop_impl(
170170
):
171171
frame.set_state_for_stmt(stmt)
172172

173-
@interp.impl(move.Initialize)
174-
def initialize_impl(
175-
self, interp_: AtomInterpreter, frame: AtomFrame, stmt: move.Initialize
176-
):
173+
@interp.impl(move.Fill)
174+
def fill_impl(self, interp_: AtomInterpreter, frame: AtomFrame, stmt: move.Fill):
177175
frame.current_state = AtomState(stmt.location_addresses)
178176
frame.set_state_for_stmt(stmt)

src/bloqade/lanes/arch/gemini/impls.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
from bloqade.lanes.layout.word import Word
77

88

9-
def site_buses(word_size_y: int):
10-
site_addresses = np.arange(word_size_y * 2).reshape((word_size_y, 2))
9+
def site_buses(site_addresses: np.ndarray):
10+
word_size_y = site_addresses.shape[0]
1111

1212
site_buses: list[Bus] = []
1313
for shift in range(word_size_y):
@@ -26,7 +26,6 @@ def site_buses(word_size_y: int):
2626
src=as_flat_tuple_int(site_addresses[shift:, 0]),
2727
)
2828
)
29-
3029
return tuple(site_buses)
3130

3231

@@ -62,18 +61,24 @@ def generate_arch(hypercube_dims: int = 4, word_size_y: int = 5) -> ArchSpec:
6261
Word(tuple(grid.shift(10.0 * ix, 0.0).positions)) for ix in range(num_word_x)
6362
)
6463

65-
word_ids = np.arange(word_size_x * word_size_y).reshape(word_size_y, word_size_x)
64+
site_ids = (
65+
np.arange(word_size_x * word_size_y)
66+
.reshape(word_size_x, word_size_y)
67+
.transpose()
68+
)
6669
word_buses = hypercube_busses(hypercube_dims)
6770
site_bus_compatibility = tuple(
6871
frozenset(range(num_word_x)) for _ in range(num_word_x)
6972
)
73+
7074
gate_zone = tuple(range(len(words)))
75+
7176
return ArchSpec(
7277
words,
7378
(gate_zone,),
7479
frozenset(range(num_word_x)),
75-
frozenset(as_flat_tuple_int(word_ids[:, 1])),
76-
site_buses(word_size_y),
80+
frozenset(as_flat_tuple_int(site_ids[:, 1])),
81+
site_buses(site_ids),
7782
word_buses,
7883
site_bus_compatibility,
7984
)

src/bloqade/lanes/heuristics/fixed.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ def validate_initial_layout(
4646
raise ValueError(
4747
"Initial layout contains invalid word id for logical arch"
4848
)
49-
if addr.site_id % 2 != 0:
49+
if addr.site_id >= 5:
5050
raise ValueError(
51-
"Initial layout should only contain even site ids for fixed home location strategy"
51+
"Initial layout should only site ids < 5 for logical arch"
5252
)
5353

5454
def _word_balance(
@@ -125,7 +125,7 @@ def cz_placements(
125125
mover, dst_addr = self._pick_mover_and_location(state, start_word_id, c, t)
126126
new_positions[mover] = LocationAddress(
127127
word_id=dst_addr.word_id,
128-
site_id=dst_addr.site_id + 1,
128+
site_id=dst_addr.site_id + 5,
129129
)
130130

131131
return self._update_positions(state, new_positions)
@@ -158,6 +158,9 @@ def assert_valid_word_bus_move(
158158
assert (
159159
src_site in self.arch_spec.has_word_buses
160160
), f"Invalid source site {src_site} for word bus move"
161+
assert src_word < len(
162+
self.arch_spec.words
163+
), f"Invalid source word {src_word} for site bus move {bus_id}"
161164

162165
return WordLaneAddress(
163166
direction,
@@ -182,6 +185,9 @@ def assert_valid_site_bus_move(
182185
assert (
183186
src_word in self.arch_spec.has_site_buses
184187
), f"Invalid source word {src_word} for site bus move {bus_id}"
188+
assert src_word < len(
189+
self.arch_spec.words
190+
), f"Invalid source word {src_word} for site bus move {bus_id}"
185191

186192
return SiteLaneAddress(
187193
direction,
@@ -200,7 +206,8 @@ def site_moves(
200206

201207
bus_moves = {}
202208
for before, end in diffs:
203-
bus_id = end.site_id // 2 - before.site_id // 2
209+
bus_id = (end.site_id % 5) - (before.site_id % 5)
210+
204211
if bus_id < 0:
205212
bus_id += len(self.arch_spec.site_buses)
206213

@@ -265,6 +272,9 @@ def compute_moves(
265272
moves.extend(self.site_moves(groups.get((0, 0), []), 0))
266273
moves.extend(self.site_moves(groups.get((1, 1), []), 1))
267274

275+
for move_group in moves:
276+
print(move_group)
277+
268278
return moves
269279

270280

@@ -322,9 +332,8 @@ def compute_layout(
322332
available_addresses = set(
323333
[
324334
LocationAddress(word_id, site_id)
325-
for word_id, word in enumerate(self.arch_spec.words)
326-
for site_id in range(len(word.sites))
327-
if site_id % 2 == 0
335+
for word_id in range(len(self.arch_spec.words))
336+
for site_id in range(5)
328337
]
329338
)
330339

src/bloqade/lanes/visualize.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ def get_drawer(mt: ir.Method, arch_spec: ArchSpec, ax: Axes, atom_marker: str =
133133
steps.append((stmt, curr_state))
134134

135135
def draw(step_index: int):
136+
if len(steps) == 0:
137+
return
136138
stmt, curr_state = steps[step_index]
137139
show_slm(ax, stmt, arch_spec, atom_marker)
138140

test/heuristics/test_fixed.py

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,19 @@ def cz_placement_cases():
3030
occupied=frozenset(),
3131
layout=(
3232
LocationAddress(0, 0),
33-
LocationAddress(0, 2),
33+
LocationAddress(0, 1),
3434
LocationAddress(1, 0),
35-
LocationAddress(1, 2),
35+
LocationAddress(1, 1),
3636
),
3737
move_count=(0, 0, 0, 0),
3838
)
3939
state_after = ConcreteState(
4040
occupied=frozenset(),
4141
layout=(
42-
LocationAddress(1, 1),
43-
LocationAddress(1, 3),
42+
LocationAddress(1, 5),
43+
LocationAddress(1, 6),
4444
LocationAddress(1, 0),
45-
LocationAddress(1, 2),
45+
LocationAddress(1, 1),
4646
),
4747
move_count=(1, 1, 0, 0),
4848
)
@@ -58,19 +58,19 @@ def cz_placement_cases():
5858
occupied=frozenset(),
5959
layout=(
6060
LocationAddress(0, 0),
61-
LocationAddress(0, 2),
61+
LocationAddress(0, 1),
6262
LocationAddress(1, 0),
63-
LocationAddress(1, 2),
63+
LocationAddress(1, 1),
6464
),
6565
move_count=(1, 1, 0, 0),
6666
)
6767
state_after = ConcreteState(
6868
occupied=frozenset(),
6969
layout=(
7070
LocationAddress(0, 0),
71-
LocationAddress(0, 2),
7271
LocationAddress(0, 1),
73-
LocationAddress(0, 3),
72+
LocationAddress(0, 5),
73+
LocationAddress(0, 6),
7474
),
7575
move_count=(1, 1, 1, 1),
7676
)
@@ -85,19 +85,19 @@ def cz_placement_cases():
8585
occupied=frozenset(),
8686
layout=(
8787
LocationAddress(0, 0),
88+
LocationAddress(0, 1),
8889
LocationAddress(0, 2),
89-
LocationAddress(0, 4),
90-
LocationAddress(0, 6),
90+
LocationAddress(0, 3),
9191
),
9292
move_count=(1, 1, 0, 0),
9393
)
9494
state_after = ConcreteState(
9595
occupied=frozenset(),
9696
layout=(
9797
LocationAddress(0, 0),
98-
LocationAddress(0, 2),
9998
LocationAddress(0, 1),
100-
LocationAddress(0, 3),
99+
LocationAddress(0, 5),
100+
LocationAddress(0, 6),
101101
),
102102
move_count=(1, 1, 1, 1),
103103
)
@@ -112,19 +112,19 @@ def cz_placement_cases():
112112
occupied=frozenset(),
113113
layout=(
114114
LocationAddress(0, 0),
115+
LocationAddress(0, 1),
115116
LocationAddress(0, 2),
116-
LocationAddress(0, 4),
117-
LocationAddress(0, 6),
117+
LocationAddress(0, 3),
118118
),
119119
move_count=(0, 0, 1, 1),
120120
)
121121
state_after = ConcreteState(
122122
occupied=frozenset(),
123123
layout=(
124-
LocationAddress(0, 5),
125124
LocationAddress(0, 7),
126-
LocationAddress(0, 4),
127-
LocationAddress(0, 6),
125+
LocationAddress(0, 8),
126+
LocationAddress(0, 2),
127+
LocationAddress(0, 3),
128128
),
129129
move_count=(1, 1, 1, 1),
130130
)
@@ -185,7 +185,7 @@ def test_fixed_invalid_initial_layout_1():
185185
LocationAddress(0, 0),
186186
LocationAddress(0, 1),
187187
LocationAddress(0, 2),
188-
LocationAddress(0, 3),
188+
LocationAddress(0, 5),
189189
)
190190
with pytest.raises(ValueError):
191191
placement_strategy.validate_initial_layout(layout)
@@ -215,15 +215,15 @@ def test_initial_layout():
215215
print(layout)
216216
assert layout == (
217217
LocationAddress(word_id=0, site_id=0),
218+
LocationAddress(word_id=0, site_id=1),
218219
LocationAddress(word_id=0, site_id=2),
220+
LocationAddress(word_id=0, site_id=3),
219221
LocationAddress(word_id=0, site_id=4),
220-
LocationAddress(word_id=0, site_id=6),
221-
LocationAddress(word_id=0, site_id=8),
222222
LocationAddress(word_id=1, site_id=0),
223+
LocationAddress(word_id=1, site_id=1),
223224
LocationAddress(word_id=1, site_id=2),
225+
LocationAddress(word_id=1, site_id=3),
224226
LocationAddress(word_id=1, site_id=4),
225-
LocationAddress(word_id=1, site_id=6),
226-
LocationAddress(word_id=1, site_id=8),
227227
)
228228

229229

@@ -234,7 +234,7 @@ def test_move_scheduler_cz():
234234
tuple(
235235
LocationAddress(word_id, site_id)
236236
for word_id in range(2)
237-
for site_id in range(0, 10, 2)
237+
for site_id in range(5)
238238
),
239239
tuple(0 for _ in range(10)),
240240
)
@@ -257,19 +257,19 @@ def test_move_scheduler_cz():
257257
direction=Direction.FORWARD, word_id=0, site_id=0, bus_id=0
258258
),
259259
SiteLaneAddress(
260-
direction=Direction.FORWARD, word_id=0, site_id=2, bus_id=0
260+
direction=Direction.FORWARD, word_id=0, site_id=1, bus_id=0
261261
),
262262
),
263-
(SiteLaneAddress(direction=Direction.FORWARD, word_id=0, site_id=8, bus_id=7),),
263+
(SiteLaneAddress(direction=Direction.FORWARD, word_id=0, site_id=4, bus_id=7),),
264264
(
265265
WordLaneAddress(
266-
direction=Direction.FORWARD, word_id=0, site_id=1, bus_id=0
266+
direction=Direction.FORWARD, word_id=0, site_id=5, bus_id=0
267267
),
268268
WordLaneAddress(
269-
direction=Direction.FORWARD, word_id=0, site_id=3, bus_id=0
269+
direction=Direction.FORWARD, word_id=0, site_id=6, bus_id=0
270270
),
271271
WordLaneAddress(
272-
direction=Direction.FORWARD, word_id=0, site_id=5, bus_id=0
272+
direction=Direction.FORWARD, word_id=0, site_id=7, bus_id=0
273273
),
274274
),
275275
]

0 commit comments

Comments
 (0)