Skip to content

Commit a33451e

Browse files
weinbe58Copilot
andauthored
Refactor standard library and updating dependencies. (#60)
* adding new submodule for standard library * updating lock * Apply suggestions from code review Co-authored-by: Copilot <[email protected]> * adding imports * adding imports --------- Co-authored-by: Copilot <[email protected]>
1 parent e58c5cb commit a33451e

File tree

10 files changed

+2295
-806
lines changed

10 files changed

+2295
-806
lines changed

pyproject.toml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,8 @@ authors = [
77
]
88
dependencies = [
99
"bloqade-geometry ~=0.3.0",
10-
"bloqade-circuit ~=0.6.0",
10+
"bloqade-circuit >=0.6.0,<0.8.0-dev",
1111
"kirin-toolchain >= 0.17.17,<0.18.0-dev",
12-
"pint>=0.24.3",
13-
"pyarrow>=17.0.0",
14-
"pytest>=8.3.2",
15-
"numpy>=1.26.4",
1612
]
1713

1814
readme = "README.md"
@@ -23,8 +19,6 @@ visualization = [
2319
"matplotlib>=3.9.4",
2420
]
2521

26-
27-
2822
[build-system]
2923
requires = ["hatchling"]
3024
build-backend = "hatchling.build"

src/bloqade/shuttle/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from . import arch as arch, passes as passes, stdlib as stdlib
21
from .dialects.action import _interface as action
32
from .dialects.atom import _interface as atom
43
from .dialects.filled import _interface as filled
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import layouts as layouts
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import single_col_zone as single_col_zone, two_col_zone as two_col_zone
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from bloqade.shuttle.prelude import tweezer
2+
3+
4+
@tweezer
5+
def assert_sorted(indices):
6+
for i in range(1, len(indices)):
7+
assert indices[i - 1] < indices[i], "Indices must be sorted in ascending order."
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
from itertools import repeat
2+
from typing import Any, TypeVar
3+
4+
from bloqade.geometry.dialects import grid
5+
from kirin.dialects import ilist
6+
7+
from bloqade.shuttle import action, gate, schedule, spec
8+
from bloqade.shuttle.prelude import move, tweezer
9+
10+
from .asserts import assert_sorted
11+
12+
13+
def get_spec(num_x: int, num_y: int, spacing: float = 10.0) -> spec.ArchSpec:
14+
"""Create a static trap spec with a single zone. compatible with the stdlib
15+
16+
Args:
17+
num_x (int): Number of traps in the x direction.
18+
num_y (int): Number of traps in the y direction.
19+
spacing (float): Spacing between traps in both directions. Default is 10.0.
20+
21+
Returns:
22+
spec.Spec: A specification object containing the layout with a single zone.
23+
24+
"""
25+
x_spacing = tuple(repeat(spacing, num_x - 1))
26+
y_spacing = tuple(repeat(spacing, num_y - 1))
27+
28+
return spec.ArchSpec(
29+
layout=spec.Layout(
30+
static_traps={"traps": grid.Grid(x_spacing, y_spacing, 0.0, 0.0)},
31+
fillable=set(["traps"]),
32+
)
33+
)
34+
35+
36+
NumX = TypeVar("NumX")
37+
NumY = TypeVar("NumY")
38+
39+
40+
@tweezer
41+
def single_zone_move_cz(
42+
zone: grid.Grid[Any, Any],
43+
ctrl_x_ids: ilist.IList[int, NumX],
44+
ctrl_y_ids: ilist.IList[int, NumY],
45+
qarg_x_ids: ilist.IList[int, NumX],
46+
qarg_y_ids: ilist.IList[int, NumY],
47+
shift_x: float,
48+
shift_y: float,
49+
):
50+
assert len(ctrl_x_ids) == len(
51+
qarg_x_ids
52+
), "Control and target x indices must have the same length."
53+
54+
assert len(ctrl_y_ids) == len(
55+
qarg_y_ids
56+
), "Control and target y indices must have the same length."
57+
58+
assert_sorted(ctrl_x_ids)
59+
assert_sorted(ctrl_y_ids)
60+
assert_sorted(qarg_x_ids)
61+
assert_sorted(qarg_y_ids)
62+
63+
start = grid.sub_grid(zone, ctrl_x_ids, ctrl_y_ids)
64+
target_atoms = grid.sub_grid(zone, qarg_x_ids, qarg_y_ids)
65+
66+
end = grid.shift(target_atoms, shift_x, shift_y)
67+
first_pos = grid.shift(start, shift_x, shift_y)
68+
second_pos = grid.from_positions(grid.get_xpos(end), grid.get_ypos(first_pos))
69+
70+
action.set_loc(start)
71+
action.turn_on(action.ALL, action.ALL)
72+
action.move(first_pos)
73+
action.move(second_pos)
74+
action.move(end)
75+
76+
77+
@move
78+
def default_move_cz_impl(
79+
zone: grid.Grid[Any, Any],
80+
x_shift: float,
81+
y_shift: float,
82+
ctrl_x_ids: ilist.IList[int, NumX],
83+
ctrl_y_ids: ilist.IList[int, NumY],
84+
qarg_x_ids: ilist.IList[int, NumX],
85+
qarg_y_ids: ilist.IList[int, NumY],
86+
):
87+
"""Move atoms from the start ids and run cz gate with the atoms at the end ids.
88+
89+
Args:
90+
zone (grid.Grid[Any, Any]): The grid representing the trap layout (zone) in which atoms are moved.
91+
x_shift (float): The amount to shift atoms in the x direction during the move.
92+
y_shift (float): The amount to shift atoms in the y direction during the move.
93+
ctrl_x_ids (ilist.IList[int, NumX]): The x-indices of the starting positions.
94+
ctrl_y_ids (ilist.IList[int, NumY]): The y-indices of the starting positions.
95+
qarg_x_ids (ilist.IList[int, NumX]): The x-indices of the ending positions.
96+
qarg_y_ids (ilist.IList[int, NumY]): The y-indices of the ending positions.
97+
"""
98+
if len(ctrl_x_ids) < 1 or len(qarg_x_ids) < 1:
99+
return
100+
101+
fwd_kernel = schedule.device_fn(
102+
single_zone_move_cz,
103+
ilist.range(len(ctrl_x_ids)),
104+
ilist.range(len(ctrl_y_ids)),
105+
)
106+
bwd_kernel = schedule.reverse(fwd_kernel)
107+
108+
fwd_kernel(zone, ctrl_x_ids, ctrl_y_ids, qarg_x_ids, qarg_y_ids, x_shift, y_shift)
109+
gate.top_hat_cz(zone)
110+
bwd_kernel(zone, qarg_x_ids, qarg_y_ids, ctrl_x_ids, ctrl_y_ids, x_shift, y_shift)
111+
112+
113+
DEFAULT_X_SHIFT = 2.0
114+
DEFAULT_Y_SHIFT = 2.0
115+
116+
117+
@move
118+
def cz_move(
119+
ctrl_x_ids: ilist.IList[int, NumX],
120+
ctrl_y_ids: ilist.IList[int, NumY],
121+
qarg_x_ids: ilist.IList[int, NumX],
122+
qarg_y_ids: ilist.IList[int, NumY],
123+
):
124+
zone = spec.get_static_trap(zone_id="traps")
125+
default_move_cz_impl(
126+
zone,
127+
DEFAULT_X_SHIFT,
128+
DEFAULT_Y_SHIFT,
129+
ctrl_x_ids,
130+
ctrl_y_ids,
131+
qarg_x_ids,
132+
qarg_y_ids,
133+
)
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
from itertools import repeat
2+
from typing import TypeVar
3+
4+
from bloqade.geometry.dialects import grid
5+
from kirin.dialects import ilist
6+
7+
from bloqade.shuttle import action, schedule, spec
8+
from bloqade.shuttle.prelude import move, tweezer
9+
10+
from .asserts import assert_sorted
11+
12+
13+
def get_spec(
14+
num_x: int, num_y: int, spacing: float = 10.0, gate_spacing: float = 2.0
15+
) -> spec.ArchSpec:
16+
"""Create a static trap spec with a single zone with pairs of traps oriented
17+
horizontally.
18+
19+
Args:
20+
num_x (int): Number of pairs of traps in the x direction.
21+
num_y (int): Number of pairs of traps in the y direction.
22+
spacing (float): Spacing between traps in both directions. Default is 10.0.
23+
gate_spacing (float): Spacing between gates. Default is 2.0.
24+
25+
Returns:
26+
spec.Spec: A specification object containing the layout with a single zone.
27+
28+
"""
29+
x_spacing = sum(repeat((gate_spacing, spacing), num_x - 1), ())
30+
y_spacing = tuple(repeat(spacing, num_y - 1))
31+
32+
return spec.ArchSpec(
33+
layout=spec.Layout(
34+
static_traps={"traps": grid.Grid(x_spacing, y_spacing, 0.0, 0.0)},
35+
fillable=set(["traps"]),
36+
)
37+
)
38+
39+
40+
NumX = TypeVar("NumX")
41+
NumY = TypeVar("NumY")
42+
43+
44+
@tweezer
45+
def rearrange_impl(
46+
src_x: ilist.IList[int, NumX],
47+
src_y: ilist.IList[int, NumY],
48+
dst_x: ilist.IList[int, NumX],
49+
dst_y: ilist.IList[int, NumY],
50+
):
51+
assert len(src_x) == len(
52+
dst_x
53+
), "Source and destination x indices must have the same length."
54+
assert len(src_y) == len(
55+
dst_y
56+
), "Source and destination y indices must have the same length."
57+
58+
assert_sorted(src_x)
59+
assert_sorted(src_y)
60+
assert_sorted(dst_x)
61+
assert_sorted(dst_y)
62+
63+
zone = spec.get_static_trap(zone_id="traps")
64+
65+
start = grid.sub_grid(zone, src_x, src_y)
66+
end = grid.sub_grid(zone, dst_x, dst_y)
67+
68+
x_positions = grid.get_xpos(start)
69+
70+
def parking_x(index: int):
71+
return x_positions[index] + 3.0 * (2 * (index % 2) - 1)
72+
73+
src_parking = grid.from_positions(ilist.map(parking_x, src_x), grid.get_ypos(zone))
74+
75+
dst_parking = grid.shift(end, 0.0, 3.0)
76+
mid_pos = grid.from_positions(
77+
grid.get_xpos(src_parking), grid.get_ypos(dst_parking)
78+
)
79+
80+
action.set_loc(start)
81+
action.turn_on(action.ALL, action.ALL)
82+
action.move(src_parking)
83+
action.move(mid_pos)
84+
action.move(dst_parking)
85+
action.move(end)
86+
action.turn_off(action.ALL, action.ALL)
87+
88+
89+
@move
90+
def rearrange(
91+
src_x: ilist.IList[int, NumX],
92+
src_y: ilist.IList[int, NumY],
93+
dst_x: ilist.IList[int, NumX],
94+
dst_y: ilist.IList[int, NumY],
95+
):
96+
if len(src_x) < 1 or len(dst_x) < 1:
97+
return
98+
99+
x_tones = ilist.range(len(src_x))
100+
y_tones = ilist.range(len(src_y))
101+
102+
device_fn = schedule.device_fn(rearrange_impl, x_tones, y_tones)
103+
device_fn(src_x, src_y, dst_x, dst_y)

src/bloqade/shuttle/stdlib/moves.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import warnings
12
from typing import Any, TypeVar
23

34
from bloqade.geometry.dialects import grid
@@ -6,6 +7,14 @@
67
from bloqade.shuttle import action, gate, schedule, spec
78
from bloqade.shuttle.prelude import move, tweezer
89

10+
warnings.warn(
11+
(
12+
"This module has been moved to `stdlib.layouts.single_col_zone` submodule and"
13+
" will be removed in 0.8.0"
14+
),
15+
DeprecationWarning,
16+
)
17+
918
NumX = TypeVar("NumX")
1019
NumY = TypeVar("NumY")
1120

src/bloqade/shuttle/stdlib/spec.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1+
import warnings
12
from itertools import repeat
23

34
from bloqade.geometry.dialects import grid
45

56
from bloqade.shuttle import spec
67

8+
warnings.warn(
9+
(
10+
"This module's contents have been moved to `stdlib.layouts.single_col_zone` submodule and"
11+
" will be removed in 0.8.0"
12+
),
13+
DeprecationWarning,
14+
)
15+
716

817
def single_zone_spec(num_x: int, num_y: int, spacing: float = 10.0) -> spec.ArchSpec:
918
"""Create a static trap spec with a single zone. compatible with the stdlib

0 commit comments

Comments
 (0)