Skip to content

Commit

Permalink
adding iscss for issue #212 (#241)
Browse files Browse the repository at this point in the history
Fixes #212

---------

Co-authored-by: Stefan Krastanov <[email protected]>
  • Loading branch information
Fe-r-oz and Krastanov authored Mar 20, 2024
1 parent 3bb4653 commit 7ff9f39
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 2 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

# News

## v0.9.1 - 2024-03-20

- Implemented `iscss` function to identify whether a given code is known to be a CSS (Calderbank-Shor-Steane) code.

## v0.9.0 - 2024-03-19

- **(breaking)** The defaults in `random_pauli` are now `realphase=true` and `nophase=true`.
Expand All @@ -13,7 +17,6 @@
- Implement an inplace `random_pauli!`, a non-allocating alternative to `random_pauli`.
- Significant improvement in the performance of the ECC decoder pipeline (but many low-hanging fruits still remain).


## v0.8.21 - 2024-03-17

- Implemented the Gottesman code family, also known as [[2^j, 2^j - j - 2, 3]] quantum Hamming codes.
Expand Down
10 changes: 9 additions & 1 deletion src/ecc/ECC.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ using Nemo: ZZ, residue_ring, matrix

abstract type AbstractECC end

export parity_checks, parity_checks_x, parity_checks_z,
export parity_checks, parity_checks_x, parity_checks_z, iscss,
code_n, code_s, code_k, rate, distance,
isdegenerate, faults_matrix,
naive_syndrome_circuit, shor_syndrome_circuit, naive_encoding_circuit,
Expand Down Expand Up @@ -49,6 +49,14 @@ function parity_checks_z(code::AbstractECC)
throw(lazy"Codes of type $(typeof(code)) do not have separate X and Z parity checks, either because they are not a CSS code and thus inherently do not have separate checks, or because its separate checks are not yet implemented in this library.")
end

function iscss(::Type{T}) where T<:AbstractECC
return false
end

function iscss(c::AbstractECC)
return iscss(typeof(c))
end

parity_checks(s::Stabilizer) = s
Stabilizer(c::AbstractECC) = parity_checks(c)
MixedDestabilizer(c::AbstractECC; kwarg...) = MixedDestabilizer(Stabilizer(c); kwarg...)
Expand Down
4 changes: 4 additions & 0 deletions src/ecc/codes/bitflipcode.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@ struct Bitflip3 <: AbstractECC end

code_n(c::Bitflip3) = 3

function iscss(::Type{Bitflip3})
return true
end

parity_checks(c::Bitflip3) = S"_ZZ
Z_Z"
4 changes: 4 additions & 0 deletions src/ecc/codes/css.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ struct CSS <: AbstractECC
end
end

function iscss(::Type{CSS})
return true
end

function parity_checks(c::CSS)
extended_Hx = Matrix{Bool}(vcat(c.Hx, zeros(size(c.Hz))))
extended_Hz = Matrix{Bool}(vcat(zeros(size(c.Hx)), c.Hz))
Expand Down
4 changes: 4 additions & 0 deletions src/ecc/codes/shorcode.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ struct Shor9 <: AbstractECC end

code_n(c::Shor9) = 9

function iscss(::Type{Shor9})
return true
end

parity_checks(c::Shor9) = S"ZZ_______
_ZZ______
___ZZ____
Expand Down
4 changes: 4 additions & 0 deletions src/ecc/codes/steanecode.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

struct Steane7 <: AbstractECC end

function iscss(::Type{Steane7})
return true
end

parity_checks(c::Steane7) = S"___XXXX
_XX__XX
X_X_X_X
Expand Down
4 changes: 4 additions & 0 deletions src/ecc/codes/toric.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ struct Toric <: AbstractECC
dz::Int
end

function iscss(::Type{Toric})
return true
end

code_n(c::Toric) = 2*c.dx*c.dz

function parity_checks_xz(c::Toric)
Expand Down
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ end
@doset "ecc_encoding"
@doset "ecc_syndromes"
@doset "ecc_gottesman"
@doset "ecc_iscss"
@doset "precompile"
@doset "pauliframe"
@doset "allocations"
Expand Down
27 changes: 27 additions & 0 deletions test/test_ecc_iscss.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Test
using QuantumClifford
using QuantumClifford.ECC
using QuantumClifford.ECC: AbstractECC

function is_css_matrix(H)
nrows, ncols = size(H)
for i in 1:nrows
has_x = false
has_z = false
for j in 1:ncols
has_x |= H[i,j][1]
has_z |= H[i,j][2]
has_x && has_z && return false
end
end
return true
end

known_all_codes = [Shor9(), Steane7(), Gottesman(3), Cleve8(), Perfect5(), Toric(8,8), CSS([0 1 1 0; 1 1 0 0], [1 1 1 1]), Bitflip3()]

@testset "is CSS" begin
for code in known_all_codes
H = parity_checks(code)
@test iscss(code) == is_css_matrix(H)
end
end

0 comments on commit 7ff9f39

Please sign in to comment.