diff --git a/CHANGELOG.md b/CHANGELOG.md index 1be214e0b..7584e4313 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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`. @@ -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. diff --git a/src/ecc/ECC.jl b/src/ecc/ECC.jl index 665cc53ff..01ef5c7d0 100644 --- a/src/ecc/ECC.jl +++ b/src/ecc/ECC.jl @@ -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, @@ -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...) diff --git a/src/ecc/codes/bitflipcode.jl b/src/ecc/codes/bitflipcode.jl index bdf132aa1..910fca98f 100644 --- a/src/ecc/codes/bitflipcode.jl +++ b/src/ecc/codes/bitflipcode.jl @@ -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" diff --git a/src/ecc/codes/css.jl b/src/ecc/codes/css.jl index bf21b69dd..89d2a1239 100644 --- a/src/ecc/codes/css.jl +++ b/src/ecc/codes/css.jl @@ -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)) diff --git a/src/ecc/codes/shorcode.jl b/src/ecc/codes/shorcode.jl index 49d99d26f..774cab519 100644 --- a/src/ecc/codes/shorcode.jl +++ b/src/ecc/codes/shorcode.jl @@ -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____ diff --git a/src/ecc/codes/steanecode.jl b/src/ecc/codes/steanecode.jl index c7e1936c5..7c1fc7ec9 100644 --- a/src/ecc/codes/steanecode.jl +++ b/src/ecc/codes/steanecode.jl @@ -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 diff --git a/src/ecc/codes/toric.jl b/src/ecc/codes/toric.jl index e9fa03b51..eeb37e2ed 100644 --- a/src/ecc/codes/toric.jl +++ b/src/ecc/codes/toric.jl @@ -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) diff --git a/test/runtests.jl b/test/runtests.jl index ef4dd4b94..ce48e99b7 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -63,6 +63,7 @@ end @doset "ecc_encoding" @doset "ecc_syndromes" @doset "ecc_gottesman" +@doset "ecc_iscss" @doset "precompile" @doset "pauliframe" @doset "allocations" diff --git a/test/test_ecc_iscss.jl b/test/test_ecc_iscss.jl new file mode 100644 index 000000000..ec2d4eb45 --- /dev/null +++ b/test/test_ecc_iscss.jl @@ -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