diff --git a/src/ecc/codes/gottesmancode.jl b/src/ecc/codes/gottesmancode.jl index eb230e045..2f849e38c 100644 --- a/src/ecc/codes/gottesmancode.jl +++ b/src/ecc/codes/gottesmancode.jl @@ -11,6 +11,10 @@ Notes: struct Gottesman <: AbstractECC j::Int + rows = c.j + 2 + cols = 2^c.j + Hx = Matrix{Bool}(undef, rows, cols) + Hz = Matrix{Bool}(undef, rows, cols) function Gottesman(j) (j >= 3 && j < 21) || error("In `Gottesman(j)`, `j` must be ≥ 3 in order to obtain a valid code and `j` must be < 21 to remain tractable") new(j) @@ -20,31 +24,28 @@ end code_n(c::Gottesman) = 2^c.j function parity_checks(c::Gottesman) - rows = c.j + 2 - cols = 2^c.j - - Hx = falses(rows,cols) - Hz = falses(rows,cols) + extended_Hx = c.Hx + extended_Hz = c.Hz - Hx[1, :] .= true - Hx[2, :] .= false + extended_Hx[1, :] .= true + extended_Hx[2, :] .= false if c.j == 3 for col in 1:cols - Hx[3, col] = (col % 8 == 1 || col % 8 == 3 || col % 8 == 6) ? 0 : 1 + extended_Hx[3, col] = (col % 8 == 1 || col % 8 == 3 || col % 8 == 6) ? 0 : 1 end - Hx[3, cols] = Hx[3, cols] == 0 ? 1 : 0 + extended_Hx[3, cols] = extended_Hx[3, cols] == 0 ? 1 : 0 for col in 1:cols - Hx[4, col] = (col % 4 == 1) || (col % 4 == 3) ? 0 : 1 + extended_Hx[4, col] = (col % 4 == 1) || (col % 4 == 3) ? 0 : 1 end for a in 1:cols - Hx[rows, a] = ((a % 4 == 0) || (a % 4 == 1) ? 0 : 1) ⊻ ((a % 8 == 5) || (a % 8 == 6)) + extended_Hx[rows, a] = ((a % 4 == 0) || (a % 4 == 1) ? 0 : 1) ⊻ ((a % 8 == 5) || (a % 8 == 6)) end - Hx[end, [end-1, end]] .= [0, 1] + extended_Hx[end, [end-1, end]] .= [0, 1] else for a in 1:cols - Hx[3, a] = (a == 0) || (a % 2 == 0) + extended_Hx[3, a] = (a == 0) || (a % 2 == 0) end for row in 4:rows - 1 for col in 1:cols @@ -53,38 +54,36 @@ function parity_checks(c::Gottesman) n = 2^(c.j - k) if (col - 1) % (m + n) < m if col % 2 == 0 - Hx[row, col] = 1 + extended_Hx[row, col] = 1 else - Hx[row, col] = 0 + extended_Hx[row, col] = 0 end else if col % 2 == 0 - Hx[row, col] = 0 + extended_Hx[row, col] = 0 else - Hx[row, col] = 1 + extended_Hx[row, col] = 1 end end end end for a in 1:cols - Hx[rows, a] = (a % 4 == 0) || (a % 4 == 1) ? 0 : 1 + extended_Hx[rows, a] = (a % 4 == 0) || (a % 4 == 1) ? 0 : 1 end end - Hz[1, :] .= false - Hz[2, :] .= true + extended_Hz[1, :] .= false + extended_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 + extended_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) + num_rows = size(extended_Hx, 1) fill_array = fill(UInt8(0), num_rows) Stabilizer(fill_array, extended_Hz, extended_Hx)