1+ """ the `prepend!` function is used to prepend any quantum operation to unitary Clifford and Pauli operations"""
2+ function prepend! end
3+ """ the prepend_inv! function is used to prepend the inverse of a quantum operation to unitary Clifford operations"""
4+ function prepend_inv! end
5+
6+ # # SLOW versions of prepend! and prepend_inv! for CliffordOperator
7+ # function prepend!(l::CliffordOperator, r::AbstractCliffordOperator; phases=false)
8+ # apply!(CliffordOperator(r, nqubits(l)), l; phases=phases)
9+ # end
10+ # function prepend_inv!(l::CliffordOperator, r::AbstractCliffordOperator; phases=false)
11+ # apply!(inv(CliffordOperator(r, nqubits(l))), l; phases=phases)
12+ # end
13+
14+
15+ # FAST versions of prepend! and prepend_inv! for CliffordOperator - TODO
16+ function prepend! (l:: CliffordOperator , r; phases)
17+ @warn " Slow prepend! operation: $r "
18+ prepend! (l, CliffordOperator (r, nqubits (l)); phases= phases)
19+ end
20+
21+ function prepend! (l:: CliffordOperator , r:: CliffordOperator ; phases= false )
22+ nqubits (l)== nqubits (r) || throw (DimensionMismatch (" The two Clifford operators need to act on the same number of qubits." ))
23+ l_tab = tab (l)
24+ r_tab = tab (r)
25+ threadlocal = l. buffer
26+ new_xzs = Vector {typeof(threadlocal)} (undef, length (l_tab))
27+ @inbounds for row_r in eachindex (r_tab)
28+ zero! (threadlocal)
29+ prepend_row_kernel! (threadlocal, row_r, l_tab, r_tab, phases= phases)
30+ new_xzs[row_r] = copy (threadlocal)
31+ end
32+ @inbounds for row_l in eachindex (l_tab)
33+ l_tab[row_l] = new_xzs[row_l]
34+ end
35+ l
36+ end
37+
38+ @inline function prepend_row_kernel! (new_lrow, row, l_tab, r_tab; phases= true )
39+ phases && (new_lrow. phase[] = r_tab. phases[row])
40+ n = nqubits (l_tab)
41+ for qubit in 1 : n
42+ x,z = r_tab[row,qubit]
43+ if phases&& x&& z
44+ new_lrow. phase[] -= 0x1
45+ end
46+ if x
47+ mul_left! (new_lrow, l_tab, qubit, phases= Val (phases))
48+ end
49+ if z
50+ mul_left! (new_lrow, l_tab, qubit+ n, phases= Val (phases))
51+ end
52+ end
53+ new_lrow
54+ end
55+
56+
57+ function prepend_inv! (l:: CliffordOperator , r; phases= false )
58+ @warn " Slow prepend_inv! operation: $r "
59+ prepend! (l, inv (CliffordOperator (r, nqubits (l))); phases= phases)
60+ end
61+ function prepend_inv! (l:: CliffordOperator , r:: CliffordOperator ; phases= false )
62+ prepend! (l, inv (r); phases= phases)
63+ end
64+
65+ # Symbolic
66+ function prepend! (l:: CliffordOperator , r:: PauliOperator ; phases= false )
67+ nqubits (l)== nqubits (r) || throw (DimensionMismatch (" The Clifford and Pauli operators need to act on the same number of qubits." ))
68+ tab (l). phases[nqubits (l)+ 1 : end ] .⊻= r[1 : nqubits (l)]
69+ tab (l). phases[1 : nqubits (l)] .⊻= r[nqubits (l)+ 1 : end ]
70+ end
71+ # struct IgnoreAntiCommute
72+ # rhs::PauliOperator
73+ # end
74+ # Base.(*)(l::PauliOpearator, r::IgnoreAntiCommute)
75+ # end
76+ function prepend! (l:: CliffordOperator , r:: sHadamard ; phases= false )
77+ l[r. q], l[nqubits (l)+ r. q] = l[nqubits (l)+ r. q], l[r. q]
78+ return l
79+ end
80+ function prepend! (l:: CliffordOperator , r:: sHadamardXY ; phases= false )
81+ error (" Not implemented: prepend!(l, r::sHadamardXY)" )
82+ l[r. q] =
83+ prepend! (l, sY (r. q); phases= phases)
84+ return l
85+ end
86+ function prepend! (l:: CliffordOperator , r:: sHadamardYZ ; phases= false )
87+ error (" Not implemented: prepend!(l, r::sHadamardYZ)" )
88+ l[nqubits (l)+ r. q] =
89+ prepend! (l, sZ (r. q); phases= phases)
90+ return l
91+ end
92+ function prepend! (l:: CliffordOperator , r:: sPhase ; phases= false )
93+ error (" Not implemented: prepend!(l, r::sPhase)" )
94+ end
95+ function prepend! (l:: CliffordOperator , r:: sInvPhase ; phases= false )
96+ error (" Not implemented: prepend!(l, r::sInvPhase)" )
97+ end
98+ function prepend! (l:: CliffordOperator , r:: sX ; phases= false )
99+ tab (l). phases[nqubits (l)+ r. q] ⊻= 0x02
100+ return l
101+ end
102+ function prepend! (l:: CliffordOperator , r:: sY ; phases= false )
103+ tab (l). phases[r. q] ⊻= 0x02
104+ tab (l). phases[nqubits (l)+ r. q] ⊻= 0x02
105+ return l
106+ end
107+ function prepend! (l:: CliffordOperator , r:: sZ ; phases= false )
108+ tab (l). phases[r. q] ⊻= 0x02
109+ return l
110+ end
111+ function prepend! (l:: CliffordOperator , r:: sSQRTX ; phases= false )
112+ error (" Not implemented: prepend!(l, r::$(typeof (r)) )" )
113+ return l
114+ end
115+ function prepend! (l:: CliffordOperator , r:: sInvSQRTX ; phases= false )
116+ error (" Not implemented: prepend!(l, r::$(typeof (r)) )" )
117+ return l
118+ end
119+ function prepend! (l:: CliffordOperator , r:: sSQRTY ; phases= false )
120+ error (" Not implemented: prepend!(l, r::$(typeof (r)) )" )
121+ return l
122+ end
123+ function prepend! (l:: CliffordOperator , r:: sInvSQRTY ; phases= false )
124+ error (" Not implemented: prepend!(l, r::$(typeof (r)) )" )
125+ return l
126+ end
127+ function prepend! (l:: CliffordOperator , r:: sCXYZ ; phases= false )
128+ error (" Not implemented: prepend!(l, r::$(typeof (r)) )" )
129+ return l
130+ end
131+ function prepend! (l:: CliffordOperator , r:: sCZYX ; phases= false )
132+ error (" Not implemented: prepend!(l, r::$(typeof (r)) )" )
133+ return l
134+ end
135+ function prepend! (l:: CliffordOperator , r:: sId1 ; phases= false )
136+ error (" Not implemented: prepend!(l, r::sId1)" )
137+ return l
138+ end
139+ function prepend! (l:: CliffordOperator , r:: SingleQubitOperator ; phases= false )
140+ error (" Not implemented: prepend!(l. r::SingleQubitOperator)" )
141+ return l
142+ end
143+
144+ function prepend! (l:: CliffordOperator , r:: sSWAP ; phases= false )
145+ l[nqubits (l)+ r. q1], l[nqubits (l)+ r. q2] = l[nqubits (l)+ r. q2], l[nqubits (l)+ r. q1]
146+ l[r. q1], l[r. q2] = l[r. q2], l[r. q1]
147+ return l
148+ end
149+ function prepend! (l:: CliffordOperator , r:: sSWAPCX ; phases= false )
150+ error (" Not implemented: prepend!(l, r::$(typeof (r)) )" )
151+ return l
152+ end
153+ function prepend! (l:: CliffordOperator , r:: sInvSWAPCX ; phases= false )
154+ error (" Not implemented: prepend!(l, r::$(typeof (r)) )" )
155+ return l
156+ end
157+ function prepend! (l:: CliffordOperator , r:: sISWAP ; phases= false )
158+ prepend! (l, sSWAP (r. q1, r. q2); phases= phases)
159+ prepend! (l, sZCZ (r. q1, r. q2); phases= phases)
160+ prepend! (l, sSQRTZ (r. q1); phases= phases)
161+ prepend! (l, sSQRTZ (r. q2); phases= phases)
162+ return l
163+ end
164+ function prepend! (l:: CliffordOperator , r:: sInvISWAP ; phases= false )
165+ error (" Not implemented: prepend!(l, r::$(typeof (r)) )" )
166+ return l
167+ end
168+ function prepend! (l:: CliffordOperator , r:: sCZSWAP ; phases= false )
169+ error (" Not implemented: prepend!(l, r::$(typeof (r)) )" )
170+ return l
171+ end
172+ function prepend! (l:: CliffordOperator , r:: sCXSWAP ; phases= false )
173+ error (" Not implemented: prepend!(l, r::$(typeof (r)) )" )
174+ return l
175+ end
176+ function prepend! (l:: CliffordOperator , r:: sCNOT ; phases= false )
177+ l[nqubits (l)+ r. q2] *= l[nqubits (l)+ r. q1]
178+ l[r. q1] *= l[r. q2]
179+ return l
180+ end
181+ function prepend! (l:: CliffordOperator , r:: sCPHASE ; phases= false )
182+ error (" Not implemented: prepend!(l, r::$(typeof (r)) )" )
183+ return l
184+ end
185+ function prepend! (l:: CliffordOperator , r:: sZCX ; phases= false )
186+ error (" Not implemented: prepend!(l, r::$(typeof (r)) )" )
187+ return l
188+ end
189+ function prepend! (l:: CliffordOperator , r:: sZCY ; phases= false )
190+ error (" Not implemented: prepend!(l, r::$(typeof (r)) )" )
191+ return l
192+ end
193+ function prepend! (l:: CliffordOperator , r:: sZCZ ; phases= false )
194+ error (" Not implemented: prepend!(l, r::$(typeof (r)) )" )
195+ return l
196+ end
197+ function prepend! (l:: CliffordOperator , r:: sXCX ; phases= false )
198+ error (" Not implemented: prepend!(l, r::$(typeof (r)) )" )
199+ return l
200+ end
201+ function prepend! (l:: CliffordOperator , r:: sXCY ; phases= false )
202+ error (" Not implemented: prepend!(l, r::$(typeof (r)) )" )
203+ return l
204+ end
205+ function prepend! (l:: CliffordOperator , r:: sXCZ ; phases= false )
206+ error (" Not implemented: prepend!(l, r::$(typeof (r)) )" )
207+ return l
208+ end
209+ function prepend! (l:: CliffordOperator , r:: sYCX ; phases= false )
210+ error (" Not implemented: prepend!(l, r::$(typeof (r)) )" )
211+ return l
212+ end
213+ function prepend! (l:: CliffordOperator , r:: sYCY ; phases= false )
214+ error (" Not implemented: prepend!(l, r::$(typeof (r)) )" )
215+ return l
216+ end
217+ function prepend! (l:: CliffordOperator , r:: sYCZ ; phases= false )
218+ error (" Not implemented: prepend!(l, r::$(typeof (r)) )" )
219+ return l
220+ end
221+ function prepend! (l:: CliffordOperator , r:: sZCrY ; phases= false )
222+ error (" Not implemented: prepend!(l, r::$(typeof (r)) )" )
223+ return l
224+ end
225+ function prepend! (l:: CliffordOperator , r:: sInvZCrY ; phases= false )
226+ error (" Not implemented: prepend!(l, r::$(typeof (r)) )" )
227+ return l
228+ end
229+ function prepend! (l:: CliffordOperator , r:: sSQRTZZ ; phases= false )
230+ error (" Not implemented: prepend!(l, r::$(typeof (r)) )" )
231+ return l
232+ end
233+ function prepend! (l:: CliffordOperator , r:: sInvSQRTZZ ; phases= false )
234+ error (" Not implemented: prepend!(l, r::$(typeof (r)) )" )
235+ return l
236+ end
237+ function prepend! (l:: CliffordOperator , r:: sSQRTXX ; phases= false )
238+ error (" Not implemented: prepend!(l, r::$(typeof (r)) )" )
239+ return l
240+ end
241+ function prepend! (l:: CliffordOperator , r:: sInvSQRTXX ; phases= false )
242+ error (" Not implemented: prepend!(l, r::$(typeof (r)) )" )
243+ return l
244+ end
245+ function prepend! (l:: CliffordOperator , r:: sSQRTYY ; phases= false )
246+ error (" Not implemented: prepend!(l, r::$(typeof (r)) )" )
247+ return l
248+ end
249+ function prepend! (l:: CliffordOperator , r:: sInvSQRTYY ; phases= false )
250+ error (" Not implemented: prepend!(l, r::$(typeof (r)) )" )
251+ return l
252+ end
253+
254+ function prepend_inv! (l:: CliffordOperator , r:: sX ; phases= false )
255+ tab (l). phases[nqubits (l)+ r. q] ⊻= 0x02
256+ return l
257+ end
258+ function prepend_inv! (l:: CliffordOperator , r:: sY ; phases= false )
259+ error (" Not implemented: prepend_inv!(l, r::sY)" )
260+ return l
261+ end
262+ function prepend_inv! (l:: CliffordOperator , r:: sZ ; phases= false )
263+ tab (l). phases[r. q] ⊻= 0x02
264+ return l
265+ end
266+ function prepend_inv! (l:: CliffordOperator , r:: sHadamard ; phases= false )
267+ l[r. q], l[nqubits (l)+ r. q] = l[nqubits (l)+ r. q], l[r. q]
268+ return l
269+ end
270+ function prepend_inv! (l:: CliffordOperator , r:: sHadamardYZ ; phases= false )
271+ error (" Not implemented: prepend_inv!(l, r::sHadamardYZ)" )
272+ return l
273+ end
274+ function prepend_inv! (l:: CliffordOperator , r:: sHadamardXY ; phases= false )
275+ error (" Not implemented: prepend_inv!(l, r::sHadamardXY)" )
276+ return l
277+ end
278+ function prepend_inv! (l:: CliffordOperator , r:: sCNOT ; phases= false )
279+ l[nqubits (l)+ r. q2] *= l[nqubits (l)+ r. q1]
280+ l[r. q1] *= l[r. q2]
281+ return l
282+ end
283+ function prepend_inv! (l:: CliffordOperator , r:: sSWAP ; phases= false )
284+ l[nqubits (l)+ r. q1], l[nqubits (l)+ r. q2] = l[nqubits (l)+ r. q2], l[nqubits (l)+ r. q1]
285+ l[r. q1], l[r. q2] = l[r. q2], l[r. q1]
286+ return l
287+ end
288+
289+ # use row swap
0 commit comments