Skip to content

Commit f25f4f0

Browse files
committed
more symbolic prepends
1 parent ef2664e commit f25f4f0

File tree

1 file changed

+201
-5
lines changed

1 file changed

+201
-5
lines changed

src/backtrajectory.jl

Lines changed: 201 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function expand_circuit(circuit::Vector{<:AbstractOperation})
1919
end
2020

2121

22-
"""the `prepend!` function is used to prepend any quantum operation to unitary Clifford operations"""
22+
"""the `prepend!` function is used to prepend any quantum operation to unitary Clifford and Pauli operations"""
2323
function prepend! end
2424
"""the prepend_inv! function is used to prepend the inverse of a quantum operation to unitary Clifford operations"""
2525
function prepend_inv! end
@@ -35,12 +35,12 @@ function prepend_inv! end
3535

3636
# FAST versions of prepend! and prepend_inv! for CliffordOperator - TODO
3737
function prepend!(l::CliffordOperator, r; phases)
38-
@warn "Slow prepend! operation"
38+
@warn "Slow prepend! operation: $r"
3939
prepend!(l, CliffordOperator(r, nqubits(l)); phases=phases)
4040
end
4141

4242
function prepend!(l::CliffordOperator, r::CliffordOperator; phases=false)
43-
nqubits(l)==nqubits(r) || throw(DimensionMismatch("The tableau and the Clifford operator need to act on the same number of qubits. Consider specifying an array of indices as a third argument to the `apply!` function to avoid this error."))
43+
nqubits(l)==nqubits(r) || throw(DimensionMismatch("The two Clifford operators need to act on the same number of qubits."))
4444
l_tab = tab(l)
4545
r_tab = tab(r)
4646
threadlocal = l.buffer
@@ -76,14 +76,46 @@ end
7676

7777

7878
function prepend_inv!(l::CliffordOperator, r; phases=false)
79-
@warn "Slow prepend_inv! operation"
79+
@warn "Slow prepend_inv! operation: $r"
8080
prepend!(l, inv(CliffordOperator(r, nqubits(l))); phases=phases)
8181
end
8282
function prepend_inv!(l::CliffordOperator, r::CliffordOperator; phases=false)
8383
prepend!(l, inv(r); phases=phases)
8484
end
8585

8686
# Symbolic
87+
function prepend!(l::CliffordOperator, r::PauliOperator; phases=false)
88+
nqubits(l)==nqubits(r) || throw(DimensionMismatch("The Clifford and Pauli operators need to act on the same number of qubits."))
89+
tab(l).phases[nqubits(l)+1:end] .⊻= r[1:nqubits(l)]
90+
tab(l).phases[1:nqubits(l)] .⊻= r[nqubits(l)+1:end]
91+
end
92+
# struct IgnoreAntiCommute
93+
# rhs::PauliOperator
94+
# end
95+
# Base.(*)(l::PauliOpearator, r::IgnoreAntiCommute)
96+
# end
97+
function prepend!(l::CliffordOperator, r::sHadamard; phases=false)
98+
l[r.q], l[nqubits(l)+r.q] = l[nqubits(l)+r.q], l[r.q]
99+
return l
100+
end
101+
function prepend!(l::CliffordOperator, r::sHadamardXY; phases=false)
102+
error("Not implemented: prepend!(l, r::sHadamardXY)")
103+
l[r.q] =
104+
prepend!(l, sY(r.q); phases=phases)
105+
return l
106+
end
107+
function prepend!(l::CliffordOperator, r::sHadamardYZ; phases=false)
108+
error("Not implemented: prepend!(l, r::sHadamardYZ)")
109+
l[nqubits(l)+r.q] =
110+
prepend!(l, sZ(r.q); phases=phases)
111+
return l
112+
end
113+
function prepend!(l::CliffordOperator, r::sPhase; phases=false)
114+
error("Not implemented: prepend!(l, r::sPhase)")
115+
end
116+
function prepend!(l::CliffordOperator, r::sInvPhase; phases=false)
117+
error("Not implemented: prepend!(l, r::sInvPhase)")
118+
end
87119
function prepend!(l::CliffordOperator, r::sX; phases=false)
88120
tab(l).phases[nqubits(l)+r.q] ⊻= 0x02
89121
return l
@@ -97,6 +129,148 @@ function prepend!(l::CliffordOperator, r::sZ; phases=false)
97129
tab(l).phases[r.q] ⊻= 0x02
98130
return l
99131
end
132+
function prepend!(l::CliffordOperator, r::sSQRTX; phases=false)
133+
error("Not implemented: prepend!(l, r::$(typeof(r)))")
134+
return l
135+
end
136+
function prepend!(l::CliffordOperator, r::sInvSQRTX; phases=false)
137+
error("Not implemented: prepend!(l, r::$(typeof(r)))")
138+
return l
139+
end
140+
function prepend!(l::CliffordOperator, r::sSQRTY; phases=false)
141+
error("Not implemented: prepend!(l, r::$(typeof(r)))")
142+
return l
143+
end
144+
function prepend!(l::CliffordOperator, r::sInvSQRTY; phases=false)
145+
error("Not implemented: prepend!(l, r::$(typeof(r)))")
146+
return l
147+
end
148+
function prepend!(l::CliffordOperator, r::sCXYZ; phases=false)
149+
error("Not implemented: prepend!(l, r::$(typeof(r)))")
150+
return l
151+
end
152+
function prepend!(l::CliffordOperator, r::sCZYX; phases=false)
153+
error("Not implemented: prepend!(l, r::$(typeof(r)))")
154+
return l
155+
end
156+
function prepend!(l::CliffordOperator, r::sId1; phases=false)
157+
error("Not implemented: prepend!(l, r::sId1)")
158+
return l
159+
end
160+
function prepend!(l::CliffordOperator, r::SingleQubitOperator; phases=false)
161+
error("Not implemented: prepend!(l. r::SingleQubitOperator)")
162+
return l
163+
end
164+
165+
function prepend!(l::CliffordOperator, r::sSWAP; phases=false)
166+
l[nqubits(l)+r.q1], l[nqubits(l)+r.q2] = l[nqubits(l)+r.q2], l[nqubits(l)+r.q1]
167+
l[r.q1], l[r.q2] = l[r.q2], l[r.q1]
168+
return l
169+
end
170+
function prepend!(l::CliffordOperator, r::sSWAPCX; phases=false)
171+
error("Not implemented: prepend!(l, r::$(typeof(r)))")
172+
return l
173+
end
174+
function prepend!(l::CliffordOperator, r::sInvSWAPCX; phases=false)
175+
error("Not implemented: prepend!(l, r::$(typeof(r)))")
176+
return l
177+
end
178+
function prepend!(l::CliffordOperator, r::sISWAP; phases=false)
179+
prepend!(l, sSWAP(r.q1, r.q2); phases=phases)
180+
prepend!(l, sZCZ(r.q1, r.q2); phases=phases)
181+
prepend!(l, sSQRTZ(r.q1); phases=phases)
182+
prepend!(l, sSQRTZ(r.q2); phases=phases)
183+
return l
184+
end
185+
function prepend!(l::CliffordOperator, r::sInvISWAP; phases=false)
186+
error("Not implemented: prepend!(l, r::$(typeof(r)))")
187+
return l
188+
end
189+
function prepend!(l::CliffordOperator, r::sCZSWAP; phases=false)
190+
error("Not implemented: prepend!(l, r::$(typeof(r)))")
191+
return l
192+
end
193+
function prepend!(l::CliffordOperator, r::sCXSWAP; phases=false)
194+
error("Not implemented: prepend!(l, r::$(typeof(r)))")
195+
return l
196+
end
197+
function prepend!(l::CliffordOperator, r::sCNOT; phases=false)
198+
l[nqubits(l)+r.q2] *= l[nqubits(l)+r.q1]
199+
l[r.q1] *= l[r.q2]
200+
return l
201+
end
202+
function prepend!(l::CliffordOperator, r::sCPHASE; phases=false)
203+
error("Not implemented: prepend!(l, r::$(typeof(r)))")
204+
return l
205+
end
206+
function prepend!(l::CliffordOperator, r::sZCX; phases=false)
207+
error("Not implemented: prepend!(l, r::$(typeof(r)))")
208+
return l
209+
end
210+
function prepend!(l::CliffordOperator, r::sZCY; phases=false)
211+
error("Not implemented: prepend!(l, r::$(typeof(r)))")
212+
return l
213+
end
214+
function prepend!(l::CliffordOperator, r::sZCZ; phases=false)
215+
error("Not implemented: prepend!(l, r::$(typeof(r)))")
216+
return l
217+
end
218+
function prepend!(l::CliffordOperator, r::sXCX; phases=false)
219+
error("Not implemented: prepend!(l, r::$(typeof(r)))")
220+
return l
221+
end
222+
function prepend!(l::CliffordOperator, r::sXCY; phases=false)
223+
error("Not implemented: prepend!(l, r::$(typeof(r)))")
224+
return l
225+
end
226+
function prepend!(l::CliffordOperator, r::sXCZ; phases=false)
227+
error("Not implemented: prepend!(l, r::$(typeof(r)))")
228+
return l
229+
end
230+
function prepend!(l::CliffordOperator, r::sYCX; phases=false)
231+
error("Not implemented: prepend!(l, r::$(typeof(r)))")
232+
return l
233+
end
234+
function prepend!(l::CliffordOperator, r::sYCY; phases=false)
235+
error("Not implemented: prepend!(l, r::$(typeof(r)))")
236+
return l
237+
end
238+
function prepend!(l::CliffordOperator, r::sYCZ; phases=false)
239+
error("Not implemented: prepend!(l, r::$(typeof(r)))")
240+
return l
241+
end
242+
function prepend!(l::CliffordOperator, r::sZCrY; phases=false)
243+
error("Not implemented: prepend!(l, r::$(typeof(r)))")
244+
return l
245+
end
246+
function prepend!(l::CliffordOperator, r::sInvZCrY; phases=false)
247+
error("Not implemented: prepend!(l, r::$(typeof(r)))")
248+
return l
249+
end
250+
function prepend!(l::CliffordOperator, r::sSQRTZZ; phases=false)
251+
error("Not implemented: prepend!(l, r::$(typeof(r)))")
252+
return l
253+
end
254+
function prepend!(l::CliffordOperator, r::sInvSQRTZZ; phases=false)
255+
error("Not implemented: prepend!(l, r::$(typeof(r)))")
256+
return l
257+
end
258+
function prepend!(l::CliffordOperator, r::sSQRTXX; phases=false)
259+
error("Not implemented: prepend!(l, r::$(typeof(r)))")
260+
return l
261+
end
262+
function prepend!(l::CliffordOperator, r::sInvSQRTXX; phases=false)
263+
error("Not implemented: prepend!(l, r::$(typeof(r)))")
264+
return l
265+
end
266+
function prepend!(l::CliffordOperator, r::sSQRTYY; phases=false)
267+
error("Not implemented: prepend!(l, r::$(typeof(r)))")
268+
return l
269+
end
270+
function prepend!(l::CliffordOperator, r::sInvSQRTYY; phases=false)
271+
error("Not implemented: prepend!(l, r::$(typeof(r)))")
272+
return l
273+
end
100274

101275
function prepend_inv!(l::CliffordOperator, r::sX; phases=false)
102276
tab(l).phases[nqubits(l)+r.q] ⊻= 0x02
@@ -110,6 +284,28 @@ function prepend_inv!(l::CliffordOperator, r::sZ; phases=false)
110284
tab(l).phases[r.q] ⊻= 0x02
111285
return l
112286
end
287+
function prepend_inv!(l::CliffordOperator, r::sHadamard; phases=false)
288+
l[r.q], l[nqubits(l)+r.q] = l[nqubits(l)+r.q], l[r.q]
289+
return l
290+
end
291+
function prepend_inv!(l::CliffordOperator, r::sHadamardYZ; phases=false)
292+
error("Not implemented: prepend_inv!(l, r::sHadamardYZ)")
293+
return l
294+
end
295+
function prepend_inv!(l::CliffordOperator, r::sHadamardXY; phases=false)
296+
error("Not implemented: prepend_inv!(l, r::sHadamardXY)")
297+
return l
298+
end
299+
function prepend_inv!(l::CliffordOperator, r::sCNOT; phases=false)
300+
l[nqubits(l)+r.q2] *= l[nqubits(l)+r.q1]
301+
l[r.q1] *= l[r.q2]
302+
return l
303+
end
304+
function prepend_inv!(l::CliffordOperator, r::sSWAP; phases=false)
305+
l[nqubits(l)+r.q1], l[nqubits(l)+r.q2] = l[nqubits(l)+r.q2], l[nqubits(l)+r.q1]
306+
l[r.q1], l[r.q2] = l[r.q2], l[r.q1]
307+
return l
308+
end
113309

114310

115311
"""
@@ -134,7 +330,7 @@ function backtrajectory(circuit0::Vector{<:AbstractOperation}, n::Int)
134330

135331
for op in circuit
136332
if op isa AbstractCliffordOperator
137-
T = prepend_inv!(T, op; phases=true)
333+
prepend_inv!(T, op; phases=true)
138334
elseif op isa sMZ
139335
pivot = 0
140336
for c in 1:n

0 commit comments

Comments
 (0)