Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding iscss for issue #222 #241

Merged
merged 43 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
4dbc3fa
adding iscss
Mar 18, 2024
0bb6ad7
updating changelog
Mar 18, 2024
3942a72
adding iscss function
Mar 18, 2024
0c6a646
multimethods
Mar 18, 2024
0274e62
changes
Mar 18, 2024
d1b1e2f
function iscss
Mar 18, 2024
e199ac2
iscss function
Mar 18, 2024
7d2cad8
iscss function
Mar 18, 2024
7d940b7
iscss function
Mar 18, 2024
9a10fd1
iscss function
Mar 18, 2024
baa6538
iscss function
Mar 18, 2024
490ae99
iscss function
Mar 19, 2024
75864d7
iscss function
Mar 19, 2024
a9b14fd
iscss function
Mar 19, 2024
c39abd0
iscss function
Mar 19, 2024
624f5e8
iscss function
Mar 19, 2024
664dc1b
iscss function
Mar 19, 2024
ce63f8e
iscss function
Mar 19, 2024
d52b2b6
iscss function
Mar 19, 2024
80e5693
iscss function
Mar 19, 2024
db6ff0f
iscss function
Mar 19, 2024
074bc47
iscss function
Mar 19, 2024
cfed1ee
iscss function
Mar 19, 2024
4f43dc2
iscss function
Mar 19, 2024
f82a018
iscss function
Mar 19, 2024
4411b85
adding iscss function
Mar 19, 2024
e7d171f
Update test/test_iscss.jl
Fe-r-oz Mar 19, 2024
a62aa4f
adding iscss function
Mar 19, 2024
033fff5
adding iscss function
Mar 19, 2024
5c2e7b6
adding iscss function
Mar 19, 2024
e742b75
adding iscss function
Mar 19, 2024
c674273
Update src/ecc/codes/clevecode.jl
Fe-r-oz Mar 19, 2024
b03ed6a
Merge branch 'master' into isCSS
Fe-r-oz Mar 19, 2024
ccc51fd
Update CHANGELOG.md
Fe-r-oz Mar 19, 2024
9dadece
Update test_ecc_iscss.jl
Fe-r-oz Mar 19, 2024
a84a6b2
Update fivequbit.jl
Fe-r-oz Mar 19, 2024
460a489
Update gottesman.jl
Fe-r-oz Mar 19, 2024
43b3ce8
Update CHANGELOG.md
Fe-r-oz Mar 19, 2024
56e1705
Update test_ecc_iscss.jl
Fe-r-oz Mar 20, 2024
e966c1c
Update test_ecc_iscss.jl
Fe-r-oz Mar 20, 2024
a8ed100
Update test_ecc_iscss.jl
Fe-r-oz Mar 20, 2024
063b417
Update test_ecc_iscss.jl
Fe-r-oz Mar 20, 2024
6eabd9c
Update CHANGELOG.md
Krastanov Mar 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

# News

## v0.8.22 - 2024-03-19

- Added `iscss` function to determine whether a given code is a CSS (Calderbank-Shor-Steane) code and to verify if its parity check matrix is indeed in CSS form.
Fe-r-oz marked this conversation as resolved.
Show resolved Hide resolved

## 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 @@

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 @@
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
Fe-r-oz marked this conversation as resolved.
Show resolved Hide resolved
return false

Check warning on line 53 in src/ecc/ECC.jl

View check run for this annotation

Codecov / codecov/patch

src/ecc/ECC.jl#L52-L53

Added lines #L52 - L53 were not covered by tests
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/clevecode.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ struct Cleve8 <: AbstractECC end

code_n(c::Cleve8) = 8

function iscss(::Type{Cleve8})
return false
end

Fe-r-oz marked this conversation as resolved.
Show resolved Hide resolved
parity_checks(c::Cleve8) = S"XXXXXXXX
ZZZZZZZZ
XIXIZYZY
Expand Down
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/fivequbit.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
struct Perfect5 <: AbstractECC end

function iscss(::Type{Perfect5})
return false
end
Fe-r-oz marked this conversation as resolved.
Show resolved Hide resolved

parity_checks(c::Perfect5) = S"XZZX_
_XZZX
X_XZZ
Expand Down
4 changes: 4 additions & 0 deletions src/ecc/codes/gottesman.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ struct Gottesman <: AbstractECC
end
end

function iscss(::Type{Gottesman})
return false
end
Fe-r-oz marked this conversation as resolved.
Show resolved Hide resolved

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

function parity_checks(c::Gottesman)
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
42 changes: 42 additions & 0 deletions test/test_ecc_iscss.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
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
e = H[i, j]
has_x |= H[i,j][1]
has_z |= H[i,j][2]
Fe-r-oz marked this conversation as resolved.
Show resolved Hide resolved
has_x && has_z && return false
end
end
return true
end

function test_code(code)
is_css = iscss(code)
H = parity_checks(code)
is_css_matrix_result = is_css_matrix(H)
if is_css
@assert is_css_matrix_result == true "If code is CSS, then parity_check_matrix must be in CSS form."
Fe-r-oz marked this conversation as resolved.
Show resolved Hide resolved
end
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()]

for code in known_all_codes
@test iscss(code) == is_css_matrix(parity_checks(code))
end

@testset "Test parity check matrix" begin
@testset "known codes" begin
for code in known_all_codes
test_code(code)
Fe-r-oz marked this conversation as resolved.
Show resolved Hide resolved
end
end
end
Loading