Skip to content

Commit

Permalink
some new codes to test with
Browse files Browse the repository at this point in the history
  • Loading branch information
amicciche committed Sep 10, 2023
1 parent 9f50184 commit 4174d2a
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 13 deletions.
23 changes: 10 additions & 13 deletions src/ecc/ECC.jl
Original file line number Diff line number Diff line change
Expand Up @@ -399,18 +399,10 @@ end
include("./bitflipcode.jl")
include("./shorcode.jl")
include("./steanecode.jl")
include("./cleavecode.jl")
include("./fiveonethreecode.jl")
include("./fivetwotwocode.jl")

"""A pedagogical example of a quantum error correcting [8,3] code used in [cleve1997efficient](@cite)."""
struct Cleve8 <: AbstractECC end

code_n(c::Cleve8) = 8

parity_checks(c::Cleve8) = S"XXXXXXXX
ZZZZZZZZ
XIXIZYZY
XIYZXIYZ
XZIYIYXZ"

function canonicalize_cleve97(checks::Stabilizer)
d, n = size(checks)
X0 = (checks |> stab_to_gf2)[:,1:n]'
Expand Down Expand Up @@ -476,6 +468,8 @@ function canonicalize_cleve97(checks::Stabilizer)
append!(qubit_order, bank)
X1 = X0_5[qubit_order, :]
Z1 = Z0_5[qubit_order, :]
println("Qubit order 1", qubit_order)
checks = checks[:, qubit_order]

# Now begins the march towards X2 and Z2, starting with B'
r1 = rank(Nemo.matrix(Z2field, Z1[1:r+k,1:r]))
Expand Down Expand Up @@ -538,6 +532,8 @@ function canonicalize_cleve97(checks::Stabilizer)
append!(qubit_order, bank)
Z2 = Z1_5[qubit_order, :]
X2 = X1[qubit_order, :] # X is unchanged by operations on b, except for reindexing of qubits
println("Qubit order 2", qubit_order)
checks = checks[:, qubit_order]

# Now time for the final steps before arriving at Xstar Zstar
B1 = Z2[1:k,1+r2:r2+r1]
Expand All @@ -552,7 +548,9 @@ function canonicalize_cleve97(checks::Stabilizer)
println("k, r2, r1, b: ", k, " ", r2, " ", r1, " ", b)
Xstar = hcat(Xs,X2)
Zstar = hcat(Zs,Z2)
return Xstar, Zstar, Stabilizer(X2',Z2')# TODO at some point unreorder the qubits? Recall they get reordered twice.

#return X0, X0_5, X1, X2, Xstar, Z0, Z0_5, Z1, Z1_5, Z2, Zstar
return Xstar, Zstar, Stabilizer(X2', Z2')# TODO Return reordered checks or Stab(X2', Z2')?
end

""" The naive implementation of the encoding circuit by arXiv:quant-ph/9607030 """
Expand All @@ -567,7 +565,6 @@ function naive_encoding_circuit(checks::Stabilizer)
k = n-d

Xstar, Zstar, standard_tab = canonicalize_cleve97(checks)
println(standard_tab)

naive_ec = AbstractOperation[]
for i in (r+k+1):(r+k+b)
Expand Down
55 changes: 55 additions & 0 deletions src/ecc/cleavecode.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
"""A pedagogical example of a quantum error correcting [8,3] code used in [cleve1997efficient](@cite)."""
struct Cleve8 <: AbstractECC end

code_n(c::Cleve8) = 8
code_k(c::Cleve8) = 3

parity_checks(c::Cleve8) = S"XXXXXXXX
ZZZZZZZZ
XIXIZYZY
XIYZXIYZ
XZIYIYXZ"

function encoding_circuit(c::Cleve8)
c1 = sCNOT(1,4)
c2 = sCNOT(2,4)
c3 = sCNOT(3,4)
h1 = sHadamard(5)
z1 = sZ(5)
h2 = sHadamard(6)
h3 = sHadamard(7)
z3 = sZ(7)
h4 = sHadamard(8)
z4 = sZ(8)
first_part = [c1,c2,c3,h1,z1,h2,h3,z3,h4,z4]

c1 = sZCX(5, 1)
c2 = sZCX(5, 2)
c3 = sZCY(5, 3)
c4 = sZCZ(5, 4)
c5 = sZCZ(5, 6)
column1 = [c1,c2,c3,c4,c5] # 1st non null column of Zstar

c1 = sZCX(6, 1)
c2 = sZCY(6, 2)
c3 = sZCY(6, 4)
c4 = sZCZ(6, 5)
c5 = sZCZ(6, 7)
column2 = [c1,c2,c3,c4,c5]

c1 = sZCX(7, 1)
c2 = sZCY(7, 3)
c3 = sZCX(7, 4)
c4 = sZCZ(7, 5)
c5 = sZCZ(7, 8)
column3 = [c1,c2,c3,c4,c5]

c1 = sZCY(8, 2)
c2 = sZCX(8, 3)
c3 = sZCX(8, 4)
c4 = sZCZ(8, 5)
c5 = sZCZ(8, 6)
column4 = [c1,c2,c3,c4,c5]

return vcat(first_part, column1, column2, column3, column4)
end
9 changes: 9 additions & 0 deletions src/ecc/fiveonethreecode.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"""http://www.codetables.de/QECC.php?q=4&n=5&k=1"""
struct FiveOneThree <: AbstractECC end

code_n(c::FiveOneThree) = 8

parity_checks(c::FiveOneThree) = S"YIZXY
ZXIZY
ZIXYZ
IZZZZ"
8 changes: 8 additions & 0 deletions src/ecc/fivetwotwocode.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""http://www.codetables.de/QECC.php?q=4&n=5&k=2"""
struct FiveTwoTwo <: AbstractECC end

code_n(c::FiveTwoTwo) = 8

parity_checks(c::FiveTwoTwo) = S"XXXXI
IIIIX
ZZZZI"

0 comments on commit 4174d2a

Please sign in to comment.