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

Quantum Tensor-product code #349

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
27 changes: 27 additions & 0 deletions docs/src/references.bib
Original file line number Diff line number Diff line change
Expand Up @@ -402,3 +402,30 @@ @inproceedings{brown2013short
pages = {346--350},
doi = {10.1109/ISIT.2013.6620245}
}

@article{wolf1965codes,
title={On codes derivable from the tensor product of check matrices},
author={Wolf, Jack},
journal={IEEE Transactions on Information Theory},
volume={11},
number={2},
pages={281--284},
year={1965},
publisher={IEEE}
}

@inproceedings{wolf2006introduction,
title={An introduction to tensor product codes and applications to digital storage systems},
author={Wolf, Jack Keil},
booktitle={2006 IEEE Information Theory Workshop-ITW'06 Chengdu},
pages={6--10},
year={2006},
organization={IEEE}
}

@article{fan2016quantum,
title={On quantum tensor product codes},
author={Fan, Jihao and Li, Yonghui and Hsieh, Min-Hsiu and Chen, Hanwu},
journal={arXiv preprint arXiv:1605.09598},
year={2016}
}
3 changes: 3 additions & 0 deletions docs/src/references.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ For quantum code construction routines:
- [kitaev2003fault](@cite)
- [fowler2012surface](@cite)
- [knill1996concatenated](@cite)
- [fan2016quantum](@cite)

For classical code construction routines:
- [muller1954application](@cite)
Expand All @@ -48,6 +49,8 @@ For classical code construction routines:
- [bose1960class](@cite)
- [bose1960further](@cite)
- [error2024lin](@cite)
- [wolf1965codes](@cite)
- [wolf2006introduction](@cite)

# References

Expand Down
7 changes: 5 additions & 2 deletions src/ecc/ECC.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,20 @@ using DocStringExtensions
using Combinatorics: combinations
using SparseArrays: sparse
using Statistics: std
using Nemo: ZZ, residue_ring, matrix, finite_field, GF, minpoly, coeff, lcm, FqPolyRingElem, FqFieldElem, is_zero, degree, defining_polynomial, is_irreducible, echelon_form
using Nemo: ZZ, residue_ring, matrix, finite_field, GF, minpoly, coeff, lcm, FqPolyRingElem, FqFieldElem, is_zero, degree, defining_polynomial, is_irreducible, echelon_form, kronecker_product

abstract type AbstractECC end

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,
RepCode,
RepCode, BCH, TensorProduct,
CSS,
Shor9, Steane7, Cleve8, Perfect5, Bitflip3,
Toric, Gottesman, Surface, Concat, CircuitCode,
random_brickwork_circuit_code, random_all_to_all_circuit_code,
QuantumTensorProduct,
evaluate_decoder,
CommutationCheckECCSetup, NaiveSyndromeECCSetup, ShorSyndromeECCSetup,
TableDecoder,
Expand Down Expand Up @@ -365,8 +366,10 @@ include("codes/toric.jl")
include("codes/gottesman.jl")
include("codes/surface.jl")
include("codes/concat.jl")
include("codes/quantumtensorproduct.jl")
include("codes/random_circuit.jl")
include("codes/classical/reedmuller.jl")
include("codes/classical/bch.jl")
include("codes/classical/recursivereedmuller.jl")
include("codes/classical/tensorproduct.jl")
end #module
2 changes: 1 addition & 1 deletion src/ecc/codes/classical/bch.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct BCH <: AbstractPolynomialCode
m::Int
t::Int
function BCH(m, t)
if m < 3 || t < 0 || t >= 2 ^ (m - 1)
if m < 3 || t < 0 || (3 <= t <= 4 && t >= 2^(m - 1) - 1) || (t > 4 && t >= 2^(m - 1))
throw(ArgumentError("Invalid parameters: `m` and `t` must be positive. Additionally, ensure `m ≥ 3` and `t < 2ᵐ ⁻ ¹` to obtain a valid code."))
end
new(m, t)
Expand Down
20 changes: 20 additions & 0 deletions src/ecc/codes/classical/tensorproduct.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""
The classical Tensor-product code was discovered by Wolf in his 1963 paper [wolf1965codes](@cite). It combines two component linear error correcting codes by taking the tensor product of their parity check matrices.

The ECC Zoo has an [entry for this family](https://errorcorrectionzoo.org/c/tensor).
"""
struct TensorProduct
A::AbstractMatrix
B::AbstractMatrix
function TensorProduct(A, B)
all(x -> x isa Bool, A) && all(x -> x isa Bool, B) || throw(ArgumentError("All matrices should be defined over the Boolean field, GF(2)"))
new(A, B)
end
end

function parity_checks(tp::TensorProduct)
A, B = tp.A, tp.B
C = kronecker_product(matrix(ZZ, B), matrix(ZZ, A))
C = Matrix{Bool}(Matrix{Int}(C))
return C
end
2 changes: 1 addition & 1 deletion src/ecc/codes/classical_codes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ function parity_checks(c::RepCode)
I = [i for i in 1:n for δ in (0,1)]
J = [(i+δ-1)%n+1 for i in 1:n for δ in (0,1)]
V = true
sparse(I,J,V,n,n)
Matrix{Bool}(sparse(I,J,V,n,n))
end
19 changes: 19 additions & 0 deletions src/ecc/codes/quantumtensorproduct.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""
The binary quantum Tensor Product Code(TQC) is derived from classical TPCs using the CSS construction. A classical TPC is dual-containing if at least one of its component codes is.

The ECC Zoo has an [entry for this family](https://errorcorrectionzoo.org/c/quantum_tensor_product).
"""
struct QuantumTensorProduct
A::AbstractMatrix
B::AbstractMatrix
function QuantumTensorProduct(A, B)
all(x -> x isa Bool, A) && all(x -> x isa Bool, B) || throw(ArgumentError("All matrices should be defined over the Boolean field, GF(2)."))
new(A, B)
end
end

function parity_checks(Tₚ::QuantumTensorProduct)
T = parity_checks(TensorProduct(Tₚ.A, Tₚ.B))
H = Stabilizer(CSS(T, T))
return H
end
3 changes: 2 additions & 1 deletion test/test_ecc_base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ const code_instance_args = Dict(
Gottesman => [3, 4, 5],
CSS => (c -> (parity_checks_x(c), parity_checks_z(c))).([Shor9(), Steane7(), Toric(4, 4)]),
Concat => [(Perfect5(), Perfect5()), (Perfect5(), Steane7()), (Steane7(), Cleve8()), (Toric(2, 2), Shor9())],
CircuitCode => random_circuit_code_args
CircuitCode => random_circuit_code_args,
QuantumTensorProduct => [(RepCode(3),RepCode(4)), (RepCode(5),RepCode(6)), (BCH(3,1),BCH(3,2)), (BCH(3,2),BCH(4,1))]
)

function all_testablable_code_instances(;maxn=nothing)
Expand Down
4 changes: 2 additions & 2 deletions test/test_ecc_bch.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using LinearAlgebra
using QuantumClifford.ECC
using QuantumClifford.ECC: AbstractECC, BCH, generator_polynomial
using Nemo: ZZ, residue_ring, matrix, finite_field, GF, minpoly, coeff, lcm, FqPolyRingElem, FqFieldElem, is_zero, degree, defining_polynomial, is_irreducible
using Nemo: ZZ, residue_ring, matrix, finite_field, GF, minpoly, coeff, lcm, FqPolyRingElem, FqFieldElem, is_zero, degree, defining_polynomial, is_irreducible

"""
- To prove that `t`-bit error correcting BCH code indeed has minimum distance of at least `2 * t + 1`, it is shown that no `2 * t` or fewer columns of its binary parity check matrix `H` sum to zero. A formal mathematical proof can be found on pages 168 and 169 of Ch6 of Error Control Coding by Lin, Shu and Costello, Daniel.
Expand All @@ -26,7 +26,7 @@
m_cases = [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
for m in m_cases
n = 2 ^ m - 1
for t in rand(1:m, 2)
for t in rand(1:m-1, 2)
H = parity_checks(BCH(m, t))
@test check_designed_distance(H, t) == true
# n - k == degree of generator polynomial, `g(x)` == rank of binary parity check matrix, `H`.
Expand Down
10 changes: 10 additions & 0 deletions test/test_ecc_tensorproduct.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@testitem "Tensor Producr codes" begin
using QuantumClifford.ECC
using QuantumClifford.ECC: TensorProduct, parity_checks
A = [1 1 1 1 1] .== 1
B = [1 1 1 0 1 0 0; 1 1 0 1 0 1 0; 1 0 1 1 0 0 1] .== 1
# Example 1 of [wolf2006introduction](@cite)
@test parity_checks(TensorProduct(A, B)) == Matrix{Bool}([ 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0;
1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0;
1 1 1 1 1 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1])
end
1 change: 1 addition & 0 deletions test/test_ecc_throws.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
@test_throws ArgumentError ReedMuller(4, 2)

@test_throws ArgumentError BCH(2, 2)
@test_throws ArgumentError BCH(3, 3)
@test_throws ArgumentError BCH(3, 4)

@test_throws ArgumentError RecursiveReedMuller(-1, 3)
Expand Down
Loading