Skip to content

Commit 0849b1c

Browse files
Fe-r-ozKrastanov
andauthored
adding all missing types of two qubit SWAP gates and sSQRTZZ/sInvSQRTZZ gate (#336)
--------- Co-authored-by: Stefan Krastanov <[email protected]> Co-authored-by: Stefan Krastanov <[email protected]>
1 parent 617843c commit 0849b1c

File tree

4 files changed

+55
-15
lines changed

4 files changed

+55
-15
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55

66
# News
77

8+
## v0.9.13 - dev
9+
10+
- Implementing additional named two-qubit gates: `sSWAPCX, sInvSWAPCX, sCZSWAP, sCXSWAP, sISWAP, sInvISWAP,
11+
sSQRTZZ, sInvSQRTZZ`
12+
813
## v0.9.12 - 2024-10-18
914

1015
- Minor compat fixes for julia 1.11 in the handling of `hgp`

src/QuantumClifford.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ export
5151
sHadamardXY, sHadamardYZ, sSQRTX, sInvSQRTX, sSQRTY, sInvSQRTY, sCXYZ, sCZYX,
5252
sCNOT, sCPHASE, sSWAP,
5353
sXCX, sXCY, sXCZ, sYCX, sYCY, sYCZ, sZCX, sZCY, sZCZ,
54-
sZCrY, sInvZCrY,
54+
sZCrY, sInvZCrY, sSWAPCX, sInvSWAPCX, sCZSWAP, sCXSWAP, sISWAP, sInvISWAP,
55+
sSQRTZZ, sInvSQRTZZ,
5556
# Misc Ops
5657
SparseGate,
5758
sMX, sMY, sMZ, PauliMeasurement, Reset, sMRX, sMRY, sMRZ,

src/symbolic_cliffords.jl

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,16 @@ macro qubitop2(name, kernel)
308308
end
309309
# x1 z1 x2 z2
310310
@qubitop2 SWAP (x2 , z2 , x1 , z1 , false)
311+
312+
@qubitop2 SWAPCX (x2 , z2z1 , x2x1 , z1 , ~iszero((x1 & z1 & x2 & z2) | (~x1 & z1 & x2 & ~z2)))
313+
@qubitop2 InvSWAPCX (x2x1 , z2 , x1 , z2z1 , ~iszero((x1 & z1 & x2 & z2) | ( x1 &~z1 &~x2 & z2)))
314+
315+
@qubitop2 ISWAP (x2 , x1z2x2 , x1 , x1x2z1 , ~iszero((x1 & z1 & ~x2) | (~x1 & x2 & z2)))
316+
@qubitop2 InvISWAP (x2 , x1z2x2 , x1 , x1x2z1 , ~iszero((x1 &~z1 & ~x2) | (~x1 & x2 &~z2)))
317+
318+
@qubitop2 CZSWAP (x2 , z2x1 , x1 , x2z1 , ~iszero((x1 & ~z1 & x2 & z2) | (x1 & z1 & x2 & ~z2)))
319+
@qubitop2 CXSWAP (x2x1 , z2 , x1 , z2z1 , ~iszero((x1 & ~z1 &~x2 & z2) | (x1 & z1 & x2 & z2)))
320+
311321
@qubitop2 CNOT (x1 , z1z2 , x2x1 , z2 , ~iszero( (x1 & z1 & x2 & z2) | (x1 & z2 &~(z1|x2)) ))
312322
@qubitop2 CPHASE (x1 , z1x2 , x2 , z2x1 , ~iszero( (x1 & z1 & x2 &~z2) | (x1 &~z1 & x2 & z2) ))
313323

@@ -326,6 +336,9 @@ end
326336
@qubitop2 ZCrY (x1, x1z1x2z2, x1x2, x1z2, ~iszero((x1 &~z1 & x2) | (x1 & ~z1 & ~z2) | (x1 & x2 & ~z2)))
327337
@qubitop2 InvZCrY (x1, x1z1x2z2, x1x2, x1z2, ~iszero((x1 & z1 &~x2) | (x1 & z1 & z2) | (x1 &~x2 & z2)))
328338

339+
@qubitop2 SQRTZZ (x1 , x1x2z1 , x2 , x1z2x2 , ~iszero((x1 & z1 & ~x2) | (~x1 & x2 & z2)))
340+
@qubitop2 InvSQRTZZ (x1 , x1x2z1 , x2 , x1z2x2 , ~iszero((x1 &~z1 & ~x2) | (~x1 & x2 &~z2)))
341+
329342
#=
330343
To get the boolean formulas for the phase, it is easiest to first write down the truth table for the phase:
331344
for i in 0:15
@@ -370,20 +383,28 @@ function Base.show(io::IO, op::AbstractTwoQubitOperator)
370383
end
371384
end
372385

373-
LinearAlgebra.inv(op::sSWAP) = sSWAP(op.q1, op.q2)
374-
LinearAlgebra.inv(op::sCNOT) = sCNOT(op.q1, op.q2)
375-
LinearAlgebra.inv(op::sCPHASE) = sCPHASE(op.q1, op.q2)
376-
LinearAlgebra.inv(op::sZCX) = sZCX(op.q1, op.q2)
377-
LinearAlgebra.inv(op::sZCY) = sZCY(op.q1, op.q2)
378-
LinearAlgebra.inv(op::sZCZ) = sZCZ(op.q1, op.q2)
379-
LinearAlgebra.inv(op::sXCX) = sXCX(op.q1, op.q2)
380-
LinearAlgebra.inv(op::sXCY) = sXCY(op.q1, op.q2)
381-
LinearAlgebra.inv(op::sXCZ) = sXCZ(op.q1, op.q2)
382-
LinearAlgebra.inv(op::sYCX) = sYCX(op.q1, op.q2)
383-
LinearAlgebra.inv(op::sYCY) = sYCY(op.q1, op.q2)
384-
LinearAlgebra.inv(op::sYCZ) = sYCZ(op.q1, op.q2)
385-
LinearAlgebra.inv(op::sZCrY) = sInvZCrY(op.q1, op.q2)
386-
LinearAlgebra.inv(op::sInvZCrY) = sZCrY(op.q1, op.q2)
386+
LinearAlgebra.inv(op::sSWAP) = sSWAP(op.q1, op.q2)
387+
LinearAlgebra.inv(op::sCNOT) = sCNOT(op.q1, op.q2)
388+
LinearAlgebra.inv(op::sCPHASE) = sCPHASE(op.q1, op.q2)
389+
LinearAlgebra.inv(op::sZCX) = sZCX(op.q1, op.q2)
390+
LinearAlgebra.inv(op::sZCY) = sZCY(op.q1, op.q2)
391+
LinearAlgebra.inv(op::sZCZ) = sZCZ(op.q1, op.q2)
392+
LinearAlgebra.inv(op::sXCX) = sXCX(op.q1, op.q2)
393+
LinearAlgebra.inv(op::sXCY) = sXCY(op.q1, op.q2)
394+
LinearAlgebra.inv(op::sXCZ) = sXCZ(op.q1, op.q2)
395+
LinearAlgebra.inv(op::sYCX) = sYCX(op.q1, op.q2)
396+
LinearAlgebra.inv(op::sYCY) = sYCY(op.q1, op.q2)
397+
LinearAlgebra.inv(op::sYCZ) = sYCZ(op.q1, op.q2)
398+
LinearAlgebra.inv(op::sZCrY) = sInvZCrY(op.q1, op.q2)
399+
LinearAlgebra.inv(op::sInvZCrY) = sZCrY(op.q1, op.q2)
400+
LinearAlgebra.inv(op::sSWAPCX) = sInvSWAPCX(op.q1, op.q2)
401+
LinearAlgebra.inv(op::sInvSWAPCX) = sSWAPCX(op.q1, op.q2)
402+
LinearAlgebra.inv(op::sCZSWAP) = sCZSWAP(op.q1, op.q2)
403+
LinearAlgebra.inv(op::sCXSWAP) = sSWAPCX(op.q1, op.q2)
404+
LinearAlgebra.inv(op::sISWAP) = sInvISWAP(op.q1, op.q2)
405+
LinearAlgebra.inv(op::sInvISWAP) = sISWAP(op.q1, op.q2)
406+
LinearAlgebra.inv(op::sSQRTZZ) = sInvSQRTZZ(op.q1, op.q2)
407+
LinearAlgebra.inv(op::sInvSQRTZZ) = sSQRTZZ(op.q1, op.q2)
387408

388409
##############################
389410
# Functions that perform direct application of common operators without needing an operator instance

test/test_symcliff.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,19 @@
9999
@test CliffordOperator(inv(sXCZ(n₁, n₂)), n₁) == inv(CliffordOperator(sCNOT(n₂, n₁), n₁))
100100
@test CliffordOperator(inv(sZCrY(n₁, n₂)), n₁) == inv(CliffordOperator(sZCrY(n₁, n₂), n₁))
101101
@test CliffordOperator(inv(sInvZCrY(n₁, n₂)), n₁) == inv(CliffordOperator(sInvZCrY(n₁, n₂), n₁))
102+
@test CliffordOperator(inv(sCXSWAP(n₁, n₂)), n₁) == inv(CliffordOperator(sInvSWAPCX(n₁, n₂), n₁))
102103
end
103104
end
105+
106+
@testset "Consistency check with STIM conventions" begin
107+
# see https://github.com/quantumlib/Stim/blob/main/doc/gates.md
108+
@test CliffordOperator(sSWAPCX) == C"IX XX ZZ ZI"
109+
@test CliffordOperator(sInvSWAPCX) == C"XX XI IZ ZZ"
110+
@test CliffordOperator(sCZSWAP) == C"ZX XZ IZ ZI"
111+
@test CliffordOperator(sCXSWAP) == C"XX XI IZ ZZ"
112+
@test CliffordOperator(sISWAP) == C"ZY YZ IZ ZI"
113+
@test CliffordOperator(sInvISWAP) == C"-ZY -YZ IZ ZI"
114+
@test CliffordOperator(sSQRTZZ) == C"YZ ZY ZI IZ"
115+
@test CliffordOperator(sInvSQRTZZ) == C"-YZ -ZY ZI IZ"
116+
end
104117
end

0 commit comments

Comments
 (0)