Skip to content

Commit

Permalink
Gottesman aka Quantum Hamming Code Implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Fe-r-oz committed Mar 8, 2024
1 parent b572c8f commit 32e8676
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 39 deletions.
10 changes: 4 additions & 6 deletions src/ecc/ECC.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ export parity_checks, parity_checks_x, parity_checks_z,
naive_syndrome_circuit, shor_syndrome_circuit, naive_encoding_circuit,
RepCode,
CSS,
Shor9, Steane7, Cleve8, Perfect5, Bitflip3,
NKD833,NKD16103,
Toric,
Shor9, Steane7, Cleve8, Perfect5, Bitflip3,
Toric, QHamming,
evaluate_decoder,
CommutationCheckECCSetup, NaiveSyndromeECCSetup, ShorSyndromeECCSetup,
TableDecoder,
Expand Down Expand Up @@ -334,6 +333,5 @@ include("codes/steanecode.jl")
include("codes/shorcode.jl")
include("codes/clevecode.jl")
include("codes/toric.jl")
include("codes/nkd833.jl")
include("codes/nkd16103.jl")
end #module
include("codes/gottesman.jl")
end #module
51 changes: 51 additions & 0 deletions src/ecc/codes/gottesman.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
struct QHamming <: AbstractECC
j::Int
function QHamming(j)
if j < 3
error("j must be greater than or equal to 3 in order to create a valid code of tractable size")
end
new(j)
end
end

code_n(c::QHamming)= 2^c.j

function parity_checks(c::QHamming)
a=c.j
rows = a + 2
cols = 2^a

Hx = falses(rows,cols)
Hz =falses(rows,cols)

Hx[1, :] .= true

Hx[2, :] .= false

for i in 3:(rows-1)
for a in 1:cols
Hx[i, a] = (a==0) || (a % 2 ==0)
end
end

for a in 1:cols
Hx[rows, a] = (a % 4 == 1) || (a % 4 == 2) ? 0 : 1
end

Hz[1, :] .= false
Hz[2, :] .= true

for i in 3:rows
period = 2^(rows - i)
for a in 1:cols
Hz[i,a]=div(a-1,period) % 2 == 1
end
end
extended_Hx = Matrix{Bool}(Hz)
extended_Hz = Matrix{Bool}(Hx)

num_rows = size(Hx, 1)

fill_array = fill(UInt8(0), num_rows)
Stabilizer(fill_array, extended_Hz, extended_Hx)
end
8 changes: 0 additions & 8 deletions src/ecc/codes/nkd16103.jl

This file was deleted.

8 changes: 0 additions & 8 deletions src/ecc/codes/nkd833.jl

This file was deleted.

5 changes: 2 additions & 3 deletions test/test_ecc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ codes = [
Shor9(),
Perfect5(),
Cleve8(),
NKD833(),
NKD16103(),
QHamming(3),
CSS([0 1 1 0; 1 1 0 0], [1 1 1 1]),
]

Expand Down Expand Up @@ -78,4 +77,4 @@ end
@test isdegenerate(Steane7()) == false
@test isdegenerate(Steane7(), 2) == true
@test isdegenerate(Bitflip3()) == true
end
end
12 changes: 5 additions & 7 deletions test/test_ecc_decoder_all_setups.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ import PyQDecoders
Steane7(),
Shor9(),
Perfect5(),
NKD833(),
NKD16103(),
Cleve8(),
Cleve8(),
]

noise = 0.001
Expand All @@ -31,7 +29,7 @@ import PyQDecoders

for c in codes
for s in setups
e = evaluate_decoder(TableDecoder(c), s, 900000000)
e = evaluate_decoder(TableDecoder(c), s,100000)
#@show c
#@show s
#@show e
Expand All @@ -58,11 +56,11 @@ end

for c in codes
for s in setups
e = evaluate_decoder(PyMatchingDecoder(c), s, 10000)
e = evaluate_decoder(PyMatchingDecoder(c), s,100000)
#@show c
#@show s
#@show e
@assert max(e...) < noise/5
@assert max(e...) < noise/4
end
end
end
end
5 changes: 2 additions & 3 deletions test/test_ecc_encoding.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ using QuantumClifford.ECC
:(Steane7()),
:(Shor9()),
:(Perfect5()),
:(NKD833()),
:(NKD16103()),
:(Bitflip3()),
:(QHamming(3)),
:(S"Y_"),
:(S"Z_"),
:(S"X_"),
Expand Down Expand Up @@ -57,4 +56,4 @@ using QuantumClifford.ECC

#println("$codeexpr, $(encodedₙ == algebraicₙ)")
end
end
end
5 changes: 2 additions & 3 deletions test/test_ecc_syndromes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ codes = [
Steane7(),
Shor9(),
Perfect5(),
NKD833(),
NKD16103(),
Cleve8(),
QHamming(3),
CSS([0 1 1 0; 1 1 0 0], [1 1 1 1]),
Toric(3,3),
Toric(3,6),
Expand Down Expand Up @@ -61,4 +60,4 @@ end
for c in codes
pframe_naive_vs_shor_syndrome(c)
end
end
end
2 changes: 1 addition & 1 deletion test/test_throws.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ for m in [sMX,sMZ,sMY,sMRX,sMRZ,sMRY]
@test_throws ArgumentError m(-1)
@test_throws ArgumentError m(0,1)
@test_throws ArgumentError m(-1,0)
end
end

0 comments on commit 32e8676

Please sign in to comment.