Skip to content

Commit 58a91e2

Browse files
cduckjohnzl-777
andauthored
Clean up squin gate generation (#564)
Co-authored-by: John Long <[email protected]>
1 parent dadcd37 commit 58a91e2

File tree

4 files changed

+101
-120
lines changed

4 files changed

+101
-120
lines changed

src/bloqade/squin/rewrite/U3_to_clifford.py

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ class Sdag(ir.Statement):
1515
pass
1616

1717

18+
class SqrtXdag(ir.Statement):
19+
pass
20+
21+
22+
class SqrtYdag(ir.Statement):
23+
pass
24+
25+
1826
# (theta, phi, lam)
1927
U3_HALF_PI_ANGLE_TO_GATES: dict[
2028
tuple[int, int, int], list[type[ir.Statement]] | list[None]
@@ -27,21 +35,21 @@ class Sdag(ir.Statement):
2735
(1, 0, 1): [gate.stmts.S, gate.stmts.SqrtY],
2836
(1, 0, 2): [gate.stmts.H],
2937
(1, 0, 3): [Sdag, gate.stmts.SqrtY],
30-
(1, 1, 0): [gate.stmts.SqrtY, gate.stmts.S],
31-
(1, 1, 1): [gate.stmts.S, gate.stmts.SqrtY, gate.stmts.S],
32-
(1, 1, 2): [gate.stmts.Z, gate.stmts.SqrtY, gate.stmts.S],
33-
(1, 1, 3): [Sdag, gate.stmts.SqrtY, gate.stmts.S],
34-
(1, 2, 0): [gate.stmts.SqrtY, gate.stmts.Z],
35-
(1, 2, 1): [gate.stmts.S, gate.stmts.SqrtY, gate.stmts.Z],
36-
(1, 2, 2): [gate.stmts.Z, gate.stmts.SqrtY, gate.stmts.Z],
37-
(1, 2, 3): [Sdag, gate.stmts.SqrtY, gate.stmts.Z],
38-
(1, 3, 0): [gate.stmts.SqrtY, Sdag],
39-
(1, 3, 1): [gate.stmts.S, gate.stmts.SqrtY, Sdag],
40-
(1, 3, 2): [gate.stmts.Z, gate.stmts.SqrtY, Sdag],
41-
(1, 3, 3): [Sdag, gate.stmts.SqrtY, Sdag],
38+
(1, 1, 0): [gate.stmts.S, SqrtXdag],
39+
(1, 1, 1): [gate.stmts.Z, SqrtXdag],
40+
(1, 1, 2): [Sdag, SqrtXdag],
41+
(1, 1, 3): [SqrtXdag],
42+
(1, 2, 0): [gate.stmts.Z, SqrtYdag],
43+
(1, 2, 1): [Sdag, SqrtYdag],
44+
(1, 2, 2): [SqrtYdag],
45+
(1, 2, 3): [gate.stmts.S, SqrtYdag],
46+
(1, 3, 0): [Sdag, gate.stmts.SqrtX],
47+
(1, 3, 1): [gate.stmts.SqrtX],
48+
(1, 3, 2): [gate.stmts.S, gate.stmts.SqrtX],
49+
(1, 3, 3): [gate.stmts.Z, gate.stmts.SqrtX],
4250
(2, 0, 0): [gate.stmts.Y],
4351
(2, 0, 1): [gate.stmts.S, gate.stmts.Y],
44-
(2, 0, 2): [gate.stmts.Z, gate.stmts.Y],
52+
(2, 0, 2): [gate.stmts.X],
4553
(2, 0, 3): [Sdag, gate.stmts.Y],
4654
}
4755

@@ -106,6 +114,10 @@ def rewrite_U3(self, node: gate.stmts.U3) -> RewriteResult:
106114
for gate_stmt in gates:
107115
if gate_stmt is Sdag:
108116
new_stmt = gate.stmts.S(adjoint=True, qubits=node.qubits)
117+
elif gate_stmt is SqrtXdag:
118+
new_stmt = gate.stmts.SqrtX(adjoint=True, qubits=node.qubits)
119+
elif gate_stmt is SqrtYdag:
120+
new_stmt = gate.stmts.SqrtY(adjoint=True, qubits=node.qubits)
109121
else:
110122
new_stmt = gate_stmt(qubits=node.qubits)
111123
new_stmt.insert_before(node)

0 commit comments

Comments
 (0)