From 3bf0779bb427d961a3a4c74f562c8869921fcd2d Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Wed, 28 Feb 2024 22:58:58 +0500 Subject: [PATCH 001/121] Update references.bib --- docs/src/references.bib | 92 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/docs/src/references.bib b/docs/src/references.bib index d260be4d7..40ebf1661 100644 --- a/docs/src/references.bib +++ b/docs/src/references.bib @@ -225,3 +225,95 @@ @article{nahum2017quantum author = {Nahum, Adam and Ruhman, Jonathan and Vijay, Sagar and Haah, Jeongwan}, year = {2017} } + +@article{Fowler_2011, + title={Two-dimensional color-code quantum computation}, + volume={83}, + ISSN={1094-1622}, + url={http://dx.doi.org/10.1103/PhysRevA.83.042310}, + DOI={10.1103/physreva.83.042310}, + number={4}, + journal={Physical Review A}, + publisher={American Physical Society (APS)}, + author={Fowler, Austin G.}, + year={2011}, + month=apr } + +@misc{bombin2015gauge, + title={Gauge Color Codes: Optimal Transversal Gates and Gauge Fixing in Topological Stabilizer Codes}, + author={H. Bombin}, + year={2015}, + eprint={1311.0879}, + archivePrefix={arXiv}, + primaryClass={quant-ph} +} + +@misc{bravyi1998quantum, + title={Quantum codes on a lattice with boundary}, + author={S. B. Bravyi and A. Yu. Kitaev}, + year={1998}, + eprint={quant-ph/9811052}, + archivePrefix={arXiv}, + primaryClass={quant-ph} +} + +@article{Vasmer_2019, + title={Three-dimensional surface codes: Transversal gates and fault-tolerant architectures}, + volume={100}, + ISSN={2469-9934}, + url={http://dx.doi.org/10.1103/PhysRevA.100.012312}, + DOI={10.1103/physreva.100.012312}, + number={1}, + journal={Physical Review A}, + publisher={American Physical Society (APS)}, + author={Vasmer, Michael and Browne, Dan E.}, + year={2019}, + month=jul } + +@misc{fahimniya2023faulttolerant, + title={Fault-tolerant hyperbolic Floquet quantum error correcting codes}, + author={Ali Fahimniya and Hossein Dehghani and Kishor Bharti and Sheryl Mathew and Alicia J. Kollár and Alexey V. Gorshkov and Michael J. Gullans}, + year={2023}, + eprint={2309.10033}, + archivePrefix={arXiv}, + primaryClass={quant-ph} +} + +@article{Breuckmann_2021, + title={Quantum Low-Density Parity-Check Codes}, + volume={2}, + ISSN={2691-3399}, + url={http://dx.doi.org/10.1103/PRXQuantum.2.040101}, + DOI={10.1103/prxquantum.2.040101}, + number={4}, + journal={PRX Quantum}, + publisher={American Physical Society (APS)}, + author={Breuckmann, Nikolas P. and Eberhardt, Jens Niklas}, + year={2021}, + month=oct } + +@article{Krishna_2021, + title={Fault-Tolerant Gates on Hypergraph Product Codes}, + volume={11}, + ISSN={2160-3308}, + url={http://dx.doi.org/10.1103/PhysRevX.11.011023}, + DOI={10.1103/physrevx.11.011023}, + number={1}, + journal={Physical Review X}, + publisher={American Physical Society (APS)}, + author={Krishna, Anirudh and Poulin, David}, + year={2021}, + month=feb } + +@article{Roffe_2023, + title={Bias-tailored quantum LDPC codes}, + volume={7}, + ISSN={2521-327X}, + url={http://dx.doi.org/10.22331/q-2023-05-15-1005}, + DOI={10.22331/q-2023-05-15-1005}, + journal={Quantum}, + publisher={Verein zur Forderung des Open Access Publizierens in den Quantenwissenschaften}, + author={Roffe, Joschka and Cohen, Lawrence Z. and Quintavalle, Armanda O. and Chandra, Daryus and Campbell, Earl T.}, + year={2023}, + month=may, pages={1005} } + From f207dc1380b88046de8f8fdd3185e55a741c3c51 Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Wed, 28 Feb 2024 22:59:22 +0500 Subject: [PATCH 002/121] Update references.md --- docs/src/references.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/docs/src/references.md b/docs/src/references.md index db6d50331..bca3b0179 100644 --- a/docs/src/references.md +++ b/docs/src/references.md @@ -28,7 +28,17 @@ For circuit construction routines (for stabilizer measurements for a given code) - [grassl2002algorithmic](@cite) - [grassl2011variations](@cite) +Quantum Error Corecting Codes: +- 2D Color Code [Fowler_2011](@cite) +- 3D Color Code [bombin2015gauge](@cite) +- 2D Surface Code [bravyi1998quantum](@cite) +- 3D Surface Code[Vasmer_2019](@cite) +- Floquent Code [fahimniya2023faulttolerant](@cite) +- Quantum Low-Density Parity Check (QLDPC) Code [Breuckmann_2021](@cite) +- Hypergraph Product Code [Krishna_2021](@cite) +- Bias-tailored Quantum LDPC Codes [Roffe_2023](@cite) + # References ```@bibliography -``` \ No newline at end of file +``` From 7070155d85a48c788f3075b003f1c19c21b34f0e Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Wed, 28 Feb 2024 23:03:27 +0500 Subject: [PATCH 003/121] Update references.md --- docs/src/references.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/references.md b/docs/src/references.md index bca3b0179..143b3d572 100644 --- a/docs/src/references.md +++ b/docs/src/references.md @@ -28,7 +28,7 @@ For circuit construction routines (for stabilizer measurements for a given code) - [grassl2002algorithmic](@cite) - [grassl2011variations](@cite) -Quantum Error Corecting Codes: +Quantum Error Correcting Codes: - 2D Color Code [Fowler_2011](@cite) - 3D Color Code [bombin2015gauge](@cite) - 2D Surface Code [bravyi1998quantum](@cite) From df8d6b85e102926a6000ce906b69cb4436b497e5 Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Thu, 29 Feb 2024 01:10:06 +0500 Subject: [PATCH 004/121] Update decoder_pipeline.jl Iterative Decoder Attempted Packages Used: 1. QuantumClifford 2. LDPCDecoders 3. Distances --- src/ecc/decoder_pipeline.jl | 48 +++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/src/ecc/decoder_pipeline.jl b/src/ecc/decoder_pipeline.jl index 1602cecf0..7b877812e 100644 --- a/src/ecc/decoder_pipeline.jl +++ b/src/ecc/decoder_pipeline.jl @@ -237,3 +237,51 @@ function PyMatchingDecoder(args...; kwargs...) end return ext.PyMatchingDecoder(args...; kwargs...) end + +"using QuantumClifford, Distances, JuMP" +# Define a struct named `IterativeDecoder` that inherits from `AbstractSyndromeDecoder` +struct IterativeDecoder <: AbstractSyndromeDecoder + # Stores the stabilizer matrix + H + # Number of qubits in the code + n + # Number of data qubits (k = n - rank(H)) + k + # Maximum number of iterations allowed in the decoding process + max_iterations +end + +# Function to initialize an `IterativeDecoder` object +function IterativeDecoder(c) + # Assuming H is already created + n, _ = size(H) + # Calculate number of data qubits based on stabilizer matrix rank + k = n - rank(H) + # Return an `IterativeDecoder` object with default max_iterations (can be adjusted) + return IterativeDecoder(H, n, k, 10) +end + +# Function to perform iterative decoding using the Belief Propagation algorithm +function decode(decoder::IterativeDecoder, syndrome_sample) + # Initialize error estimate vector with zeros + error_estimate = zeros(Int, decoder.n) + # Copy syndrome sample to a local variable + syndrome = syndrome_sample + + # Loop for the maximum number of iterations + for _ in 1:decoder.max_iterations + # Use LDPCDecoders' belief_propagate function for one BP iteration + error_estimate = belief_propagate(decoder.H, syndrome, max_iterations=1)[:, end] + + # Recalculate syndrome based on the updated error estimate using QuantumClifford's comm_all function + syndrome = comm_all(decoder.H, error_estimate) + + # Check for stopping criteria: zero syndrome or max iterations reached + if all(syndrome == 0) || _ >= decoder.max_iterations + break + end + end + + # Return the final error estimate vector + return error_estimate +end From 296c634332c201f23a994df202f8899baa25f4a9 Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Thu, 29 Feb 2024 01:29:38 +0500 Subject: [PATCH 005/121] Update decoder_pipeline.jl --- src/ecc/decoder_pipeline.jl | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/ecc/decoder_pipeline.jl b/src/ecc/decoder_pipeline.jl index 7b877812e..9e99de402 100644 --- a/src/ecc/decoder_pipeline.jl +++ b/src/ecc/decoder_pipeline.jl @@ -285,3 +285,18 @@ function decode(decoder::IterativeDecoder, syndrome_sample) # Return the final error estimate vector return error_estimate end + +function test_iterative_decoder() + # Create an instance of the decoder + decoder = IterativeDecoder(H) + + # Generate a random syndrome sample + n = size(H, 1) # Number of qubits based on H + syndrome = rand(Bool, n) + + # Decode the syndrome + decoded_errors = decode(decoder, syndrome) + + # Define a test assertion: Check if all decoded errors are zeros (perfect decoding) + @test isall(decoded_errors == 0) +end From 4032b7f05735636727b3a6b292facd6acd19cbbc Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Fri, 1 Mar 2024 11:04:51 +0500 Subject: [PATCH 006/121] Create code833 --- src/ecc/code833 | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/ecc/code833 diff --git a/src/ecc/code833 b/src/ecc/code833 new file mode 100644 index 000000000..64c44947c --- /dev/null +++ b/src/ecc/code833 @@ -0,0 +1,15 @@ + +# TODO [[8,1,3]] qubit code + +struct code833 <: AbstractECC end + +parity_checks(c::code833) = S"XXXXXXXX + ZZZZZZZZ + _X_XYZYZ + _XZY_XZY + _YXZXZ_Y" + +parity_checks_x(c::code833) = stab_to_gf2(parity_checks(code822()))[1:3,1:end÷2] +parity_checks_z(c::code833) = stab_to_gf2(parity_checks(code833()))[5:end,end÷2+1:end] + +distance(c::code833) = 3 From 55a4955bbd39e1304f9506fd0a66de17a2237e4f Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Fri, 1 Mar 2024 11:05:51 +0500 Subject: [PATCH 007/121] Create code833 --- src/ecc/codes/code833 | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 src/ecc/codes/code833 diff --git a/src/ecc/codes/code833 b/src/ecc/codes/code833 new file mode 100644 index 000000000..c650103ef --- /dev/null +++ b/src/ecc/codes/code833 @@ -0,0 +1,14 @@ +# TODO [[8,1,3]] qubit code + +struct code833 <: AbstractECC end + +parity_checks(c::code833) = S"XXXXXXXX + ZZZZZZZZ + _X_XYZYZ + _XZY_XZY + _YXZXZ_Y" + +parity_checks_x(c::code833) = stab_to_gf2(parity_checks(code822()))[1:3,1:end÷2] +parity_checks_z(c::code833) = stab_to_gf2(parity_checks(code833()))[5:end,end÷2+1:end] + +distance(c::code833) = 3 From 5242529b7154c1742c816d449331e16faba1bd6e Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Fri, 1 Mar 2024 11:06:14 +0500 Subject: [PATCH 008/121] Delete src/ecc/code833 --- src/ecc/code833 | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 src/ecc/code833 diff --git a/src/ecc/code833 b/src/ecc/code833 deleted file mode 100644 index 64c44947c..000000000 --- a/src/ecc/code833 +++ /dev/null @@ -1,15 +0,0 @@ - -# TODO [[8,1,3]] qubit code - -struct code833 <: AbstractECC end - -parity_checks(c::code833) = S"XXXXXXXX - ZZZZZZZZ - _X_XYZYZ - _XZY_XZY - _YXZXZ_Y" - -parity_checks_x(c::code833) = stab_to_gf2(parity_checks(code822()))[1:3,1:end÷2] -parity_checks_z(c::code833) = stab_to_gf2(parity_checks(code833()))[5:end,end÷2+1:end] - -distance(c::code833) = 3 From fe4b153c51383e337fc90d19895d14be4625a585 Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Fri, 1 Mar 2024 11:07:34 +0500 Subject: [PATCH 009/121] Rename code833 to code833.jl --- src/ecc/codes/{code833 => code833.jl} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/ecc/codes/{code833 => code833.jl} (100%) diff --git a/src/ecc/codes/code833 b/src/ecc/codes/code833.jl similarity index 100% rename from src/ecc/codes/code833 rename to src/ecc/codes/code833.jl From 568f31dbf6f82e7453498d8da53d89dab737d009 Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Fri, 1 Mar 2024 11:18:10 +0500 Subject: [PATCH 010/121] Update code833.jl --- src/ecc/codes/code833.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ecc/codes/code833.jl b/src/ecc/codes/code833.jl index c650103ef..c2ebb2549 100644 --- a/src/ecc/codes/code833.jl +++ b/src/ecc/codes/code833.jl @@ -8,7 +8,7 @@ parity_checks(c::code833) = S"XXXXXXXX _XZY_XZY _YXZXZ_Y" -parity_checks_x(c::code833) = stab_to_gf2(parity_checks(code822()))[1:3,1:end÷2] +parity_checks_x(c::code833) = stab_to_gf2(parity_checks(code833()))[1:3,1:end÷2] parity_checks_z(c::code833) = stab_to_gf2(parity_checks(code833()))[5:end,end÷2+1:end] distance(c::code833) = 3 From b39260ec0405f45685b35a37ddda9c77c8e71a36 Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Fri, 1 Mar 2024 21:56:58 +0500 Subject: [PATCH 011/121] Create code422.jl --- src/ecc/codes/code422.jl | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/ecc/codes/code422.jl diff --git a/src/ecc/codes/code422.jl b/src/ecc/codes/code422.jl new file mode 100644 index 000000000..15ea0f02b --- /dev/null +++ b/src/ecc/codes/code422.jl @@ -0,0 +1,11 @@ +# TODO [[4,2,2]] qubit code (Simplest Surface Code) + +struct code422 <: AbstractECC end + +parity_checks(c::code422) = S"XZZX + YXXY" +#not sure about the two lines,I have a hunch it's correct. Need verification. +parity_checks_x(c::code422) = stab_to_gf2(parity_checks(code422()))[1:2,1:end÷2] +parity_checks_z(c::code422) = stab_to_gf2(parity_checks(code422()))[2:end,end÷2+1:end] + +distance(c::code422) = 2 From e0f960ca3f3d82fa5963c2297df866cf459e45a0 Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Sat, 2 Mar 2024 00:40:42 +0500 Subject: [PATCH 012/121] Create QHammingcode.jl #how to use # Create two different instances of the quantum Hamming code #code1 = QHamming(5) # r = 5 #code2 = QHamming(7) # r = 7 # Get the parity check matrices for each instance #H1 = parity_checks(code1) #H2 = parity_checks(code2) --- src/ecc/codes/QHammingcode.jl | 41 +++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/ecc/codes/QHammingcode.jl diff --git a/src/ecc/codes/QHammingcode.jl b/src/ecc/codes/QHammingcode.jl new file mode 100644 index 000000000..df0dcac2e --- /dev/null +++ b/src/ecc/codes/QHammingcode.jl @@ -0,0 +1,41 @@ +#The Gottesman code has the parameters [[2^r, 2^r - r - 2, 3]] +#So, the parity check matrix will be of the form: +#[[I_r, K, -I_r] +#[K^T, I_(2^r - r - 2), 0] +#[0, -K, I_r]] + +struct QHamming + r::Int +end + +function parity_checks(code::QHamming) + r = code.r + n = 2^r + + # Construct the K matrix (refer to Gottesman-Chuang codes for details) + K = zeros(Int, (n - r - 2), r) + for i in 1:n-r-2 + j = i + 1 + while j <= n + K[i, bit2int(Integer.tobits(j - 1)[end])] = 1 + j += 1 + end + end + + # Parity check matrix + H = [[diagm(ones(Int, r)), K, -diagm(ones(Int, r))] + [K', diagm(ones(Int, n - r - 2)), zeros(Int, n - r - 2)] + [zeros(Int, n - r - 2), -K, diagm(ones(Int, r))]] + + return CSS(H) +end + +#how to use +# Create two different instances of the quantum Hamming code +#code1 = QHamming(5) # r = 5 +#code2 = QHamming(7) # r = 7 + +# Get the parity check matrices for each instance +#H1 = parity_checks(code1) +#H2 = parity_checks(code2) + From 3f8a37e19bb898b2daed8c440036333b5393838e Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Sat, 2 Mar 2024 01:32:24 +0500 Subject: [PATCH 013/121] Create hypergraphproductcode.jl Package to be used: Linear Algebra # Example usage #n_i = [2, 3] # Valid example #k_i = [1, 2] #d_i = [1, 1] #r_i = [1, 1] #code = HypergraphProduct(n_i, k_i, d_i, r_i) # Access and use functionalities: #println("Code block size (n):") #println(code_n(code)) #println("X parity-check matrix:") #println(parity_checks_x(code)) #println("Z parity-check matrix:") #println(parity_checks_z(code)) --- src/ecc/codes/hypergraphproductcode.jl | 83 ++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 src/ecc/codes/hypergraphproductcode.jl diff --git a/src/ecc/codes/hypergraphproductcode.jl b/src/ecc/codes/hypergraphproductcode.jl new file mode 100644 index 000000000..06e82926c --- /dev/null +++ b/src/ecc/codes/hypergraphproductcode.jl @@ -0,0 +1,83 @@ +#The [[n,k,d]] CSS code's constuction is based on two binary linear seeds codes, i element of {1,2} C sub i with parameters [n sub i, k sub i, d sub i] defined as the kernel of r sub i x n sub i check matrices H sub i of rank n sub i - k sub i. The hypergraph product yields two classical codes C sub x,z with parity-check matrices + +#H sub x = (H sub 1 ⊗ I sub n2 I sub r1 ⊗ (H sub 2)^T) (1) +#H sub z =( I sub n1 ⊗ H sub 2 (H sub 1)^T ⊗ I sub r2) (2) +#where I sub m is the m-dimensonal identity matrix. These two codes then yied a hypergraph product code via the CSS construction + +struct HypergraphProduct <: AbstractECC + n_i::Vector{Int} # Vector of n_i values + k_i::Vector{Int} # Vector of k_i values + d_i::Vector{Int} # Vector of d_i values + r_i::Vector{Int} # Vector of r_i values + Hx::Matrix{Bool} # H_x parity-check matrix + Hz::Matrix{Bool} # H_z parity-check matrix + + function HypergraphProduct(n_i, k_i, d_i, r_i) + if length(n_i) != 2 || length(k_i) != 2 || length(d_i) != 2 || length(r_i) != 2 + error("Hypergraph product requires exactly two seed codes (length of n_i, k_i, d_i, and r_i must be 2)") + end + # Check for valid seed code parameters + for i in 1:2 + if !(n_i[i] in [1, 2]) || !(k_i[i] <= n_i[i]) + error("Seed code parameters for code $i are invalid (n_i[$i]: $(n_i[i]), k_i[$i]: $(k_i[i]))") + end + end + new(n_i, k_i, d_i, r_i) + end + + function compute_Hx(n_i, k_i, d_i, r_i) + H1 = IMatrix(n_i[1]) - IMatrix(k_i[1]) + H2 = IMatrix(n_i[2]) - IMatrix(k_i[2]) + kron(H1, IMatrix(n_i[2])) * kron(IMatrix(r_i[1]), H2') + end + + function compute_Hz(n_i, k_i, d_i, r_i) + H1 = IMatrix(n_i[1]) - IMatrix(k_i[1]) + H2 = IMatrix(n_i[2]) - IMatrix(k_i[2]) + kron(IMatrix(n_i[1]), H2) * kron(H1', IMatrix(r_i[2])) + end + + function code_n(c::HypergraphProduct) + n_x = size(compute_Hx(c.n_i, c.k_i, c.d_i, c.r_i), 2) + n_z = size(compute_Hz(c.n_i, c.k_i, c.d_i, c.r_i), 2) + return n_x * n_z + end + + function parity_checks_xz(c::HypergraphProduct) + hx = compute_Hx(c.n_i, c.k_i, c.d_i, c.r_i) + hz = compute_Hz(c.n_i, c.k_i, c.d_i, c.r_i) + return hx[:, 1:end], hz[:, 1:end] # Remove first column (redundant) + end + + function parity_checks_x(c::HypergraphProduct) + hx, _ = parity_checks_xz(c) + return hx + end + + function parity_checks_z(c::HypergraphProduct) + _, hz = parity_checks_xz(c) + return hz + end + + # Full parity checks based on CSS construction + function parity_checks(c::HypergraphProduct) + hx, hz = parity_checks_xz(c) + + # Construct extended parity-check matrices + extended_Hx = vcat(hx, zeros(size(hz))) + extended_Hz = vcat(zeros(size(hx)), hz) + + # Create and return stabilizer representation + Stabilizer(fill(0x0, size(hx, 1) + size(hz, 1)), extended_Hx, extended_Hz) + end +end + +# Helper function for identity matrix +function IMatrix(n) + return eye(n, n) +end + + + +#println("Full parity checks:") +#println(parity_checks(code)) From 344e13b1c294e7ef587402a7b6c22ec2dd71760e Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Sat, 2 Mar 2024 01:38:19 +0500 Subject: [PATCH 014/121] Update hypergraphproductcode.jl --- src/ecc/codes/hypergraphproductcode.jl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/ecc/codes/hypergraphproductcode.jl b/src/ecc/codes/hypergraphproductcode.jl index 06e82926c..6f239540f 100644 --- a/src/ecc/codes/hypergraphproductcode.jl +++ b/src/ecc/codes/hypergraphproductcode.jl @@ -2,7 +2,7 @@ #H sub x = (H sub 1 ⊗ I sub n2 I sub r1 ⊗ (H sub 2)^T) (1) #H sub z =( I sub n1 ⊗ H sub 2 (H sub 1)^T ⊗ I sub r2) (2) -#where I sub m is the m-dimensonal identity matrix. These two codes then yied a hypergraph product code via the CSS construction +#where I sub m is the m-dimensional identity matrix. These two codes then yied a hypergraph product code via the CSS construction struct HypergraphProduct <: AbstractECC n_i::Vector{Int} # Vector of n_i values @@ -78,6 +78,5 @@ function IMatrix(n) end - #println("Full parity checks:") #println(parity_checks(code)) From b81d4deb67238ac748cfe3da8216cb39934bab23 Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Sat, 2 Mar 2024 01:48:45 +0500 Subject: [PATCH 015/121] Update QHammingcode.jl --- src/ecc/codes/QHammingcode.jl | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/src/ecc/codes/QHammingcode.jl b/src/ecc/codes/QHammingcode.jl index df0dcac2e..a78342f42 100644 --- a/src/ecc/codes/QHammingcode.jl +++ b/src/ecc/codes/QHammingcode.jl @@ -1,9 +1,3 @@ -#The Gottesman code has the parameters [[2^r, 2^r - r - 2, 3]] -#So, the parity check matrix will be of the form: -#[[I_r, K, -I_r] -#[K^T, I_(2^r - r - 2), 0] -#[0, -K, I_r]] - struct QHamming r::Int end @@ -29,13 +23,3 @@ function parity_checks(code::QHamming) return CSS(H) end - -#how to use -# Create two different instances of the quantum Hamming code -#code1 = QHamming(5) # r = 5 -#code2 = QHamming(7) # r = 7 - -# Get the parity check matrices for each instance -#H1 = parity_checks(code1) -#H2 = parity_checks(code2) - From 5d48c01f930983bda503d206ea59574f40b7585e Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Sat, 2 Mar 2024 01:49:21 +0500 Subject: [PATCH 016/121] Update hypergraphproductcode.jl --- src/ecc/codes/hypergraphproductcode.jl | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/ecc/codes/hypergraphproductcode.jl b/src/ecc/codes/hypergraphproductcode.jl index 6f239540f..c5ffd771e 100644 --- a/src/ecc/codes/hypergraphproductcode.jl +++ b/src/ecc/codes/hypergraphproductcode.jl @@ -1,8 +1,4 @@ -#The [[n,k,d]] CSS code's constuction is based on two binary linear seeds codes, i element of {1,2} C sub i with parameters [n sub i, k sub i, d sub i] defined as the kernel of r sub i x n sub i check matrices H sub i of rank n sub i - k sub i. The hypergraph product yields two classical codes C sub x,z with parity-check matrices -#H sub x = (H sub 1 ⊗ I sub n2 I sub r1 ⊗ (H sub 2)^T) (1) -#H sub z =( I sub n1 ⊗ H sub 2 (H sub 1)^T ⊗ I sub r2) (2) -#where I sub m is the m-dimensional identity matrix. These two codes then yied a hypergraph product code via the CSS construction struct HypergraphProduct <: AbstractECC n_i::Vector{Int} # Vector of n_i values @@ -77,6 +73,3 @@ function IMatrix(n) return eye(n, n) end - -#println("Full parity checks:") -#println(parity_checks(code)) From 3ca1cc2468096bf224224dacb75979d9c57ea96b Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Sat, 2 Mar 2024 01:52:42 +0500 Subject: [PATCH 017/121] Delete src/ecc/codes/code833.jl --- src/ecc/codes/code833.jl | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 src/ecc/codes/code833.jl diff --git a/src/ecc/codes/code833.jl b/src/ecc/codes/code833.jl deleted file mode 100644 index c2ebb2549..000000000 --- a/src/ecc/codes/code833.jl +++ /dev/null @@ -1,14 +0,0 @@ -# TODO [[8,1,3]] qubit code - -struct code833 <: AbstractECC end - -parity_checks(c::code833) = S"XXXXXXXX - ZZZZZZZZ - _X_XYZYZ - _XZY_XZY - _YXZXZ_Y" - -parity_checks_x(c::code833) = stab_to_gf2(parity_checks(code833()))[1:3,1:end÷2] -parity_checks_z(c::code833) = stab_to_gf2(parity_checks(code833()))[5:end,end÷2+1:end] - -distance(c::code833) = 3 From 7d1b34d8e2d9f92801b1dc0f1ca5a37bcbc396ac Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Sat, 2 Mar 2024 01:53:03 +0500 Subject: [PATCH 018/121] Delete src/ecc/codes/code422.jl --- src/ecc/codes/code422.jl | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 src/ecc/codes/code422.jl diff --git a/src/ecc/codes/code422.jl b/src/ecc/codes/code422.jl deleted file mode 100644 index 15ea0f02b..000000000 --- a/src/ecc/codes/code422.jl +++ /dev/null @@ -1,11 +0,0 @@ -# TODO [[4,2,2]] qubit code (Simplest Surface Code) - -struct code422 <: AbstractECC end - -parity_checks(c::code422) = S"XZZX - YXXY" -#not sure about the two lines,I have a hunch it's correct. Need verification. -parity_checks_x(c::code422) = stab_to_gf2(parity_checks(code422()))[1:2,1:end÷2] -parity_checks_z(c::code422) = stab_to_gf2(parity_checks(code422()))[2:end,end÷2+1:end] - -distance(c::code422) = 2 From 7e6c48e515dc66f7af2339f1b9bd185802972b87 Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Sat, 2 Mar 2024 02:06:37 +0500 Subject: [PATCH 019/121] Delete src/ecc/codes/hypergraphproductcode.jl --- src/ecc/codes/hypergraphproductcode.jl | 75 -------------------------- 1 file changed, 75 deletions(-) delete mode 100644 src/ecc/codes/hypergraphproductcode.jl diff --git a/src/ecc/codes/hypergraphproductcode.jl b/src/ecc/codes/hypergraphproductcode.jl deleted file mode 100644 index c5ffd771e..000000000 --- a/src/ecc/codes/hypergraphproductcode.jl +++ /dev/null @@ -1,75 +0,0 @@ - - -struct HypergraphProduct <: AbstractECC - n_i::Vector{Int} # Vector of n_i values - k_i::Vector{Int} # Vector of k_i values - d_i::Vector{Int} # Vector of d_i values - r_i::Vector{Int} # Vector of r_i values - Hx::Matrix{Bool} # H_x parity-check matrix - Hz::Matrix{Bool} # H_z parity-check matrix - - function HypergraphProduct(n_i, k_i, d_i, r_i) - if length(n_i) != 2 || length(k_i) != 2 || length(d_i) != 2 || length(r_i) != 2 - error("Hypergraph product requires exactly two seed codes (length of n_i, k_i, d_i, and r_i must be 2)") - end - # Check for valid seed code parameters - for i in 1:2 - if !(n_i[i] in [1, 2]) || !(k_i[i] <= n_i[i]) - error("Seed code parameters for code $i are invalid (n_i[$i]: $(n_i[i]), k_i[$i]: $(k_i[i]))") - end - end - new(n_i, k_i, d_i, r_i) - end - - function compute_Hx(n_i, k_i, d_i, r_i) - H1 = IMatrix(n_i[1]) - IMatrix(k_i[1]) - H2 = IMatrix(n_i[2]) - IMatrix(k_i[2]) - kron(H1, IMatrix(n_i[2])) * kron(IMatrix(r_i[1]), H2') - end - - function compute_Hz(n_i, k_i, d_i, r_i) - H1 = IMatrix(n_i[1]) - IMatrix(k_i[1]) - H2 = IMatrix(n_i[2]) - IMatrix(k_i[2]) - kron(IMatrix(n_i[1]), H2) * kron(H1', IMatrix(r_i[2])) - end - - function code_n(c::HypergraphProduct) - n_x = size(compute_Hx(c.n_i, c.k_i, c.d_i, c.r_i), 2) - n_z = size(compute_Hz(c.n_i, c.k_i, c.d_i, c.r_i), 2) - return n_x * n_z - end - - function parity_checks_xz(c::HypergraphProduct) - hx = compute_Hx(c.n_i, c.k_i, c.d_i, c.r_i) - hz = compute_Hz(c.n_i, c.k_i, c.d_i, c.r_i) - return hx[:, 1:end], hz[:, 1:end] # Remove first column (redundant) - end - - function parity_checks_x(c::HypergraphProduct) - hx, _ = parity_checks_xz(c) - return hx - end - - function parity_checks_z(c::HypergraphProduct) - _, hz = parity_checks_xz(c) - return hz - end - - # Full parity checks based on CSS construction - function parity_checks(c::HypergraphProduct) - hx, hz = parity_checks_xz(c) - - # Construct extended parity-check matrices - extended_Hx = vcat(hx, zeros(size(hz))) - extended_Hz = vcat(zeros(size(hx)), hz) - - # Create and return stabilizer representation - Stabilizer(fill(0x0, size(hx, 1) + size(hz, 1)), extended_Hx, extended_Hz) - end -end - -# Helper function for identity matrix -function IMatrix(n) - return eye(n, n) -end - From 0f43554ffef84ad1070de2df5fdf14427d0232fb Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Sat, 2 Mar 2024 02:08:03 +0500 Subject: [PATCH 020/121] Update references.bib --- docs/src/references.bib | 91 ----------------------------------------- 1 file changed, 91 deletions(-) diff --git a/docs/src/references.bib b/docs/src/references.bib index 40ebf1661..33c9a012c 100644 --- a/docs/src/references.bib +++ b/docs/src/references.bib @@ -226,94 +226,3 @@ @article{nahum2017quantum year = {2017} } -@article{Fowler_2011, - title={Two-dimensional color-code quantum computation}, - volume={83}, - ISSN={1094-1622}, - url={http://dx.doi.org/10.1103/PhysRevA.83.042310}, - DOI={10.1103/physreva.83.042310}, - number={4}, - journal={Physical Review A}, - publisher={American Physical Society (APS)}, - author={Fowler, Austin G.}, - year={2011}, - month=apr } - -@misc{bombin2015gauge, - title={Gauge Color Codes: Optimal Transversal Gates and Gauge Fixing in Topological Stabilizer Codes}, - author={H. Bombin}, - year={2015}, - eprint={1311.0879}, - archivePrefix={arXiv}, - primaryClass={quant-ph} -} - -@misc{bravyi1998quantum, - title={Quantum codes on a lattice with boundary}, - author={S. B. Bravyi and A. Yu. Kitaev}, - year={1998}, - eprint={quant-ph/9811052}, - archivePrefix={arXiv}, - primaryClass={quant-ph} -} - -@article{Vasmer_2019, - title={Three-dimensional surface codes: Transversal gates and fault-tolerant architectures}, - volume={100}, - ISSN={2469-9934}, - url={http://dx.doi.org/10.1103/PhysRevA.100.012312}, - DOI={10.1103/physreva.100.012312}, - number={1}, - journal={Physical Review A}, - publisher={American Physical Society (APS)}, - author={Vasmer, Michael and Browne, Dan E.}, - year={2019}, - month=jul } - -@misc{fahimniya2023faulttolerant, - title={Fault-tolerant hyperbolic Floquet quantum error correcting codes}, - author={Ali Fahimniya and Hossein Dehghani and Kishor Bharti and Sheryl Mathew and Alicia J. Kollár and Alexey V. Gorshkov and Michael J. Gullans}, - year={2023}, - eprint={2309.10033}, - archivePrefix={arXiv}, - primaryClass={quant-ph} -} - -@article{Breuckmann_2021, - title={Quantum Low-Density Parity-Check Codes}, - volume={2}, - ISSN={2691-3399}, - url={http://dx.doi.org/10.1103/PRXQuantum.2.040101}, - DOI={10.1103/prxquantum.2.040101}, - number={4}, - journal={PRX Quantum}, - publisher={American Physical Society (APS)}, - author={Breuckmann, Nikolas P. and Eberhardt, Jens Niklas}, - year={2021}, - month=oct } - -@article{Krishna_2021, - title={Fault-Tolerant Gates on Hypergraph Product Codes}, - volume={11}, - ISSN={2160-3308}, - url={http://dx.doi.org/10.1103/PhysRevX.11.011023}, - DOI={10.1103/physrevx.11.011023}, - number={1}, - journal={Physical Review X}, - publisher={American Physical Society (APS)}, - author={Krishna, Anirudh and Poulin, David}, - year={2021}, - month=feb } - -@article{Roffe_2023, - title={Bias-tailored quantum LDPC codes}, - volume={7}, - ISSN={2521-327X}, - url={http://dx.doi.org/10.22331/q-2023-05-15-1005}, - DOI={10.22331/q-2023-05-15-1005}, - journal={Quantum}, - publisher={Verein zur Forderung des Open Access Publizierens in den Quantenwissenschaften}, - author={Roffe, Joschka and Cohen, Lawrence Z. and Quintavalle, Armanda O. and Chandra, Daryus and Campbell, Earl T.}, - year={2023}, - month=may, pages={1005} } - From 0597d3528d4854914fab7500e85c72bf3e3ba192 Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Sat, 2 Mar 2024 02:11:40 +0500 Subject: [PATCH 021/121] Update references.md --- docs/src/references.md | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/docs/src/references.md b/docs/src/references.md index 143b3d572..eb9d4230d 100644 --- a/docs/src/references.md +++ b/docs/src/references.md @@ -28,16 +28,6 @@ For circuit construction routines (for stabilizer measurements for a given code) - [grassl2002algorithmic](@cite) - [grassl2011variations](@cite) -Quantum Error Correcting Codes: -- 2D Color Code [Fowler_2011](@cite) -- 3D Color Code [bombin2015gauge](@cite) -- 2D Surface Code [bravyi1998quantum](@cite) -- 3D Surface Code[Vasmer_2019](@cite) -- Floquent Code [fahimniya2023faulttolerant](@cite) -- Quantum Low-Density Parity Check (QLDPC) Code [Breuckmann_2021](@cite) -- Hypergraph Product Code [Krishna_2021](@cite) -- Bias-tailored Quantum LDPC Codes [Roffe_2023](@cite) - # References ```@bibliography From 9f86c779246d24b3464e07635db140116d06c8d8 Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Sat, 2 Mar 2024 02:47:09 +0500 Subject: [PATCH 022/121] Rename QHammingcode.jl to qhammingcode.jl --- src/ecc/codes/{QHammingcode.jl => qhammingcode.jl} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/ecc/codes/{QHammingcode.jl => qhammingcode.jl} (100%) diff --git a/src/ecc/codes/QHammingcode.jl b/src/ecc/codes/qhammingcode.jl similarity index 100% rename from src/ecc/codes/QHammingcode.jl rename to src/ecc/codes/qhammingcode.jl From 5997735cb6fa0eff2eaa64d92a81da285864d071 Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Sat, 2 Mar 2024 02:48:42 +0500 Subject: [PATCH 023/121] Update decoder_pipeline.jl --- src/ecc/decoder_pipeline.jl | 63 ------------------------------------- 1 file changed, 63 deletions(-) diff --git a/src/ecc/decoder_pipeline.jl b/src/ecc/decoder_pipeline.jl index 9e99de402..1602cecf0 100644 --- a/src/ecc/decoder_pipeline.jl +++ b/src/ecc/decoder_pipeline.jl @@ -237,66 +237,3 @@ function PyMatchingDecoder(args...; kwargs...) end return ext.PyMatchingDecoder(args...; kwargs...) end - -"using QuantumClifford, Distances, JuMP" -# Define a struct named `IterativeDecoder` that inherits from `AbstractSyndromeDecoder` -struct IterativeDecoder <: AbstractSyndromeDecoder - # Stores the stabilizer matrix - H - # Number of qubits in the code - n - # Number of data qubits (k = n - rank(H)) - k - # Maximum number of iterations allowed in the decoding process - max_iterations -end - -# Function to initialize an `IterativeDecoder` object -function IterativeDecoder(c) - # Assuming H is already created - n, _ = size(H) - # Calculate number of data qubits based on stabilizer matrix rank - k = n - rank(H) - # Return an `IterativeDecoder` object with default max_iterations (can be adjusted) - return IterativeDecoder(H, n, k, 10) -end - -# Function to perform iterative decoding using the Belief Propagation algorithm -function decode(decoder::IterativeDecoder, syndrome_sample) - # Initialize error estimate vector with zeros - error_estimate = zeros(Int, decoder.n) - # Copy syndrome sample to a local variable - syndrome = syndrome_sample - - # Loop for the maximum number of iterations - for _ in 1:decoder.max_iterations - # Use LDPCDecoders' belief_propagate function for one BP iteration - error_estimate = belief_propagate(decoder.H, syndrome, max_iterations=1)[:, end] - - # Recalculate syndrome based on the updated error estimate using QuantumClifford's comm_all function - syndrome = comm_all(decoder.H, error_estimate) - - # Check for stopping criteria: zero syndrome or max iterations reached - if all(syndrome == 0) || _ >= decoder.max_iterations - break - end - end - - # Return the final error estimate vector - return error_estimate -end - -function test_iterative_decoder() - # Create an instance of the decoder - decoder = IterativeDecoder(H) - - # Generate a random syndrome sample - n = size(H, 1) # Number of qubits based on H - syndrome = rand(Bool, n) - - # Decode the syndrome - decoded_errors = decode(decoder, syndrome) - - # Define a test assertion: Check if all decoded errors are zeros (perfect decoding) - @test isall(decoded_errors == 0) -end From 748b866b5f7177905980ef5abd46ab6446c1785b Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Sat, 2 Mar 2024 02:50:44 +0500 Subject: [PATCH 024/121] Update ECC.jl --- src/ecc/ECC.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ecc/ECC.jl b/src/ecc/ECC.jl index 4df23d852..d250a71f8 100644 --- a/src/ecc/ECC.jl +++ b/src/ecc/ECC.jl @@ -334,5 +334,6 @@ include("codes/steanecode.jl") include("codes/shorcode.jl") include("codes/clevecode.jl") include("codes/toric.jl") +include("codes/qhammingcode.jl") end #module From d3f00c3442258227e17b6b22a121690b6ac37427 Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Sat, 2 Mar 2024 03:05:41 +0500 Subject: [PATCH 025/121] Update ECC.jl --- src/ecc/ECC.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ecc/ECC.jl b/src/ecc/ECC.jl index d250a71f8..40a7eeeae 100644 --- a/src/ecc/ECC.jl +++ b/src/ecc/ECC.jl @@ -20,6 +20,7 @@ export parity_checks, parity_checks_x, parity_checks_z, CSS, Shor9, Steane7, Cleve8, Perfect5, Bitflip3, Toric, + QHamming, evaluate_decoder, CommutationCheckECCSetup, NaiveSyndromeECCSetup, ShorSyndromeECCSetup, TableDecoder, @@ -324,7 +325,6 @@ end include("circuits.jl") include("decoder_pipeline.jl") - include("codes/util.jl") include("codes/classical_codes.jl") include("codes/css.jl") From ce21699eed38980dc87909dec5efd47b9b7ec8d2 Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Sat, 2 Mar 2024 22:17:25 +0500 Subject: [PATCH 026/121] Update qhammingcode.jl --- src/ecc/codes/qhammingcode.jl | 42 +++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/src/ecc/codes/qhammingcode.jl b/src/ecc/codes/qhammingcode.jl index a78342f42..8d130b659 100644 --- a/src/ecc/codes/qhammingcode.jl +++ b/src/ecc/codes/qhammingcode.jl @@ -1,25 +1,29 @@ struct QHamming - r::Int + r::Int end -function parity_checks(code::QHamming) - r = code.r - n = 2^r +struct InvalidRError <: Exception end # Define a custom exception type - # Construct the K matrix (refer to Gottesman-Chuang codes for details) - K = zeros(Int, (n - r - 2), r) - for i in 1:n-r-2 - j = i + 1 - while j <= n - K[i, bit2int(Integer.tobits(j - 1)[end])] = 1 - j += 1 +function parity_checks(c::QHamming) + if !(3 <= c.r < 15) + throw(InvalidRError()) # Throw the exception if r is out of bounds end - end - - # Parity check matrix - H = [[diagm(ones(Int, r)), K, -diagm(ones(Int, r))] - [K', diagm(ones(Int, n - r - 2)), zeros(Int, n - r - 2)] - [zeros(Int, n - r - 2), -K, diagm(ones(Int, r))]] - - return CSS(H) + n = 2^c.r + k = 2^c.r - c.r - 2 + + # Initialize parity check matrix + H = zeros(Int, k, n) + + # Generate parity checks for the quantum Hamming code + for i in 1:k + for j in 1:n + if j & (1 << (i - 1)) != 0 + H[i, j] = 1 + end + end + end + + return H end + +code_n(c::QHamming) = 2^c.r From 683933d32db8da43185b382207edab35309b2e04 Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Sun, 3 Mar 2024 03:48:23 +0500 Subject: [PATCH 027/121] Update test_ecc_encoding.jl --- test/test_ecc_encoding.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test_ecc_encoding.jl b/test/test_ecc_encoding.jl index c80d03bc3..4cb6a001e 100644 --- a/test/test_ecc_encoding.jl +++ b/test/test_ecc_encoding.jl @@ -14,6 +14,7 @@ using QuantumClifford.ECC :(Steane7()), :(Shor9()), :(Perfect5()), + :QHamming(), :(Bitflip3()), :(S"Y_"), :(S"Z_"), From 48e2d094ee452351ab60def8d925713439ab01b2 Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Sun, 3 Mar 2024 03:50:35 +0500 Subject: [PATCH 028/121] Update test_ecc_syndromes.jl --- test/test_ecc_syndromes.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test_ecc_syndromes.jl b/test/test_ecc_syndromes.jl index 64a4035f3..ba71a4b8e 100644 --- a/test/test_ecc_syndromes.jl +++ b/test/test_ecc_syndromes.jl @@ -9,6 +9,7 @@ codes = [ Steane7(), Shor9(), Perfect5(), + QHamming(), Cleve8(), CSS([0 1 1 0; 1 1 0 0], [1 1 1 1]), Toric(3,3), From 3b12a0a11321f3c4e906c226ddf6b530629d6472 Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Sun, 3 Mar 2024 03:51:40 +0500 Subject: [PATCH 029/121] Update test_ecc_decoder_all_setups.jl --- test/test_ecc_decoder_all_setups.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/test_ecc_decoder_all_setups.jl b/test/test_ecc_decoder_all_setups.jl index 8fc483101..698713c9c 100644 --- a/test/test_ecc_decoder_all_setups.jl +++ b/test/test_ecc_decoder_all_setups.jl @@ -16,7 +16,9 @@ import PyQDecoders Steane7(), Shor9(), Perfect5(), + QHamming(), Cleve8(), + ] noise = 0.001 From 3f784ea85cdd572d5ec3522cc186bda372903311 Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Sun, 3 Mar 2024 03:53:06 +0500 Subject: [PATCH 030/121] Update test_ecc.jl --- test/test_ecc.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test_ecc.jl b/test/test_ecc.jl index c790fbae7..238306439 100644 --- a/test/test_ecc.jl +++ b/test/test_ecc.jl @@ -8,6 +8,7 @@ codes = [ Steane7(), Shor9(), Perfect5(), + QHamming(), Cleve8(), CSS([0 1 1 0; 1 1 0 0], [1 1 1 1]), ] From 2f0afcf5779d358731e2ca446e5c6458606bc2bd Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Sun, 3 Mar 2024 04:21:37 +0500 Subject: [PATCH 031/121] Update qhammingcode.jl --- src/ecc/codes/qhammingcode.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ecc/codes/qhammingcode.jl b/src/ecc/codes/qhammingcode.jl index 8d130b659..aa363a9dc 100644 --- a/src/ecc/codes/qhammingcode.jl +++ b/src/ecc/codes/qhammingcode.jl @@ -1,4 +1,4 @@ -struct QHamming +struct QHamming <:AbstractECC r::Int end From ccf449997f018b8703dc068b5879affd683f2775 Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Sun, 3 Mar 2024 04:40:57 +0500 Subject: [PATCH 032/121] Add files via upload --- docs/src/notebooks/quantumhammingcode.ipynb | 303 ++++++++++++++++++++ 1 file changed, 303 insertions(+) create mode 100644 docs/src/notebooks/quantumhammingcode.ipynb diff --git a/docs/src/notebooks/quantumhammingcode.ipynb b/docs/src/notebooks/quantumhammingcode.ipynb new file mode 100644 index 000000000..d86a34b9a --- /dev/null +++ b/docs/src/notebooks/quantumhammingcode.ipynb @@ -0,0 +1,303 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 7, + "id": "779eb6c7-d9a8-4015-8cf0-b57f3e744782", + "metadata": {}, + "outputs": [], + "source": [ + "using Pkg" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "4ae95dee-f3d1-4090-897e-248aed04b5e8", + "metadata": {}, + "outputs": [], + "source": [ + "using QuantumClifford\n", + "using QuantumClifford.ECC: QHamming, naive_syndrome_circuit, naive_encoding_circuit, parity_checks, code_s, code_n\n", + "using Quantikz\n" + ] + }, + { + "cell_type": "markdown", + "id": "db939930-4e6b-4582-b1d7-73509dce985f", + "metadata": {}, + "source": [ + "# **Quantum Hamming Code aka Gottesman Codes**\n", + "\n", + "Infinite Family of [[ 2^r, 2^r-r-2,3]] Gottesman Codes with r>=3 also called Quantum Hamming Codes. They belong to the family of CSS codes CSS constructed with a classical hamming code, [[2^r-1,2^r-1-r,3]] =C sub x = C sub z a.k.a first-ordered punctured Reed-Muller code RM(r-2,r)\n", + "\n", + "[1] https://errorcorrectionzoo.org/c/quantum_hamming_css\n", + "\n", + "[2] https://arxiv.org/pdf/quant-ph/9604038.pdf" + ] + }, + { + "cell_type": "markdown", + "id": "0b870a27-0d43-4a2b-b8a1-a13a83fb81b9", + "metadata": {}, + "source": [ + "### **When r=3**" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "745e5533-0861-4564-a717-cdcbef176126", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3×8 Matrix{Int64}:\n", + " 1 0 1 0 1 0 1 0\n", + " 0 1 1 0 0 1 1 0\n", + " 0 0 0 1 1 1 1 0" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "code = QHamming(3)\n", + "H = parity_checks(code)" + ] + }, + { + "cell_type": "markdown", + "id": "af089959-1c9b-40cf-84fe-b1c5a77ff7bb", + "metadata": {}, + "source": [ + "### **When r=4**" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "1e6544f4-bf86-4d0b-af6b-817a78e58ffe", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "10×16 Matrix{Int64}:\n", + " 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0\n", + " 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0\n", + " 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0\n", + " 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "code = QHamming(4)\n", + "H = parity_checks(code)" + ] + }, + { + "cell_type": "markdown", + "id": "f5eaf3f7-1b71-4eca-b24b-e3b277da73af", + "metadata": {}, + "source": [ + "### **When r=5**" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "3158e32b-347f-4141-b1d7-332212a068db", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "25×32 Matrix{Int64}:\n", + " 1 0 1 0 1 0 1 0 1 0 1 0 1 … 1 0 1 0 1 0 1 0 1 0 1 0\n", + " 0 1 1 0 0 1 1 0 0 1 1 0 0 0 1 1 0 0 1 1 0 0 1 1 0\n", + " 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 1 0 0 0 0 1 1 1 1 0\n", + " 0 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 1 1 1 1 1 1 1 1 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 … 0 0 0 0 0 0 0 0 0 0 0 1\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 … 0 0 0 0 0 0 0 0 0 0 0 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 … 0 0 0 0 0 0 0 0 0 0 0 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 … 0 0 0 0 0 0 0 0 0 0 0 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "code = QHamming(5)\n", + "H = parity_checks(code)" + ] + }, + { + "cell_type": "markdown", + "id": "1b313647-9e75-4e3f-af9a-3a628856428e", + "metadata": {}, + "source": [ + "### **When r= 6**" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "50673143-7600-402f-af24-af5ae3692527", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "56×64 Matrix{Int64}:\n", + " 1 0 1 0 1 0 1 0 1 0 1 0 1 … 1 0 1 0 1 0 1 0 1 0 1 0\n", + " 0 1 1 0 0 1 1 0 0 1 1 0 0 0 1 1 0 0 1 1 0 0 1 1 0\n", + " 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 1 0 0 0 0 1 1 1 1 0\n", + " 0 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 1 1 1 1 1 1 1 1 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 … 1 1 1 1 1 1 1 1 1 1 1 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 … 0 0 0 0 0 0 0 0 0 0 0 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", + " ⋮ ⋮ ⋮ ⋱ ⋮ ⋮ \n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 … 0 0 0 0 0 0 0 0 0 0 0 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 … 0 0 0 0 0 0 0 0 0 0 0 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 … 0 0 0 0 0 0 0 0 0 0 0 0" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "code = QHamming(6)\n", + "H = parity_checks(code)" + ] + }, + { + "cell_type": "markdown", + "id": "251347ce-7854-409e-9602-8965bef5ed2f", + "metadata": {}, + "source": [ + "### **When r= 7**" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "d1ae3a85-cb4b-43b7-9f75-63e7fc880b27", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "119×128 Matrix{Int64}:\n", + " 1 0 1 0 1 0 1 0 1 0 1 0 1 … 1 0 1 0 1 0 1 0 1 0 1 0\n", + " 0 1 1 0 0 1 1 0 0 1 1 0 0 0 1 1 0 0 1 1 0 0 1 1 0\n", + " 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 1 0 0 0 0 1 1 1 1 0\n", + " 0 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 1 1 1 1 1 1 1 1 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 … 1 1 1 1 1 1 1 1 1 1 1 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 … 0 0 0 0 0 0 0 0 0 0 0 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", + " ⋮ ⋮ ⋮ ⋱ ⋮ ⋮ \n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 … 0 0 0 0 0 0 0 0 0 0 0 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 … 0 0 0 0 0 0 0 0 0 0 0 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", + " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "code = QHamming(7)\n", + "H = parity_checks(code)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5202f1f4-1777-4013-83e4-539bed057115", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Julia 1.10.1", + "language": "julia", + "name": "julia-1.10" + }, + "language_info": { + "file_extension": ".jl", + "mimetype": "application/julia", + "name": "julia", + "version": "1.10.1" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} From fa2fc87691fa4e534775d61af0937efaa8ad482f Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Sun, 3 Mar 2024 04:52:25 +0500 Subject: [PATCH 033/121] Create test_qhamming_code.jl --- test/test_qhamming_code.jl | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 test/test_qhamming_code.jl diff --git a/test/test_qhamming_code.jl b/test/test_qhamming_code.jl new file mode 100644 index 000000000..bed2d0bd0 --- /dev/null +++ b/test/test_qhamming_code.jl @@ -0,0 +1,20 @@ +using Test +include("src/ecc/codes/qhammingcode.jl") + +# Define test cases +@testset "QHamming Code Tests" begin + # Test parity checks generation + @testset "Parity Checks" begin + hamming_code = QHamming(3) + @test size(parity_checks(hamming_code)) == (3, 8) + @test all(parity_checks(hamming_code) .>= 0) + # Add more parity check tests if needed + end + + # Test block size calculation + @testset "Block Size" begin + hamming_code = QHamming(3) + @test code_n(hamming_code) == 8 + # Add more block size tests if needed + end +end From 042ef3ee261f62fd07e40713cf49735cf5907374 Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Sun, 3 Mar 2024 21:17:39 +0500 Subject: [PATCH 034/121] Delete docs/src/notebooks/quantumhammingcode.ipynb --- docs/src/notebooks/quantumhammingcode.ipynb | 303 -------------------- 1 file changed, 303 deletions(-) delete mode 100644 docs/src/notebooks/quantumhammingcode.ipynb diff --git a/docs/src/notebooks/quantumhammingcode.ipynb b/docs/src/notebooks/quantumhammingcode.ipynb deleted file mode 100644 index d86a34b9a..000000000 --- a/docs/src/notebooks/quantumhammingcode.ipynb +++ /dev/null @@ -1,303 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 7, - "id": "779eb6c7-d9a8-4015-8cf0-b57f3e744782", - "metadata": {}, - "outputs": [], - "source": [ - "using Pkg" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "id": "4ae95dee-f3d1-4090-897e-248aed04b5e8", - "metadata": {}, - "outputs": [], - "source": [ - "using QuantumClifford\n", - "using QuantumClifford.ECC: QHamming, naive_syndrome_circuit, naive_encoding_circuit, parity_checks, code_s, code_n\n", - "using Quantikz\n" - ] - }, - { - "cell_type": "markdown", - "id": "db939930-4e6b-4582-b1d7-73509dce985f", - "metadata": {}, - "source": [ - "# **Quantum Hamming Code aka Gottesman Codes**\n", - "\n", - "Infinite Family of [[ 2^r, 2^r-r-2,3]] Gottesman Codes with r>=3 also called Quantum Hamming Codes. They belong to the family of CSS codes CSS constructed with a classical hamming code, [[2^r-1,2^r-1-r,3]] =C sub x = C sub z a.k.a first-ordered punctured Reed-Muller code RM(r-2,r)\n", - "\n", - "[1] https://errorcorrectionzoo.org/c/quantum_hamming_css\n", - "\n", - "[2] https://arxiv.org/pdf/quant-ph/9604038.pdf" - ] - }, - { - "cell_type": "markdown", - "id": "0b870a27-0d43-4a2b-b8a1-a13a83fb81b9", - "metadata": {}, - "source": [ - "### **When r=3**" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "id": "745e5533-0861-4564-a717-cdcbef176126", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "3×8 Matrix{Int64}:\n", - " 1 0 1 0 1 0 1 0\n", - " 0 1 1 0 0 1 1 0\n", - " 0 0 0 1 1 1 1 0" - ] - }, - "execution_count": 9, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "code = QHamming(3)\n", - "H = parity_checks(code)" - ] - }, - { - "cell_type": "markdown", - "id": "af089959-1c9b-40cf-84fe-b1c5a77ff7bb", - "metadata": {}, - "source": [ - "### **When r=4**" - ] - }, - { - "cell_type": "code", - "execution_count": 13, - "id": "1e6544f4-bf86-4d0b-af6b-817a78e58ffe", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "10×16 Matrix{Int64}:\n", - " 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0\n", - " 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0\n", - " 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0\n", - " 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0" - ] - }, - "execution_count": 13, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "code = QHamming(4)\n", - "H = parity_checks(code)" - ] - }, - { - "cell_type": "markdown", - "id": "f5eaf3f7-1b71-4eca-b24b-e3b277da73af", - "metadata": {}, - "source": [ - "### **When r=5**" - ] - }, - { - "cell_type": "code", - "execution_count": 14, - "id": "3158e32b-347f-4141-b1d7-332212a068db", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "25×32 Matrix{Int64}:\n", - " 1 0 1 0 1 0 1 0 1 0 1 0 1 … 1 0 1 0 1 0 1 0 1 0 1 0\n", - " 0 1 1 0 0 1 1 0 0 1 1 0 0 0 1 1 0 0 1 1 0 0 1 1 0\n", - " 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 1 0 0 0 0 1 1 1 1 0\n", - " 0 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 1 1 1 1 1 1 1 1 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 … 0 0 0 0 0 0 0 0 0 0 0 1\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 … 0 0 0 0 0 0 0 0 0 0 0 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 … 0 0 0 0 0 0 0 0 0 0 0 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 … 0 0 0 0 0 0 0 0 0 0 0 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0" - ] - }, - "execution_count": 14, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "code = QHamming(5)\n", - "H = parity_checks(code)" - ] - }, - { - "cell_type": "markdown", - "id": "1b313647-9e75-4e3f-af9a-3a628856428e", - "metadata": {}, - "source": [ - "### **When r= 6**" - ] - }, - { - "cell_type": "code", - "execution_count": 15, - "id": "50673143-7600-402f-af24-af5ae3692527", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "56×64 Matrix{Int64}:\n", - " 1 0 1 0 1 0 1 0 1 0 1 0 1 … 1 0 1 0 1 0 1 0 1 0 1 0\n", - " 0 1 1 0 0 1 1 0 0 1 1 0 0 0 1 1 0 0 1 1 0 0 1 1 0\n", - " 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 1 0 0 0 0 1 1 1 1 0\n", - " 0 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 1 1 1 1 1 1 1 1 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 … 1 1 1 1 1 1 1 1 1 1 1 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 … 0 0 0 0 0 0 0 0 0 0 0 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", - " ⋮ ⋮ ⋮ ⋱ ⋮ ⋮ \n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 … 0 0 0 0 0 0 0 0 0 0 0 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 … 0 0 0 0 0 0 0 0 0 0 0 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 … 0 0 0 0 0 0 0 0 0 0 0 0" - ] - }, - "execution_count": 15, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "code = QHamming(6)\n", - "H = parity_checks(code)" - ] - }, - { - "cell_type": "markdown", - "id": "251347ce-7854-409e-9602-8965bef5ed2f", - "metadata": {}, - "source": [ - "### **When r= 7**" - ] - }, - { - "cell_type": "code", - "execution_count": 20, - "id": "d1ae3a85-cb4b-43b7-9f75-63e7fc880b27", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "119×128 Matrix{Int64}:\n", - " 1 0 1 0 1 0 1 0 1 0 1 0 1 … 1 0 1 0 1 0 1 0 1 0 1 0\n", - " 0 1 1 0 0 1 1 0 0 1 1 0 0 0 1 1 0 0 1 1 0 0 1 1 0\n", - " 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 1 0 0 0 0 1 1 1 1 0\n", - " 0 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0 1 1 1 1 1 1 1 1 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 … 1 1 1 1 1 1 1 1 1 1 1 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 … 0 0 0 0 0 0 0 0 0 0 0 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", - " ⋮ ⋮ ⋮ ⋱ ⋮ ⋮ \n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 … 0 0 0 0 0 0 0 0 0 0 0 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 … 0 0 0 0 0 0 0 0 0 0 0 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n", - " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0" - ] - }, - "execution_count": 20, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "code = QHamming(7)\n", - "H = parity_checks(code)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "5202f1f4-1777-4013-83e4-539bed057115", - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Julia 1.10.1", - "language": "julia", - "name": "julia-1.10" - }, - "language_info": { - "file_extension": ".jl", - "mimetype": "application/julia", - "name": "julia", - "version": "1.10.1" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} From f091649130c6bdc27b1c4d16b1d081ac6def6ee3 Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Sun, 3 Mar 2024 21:28:22 +0500 Subject: [PATCH 035/121] Update test/test_ecc_decoder_all_setups.jl Co-authored-by: Stefan Krastanov --- test/test_ecc_decoder_all_setups.jl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/test_ecc_decoder_all_setups.jl b/test/test_ecc_decoder_all_setups.jl index 698713c9c..e70ae69e1 100644 --- a/test/test_ecc_decoder_all_setups.jl +++ b/test/test_ecc_decoder_all_setups.jl @@ -17,8 +17,7 @@ import PyQDecoders Shor9(), Perfect5(), QHamming(), - Cleve8(), - + Cleve8(), ] noise = 0.001 From 8547a2da0aa2851c99ad7312cfd388909127a5ee Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Sun, 3 Mar 2024 21:29:58 +0500 Subject: [PATCH 036/121] Update ECC.jl --- src/ecc/ECC.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/src/ecc/ECC.jl b/src/ecc/ECC.jl index 40a7eeeae..a067f4132 100644 --- a/src/ecc/ECC.jl +++ b/src/ecc/ECC.jl @@ -20,7 +20,6 @@ export parity_checks, parity_checks_x, parity_checks_z, CSS, Shor9, Steane7, Cleve8, Perfect5, Bitflip3, Toric, - QHamming, evaluate_decoder, CommutationCheckECCSetup, NaiveSyndromeECCSetup, ShorSyndromeECCSetup, TableDecoder, From 912321b6a09d3300fdec5c6b660d264232edf7ab Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Sun, 3 Mar 2024 21:33:37 +0500 Subject: [PATCH 037/121] Update test_ecc.jl --- test/test_ecc.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_ecc.jl b/test/test_ecc.jl index 238306439..166e0188b 100644 --- a/test/test_ecc.jl +++ b/test/test_ecc.jl @@ -8,7 +8,7 @@ codes = [ Steane7(), Shor9(), Perfect5(), - QHamming(), + QHamming(3), Cleve8(), CSS([0 1 1 0; 1 1 0 0], [1 1 1 1]), ] From 1a1eefdc0f55905f23cc16ba5d18b7e7375dffbe Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Sun, 3 Mar 2024 21:35:22 +0500 Subject: [PATCH 038/121] Update test_ecc_syndromes.jl --- test/test_ecc_syndromes.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_ecc_syndromes.jl b/test/test_ecc_syndromes.jl index ba71a4b8e..78ff558fa 100644 --- a/test/test_ecc_syndromes.jl +++ b/test/test_ecc_syndromes.jl @@ -9,7 +9,7 @@ codes = [ Steane7(), Shor9(), Perfect5(), - QHamming(), + QHamming(3), Cleve8(), CSS([0 1 1 0; 1 1 0 0], [1 1 1 1]), Toric(3,3), From d5187f01c401992b3ea70ef9283da40207d2e8ce Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Sun, 3 Mar 2024 21:36:37 +0500 Subject: [PATCH 039/121] Update test_ecc_encoding.jl --- test/test_ecc_encoding.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_ecc_encoding.jl b/test/test_ecc_encoding.jl index 4cb6a001e..11c3a6c6a 100644 --- a/test/test_ecc_encoding.jl +++ b/test/test_ecc_encoding.jl @@ -14,7 +14,7 @@ using QuantumClifford.ECC :(Steane7()), :(Shor9()), :(Perfect5()), - :QHamming(), + :(QHamming(3)), :(Bitflip3()), :(S"Y_"), :(S"Z_"), From 6449d6b09db5c3f9ca7bddd6e533ee65917ea4ad Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Sun, 3 Mar 2024 22:01:13 +0500 Subject: [PATCH 040/121] Update references.md From 72f2f16c3c14202b03295254a34bafbc979867fd Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Sun, 3 Mar 2024 22:19:35 +0500 Subject: [PATCH 041/121] Update ECC.jl --- src/ecc/ECC.jl | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/ecc/ECC.jl b/src/ecc/ECC.jl index a067f4132..99a3b457b 100644 --- a/src/ecc/ECC.jl +++ b/src/ecc/ECC.jl @@ -333,6 +333,4 @@ include("codes/steanecode.jl") include("codes/shorcode.jl") include("codes/clevecode.jl") include("codes/toric.jl") -include("codes/qhammingcode.jl") - end #module From 845b7b19c4181cfa006520ba38039d9ac2b268e1 Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Sun, 3 Mar 2024 22:29:46 +0500 Subject: [PATCH 042/121] Update test_qhamming_code.jl --- test/test_qhamming_code.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/test_qhamming_code.jl b/test/test_qhamming_code.jl index bed2d0bd0..be7a19e93 100644 --- a/test/test_qhamming_code.jl +++ b/test/test_qhamming_code.jl @@ -1,5 +1,6 @@ using Test -include("src/ecc/codes/qhammingcode.jl") +using QuantumClifford +using QuantumClifford.ECC: QHamming # Define test cases @testset "QHamming Code Tests" begin From 73b4c1de6829159251a33d31f68b24f000a4fb08 Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Sun, 3 Mar 2024 22:36:58 +0500 Subject: [PATCH 043/121] Update test_throws.jl --- test/test_throws.jl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/test_throws.jl b/test/test_throws.jl index 724cc7de5..caf5cf39f 100644 --- a/test/test_throws.jl +++ b/test/test_throws.jl @@ -1,6 +1,7 @@ using Test using QuantumClifford using QuantumClifford: rank, mul_left!, mul_right! +using QuantumClifford.ECC: QHamming using InteractiveUtils: subtypes @@ -65,3 +66,5 @@ for m in [sMX,sMZ,sMY,sMRX,sMRZ,sMRY] @test_throws ArgumentError m(0,1) @test_throws ArgumentError m(-1,0) end + +@test_throws ArgumentError parity_checks(QHamming(2)) From a1901f5e75e8605b5dd6e96156726e8aabd78326 Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Sun, 3 Mar 2024 22:38:49 +0500 Subject: [PATCH 044/121] Update qhammingcode.jl --- src/ecc/codes/qhammingcode.jl | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/ecc/codes/qhammingcode.jl b/src/ecc/codes/qhammingcode.jl index aa363a9dc..ff010f4fc 100644 --- a/src/ecc/codes/qhammingcode.jl +++ b/src/ecc/codes/qhammingcode.jl @@ -2,11 +2,8 @@ struct QHamming <:AbstractECC r::Int end -struct InvalidRError <: Exception end # Define a custom exception type - function parity_checks(c::QHamming) - if !(3 <= c.r < 15) - throw(InvalidRError()) # Throw the exception if r is out of bounds + if (3 <= c.r <= 15) || error("The r parameter in QHamming has to be between 3 and 15, in order to create a valid code of tractable size") end n = 2^c.r k = 2^c.r - c.r - 2 From c8bc9f4e0ef8878b54a2d52e4e5bcef9146939ed Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Mon, 4 Mar 2024 20:13:15 +0500 Subject: [PATCH 045/121] Update ECC.jl --- src/ecc/ECC.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ecc/ECC.jl b/src/ecc/ECC.jl index 99a3b457b..24d0c12da 100644 --- a/src/ecc/ECC.jl +++ b/src/ecc/ECC.jl @@ -19,6 +19,7 @@ export parity_checks, parity_checks_x, parity_checks_z, RepCode, CSS, Shor9, Steane7, Cleve8, Perfect5, Bitflip3, + QHamming, Toric, evaluate_decoder, CommutationCheckECCSetup, NaiveSyndromeECCSetup, ShorSyndromeECCSetup, @@ -333,4 +334,5 @@ include("codes/steanecode.jl") include("codes/shorcode.jl") include("codes/clevecode.jl") include("codes/toric.jl") +include("codes/qhammingcode.jl") end #module From 17c66ebe65268f8b2f75415d7a69f222bb948893 Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Mon, 4 Mar 2024 20:14:41 +0500 Subject: [PATCH 046/121] Update qhammingcode.jl --- src/ecc/codes/qhammingcode.jl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ecc/codes/qhammingcode.jl b/src/ecc/codes/qhammingcode.jl index ff010f4fc..3b5d491c9 100644 --- a/src/ecc/codes/qhammingcode.jl +++ b/src/ecc/codes/qhammingcode.jl @@ -2,6 +2,9 @@ struct QHamming <:AbstractECC r::Int end +code_n(c::QHamming) = 2^c.r +code_s(c::QHamming) = c.r + function parity_checks(c::QHamming) if (3 <= c.r <= 15) || error("The r parameter in QHamming has to be between 3 and 15, in order to create a valid code of tractable size") end @@ -22,5 +25,3 @@ function parity_checks(c::QHamming) return H end - -code_n(c::QHamming) = 2^c.r From d1945e6c54eb2303a8e0bd5432dc67052ffbe014 Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Tue, 5 Mar 2024 09:40:28 +0500 Subject: [PATCH 047/121] Update qhammingcode.jl --- src/ecc/codes/qhammingcode.jl | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/ecc/codes/qhammingcode.jl b/src/ecc/codes/qhammingcode.jl index 3b5d491c9..ad3897801 100644 --- a/src/ecc/codes/qhammingcode.jl +++ b/src/ecc/codes/qhammingcode.jl @@ -2,26 +2,30 @@ struct QHamming <:AbstractECC r::Int end -code_n(c::QHamming) = 2^c.r -code_s(c::QHamming) = c.r - function parity_checks(c::QHamming) - if (3 <= c.r <= 15) || error("The r parameter in QHamming has to be between 3 and 15, in order to create a valid code of tractable size") - end - n = 2^c.r - k = 2^c.r - c.r - 2 - + r = c.r + n = 2^r + k = 2^r - r - 2 # Calculate number of checks + # Initialize parity check matrix - H = zeros(Int, k, n) - + H = zeros(Bool, k, n) + # Generate parity checks for the quantum Hamming code for i in 1:k for j in 1:n if j & (1 << (i - 1)) != 0 - H[i, j] = 1 + H[i, j] = true end end end + - return H + # Extract Hx and Hz from H + Hx = H[:, 1:end-r] + Hz = H[:, end-r+1:end] + + # Construct the Stabilizer object using the built-in constructor + Stabilizer(fill(0x0, 2k), Hx, Hz) end + + From 6035ff92714b59db3a7d38b7066d035870c20ed4 Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Tue, 5 Mar 2024 15:15:27 +0500 Subject: [PATCH 048/121] Update and rename qhammingcode.jl to eightqubit.jl --- src/ecc/codes/eightqubit.jl | 10 ++++++++++ src/ecc/codes/qhammingcode.jl | 31 ------------------------------- 2 files changed, 10 insertions(+), 31 deletions(-) create mode 100644 src/ecc/codes/eightqubit.jl delete mode 100644 src/ecc/codes/qhammingcode.jl diff --git a/src/ecc/codes/eightqubit.jl b/src/ecc/codes/eightqubit.jl new file mode 100644 index 000000000..9e226ee7e --- /dev/null +++ b/src/ecc/codes/eightqubit.jl @@ -0,0 +1,10 @@ +struct EightQubit <: AbstractECC end + +code_n(c::EightQubit) = 8 + +parity_checks(c::EightQubit) = S"XXXXXXXX + ZZZZZZZZ + _X_XYZYZ + _XZY_XZY + _YXZXZ_Y" +distance(c::EightQubit) = 3 diff --git a/src/ecc/codes/qhammingcode.jl b/src/ecc/codes/qhammingcode.jl deleted file mode 100644 index ad3897801..000000000 --- a/src/ecc/codes/qhammingcode.jl +++ /dev/null @@ -1,31 +0,0 @@ -struct QHamming <:AbstractECC - r::Int -end - -function parity_checks(c::QHamming) - r = c.r - n = 2^r - k = 2^r - r - 2 # Calculate number of checks - - # Initialize parity check matrix - H = zeros(Bool, k, n) - - # Generate parity checks for the quantum Hamming code - for i in 1:k - for j in 1:n - if j & (1 << (i - 1)) != 0 - H[i, j] = true - end - end - end - - - # Extract Hx and Hz from H - Hx = H[:, 1:end-r] - Hz = H[:, end-r+1:end] - - # Construct the Stabilizer object using the built-in constructor - Stabilizer(fill(0x0, 2k), Hx, Hz) -end - - From 31e0a0e8c23c667801ecac54c5168c296276b2f2 Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Tue, 5 Mar 2024 15:16:08 +0500 Subject: [PATCH 049/121] Update eightqubit.jl --- src/ecc/codes/eightqubit.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ecc/codes/eightqubit.jl b/src/ecc/codes/eightqubit.jl index 9e226ee7e..cf75e465e 100644 --- a/src/ecc/codes/eightqubit.jl +++ b/src/ecc/codes/eightqubit.jl @@ -3,8 +3,8 @@ struct EightQubit <: AbstractECC end code_n(c::EightQubit) = 8 parity_checks(c::EightQubit) = S"XXXXXXXX - ZZZZZZZZ - _X_XYZYZ - _XZY_XZY - _YXZXZ_Y" + ZZZZZZZZ + _X_XYZYZ + _XZY_XZY + _YXZXZ_Y" distance(c::EightQubit) = 3 From 6f6704f35c790f512995066f1572e5780ef87015 Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Tue, 5 Mar 2024 15:17:36 +0500 Subject: [PATCH 050/121] Update ECC.jl --- src/ecc/ECC.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ecc/ECC.jl b/src/ecc/ECC.jl index 24d0c12da..291b5dcd0 100644 --- a/src/ecc/ECC.jl +++ b/src/ecc/ECC.jl @@ -19,7 +19,7 @@ export parity_checks, parity_checks_x, parity_checks_z, RepCode, CSS, Shor9, Steane7, Cleve8, Perfect5, Bitflip3, - QHamming, + EightQubit, Toric, evaluate_decoder, CommutationCheckECCSetup, NaiveSyndromeECCSetup, ShorSyndromeECCSetup, @@ -334,5 +334,5 @@ include("codes/steanecode.jl") include("codes/shorcode.jl") include("codes/clevecode.jl") include("codes/toric.jl") -include("codes/qhammingcode.jl") +include("codes/eightqubit.jl") end #module From 84dfb02c7fe7cf5f3734fd552070c63312b06b72 Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Tue, 5 Mar 2024 16:08:47 +0500 Subject: [PATCH 051/121] Update test_ecc.jl --- test/test_ecc.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/test/test_ecc.jl b/test/test_ecc.jl index 166e0188b..c790fbae7 100644 --- a/test/test_ecc.jl +++ b/test/test_ecc.jl @@ -8,7 +8,6 @@ codes = [ Steane7(), Shor9(), Perfect5(), - QHamming(3), Cleve8(), CSS([0 1 1 0; 1 1 0 0], [1 1 1 1]), ] From e4d07593af79b5f01586b31f554c1fbc3dcfc32c Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Tue, 5 Mar 2024 16:10:11 +0500 Subject: [PATCH 052/121] Update test_throws.jl --- test/test_throws.jl | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/test_throws.jl b/test/test_throws.jl index caf5cf39f..724cc7de5 100644 --- a/test/test_throws.jl +++ b/test/test_throws.jl @@ -1,7 +1,6 @@ using Test using QuantumClifford using QuantumClifford: rank, mul_left!, mul_right! -using QuantumClifford.ECC: QHamming using InteractiveUtils: subtypes @@ -66,5 +65,3 @@ for m in [sMX,sMZ,sMY,sMRX,sMRZ,sMRY] @test_throws ArgumentError m(0,1) @test_throws ArgumentError m(-1,0) end - -@test_throws ArgumentError parity_checks(QHamming(2)) From 412d54a86b2fe9d1d7bcce0b3ab02ed17739df52 Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Tue, 5 Mar 2024 16:15:16 +0500 Subject: [PATCH 053/121] Update test_qhamming_code.jl Delete [test_qhamming_code.jl] --- test/test_qhamming_code.jl | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/test/test_qhamming_code.jl b/test/test_qhamming_code.jl index be7a19e93..8b1378917 100644 --- a/test/test_qhamming_code.jl +++ b/test/test_qhamming_code.jl @@ -1,21 +1 @@ -using Test -using QuantumClifford -using QuantumClifford.ECC: QHamming -# Define test cases -@testset "QHamming Code Tests" begin - # Test parity checks generation - @testset "Parity Checks" begin - hamming_code = QHamming(3) - @test size(parity_checks(hamming_code)) == (3, 8) - @test all(parity_checks(hamming_code) .>= 0) - # Add more parity check tests if needed - end - - # Test block size calculation - @testset "Block Size" begin - hamming_code = QHamming(3) - @test code_n(hamming_code) == 8 - # Add more block size tests if needed - end -end From 8eb5bb717dfbd4cc28ab95712931e5e7d723b7dc Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Wed, 6 Mar 2024 09:28:41 +0500 Subject: [PATCH 054/121] Update test_ecc_encoding.jl --- test/test_ecc_encoding.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_ecc_encoding.jl b/test/test_ecc_encoding.jl index 11c3a6c6a..8f8d6b7d8 100644 --- a/test/test_ecc_encoding.jl +++ b/test/test_ecc_encoding.jl @@ -14,7 +14,7 @@ using QuantumClifford.ECC :(Steane7()), :(Shor9()), :(Perfect5()), - :(QHamming(3)), + :(EightQubit()), :(Bitflip3()), :(S"Y_"), :(S"Z_"), From d1bc220da3b12ad4d18b8b701280a0e8aa04282d Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Wed, 6 Mar 2024 09:29:11 +0500 Subject: [PATCH 055/121] Update test_ecc_syndromes.jl --- test/test_ecc_syndromes.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_ecc_syndromes.jl b/test/test_ecc_syndromes.jl index 78ff558fa..6fe5e6c17 100644 --- a/test/test_ecc_syndromes.jl +++ b/test/test_ecc_syndromes.jl @@ -9,7 +9,7 @@ codes = [ Steane7(), Shor9(), Perfect5(), - QHamming(3), + EightQubit(), Cleve8(), CSS([0 1 1 0; 1 1 0 0], [1 1 1 1]), Toric(3,3), From fd4d07384af32afc530ea6dcb9f7df96f18d6beb Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Wed, 6 Mar 2024 11:53:12 +0500 Subject: [PATCH 056/121] Update test_ecc_decoder_all_setups.jl --- test/test_ecc_decoder_all_setups.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_ecc_decoder_all_setups.jl b/test/test_ecc_decoder_all_setups.jl index e70ae69e1..5766fd1a8 100644 --- a/test/test_ecc_decoder_all_setups.jl +++ b/test/test_ecc_decoder_all_setups.jl @@ -16,7 +16,7 @@ import PyQDecoders Steane7(), Shor9(), Perfect5(), - QHamming(), + EightQubit(), Cleve8(), ] From e3a1fcfcca1fdc05afebcc87df305681a6fa4fef Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Wed, 6 Mar 2024 15:57:13 +0500 Subject: [PATCH 057/121] Update references.md Removed the extra blank line (#line 35) that was present! It was there from when I first added extra references of QECC . In original there are only 34 line so made sure that nothing changed here, From 9364f6c5ce6e2d968584d5900a4a44f34d74cb71 Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Wed, 6 Mar 2024 17:35:25 +0500 Subject: [PATCH 058/121] Create sixteenqubit.jl --- src/ecc/codes/sixteenqubit.jl | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/ecc/codes/sixteenqubit.jl diff --git a/src/ecc/codes/sixteenqubit.jl b/src/ecc/codes/sixteenqubit.jl new file mode 100644 index 000000000..153a8bb64 --- /dev/null +++ b/src/ecc/codes/sixteenqubit.jl @@ -0,0 +1,11 @@ +struct SixteenQubit <: AbstractECC end + +code_n(c::SixteenQubit) = 16 + +parity_checks(c: SixteenQubit) = S"XXXXXXXXXXXXXXXX + ZZZZZZZZZZZZZZZZ + _X_X_X_XZYZYZYZY + _X_XZYZYX_X_YZYZ + _XZYX_YZ_XZYX_YZ + _YXZ_YXZ_YXZ_YXZ" +distance(c::SixteenQubit) = 3 From 1c740cf1bb0f662115170b7b40dd56c079feebe2 Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Wed, 6 Mar 2024 17:37:26 +0500 Subject: [PATCH 059/121] Update ECC.jl --- src/ecc/ECC.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ecc/ECC.jl b/src/ecc/ECC.jl index 291b5dcd0..2aef25595 100644 --- a/src/ecc/ECC.jl +++ b/src/ecc/ECC.jl @@ -19,7 +19,7 @@ export parity_checks, parity_checks_x, parity_checks_z, RepCode, CSS, Shor9, Steane7, Cleve8, Perfect5, Bitflip3, - EightQubit, + EightQubit, SixteenQubit Toric, evaluate_decoder, CommutationCheckECCSetup, NaiveSyndromeECCSetup, ShorSyndromeECCSetup, @@ -335,4 +335,5 @@ include("codes/shorcode.jl") include("codes/clevecode.jl") include("codes/toric.jl") include("codes/eightqubit.jl") +include("codes/sixteenqubit.jl") end #module From e40f1aba8d3935b4c49e8d51d94fabeea49d6d5c Mon Sep 17 00:00:00 2001 From: Fe-r-oz Date: Thu, 7 Mar 2024 05:47:52 +0500 Subject: [PATCH 060/121] added better names of eccs in the zoo, removed the test_hamming_code file, etc. --- src/ecc/ECC.jl | 6 +++--- src/ecc/codes/{sixteenqubit.jl => n16_k10_d3.jl} | 8 ++++---- src/ecc/codes/{eightqubit.jl => n8_k3_d3.jl} | 8 ++++---- test/test_ecc.jl | 2 ++ test/test_ecc_decoder_all_setups.jl | 3 ++- test/test_ecc_encoding.jl | 3 ++- test/test_ecc_syndromes.jl | 3 ++- test/test_qhamming_code.jl | 1 - 8 files changed, 19 insertions(+), 15 deletions(-) rename src/ecc/codes/{sixteenqubit.jl => n16_k10_d3.jl} (63%) rename src/ecc/codes/{eightqubit.jl => n8_k3_d3.jl} (56%) delete mode 100644 test/test_qhamming_code.jl diff --git a/src/ecc/ECC.jl b/src/ecc/ECC.jl index 2aef25595..a370a7ea1 100644 --- a/src/ecc/ECC.jl +++ b/src/ecc/ECC.jl @@ -19,7 +19,7 @@ export parity_checks, parity_checks_x, parity_checks_z, RepCode, CSS, Shor9, Steane7, Cleve8, Perfect5, Bitflip3, - EightQubit, SixteenQubit + N8_K3_D3, N16_K10_D3, Toric, evaluate_decoder, CommutationCheckECCSetup, NaiveSyndromeECCSetup, ShorSyndromeECCSetup, @@ -334,6 +334,6 @@ include("codes/steanecode.jl") include("codes/shorcode.jl") include("codes/clevecode.jl") include("codes/toric.jl") -include("codes/eightqubit.jl") -include("codes/sixteenqubit.jl") +include("codes/n8_k3_d3.jl") +include("codes/n16_k10_d3.jl") end #module diff --git a/src/ecc/codes/sixteenqubit.jl b/src/ecc/codes/n16_k10_d3.jl similarity index 63% rename from src/ecc/codes/sixteenqubit.jl rename to src/ecc/codes/n16_k10_d3.jl index 153a8bb64..cf46cc3f5 100644 --- a/src/ecc/codes/sixteenqubit.jl +++ b/src/ecc/codes/n16_k10_d3.jl @@ -1,11 +1,11 @@ -struct SixteenQubit <: AbstractECC end +struct N16_K10_D3 <: AbstractECC end -code_n(c::SixteenQubit) = 16 +code_n(c::N16_K10_D3) = 16 -parity_checks(c: SixteenQubit) = S"XXXXXXXXXXXXXXXX +parity_checks(c: N16_K10_D3) = S"XXXXXXXXXXXXXXXX ZZZZZZZZZZZZZZZZ _X_X_X_XZYZYZYZY _X_XZYZYX_X_YZYZ _XZYX_YZ_XZYX_YZ _YXZ_YXZ_YXZ_YXZ" -distance(c::SixteenQubit) = 3 +distance(c::N16_K10_D3) = 3 diff --git a/src/ecc/codes/eightqubit.jl b/src/ecc/codes/n8_k3_d3.jl similarity index 56% rename from src/ecc/codes/eightqubit.jl rename to src/ecc/codes/n8_k3_d3.jl index cf75e465e..b0dde3d03 100644 --- a/src/ecc/codes/eightqubit.jl +++ b/src/ecc/codes/n8_k3_d3.jl @@ -1,10 +1,10 @@ -struct EightQubit <: AbstractECC end +struct N8_K3_D3 <: AbstractECC end -code_n(c::EightQubit) = 8 +code_n(c::N8_K3_D3) = 8 -parity_checks(c::EightQubit) = S"XXXXXXXX +parity_checks(c::N8_K3_D3) = S"XXXXXXXX ZZZZZZZZ _X_XYZYZ _XZY_XZY _YXZXZ_Y" -distance(c::EightQubit) = 3 +distance(c::N8_K3_D3) = 3 diff --git a/test/test_ecc.jl b/test/test_ecc.jl index c790fbae7..71fad9a68 100644 --- a/test/test_ecc.jl +++ b/test/test_ecc.jl @@ -9,6 +9,8 @@ codes = [ Shor9(), Perfect5(), Cleve8(), + N8_K3_D3(), + N16_K10_D3(), CSS([0 1 1 0; 1 1 0 0], [1 1 1 1]), ] diff --git a/test/test_ecc_decoder_all_setups.jl b/test/test_ecc_decoder_all_setups.jl index 5766fd1a8..98f1f83e2 100644 --- a/test/test_ecc_decoder_all_setups.jl +++ b/test/test_ecc_decoder_all_setups.jl @@ -16,7 +16,8 @@ import PyQDecoders Steane7(), Shor9(), Perfect5(), - EightQubit(), + N8_K3_D3(), + N16_K10_D3(), Cleve8(), ] diff --git a/test/test_ecc_encoding.jl b/test/test_ecc_encoding.jl index 8f8d6b7d8..e7e85b495 100644 --- a/test/test_ecc_encoding.jl +++ b/test/test_ecc_encoding.jl @@ -14,7 +14,8 @@ using QuantumClifford.ECC :(Steane7()), :(Shor9()), :(Perfect5()), - :(EightQubit()), + :(N8_K3_D3()), + :(N16_K10_D3()), :(Bitflip3()), :(S"Y_"), :(S"Z_"), diff --git a/test/test_ecc_syndromes.jl b/test/test_ecc_syndromes.jl index 6fe5e6c17..7700d44ed 100644 --- a/test/test_ecc_syndromes.jl +++ b/test/test_ecc_syndromes.jl @@ -9,7 +9,8 @@ codes = [ Steane7(), Shor9(), Perfect5(), - EightQubit(), + N8_K3_D3(), + N16_K10_D3(), Cleve8(), CSS([0 1 1 0; 1 1 0 0], [1 1 1 1]), Toric(3,3), diff --git a/test/test_qhamming_code.jl b/test/test_qhamming_code.jl deleted file mode 100644 index 8b1378917..000000000 --- a/test/test_qhamming_code.jl +++ /dev/null @@ -1 +0,0 @@ - From 733a7ad7bd0372d7a0fe2329366996e60c8f1cca Mon Sep 17 00:00:00 2001 From: Fe-r-oz Date: Thu, 7 Mar 2024 05:52:14 +0500 Subject: [PATCH 061/121] minor modifications --- src/ecc/codes/n16_k10_d3.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ecc/codes/n16_k10_d3.jl b/src/ecc/codes/n16_k10_d3.jl index cf46cc3f5..f95220e8b 100644 --- a/src/ecc/codes/n16_k10_d3.jl +++ b/src/ecc/codes/n16_k10_d3.jl @@ -2,7 +2,7 @@ struct N16_K10_D3 <: AbstractECC end code_n(c::N16_K10_D3) = 16 -parity_checks(c: N16_K10_D3) = S"XXXXXXXXXXXXXXXX +parity_checks(c::N16_K10_D3) = S"XXXXXXXXXXXXXXXX ZZZZZZZZZZZZZZZZ _X_X_X_XZYZYZYZY _X_XZYZYX_X_YZYZ From a6d1d1b8ce51bda31a8aae858003e50d1d92f8ae Mon Sep 17 00:00:00 2001 From: Fe-r-oz Date: Thu, 7 Mar 2024 06:12:48 +0500 Subject: [PATCH 062/121] minor modifications --- src/ecc/ECC.jl | 6 +++--- src/ecc/codes/n16_k10_d3.jl | 11 ----------- src/ecc/codes/n16k10d3.jl | 8 ++++++++ src/ecc/codes/n8_k3_d3.jl | 10 ---------- src/ecc/codes/n8k3d3.jl | 8 ++++++++ test/test_ecc.jl | 4 ++-- test/test_ecc_decoder_all_setups.jl | 4 ++-- test/test_ecc_encoding.jl | 4 ++-- test/test_ecc_syndromes.jl | 4 ++-- 9 files changed, 27 insertions(+), 32 deletions(-) delete mode 100644 src/ecc/codes/n16_k10_d3.jl create mode 100644 src/ecc/codes/n16k10d3.jl delete mode 100644 src/ecc/codes/n8_k3_d3.jl create mode 100644 src/ecc/codes/n8k3d3.jl diff --git a/src/ecc/ECC.jl b/src/ecc/ECC.jl index a370a7ea1..9596cc92a 100644 --- a/src/ecc/ECC.jl +++ b/src/ecc/ECC.jl @@ -19,7 +19,7 @@ export parity_checks, parity_checks_x, parity_checks_z, RepCode, CSS, Shor9, Steane7, Cleve8, Perfect5, Bitflip3, - N8_K3_D3, N16_K10_D3, + N8K3D3, N16K10D3, Toric, evaluate_decoder, CommutationCheckECCSetup, NaiveSyndromeECCSetup, ShorSyndromeECCSetup, @@ -334,6 +334,6 @@ include("codes/steanecode.jl") include("codes/shorcode.jl") include("codes/clevecode.jl") include("codes/toric.jl") -include("codes/n8_k3_d3.jl") -include("codes/n16_k10_d3.jl") +include("codes/n8k3d3.jl") +include("codes/n16k10d3.jl") end #module diff --git a/src/ecc/codes/n16_k10_d3.jl b/src/ecc/codes/n16_k10_d3.jl deleted file mode 100644 index f95220e8b..000000000 --- a/src/ecc/codes/n16_k10_d3.jl +++ /dev/null @@ -1,11 +0,0 @@ -struct N16_K10_D3 <: AbstractECC end - -code_n(c::N16_K10_D3) = 16 - -parity_checks(c::N16_K10_D3) = S"XXXXXXXXXXXXXXXX - ZZZZZZZZZZZZZZZZ - _X_X_X_XZYZYZYZY - _X_XZYZYX_X_YZYZ - _XZYX_YZ_XZYX_YZ - _YXZ_YXZ_YXZ_YXZ" -distance(c::N16_K10_D3) = 3 diff --git a/src/ecc/codes/n16k10d3.jl b/src/ecc/codes/n16k10d3.jl new file mode 100644 index 000000000..8ffb681b3 --- /dev/null +++ b/src/ecc/codes/n16k10d3.jl @@ -0,0 +1,8 @@ +struct N16K10D3 <: AbstractECC end + +parity_checks(c::N16K10D3) = S"XXXXXXXXXXXXXXXX + ZZZZZZZZZZZZZZZZ + _X_X_X_XZYZYZYZY + _X_XZYZYX_X_YZYZ + _XZYX_YZ_XZYX_YZ + _YXZ_YXZ_YXZ_YXZ" \ No newline at end of file diff --git a/src/ecc/codes/n8_k3_d3.jl b/src/ecc/codes/n8_k3_d3.jl deleted file mode 100644 index b0dde3d03..000000000 --- a/src/ecc/codes/n8_k3_d3.jl +++ /dev/null @@ -1,10 +0,0 @@ -struct N8_K3_D3 <: AbstractECC end - -code_n(c::N8_K3_D3) = 8 - -parity_checks(c::N8_K3_D3) = S"XXXXXXXX - ZZZZZZZZ - _X_XYZYZ - _XZY_XZY - _YXZXZ_Y" -distance(c::N8_K3_D3) = 3 diff --git a/src/ecc/codes/n8k3d3.jl b/src/ecc/codes/n8k3d3.jl new file mode 100644 index 000000000..249c406cc --- /dev/null +++ b/src/ecc/codes/n8k3d3.jl @@ -0,0 +1,8 @@ +struct N8K3D3 <: AbstractECC end + +parity_checks(c::N8K3D3) = S"XXXXXXXX + ZZZZZZZZ + _X_XYZYZ + _XZY_XZY + _YXZXZ_Y" + diff --git a/test/test_ecc.jl b/test/test_ecc.jl index 71fad9a68..35830f47d 100644 --- a/test/test_ecc.jl +++ b/test/test_ecc.jl @@ -9,8 +9,8 @@ codes = [ Shor9(), Perfect5(), Cleve8(), - N8_K3_D3(), - N16_K10_D3(), + N8K3D3(), + N16K10D3(), CSS([0 1 1 0; 1 1 0 0], [1 1 1 1]), ] diff --git a/test/test_ecc_decoder_all_setups.jl b/test/test_ecc_decoder_all_setups.jl index 98f1f83e2..b6afae230 100644 --- a/test/test_ecc_decoder_all_setups.jl +++ b/test/test_ecc_decoder_all_setups.jl @@ -16,8 +16,8 @@ import PyQDecoders Steane7(), Shor9(), Perfect5(), - N8_K3_D3(), - N16_K10_D3(), + N8K3D3(), + N16K10D3(), Cleve8(), ] diff --git a/test/test_ecc_encoding.jl b/test/test_ecc_encoding.jl index e7e85b495..3231d0cf2 100644 --- a/test/test_ecc_encoding.jl +++ b/test/test_ecc_encoding.jl @@ -14,8 +14,8 @@ using QuantumClifford.ECC :(Steane7()), :(Shor9()), :(Perfect5()), - :(N8_K3_D3()), - :(N16_K10_D3()), + :(N8K3D3()), + :(N16K10D3()), :(Bitflip3()), :(S"Y_"), :(S"Z_"), diff --git a/test/test_ecc_syndromes.jl b/test/test_ecc_syndromes.jl index 7700d44ed..7669f2ec1 100644 --- a/test/test_ecc_syndromes.jl +++ b/test/test_ecc_syndromes.jl @@ -9,8 +9,8 @@ codes = [ Steane7(), Shor9(), Perfect5(), - N8_K3_D3(), - N16_K10_D3(), + N8K3D3(), + N16K10D3(), Cleve8(), CSS([0 1 1 0; 1 1 0 0], [1 1 1 1]), Toric(3,3), From 5a2913f509c1ef7f29223b9b6a15455e7ee28eca Mon Sep 17 00:00:00 2001 From: Fe-r-oz Date: Thu, 7 Mar 2024 07:09:34 +0500 Subject: [PATCH 063/121] minor modifications --- src/ecc/ECC.jl | 6 +++--- src/ecc/codes/{n16k10d3.jl => nkd16103.jl} | 4 ++-- src/ecc/codes/{n8k3d3.jl => nkd833.jl} | 4 ++-- test/test_ecc.jl | 4 ++-- test/test_ecc_decoder_all_setups.jl | 4 ++-- test/test_ecc_encoding.jl | 4 ++-- test/test_ecc_syndromes.jl | 4 ++-- 7 files changed, 15 insertions(+), 15 deletions(-) rename src/ecc/codes/{n16k10d3.jl => nkd16103.jl} (74%) rename src/ecc/codes/{n8k3d3.jl => nkd833.jl} (68%) diff --git a/src/ecc/ECC.jl b/src/ecc/ECC.jl index 9596cc92a..c3db023fe 100644 --- a/src/ecc/ECC.jl +++ b/src/ecc/ECC.jl @@ -19,7 +19,7 @@ export parity_checks, parity_checks_x, parity_checks_z, RepCode, CSS, Shor9, Steane7, Cleve8, Perfect5, Bitflip3, - N8K3D3, N16K10D3, + NKD833,NKD16103, Toric, evaluate_decoder, CommutationCheckECCSetup, NaiveSyndromeECCSetup, ShorSyndromeECCSetup, @@ -334,6 +334,6 @@ include("codes/steanecode.jl") include("codes/shorcode.jl") include("codes/clevecode.jl") include("codes/toric.jl") -include("codes/n8k3d3.jl") -include("codes/n16k10d3.jl") +include("codes/nkd833.jl") +include("codes/nkd16103.jl") end #module diff --git a/src/ecc/codes/n16k10d3.jl b/src/ecc/codes/nkd16103.jl similarity index 74% rename from src/ecc/codes/n16k10d3.jl rename to src/ecc/codes/nkd16103.jl index 8ffb681b3..57d40beb4 100644 --- a/src/ecc/codes/n16k10d3.jl +++ b/src/ecc/codes/nkd16103.jl @@ -1,6 +1,6 @@ -struct N16K10D3 <: AbstractECC end +struct NKD16103 <: AbstractECC end -parity_checks(c::N16K10D3) = S"XXXXXXXXXXXXXXXX +parity_checks(c::NKD16103) =S"XXXXXXXXXXXXXXXX ZZZZZZZZZZZZZZZZ _X_X_X_XZYZYZYZY _X_XZYZYX_X_YZYZ diff --git a/src/ecc/codes/n8k3d3.jl b/src/ecc/codes/nkd833.jl similarity index 68% rename from src/ecc/codes/n8k3d3.jl rename to src/ecc/codes/nkd833.jl index 249c406cc..5512b4895 100644 --- a/src/ecc/codes/n8k3d3.jl +++ b/src/ecc/codes/nkd833.jl @@ -1,6 +1,6 @@ -struct N8K3D3 <: AbstractECC end +struct NKD833 <: AbstractECC end -parity_checks(c::N8K3D3) = S"XXXXXXXX +parity_checks(c::NKD833) =S"XXXXXXXX ZZZZZZZZ _X_XYZYZ _XZY_XZY diff --git a/test/test_ecc.jl b/test/test_ecc.jl index 35830f47d..9b25ad798 100644 --- a/test/test_ecc.jl +++ b/test/test_ecc.jl @@ -9,8 +9,8 @@ codes = [ Shor9(), Perfect5(), Cleve8(), - N8K3D3(), - N16K10D3(), + NKD833(), + NKD16103(), CSS([0 1 1 0; 1 1 0 0], [1 1 1 1]), ] diff --git a/test/test_ecc_decoder_all_setups.jl b/test/test_ecc_decoder_all_setups.jl index b6afae230..c92759e05 100644 --- a/test/test_ecc_decoder_all_setups.jl +++ b/test/test_ecc_decoder_all_setups.jl @@ -16,8 +16,8 @@ import PyQDecoders Steane7(), Shor9(), Perfect5(), - N8K3D3(), - N16K10D3(), + NKD833(), + NKD16103(), Cleve8(), ] diff --git a/test/test_ecc_encoding.jl b/test/test_ecc_encoding.jl index 3231d0cf2..b5f977d6b 100644 --- a/test/test_ecc_encoding.jl +++ b/test/test_ecc_encoding.jl @@ -14,8 +14,8 @@ using QuantumClifford.ECC :(Steane7()), :(Shor9()), :(Perfect5()), - :(N8K3D3()), - :(N16K10D3()), + :(NKD833()), + :(NKD16103()), :(Bitflip3()), :(S"Y_"), :(S"Z_"), diff --git a/test/test_ecc_syndromes.jl b/test/test_ecc_syndromes.jl index 7669f2ec1..cddd15a15 100644 --- a/test/test_ecc_syndromes.jl +++ b/test/test_ecc_syndromes.jl @@ -9,8 +9,8 @@ codes = [ Steane7(), Shor9(), Perfect5(), - N8K3D3(), - N16K10D3(), + NKD833(), + NKD16103(), Cleve8(), CSS([0 1 1 0; 1 1 0 0], [1 1 1 1]), Toric(3,3), From 62fdcbe9f795ad83e2b783de1c84fc371a46e190 Mon Sep 17 00:00:00 2001 From: Fe-r-oz Date: Thu, 7 Mar 2024 08:30:14 +0500 Subject: [PATCH 064/121] tweaking decoders parameters for pedagogical nkd16103 --- test/test_ecc_decoder_all_setups.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_ecc_decoder_all_setups.jl b/test/test_ecc_decoder_all_setups.jl index c92759e05..ab8113a75 100644 --- a/test/test_ecc_decoder_all_setups.jl +++ b/test/test_ecc_decoder_all_setups.jl @@ -31,7 +31,7 @@ import PyQDecoders for c in codes for s in setups - e = evaluate_decoder(TableDecoder(c), s, 100000) + e = evaluate_decoder(TableDecoder(c), s, 20000000) #@show c #@show s #@show e From b572c8f737a5aad6ee02ae22053d4f1f999f25e9 Mon Sep 17 00:00:00 2001 From: Fe-r-oz Date: Thu, 7 Mar 2024 08:44:40 +0500 Subject: [PATCH 065/121] minor tweak --- test/test_ecc_decoder_all_setups.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_ecc_decoder_all_setups.jl b/test/test_ecc_decoder_all_setups.jl index ab8113a75..a9828ea61 100644 --- a/test/test_ecc_decoder_all_setups.jl +++ b/test/test_ecc_decoder_all_setups.jl @@ -31,7 +31,7 @@ import PyQDecoders for c in codes for s in setups - e = evaluate_decoder(TableDecoder(c), s, 20000000) + e = evaluate_decoder(TableDecoder(c), s, 900000000) #@show c #@show s #@show e From 32e8676f5e9df9f6bbc6d415572a568d3bcb6ffd Mon Sep 17 00:00:00 2001 From: Fe-r-oz Date: Fri, 8 Mar 2024 12:07:33 +0500 Subject: [PATCH 066/121] Gottesman aka Quantum Hamming Code Implementation --- src/ecc/ECC.jl | 10 +++--- src/ecc/codes/gottesman.jl | 51 +++++++++++++++++++++++++++++ src/ecc/codes/nkd16103.jl | 8 ----- src/ecc/codes/nkd833.jl | 8 ----- test/test_ecc.jl | 5 ++- test/test_ecc_decoder_all_setups.jl | 12 +++---- test/test_ecc_encoding.jl | 5 ++- test/test_ecc_syndromes.jl | 5 ++- test/test_throws.jl | 2 +- 9 files changed, 67 insertions(+), 39 deletions(-) create mode 100644 src/ecc/codes/gottesman.jl delete mode 100644 src/ecc/codes/nkd16103.jl delete mode 100644 src/ecc/codes/nkd833.jl diff --git a/src/ecc/ECC.jl b/src/ecc/ECC.jl index c3db023fe..27ab91d37 100644 --- a/src/ecc/ECC.jl +++ b/src/ecc/ECC.jl @@ -18,9 +18,8 @@ export parity_checks, parity_checks_x, parity_checks_z, naive_syndrome_circuit, shor_syndrome_circuit, naive_encoding_circuit, RepCode, CSS, - Shor9, Steane7, Cleve8, Perfect5, Bitflip3, - NKD833,NKD16103, - Toric, + Shor9, Steane7, Cleve8, Perfect5, Bitflip3, + Toric, QHamming, evaluate_decoder, CommutationCheckECCSetup, NaiveSyndromeECCSetup, ShorSyndromeECCSetup, TableDecoder, @@ -334,6 +333,5 @@ include("codes/steanecode.jl") include("codes/shorcode.jl") include("codes/clevecode.jl") include("codes/toric.jl") -include("codes/nkd833.jl") -include("codes/nkd16103.jl") -end #module +include("codes/gottesman.jl") +end #module \ No newline at end of file diff --git a/src/ecc/codes/gottesman.jl b/src/ecc/codes/gottesman.jl new file mode 100644 index 000000000..216071ff7 --- /dev/null +++ b/src/ecc/codes/gottesman.jl @@ -0,0 +1,51 @@ +struct QHamming <: AbstractECC + j::Int + function QHamming(j) + if j < 3 + error("j must be greater than or equal to 3 in order to create a valid code of tractable size") + end + new(j) + end +end + +code_n(c::QHamming)= 2^c.j + +function parity_checks(c::QHamming) + a=c.j + rows = a + 2 + cols = 2^a + + Hx = falses(rows,cols) + Hz =falses(rows,cols) + + Hx[1, :] .= true + + Hx[2, :] .= false + + for i in 3:(rows-1) + for a in 1:cols + Hx[i, a] = (a==0) || (a % 2 ==0) + end + end + + for a in 1:cols + Hx[rows, a] = (a % 4 == 1) || (a % 4 == 2) ? 0 : 1 + end + + Hz[1, :] .= false + 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 + end + end + extended_Hx = Matrix{Bool}(Hz) + extended_Hz = Matrix{Bool}(Hx) + + num_rows = size(Hx, 1) + + fill_array = fill(UInt8(0), num_rows) + Stabilizer(fill_array, extended_Hz, extended_Hx) +end \ No newline at end of file diff --git a/src/ecc/codes/nkd16103.jl b/src/ecc/codes/nkd16103.jl deleted file mode 100644 index 57d40beb4..000000000 --- a/src/ecc/codes/nkd16103.jl +++ /dev/null @@ -1,8 +0,0 @@ -struct NKD16103 <: AbstractECC end - -parity_checks(c::NKD16103) =S"XXXXXXXXXXXXXXXX - ZZZZZZZZZZZZZZZZ - _X_X_X_XZYZYZYZY - _X_XZYZYX_X_YZYZ - _XZYX_YZ_XZYX_YZ - _YXZ_YXZ_YXZ_YXZ" \ No newline at end of file diff --git a/src/ecc/codes/nkd833.jl b/src/ecc/codes/nkd833.jl deleted file mode 100644 index 5512b4895..000000000 --- a/src/ecc/codes/nkd833.jl +++ /dev/null @@ -1,8 +0,0 @@ -struct NKD833 <: AbstractECC end - -parity_checks(c::NKD833) =S"XXXXXXXX - ZZZZZZZZ - _X_XYZYZ - _XZY_XZY - _YXZXZ_Y" - diff --git a/test/test_ecc.jl b/test/test_ecc.jl index 9b25ad798..d1f4ef408 100644 --- a/test/test_ecc.jl +++ b/test/test_ecc.jl @@ -9,8 +9,7 @@ codes = [ Shor9(), Perfect5(), Cleve8(), - NKD833(), - NKD16103(), + QHamming(3), CSS([0 1 1 0; 1 1 0 0], [1 1 1 1]), ] @@ -78,4 +77,4 @@ end @test isdegenerate(Steane7()) == false @test isdegenerate(Steane7(), 2) == true @test isdegenerate(Bitflip3()) == true -end +end \ No newline at end of file diff --git a/test/test_ecc_decoder_all_setups.jl b/test/test_ecc_decoder_all_setups.jl index a9828ea61..3608bfa98 100644 --- a/test/test_ecc_decoder_all_setups.jl +++ b/test/test_ecc_decoder_all_setups.jl @@ -16,9 +16,7 @@ import PyQDecoders Steane7(), Shor9(), Perfect5(), - NKD833(), - NKD16103(), - Cleve8(), + Cleve8(), ] noise = 0.001 @@ -31,7 +29,7 @@ import PyQDecoders for c in codes for s in setups - e = evaluate_decoder(TableDecoder(c), s, 900000000) + e = evaluate_decoder(TableDecoder(c), s,100000) #@show c #@show s #@show e @@ -58,11 +56,11 @@ end for c in codes for s in setups - e = evaluate_decoder(PyMatchingDecoder(c), s, 10000) + e = evaluate_decoder(PyMatchingDecoder(c), s,100000) #@show c #@show s #@show e - @assert max(e...) < noise/5 + @assert max(e...) < noise/4 end end -end +end \ No newline at end of file diff --git a/test/test_ecc_encoding.jl b/test/test_ecc_encoding.jl index b5f977d6b..ece718dd9 100644 --- a/test/test_ecc_encoding.jl +++ b/test/test_ecc_encoding.jl @@ -14,9 +14,8 @@ using QuantumClifford.ECC :(Steane7()), :(Shor9()), :(Perfect5()), - :(NKD833()), - :(NKD16103()), :(Bitflip3()), + :(QHamming(3)), :(S"Y_"), :(S"Z_"), :(S"X_"), @@ -57,4 +56,4 @@ using QuantumClifford.ECC #println("$codeexpr, $(encodedₙ == algebraicₙ)") end -end +end \ No newline at end of file diff --git a/test/test_ecc_syndromes.jl b/test/test_ecc_syndromes.jl index cddd15a15..d164c68d1 100644 --- a/test/test_ecc_syndromes.jl +++ b/test/test_ecc_syndromes.jl @@ -9,9 +9,8 @@ codes = [ Steane7(), Shor9(), Perfect5(), - NKD833(), - NKD16103(), Cleve8(), + QHamming(3), CSS([0 1 1 0; 1 1 0 0], [1 1 1 1]), Toric(3,3), Toric(3,6), @@ -61,4 +60,4 @@ end for c in codes pframe_naive_vs_shor_syndrome(c) end -end +end \ No newline at end of file diff --git a/test/test_throws.jl b/test/test_throws.jl index 724cc7de5..9aa678d58 100644 --- a/test/test_throws.jl +++ b/test/test_throws.jl @@ -64,4 +64,4 @@ for m in [sMX,sMZ,sMY,sMRX,sMRZ,sMRY] @test_throws ArgumentError m(-1) @test_throws ArgumentError m(0,1) @test_throws ArgumentError m(-1,0) -end +end \ No newline at end of file From e7e9b40f9b4a06eb7c7fff0b012603ba6b224f9b Mon Sep 17 00:00:00 2001 From: Fe-r-oz Date: Fri, 8 Mar 2024 15:21:52 +0500 Subject: [PATCH 067/121] Original Paramters --- docs/src/references.bib | 3 +-- test/test_ecc_decoder_all_setups.jl | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/src/references.bib b/docs/src/references.bib index 33c9a012c..12aec7ad9 100644 --- a/docs/src/references.bib +++ b/docs/src/references.bib @@ -224,5 +224,4 @@ @article{nahum2017quantum journal = {Physical Review X}, author = {Nahum, Adam and Ruhman, Jonathan and Vijay, Sagar and Haah, Jeongwan}, year = {2017} -} - +} \ No newline at end of file diff --git a/test/test_ecc_decoder_all_setups.jl b/test/test_ecc_decoder_all_setups.jl index 3608bfa98..87f659eeb 100644 --- a/test/test_ecc_decoder_all_setups.jl +++ b/test/test_ecc_decoder_all_setups.jl @@ -60,7 +60,7 @@ end #@show c #@show s #@show e - @assert max(e...) < noise/4 + @assert max(e...) < noise/5 end end end \ No newline at end of file From 04c62e85089415ef35e529e12d1c57507c7712d4 Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Sat, 9 Mar 2024 13:08:29 +0500 Subject: [PATCH 068/121] Update src/ecc/codes/gottesman.jl Co-authored-by: Stefan Krastanov --- src/ecc/codes/gottesman.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ecc/codes/gottesman.jl b/src/ecc/codes/gottesman.jl index 216071ff7..abb6ffe9d 100644 --- a/src/ecc/codes/gottesman.jl +++ b/src/ecc/codes/gottesman.jl @@ -16,7 +16,7 @@ function parity_checks(c::QHamming) cols = 2^a Hx = falses(rows,cols) - Hz =falses(rows,cols) + Hz = falses(rows,cols) Hx[1, :] .= true From 4ab69ae625d9dfcbd0f7ac67c16acd7d0a4eb506 Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Sat, 9 Mar 2024 13:08:57 +0500 Subject: [PATCH 069/121] Update src/ecc/ECC.jl Co-authored-by: Stefan Krastanov --- src/ecc/ECC.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ecc/ECC.jl b/src/ecc/ECC.jl index 27ab91d37..9efd96471 100644 --- a/src/ecc/ECC.jl +++ b/src/ecc/ECC.jl @@ -18,7 +18,7 @@ export parity_checks, parity_checks_x, parity_checks_z, naive_syndrome_circuit, shor_syndrome_circuit, naive_encoding_circuit, RepCode, CSS, - Shor9, Steane7, Cleve8, Perfect5, Bitflip3, + Shor9, Steane7, Cleve8, Perfect5, Bitflip3, Toric, QHamming, evaluate_decoder, CommutationCheckECCSetup, NaiveSyndromeECCSetup, ShorSyndromeECCSetup, From 1b602f444ccd07350acaeec6d7ededc37c144ad2 Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Sat, 9 Mar 2024 13:13:34 +0500 Subject: [PATCH 070/121] Update src/ecc/codes/gottesman.jl Co-authored-by: Stefan Krastanov --- src/ecc/codes/gottesman.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ecc/codes/gottesman.jl b/src/ecc/codes/gottesman.jl index abb6ffe9d..98e2d758d 100644 --- a/src/ecc/codes/gottesman.jl +++ b/src/ecc/codes/gottesman.jl @@ -29,7 +29,7 @@ function parity_checks(c::QHamming) end for a in 1:cols - Hx[rows, a] = (a % 4 == 1) || (a % 4 == 2) ? 0 : 1 + Hx[rows, a] = (a % 4 == 1) || (a % 4 == 2) ? 0 : 1 end Hz[1, :] .= false From cc8c6e2bc55207fc8f94c4cf6c756ac55ca71dd7 Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Sat, 9 Mar 2024 13:13:53 +0500 Subject: [PATCH 071/121] Update src/ecc/codes/gottesman.jl Co-authored-by: Stefan Krastanov --- src/ecc/codes/gottesman.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ecc/codes/gottesman.jl b/src/ecc/codes/gottesman.jl index 98e2d758d..a505d0803 100644 --- a/src/ecc/codes/gottesman.jl +++ b/src/ecc/codes/gottesman.jl @@ -24,7 +24,7 @@ function parity_checks(c::QHamming) for i in 3:(rows-1) for a in 1:cols - Hx[i, a] = (a==0) || (a % 2 ==0) + Hx[i, a] = (a==0) || (a % 2 ==0) end end From bdac20bf50e65420faa03107a5592791330e41d3 Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Sat, 9 Mar 2024 14:20:04 +0500 Subject: [PATCH 072/121] Update src/ecc/codes/gottesman.jl Co-authored-by: Stefan Krastanov --- src/ecc/codes/gottesman.jl | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/ecc/codes/gottesman.jl b/src/ecc/codes/gottesman.jl index a505d0803..e4fc36611 100644 --- a/src/ecc/codes/gottesman.jl +++ b/src/ecc/codes/gottesman.jl @@ -1,9 +1,7 @@ struct QHamming <: AbstractECC j::Int function QHamming(j) - if j < 3 - error("j must be greater than or equal to 3 in order to create a valid code of tractable size") - end + (j >= 3 && j < 16) || error("In `QHamming(j)`, `j` must be ≥ 3 in order to obtain a valid code and `j` must be < 16 to remain tractable") new(j) end end From 39344e058c9accaa9536430a158a1ca5f4009292 Mon Sep 17 00:00:00 2001 From: Fe-r-oz Date: Sat, 9 Mar 2024 14:40:11 +0500 Subject: [PATCH 073/121] sompleting suggested changes --- src/ecc/ECC.jl | 2 +- src/ecc/codes/{gottesman.jl => qhamming.jl} | 4 +++- test/test_ecc.jl | 5 ++--- test/test_ecc_decoder_all_setups.jl | 4 ++-- test/test_ecc_encoding.jl | 3 +-- test/test_ecc_syndromes.jl | 3 +-- 6 files changed, 10 insertions(+), 11 deletions(-) rename src/ecc/codes/{gottesman.jl => qhamming.jl} (74%) diff --git a/src/ecc/ECC.jl b/src/ecc/ECC.jl index 9efd96471..3a7c68316 100644 --- a/src/ecc/ECC.jl +++ b/src/ecc/ECC.jl @@ -333,5 +333,5 @@ include("codes/steanecode.jl") include("codes/shorcode.jl") include("codes/clevecode.jl") include("codes/toric.jl") -include("codes/gottesman.jl") +include("codes/qhamming.jl") end #module \ No newline at end of file diff --git a/src/ecc/codes/gottesman.jl b/src/ecc/codes/qhamming.jl similarity index 74% rename from src/ecc/codes/gottesman.jl rename to src/ecc/codes/qhamming.jl index e4fc36611..73afa4860 100644 --- a/src/ecc/codes/gottesman.jl +++ b/src/ecc/codes/qhamming.jl @@ -1,7 +1,9 @@ +"""This class implements the Gottesman codes [[2^j, 2^j-j-2,3], also known as quantum Hamming codes, as described in Gottesman's 1997 paper on stabilizer codes [gottesman1997stabilizer](@cite).""" + struct QHamming <: AbstractECC j::Int function QHamming(j) - (j >= 3 && j < 16) || error("In `QHamming(j)`, `j` must be ≥ 3 in order to obtain a valid code and `j` must be < 16 to remain tractable") + (j >= 3 && j < 21) || error("In `QHamming(j)`, `j` must be ≥ 3 in order to obtain a valid code and `j` must be < 21 to remain tractable") new(j) end end diff --git a/test/test_ecc.jl b/test/test_ecc.jl index d1f4ef408..a77f30fef 100644 --- a/test/test_ecc.jl +++ b/test/test_ecc.jl @@ -8,11 +8,10 @@ codes = [ Steane7(), Shor9(), Perfect5(), - Cleve8(), - QHamming(3), + Cleve8(), + QHamming(3), QHamming(5), CSS([0 1 1 0; 1 1 0 0], [1 1 1 1]), ] - ## function test_naive_syndrome(c::AbstractECC, e::Bool) diff --git a/test/test_ecc_decoder_all_setups.jl b/test/test_ecc_decoder_all_setups.jl index 87f659eeb..6aa91e571 100644 --- a/test/test_ecc_decoder_all_setups.jl +++ b/test/test_ecc_decoder_all_setups.jl @@ -17,6 +17,7 @@ import PyQDecoders Shor9(), Perfect5(), Cleve8(), + QHamming(3), QHamming(5), ] noise = 0.001 @@ -39,7 +40,6 @@ import PyQDecoders end ## - @testset "matching decoder" begin codes = [ Toric(8,8), @@ -62,5 +62,5 @@ end #@show e @assert max(e...) < noise/5 end - end + end end \ No newline at end of file diff --git a/test/test_ecc_encoding.jl b/test/test_ecc_encoding.jl index ece718dd9..c2f9571b3 100644 --- a/test/test_ecc_encoding.jl +++ b/test/test_ecc_encoding.jl @@ -3,7 +3,6 @@ using QuantumClifford using QuantumClifford.ECC ## - @testset "encoding circuits - compare to algebraic construction of encoded state" begin # This test verifies that logical measurements on an encoded state match the physical pre-encoded state. # This test skips verifying the permutations of qubits during canonicalization are properly undone, @@ -16,6 +15,7 @@ using QuantumClifford.ECC :(Perfect5()), :(Bitflip3()), :(QHamming(3)), + :(QHamming(5)), :(S"Y_"), :(S"Z_"), :(S"X_"), @@ -26,7 +26,6 @@ using QuantumClifford.ECC :(Toric(8,8)), fill(:(random_stabilizer(5,7)), 100)... ] - code = eval(codeexpr) if undoperm==false # Pre-process the tableau to remove permutations and negative phases. diff --git a/test/test_ecc_syndromes.jl b/test/test_ecc_syndromes.jl index d164c68d1..53a5c3dc2 100644 --- a/test/test_ecc_syndromes.jl +++ b/test/test_ecc_syndromes.jl @@ -10,7 +10,7 @@ codes = [ Shor9(), Perfect5(), Cleve8(), - QHamming(3), + QHamming(3), QHamming(5), CSS([0 1 1 0; 1 1 0 0], [1 1 1 1]), Toric(3,3), Toric(3,6), @@ -19,7 +19,6 @@ codes = [ ] ## - function pframe_naive_vs_shor_syndrome(code) ecirc = naive_encoding_circuit(code) naive_scirc, naive_ancillaries = naive_syndrome_circuit(code) From f547dd4db3836f553e023c99a420d5cc9aad75b1 Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Sat, 9 Mar 2024 14:44:41 +0500 Subject: [PATCH 074/121] Update test/test_ecc_decoder_all_setups.jl Co-authored-by: Stefan Krastanov --- test/test_ecc_decoder_all_setups.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_ecc_decoder_all_setups.jl b/test/test_ecc_decoder_all_setups.jl index 6aa91e571..ea823b091 100644 --- a/test/test_ecc_decoder_all_setups.jl +++ b/test/test_ecc_decoder_all_setups.jl @@ -56,7 +56,7 @@ end for c in codes for s in setups - e = evaluate_decoder(PyMatchingDecoder(c), s,100000) + e = evaluate_decoder(PyMatchingDecoder(c), s, 100000) #@show c #@show s #@show e From a907f560cf1141517bb764bae2127933548cad66 Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Sat, 9 Mar 2024 14:44:57 +0500 Subject: [PATCH 075/121] Update test/test_ecc_decoder_all_setups.jl Co-authored-by: Stefan Krastanov --- test/test_ecc_decoder_all_setups.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_ecc_decoder_all_setups.jl b/test/test_ecc_decoder_all_setups.jl index ea823b091..82d88064d 100644 --- a/test/test_ecc_decoder_all_setups.jl +++ b/test/test_ecc_decoder_all_setups.jl @@ -30,7 +30,7 @@ import PyQDecoders for c in codes for s in setups - e = evaluate_decoder(TableDecoder(c), s,100000) + e = evaluate_decoder(TableDecoder(c), s, 100000) #@show c #@show s #@show e From ba2f3fff789801f56932ce11ca8bd446fb35d37a Mon Sep 17 00:00:00 2001 From: Fe-r-oz Date: Sat, 9 Mar 2024 14:54:41 +0500 Subject: [PATCH 076/121] suggested changes --- src/ecc/codes/qhamming.jl | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ecc/codes/qhamming.jl b/src/ecc/codes/qhamming.jl index 73afa4860..bfffa5f99 100644 --- a/src/ecc/codes/qhamming.jl +++ b/src/ecc/codes/qhamming.jl @@ -11,9 +11,8 @@ end code_n(c::QHamming)= 2^c.j function parity_checks(c::QHamming) - a=c.j - rows = a + 2 - cols = 2^a + rows = c.j + 2 + cols = 2^c.j Hx = falses(rows,cols) Hz = falses(rows,cols) From 0828eaf5147f935f8fae289a39ec3a8815c42397 Mon Sep 17 00:00:00 2001 From: Fe-r-oz Date: Sat, 9 Mar 2024 15:08:40 +0500 Subject: [PATCH 077/121] undoing extra lines --- src/ecc/ECC.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ecc/ECC.jl b/src/ecc/ECC.jl index 3a7c68316..a9f3db86d 100644 --- a/src/ecc/ECC.jl +++ b/src/ecc/ECC.jl @@ -334,4 +334,5 @@ include("codes/shorcode.jl") include("codes/clevecode.jl") include("codes/toric.jl") include("codes/qhamming.jl") + end #module \ No newline at end of file From bd16194ad82c3e5f7f96d12afb81ee2b3fe1bb5f Mon Sep 17 00:00:00 2001 From: Fe-r-oz Date: Sat, 9 Mar 2024 15:14:15 +0500 Subject: [PATCH 078/121] minor modification --- src/ecc/codes/qhamming.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ecc/codes/qhamming.jl b/src/ecc/codes/qhamming.jl index bfffa5f99..9e5bc2865 100644 --- a/src/ecc/codes/qhamming.jl +++ b/src/ecc/codes/qhamming.jl @@ -1,4 +1,4 @@ -"""This class implements the Gottesman codes [[2^j, 2^j-j-2,3], also known as quantum Hamming codes, as described in Gottesman's 1997 paper on stabilizer codes [gottesman1997stabilizer](@cite).""" +"""This class implements the Gottesman codes [[2^j, 2^j-j-2,3]], also known as quantum Hamming codes, as described in Gottesman's 1997 paper on stabilizer codes [gottesman1997stabilizer](@cite).""" struct QHamming <: AbstractECC j::Int From 63b10931d5ddab722659b61e79b53f12dfa6e4cf Mon Sep 17 00:00:00 2001 From: Fe-r-oz Date: Sat, 9 Mar 2024 15:24:22 +0500 Subject: [PATCH 079/121] suggested changes --- src/ecc/codes/qhamming.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ecc/codes/qhamming.jl b/src/ecc/codes/qhamming.jl index 9e5bc2865..35579f9d6 100644 --- a/src/ecc/codes/qhamming.jl +++ b/src/ecc/codes/qhamming.jl @@ -8,7 +8,7 @@ struct QHamming <: AbstractECC end end -code_n(c::QHamming)= 2^c.j +code_n(c::QHamming) = 2^c.j function parity_checks(c::QHamming) rows = c.j + 2 @@ -21,7 +21,7 @@ function parity_checks(c::QHamming) Hx[2, :] .= false - for i in 3:(rows-1) + for i in 3:(rows - 1) for a in 1:cols Hx[i, a] = (a==0) || (a % 2 ==0) end @@ -37,7 +37,7 @@ function parity_checks(c::QHamming) for i in 3:rows period = 2^(rows - i) for a in 1:cols - Hz[i,a]=div(a-1,period) % 2 == 1 + Hz[i, a] = div(a - 1, period) % 2 == 1 end end extended_Hx = Matrix{Bool}(Hz) From d52a03b2d0578aef30224b8d070190d2dec9fc57 Mon Sep 17 00:00:00 2001 From: Fe-r-oz Date: Sat, 9 Mar 2024 15:38:45 +0500 Subject: [PATCH 080/121] completing suggested changes --- src/ecc/codes/qhamming.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ecc/codes/qhamming.jl b/src/ecc/codes/qhamming.jl index 35579f9d6..782b2d894 100644 --- a/src/ecc/codes/qhamming.jl +++ b/src/ecc/codes/qhamming.jl @@ -23,7 +23,7 @@ function parity_checks(c::QHamming) for i in 3:(rows - 1) for a in 1:cols - Hx[i, a] = (a==0) || (a % 2 ==0) + Hx[i, a] = (a == 0) || (a % 2 == 0) end end From 3dbd5a36360737d9c1b9cb2d0fae4539aca37160 Mon Sep 17 00:00:00 2001 From: Fe-r-oz Date: Sat, 9 Mar 2024 16:40:09 +0500 Subject: [PATCH 081/121] completing suggested changes --- docs/src/references.md | 2 +- src/ecc/codes/qhamming.jl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/src/references.md b/docs/src/references.md index eb9d4230d..db6d50331 100644 --- a/docs/src/references.md +++ b/docs/src/references.md @@ -31,4 +31,4 @@ For circuit construction routines (for stabilizer measurements for a given code) # References ```@bibliography -``` +``` \ No newline at end of file diff --git a/src/ecc/codes/qhamming.jl b/src/ecc/codes/qhamming.jl index 782b2d894..c3730e3af 100644 --- a/src/ecc/codes/qhamming.jl +++ b/src/ecc/codes/qhamming.jl @@ -1,4 +1,4 @@ -"""This class implements the Gottesman codes [[2^j, 2^j-j-2,3]], also known as quantum Hamming codes, as described in Gottesman's 1997 paper on stabilizer codes [gottesman1997stabilizer](@cite).""" +"""This class implements the Gottesman codes [[2^j, 2^j-j-2,3]], also known as quantum Hamming codes, as described in Gottesman's 1997 thesis on stabilizer codes [gottesman1997stabilizer](@cite).""" struct QHamming <: AbstractECC j::Int From 66255aa811c08a02c1f89660ab06552ff256f02a Mon Sep 17 00:00:00 2001 From: Fe-r-oz Date: Sat, 9 Mar 2024 16:47:38 +0500 Subject: [PATCH 082/121] undoing extra lines in files --- docs/src/references.bib | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/src/references.bib b/docs/src/references.bib index 12aec7ad9..9096a173c 100644 --- a/docs/src/references.bib +++ b/docs/src/references.bib @@ -223,5 +223,4 @@ @article{nahum2017quantum number = {3}, journal = {Physical Review X}, author = {Nahum, Adam and Ruhman, Jonathan and Vijay, Sagar and Haah, Jeongwan}, - year = {2017} -} \ No newline at end of file + year = {2017}} \ No newline at end of file From e39fd215cb661fcc148c125a288cf011265c1242 Mon Sep 17 00:00:00 2001 From: Fe-r-oz Date: Sat, 9 Mar 2024 16:49:17 +0500 Subject: [PATCH 083/121] undoing extra lines --- docs/src/references.bib | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/src/references.bib b/docs/src/references.bib index 9096a173c..12aec7ad9 100644 --- a/docs/src/references.bib +++ b/docs/src/references.bib @@ -223,4 +223,5 @@ @article{nahum2017quantum number = {3}, journal = {Physical Review X}, author = {Nahum, Adam and Ruhman, Jonathan and Vijay, Sagar and Haah, Jeongwan}, - year = {2017}} \ No newline at end of file + year = {2017} +} \ No newline at end of file From 67a979cff500421426b7478b08e2b3bb4e29bec5 Mon Sep 17 00:00:00 2001 From: Fe-r-oz Date: Sat, 9 Mar 2024 16:55:03 +0500 Subject: [PATCH 084/121] suggested changes --- test/test_ecc.jl | 4 ++-- test/test_ecc_decoder_all_setups.jl | 4 ++-- test/test_ecc_syndromes.jl | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/test_ecc.jl b/test/test_ecc.jl index a77f30fef..7a510c2f7 100644 --- a/test/test_ecc.jl +++ b/test/test_ecc.jl @@ -8,10 +8,10 @@ codes = [ Steane7(), Shor9(), Perfect5(), - Cleve8(), - QHamming(3), QHamming(5), + Cleve8(), QHamming(3), QHamming(5), CSS([0 1 1 0; 1 1 0 0], [1 1 1 1]), ] + ## function test_naive_syndrome(c::AbstractECC, e::Bool) diff --git a/test/test_ecc_decoder_all_setups.jl b/test/test_ecc_decoder_all_setups.jl index 82d88064d..be3ea9263 100644 --- a/test/test_ecc_decoder_all_setups.jl +++ b/test/test_ecc_decoder_all_setups.jl @@ -16,8 +16,7 @@ import PyQDecoders Steane7(), Shor9(), Perfect5(), - Cleve8(), - QHamming(3), QHamming(5), + Cleve8(), QHamming(3), QHamming(5), ] noise = 0.001 @@ -40,6 +39,7 @@ import PyQDecoders end ## + @testset "matching decoder" begin codes = [ Toric(8,8), diff --git a/test/test_ecc_syndromes.jl b/test/test_ecc_syndromes.jl index 53a5c3dc2..92b941498 100644 --- a/test/test_ecc_syndromes.jl +++ b/test/test_ecc_syndromes.jl @@ -9,8 +9,7 @@ codes = [ Steane7(), Shor9(), Perfect5(), - Cleve8(), - QHamming(3), QHamming(5), + Cleve8(), QHamming(3), QHamming(5), CSS([0 1 1 0; 1 1 0 0], [1 1 1 1]), Toric(3,3), Toric(3,6), @@ -19,6 +18,7 @@ codes = [ ] ## + function pframe_naive_vs_shor_syndrome(code) ecirc = naive_encoding_circuit(code) naive_scirc, naive_ancillaries = naive_syndrome_circuit(code) From c54744f78c15d8665110a7d1da88e433439fdf1d Mon Sep 17 00:00:00 2001 From: Fe-r-oz Date: Sat, 9 Mar 2024 17:01:45 +0500 Subject: [PATCH 085/121] undoing extra lines --- src/ecc/ECC.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ecc/ECC.jl b/src/ecc/ECC.jl index a9f3db86d..e641bbe47 100644 --- a/src/ecc/ECC.jl +++ b/src/ecc/ECC.jl @@ -324,6 +324,7 @@ end include("circuits.jl") include("decoder_pipeline.jl") + include("codes/util.jl") include("codes/classical_codes.jl") include("codes/css.jl") @@ -334,5 +335,4 @@ include("codes/shorcode.jl") include("codes/clevecode.jl") include("codes/toric.jl") include("codes/qhamming.jl") - end #module \ No newline at end of file From 38aa86f8f89c43e9c3172907591bfb82b8ddccca Mon Sep 17 00:00:00 2001 From: Fe-r-oz Date: Mon, 11 Mar 2024 08:46:41 +0500 Subject: [PATCH 086/121] minor modification --- src/ecc/codes/qhamming.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ecc/codes/qhamming.jl b/src/ecc/codes/qhamming.jl index c3730e3af..48e03720b 100644 --- a/src/ecc/codes/qhamming.jl +++ b/src/ecc/codes/qhamming.jl @@ -28,7 +28,7 @@ function parity_checks(c::QHamming) end for a in 1:cols - Hx[rows, a] = (a % 4 == 1) || (a % 4 == 2) ? 0 : 1 + Hx[rows, a] = (a % 4 == 0) || (a % 4 == 1) ? 0 : 1 end Hz[1, :] .= false From e50a44b12dd01dc7190e771ebd80657d5d584b50 Mon Sep 17 00:00:00 2001 From: Fe-r-oz Date: Mon, 11 Mar 2024 18:38:38 +0500 Subject: [PATCH 087/121] implementation of Gottesman aka Quantum Hamming Code --- src/ecc/codes/qhamming.jl | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/ecc/codes/qhamming.jl b/src/ecc/codes/qhamming.jl index 48e03720b..1cab67de3 100644 --- a/src/ecc/codes/qhamming.jl +++ b/src/ecc/codes/qhamming.jl @@ -21,12 +21,31 @@ function parity_checks(c::QHamming) Hx[2, :] .= false - for i in 3:(rows - 1) - for a in 1:cols - Hx[i, a] = (a == 0) || (a % 2 == 0) + for a in 1:cols + Hx[3, a] = (a == 0) || (a % 2 == 0) + end + + for row in 4:rows + for col in 1:cols + k = row - 3 + m = 2^(c.j - k) + n = 2^(c.j - k) + if (col - 1) % (m + n) < m + if col % 2 == 0 + Hx[row, col] = 1 + else + Hx[row, col] = 0 + end + else + if col % 2 == 0 + Hx[row, col] = 0 + else + Hx[row, col] = 1 + end + end end end - + for a in 1:cols Hx[rows, a] = (a % 4 == 0) || (a % 4 == 1) ? 0 : 1 end From 3eb22e1eec4f4c45724faf4b0542250a65f1f11d Mon Sep 17 00:00:00 2001 From: Fe-r-oz Date: Mon, 11 Mar 2024 18:47:14 +0500 Subject: [PATCH 088/121] minor modification --- src/ecc/codes/qhamming.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ecc/codes/qhamming.jl b/src/ecc/codes/qhamming.jl index 1cab67de3..952c17146 100644 --- a/src/ecc/codes/qhamming.jl +++ b/src/ecc/codes/qhamming.jl @@ -25,7 +25,7 @@ function parity_checks(c::QHamming) Hx[3, a] = (a == 0) || (a % 2 == 0) end - for row in 4:rows + for row in 4:rows-1 for col in 1:cols k = row - 3 m = 2^(c.j - k) From 5c3864e7f48e9e68f3b9921b99c67d58efd2b948 Mon Sep 17 00:00:00 2001 From: Fe-r-oz Date: Mon, 11 Mar 2024 18:48:57 +0500 Subject: [PATCH 089/121] minor modification --- src/ecc/codes/qhamming.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ecc/codes/qhamming.jl b/src/ecc/codes/qhamming.jl index 952c17146..52b2757d3 100644 --- a/src/ecc/codes/qhamming.jl +++ b/src/ecc/codes/qhamming.jl @@ -25,7 +25,7 @@ function parity_checks(c::QHamming) Hx[3, a] = (a == 0) || (a % 2 == 0) end - for row in 4:rows-1 + for row in 4:rows - 1 for col in 1:cols k = row - 3 m = 2^(c.j - k) From a0698b707337fba6cd9eca69258f1edf4ba9b5d0 Mon Sep 17 00:00:00 2001 From: Fe-r-oz Date: Tue, 12 Mar 2024 00:22:20 +0500 Subject: [PATCH 090/121] Gottesman aka quantum Hamming code implementation --- src/ecc/codes/qhamming.jl | 59 ++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 23 deletions(-) diff --git a/src/ecc/codes/qhamming.jl b/src/ecc/codes/qhamming.jl index 52b2757d3..0105bf761 100644 --- a/src/ecc/codes/qhamming.jl +++ b/src/ecc/codes/qhamming.jl @@ -18,38 +18,51 @@ function parity_checks(c::QHamming) Hz = falses(rows,cols) Hx[1, :] .= true - Hx[2, :] .= false - for a in 1:cols - Hx[3, a] = (a == 0) || (a % 2 == 0) - end - - for row in 4:rows - 1 + if c.j == 3 for col in 1:cols - k = row - 3 - m = 2^(c.j - k) - n = 2^(c.j - k) - if (col - 1) % (m + n) < m - if col % 2 == 0 - Hx[row, col] = 1 - else - Hx[row, col] = 0 - end - else - if col % 2 == 0 - Hx[row, col] = 0 + Hx[3, col] = (col % 8 == 1 || col % 8 == 3 || col % 8 == 6) ? 0 : 1 + end + Hx[3, cols] = Hx[3, cols] == 0 ? 1 : 0 + for col in 1:cols + 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)) + end + Hx[end, [end-1, end]] .= [0, 1] + + else + for a in 1:cols + Hx[3, a] = (a == 0) || (a % 2 == 0) + end + for row in 4:rows - 1 + for col in 1:cols + k = row - 3 + m = 2^(c.j - k) + n = 2^(c.j - k) + if (col - 1) % (m + n) < m + if col % 2 == 0 + Hx[row, col] = 1 + else + Hx[row, col] = 0 + end else - Hx[row, col] = 1 + if col % 2 == 0 + Hx[row, col] = 0 + else + Hx[row, col] = 1 + end end end end - end - for a in 1:cols - Hx[rows, a] = (a % 4 == 0) || (a % 4 == 1) ? 0 : 1 + for a in 1:cols + Hx[rows, a] = (a % 4 == 0) || (a % 4 == 1) ? 0 : 1 + end end - + Hz[1, :] .= false Hz[2, :] .= true From 1a7e9267cb1b78eab0b375fa43ef4b80137ffffe Mon Sep 17 00:00:00 2001 From: Fe-r-oz Date: Tue, 12 Mar 2024 02:24:08 +0500 Subject: [PATCH 091/121] Adding documentation for Gottesman codes aka quantum Hamming codes --- docs/src/references.bib | 26 ++++++++++++++++++++++++++ src/ecc/codes/qhamming.jl | 12 +++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/docs/src/references.bib b/docs/src/references.bib index 12aec7ad9..c3408f8e7 100644 --- a/docs/src/references.bib +++ b/docs/src/references.bib @@ -224,4 +224,30 @@ @article{nahum2017quantum journal = {Physical Review X}, author = {Nahum, Adam and Ruhman, Jonathan and Vijay, Sagar and Haah, Jeongwan}, year = {2017} +} + +% Key details about [[8, 3, 3]] stabilizer construction via alternative approach + +@article{6506105, + author={Yu, Sixia and Bierbrauer, Jürgen and Dong, Ying and Chen, Qing and Oh, C. H.}, + journal={IEEE Transactions on Information Theory}, + title={All the Stabilizer Codes of Distance 3}, + year={2013}, + volume={59}, + number={8}, + pages={5179-5185}, + keywords= {Generators;Frequency modulation;Vectors;Educational institutions;Error correction codes;Physics;Indexes;1-error correcting stabilizer codes;optimal codes;quantum error correction;quantum Hamming bound}, + doi={10.1109/TIT.2013.2259138} +} + +@article{Chao2017QuantumEC, + title={Quantum Error Correction with Only Two Extra Qubits.}, + author={Rui Chao and Ben W Reichardt}, + journal={Physical review letters}, + year={2017}, + volume={121 5}, + pages={ + 050502 + }, + url={https://api.semanticscholar.org/CorpusID:206314271} } \ No newline at end of file diff --git a/src/ecc/codes/qhamming.jl b/src/ecc/codes/qhamming.jl index 0105bf761..1abfb77e7 100644 --- a/src/ecc/codes/qhamming.jl +++ b/src/ecc/codes/qhamming.jl @@ -1,4 +1,14 @@ -"""This class implements the Gottesman codes [[2^j, 2^j-j-2,3]], also known as quantum Hamming codes, as described in Gottesman's 1997 thesis on stabilizer codes [gottesman1997stabilizer](@cite).""" +"""This class implements the family of Gottesman codes [[2^j, 2^j - j - 2, 3]], also known as quantum Hamming codes, as described in Gottesman's 1997 thesis on stabilizer codes [Gottesman1997](@cite). + +Key details for the [[8, 3, 3]] code when j = 3 using Stabilizer Formalism: +- [6506105](@cite) utilizes an explicit construction method for the stabilizer generators. The remaining m generators, apart from Mx and Mz, are constructed using the check matrix [Hm|AmHm], where Hm = [c0, c1, ..., c^2m − 1]. Each column ck (for k = 0, 1, ..., 2^m − 1) represents a binary vector corresponding to the integer k. Also, Am refers to any invertible m × m matrix devoid of fixed points such that Am​.s ≠ 0 and Am.s ≠ s for all s ∈ F₂ᵐ. +- [Chao2017QuantumEC](@cite) introduces alternative stabilizer generators for the [[8, 3, 3]] code. It identifies permutations effective for all stabilizer generators except for X^⊗8 and Z^⊗8. However, these can be replaced with XXYZIYZI and ZZIXYIXY, respectively. The stabilizer generators are permuted to achieve desired properties, reflecting an alternative approach to constructing the stabilizer code. + +Notes: +- This implementation adopts the Gottesman Notation for the [[8, 3, 3]] stabilizer as depicted in Table 3.3 on Page 22 on the Gottesman's thesis. Additionally, for j = 4, our [[16, 10, 3]] stabilizer stemming from QHamming(4) can be cross-verified from Table 8.1 on Page 91 as well [Gottesman1997](@cite). +- The differences between [6506105](@cite), [Chao2017QuantumEC](@cite), and [Gottesman1997](@cite) primarily lie in the choice of stabilizer generators and their permutations. +- The discrepancy in stabilizer generator representations underscores the flexibility within the stabilizer formalism, allowing for various valid choices and permutations, albeit with different notations and implementation details. +""" struct QHamming <: AbstractECC j::Int From 90e52f0b7de392769971a0cc7db4e28783e02b03 Mon Sep 17 00:00:00 2001 From: Fe-r-oz Date: Tue, 12 Mar 2024 03:05:56 +0500 Subject: [PATCH 092/121] Minor Modification --- src/ecc/codes/qhamming.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ecc/codes/qhamming.jl b/src/ecc/codes/qhamming.jl index 1abfb77e7..b9262c1f1 100644 --- a/src/ecc/codes/qhamming.jl +++ b/src/ecc/codes/qhamming.jl @@ -32,14 +32,14 @@ function parity_checks(c::QHamming) if c.j == 3 for col in 1:cols - Hx[3, col] = (col % 8 == 1 || col % 8 == 3 || col % 8 == 6) ? 0 : 1 + Hx[3, col] = (col % 8 == 1 || col % 8 == 3 || col % 8 == 6) ? 0 : 1 end Hx[3, cols] = Hx[3, cols] == 0 ? 1 : 0 for col in 1:cols - Hx[4, col] = (col % 4 == 1) || (col % 4 == 3) ? 0 : 1 + 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)) + 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] From ead9bbe9e945fefbf64734e2995f47d76783f293 Mon Sep 17 00:00:00 2001 From: Fe-r-oz Date: Wed, 13 Mar 2024 19:50:13 +0500 Subject: [PATCH 093/121] Using Precise Naming Convention --- src/ecc/ECC.jl | 4 ++-- src/ecc/codes/{qhamming.jl => gottesmancode.jl} | 16 ++++++++-------- test/test_ecc.jl | 2 +- test/test_ecc_decoder_all_setups.jl | 2 +- test/test_ecc_encoding.jl | 4 ++-- test/test_ecc_syndromes.jl | 2 +- 6 files changed, 15 insertions(+), 15 deletions(-) rename src/ecc/codes/{qhamming.jl => gottesmancode.jl} (78%) diff --git a/src/ecc/ECC.jl b/src/ecc/ECC.jl index e641bbe47..745eea428 100644 --- a/src/ecc/ECC.jl +++ b/src/ecc/ECC.jl @@ -19,7 +19,7 @@ export parity_checks, parity_checks_x, parity_checks_z, RepCode, CSS, Shor9, Steane7, Cleve8, Perfect5, Bitflip3, - Toric, QHamming, + Toric, Gottesman, evaluate_decoder, CommutationCheckECCSetup, NaiveSyndromeECCSetup, ShorSyndromeECCSetup, TableDecoder, @@ -334,5 +334,5 @@ include("codes/steanecode.jl") include("codes/shorcode.jl") include("codes/clevecode.jl") include("codes/toric.jl") -include("codes/qhamming.jl") +include("codes/gottesmancode.jl") end #module \ No newline at end of file diff --git a/src/ecc/codes/qhamming.jl b/src/ecc/codes/gottesmancode.jl similarity index 78% rename from src/ecc/codes/qhamming.jl rename to src/ecc/codes/gottesmancode.jl index b9262c1f1..6f7d5b0e7 100644 --- a/src/ecc/codes/qhamming.jl +++ b/src/ecc/codes/gottesmancode.jl @@ -1,26 +1,26 @@ -"""This class implements the family of Gottesman codes [[2^j, 2^j - j - 2, 3]], also known as quantum Hamming codes, as described in Gottesman's 1997 thesis on stabilizer codes [Gottesman1997](@cite). +"""This class implements the family of [[2^j, 2^j - j - 2, 3]] Gottesman codes, also known as [[2^j, 2^j - j - 2, 3]] quantum Hamming codes, as described in Gottesman's 1997 PhD thesis on 'Stabilizer Codes and Quantum Error Correction' [Gottesman1997](@cite). Key details for the [[8, 3, 3]] code when j = 3 using Stabilizer Formalism: - [6506105](@cite) utilizes an explicit construction method for the stabilizer generators. The remaining m generators, apart from Mx and Mz, are constructed using the check matrix [Hm|AmHm], where Hm = [c0, c1, ..., c^2m − 1]. Each column ck (for k = 0, 1, ..., 2^m − 1) represents a binary vector corresponding to the integer k. Also, Am refers to any invertible m × m matrix devoid of fixed points such that Am​.s ≠ 0 and Am.s ≠ s for all s ∈ F₂ᵐ. - [Chao2017QuantumEC](@cite) introduces alternative stabilizer generators for the [[8, 3, 3]] code. It identifies permutations effective for all stabilizer generators except for X^⊗8 and Z^⊗8. However, these can be replaced with XXYZIYZI and ZZIXYIXY, respectively. The stabilizer generators are permuted to achieve desired properties, reflecting an alternative approach to constructing the stabilizer code. Notes: -- This implementation adopts the Gottesman Notation for the [[8, 3, 3]] stabilizer as depicted in Table 3.3 on Page 22 on the Gottesman's thesis. Additionally, for j = 4, our [[16, 10, 3]] stabilizer stemming from QHamming(4) can be cross-verified from Table 8.1 on Page 91 as well [Gottesman1997](@cite). -- The differences between [6506105](@cite), [Chao2017QuantumEC](@cite), and [Gottesman1997](@cite) primarily lie in the choice of stabilizer generators and their permutations. +- This implementation adopts the Gottesman Notation for the [[8, 3, 3]] stabilizer code as depicted in Table 3.3 on Page 22 on the Gottesman's PhD thesis. Additionally, for j = 4, our [[16, 10, 3]] stabilizer code stemming from QHamming(4) can be cross-verified from Table 8.1 on Page 91 as well [Gottesman1997](@cite). +- The differences between [6506105](@cite), [Chao2017QuantumEC](@cite), and [Gottesman1997](@cite) primarily lie in the choice of stabilizer generators and their permutations for the [[8, 3, 3]] stabilizer code. - The discrepancy in stabilizer generator representations underscores the flexibility within the stabilizer formalism, allowing for various valid choices and permutations, albeit with different notations and implementation details. """ -struct QHamming <: AbstractECC +struct Gottesman <: AbstractECC j::Int - function QHamming(j) - (j >= 3 && j < 21) || error("In `QHamming(j)`, `j` must be ≥ 3 in order to obtain a valid code and `j` must be < 21 to remain tractable") + 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) end end -code_n(c::QHamming) = 2^c.j +code_n(c::Gottesman) = 2^c.j -function parity_checks(c::QHamming) +function parity_checks(c::Gottesman) rows = c.j + 2 cols = 2^c.j diff --git a/test/test_ecc.jl b/test/test_ecc.jl index 7a510c2f7..93a728e41 100644 --- a/test/test_ecc.jl +++ b/test/test_ecc.jl @@ -8,7 +8,7 @@ codes = [ Steane7(), Shor9(), Perfect5(), - Cleve8(), QHamming(3), QHamming(5), + Cleve8(), Gottesman(3), Gottesman(5), CSS([0 1 1 0; 1 1 0 0], [1 1 1 1]), ] diff --git a/test/test_ecc_decoder_all_setups.jl b/test/test_ecc_decoder_all_setups.jl index be3ea9263..c8d06253a 100644 --- a/test/test_ecc_decoder_all_setups.jl +++ b/test/test_ecc_decoder_all_setups.jl @@ -16,7 +16,7 @@ import PyQDecoders Steane7(), Shor9(), Perfect5(), - Cleve8(), QHamming(3), QHamming(5), + Cleve8(), Gottesman(3), Gottesman(5), ] noise = 0.001 diff --git a/test/test_ecc_encoding.jl b/test/test_ecc_encoding.jl index c2f9571b3..c8f9e0ca7 100644 --- a/test/test_ecc_encoding.jl +++ b/test/test_ecc_encoding.jl @@ -14,8 +14,8 @@ using QuantumClifford.ECC :(Shor9()), :(Perfect5()), :(Bitflip3()), - :(QHamming(3)), - :(QHamming(5)), + :(Gottesman(3)), + :(Gottesman(5)), :(S"Y_"), :(S"Z_"), :(S"X_"), diff --git a/test/test_ecc_syndromes.jl b/test/test_ecc_syndromes.jl index 92b941498..61b2eb8c8 100644 --- a/test/test_ecc_syndromes.jl +++ b/test/test_ecc_syndromes.jl @@ -9,7 +9,7 @@ codes = [ Steane7(), Shor9(), Perfect5(), - Cleve8(), QHamming(3), QHamming(5), + Cleve8(), Gottesman(3), Gottesman(5), CSS([0 1 1 0; 1 1 0 0], [1 1 1 1]), Toric(3,3), Toric(3,6), From 227b9d6d71b77e67218bfaf4c14fb57deff143ef Mon Sep 17 00:00:00 2001 From: Stefan Krastanov Date: Fri, 15 Mar 2024 22:13:39 -0400 Subject: [PATCH 094/121] relax testing requirements for decoding Gottesman code --- test/test_ecc_decoder_all_setups.jl | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/test/test_ecc_decoder_all_setups.jl b/test/test_ecc_decoder_all_setups.jl index 84d0d6bc2..4b44b5bd7 100644 --- a/test/test_ecc_decoder_all_setups.jl +++ b/test/test_ecc_decoder_all_setups.jl @@ -10,7 +10,10 @@ import LDPCDecoders Steane7(), Shor9(), Perfect5(), - Cleve8(), Gottesman(3), Gottesman(5), + Cleve8(), + Gottesman(3), + Gottesman(4), + #Gottesman(5), performs poorly ] noise = 0.001 @@ -28,7 +31,7 @@ import LDPCDecoders #@show c #@show s #@show e - @assert max(e...) < noise/4 + @assert max(e...) < noise/3 end end end @@ -38,6 +41,7 @@ end @testset "belief prop decoders, good for small codes" begin codes = [ + Gottesman(3), ] noise = 0.001 @@ -85,5 +89,5 @@ end #@show e @assert max(e...) < noise/5 end - end -end \ No newline at end of file + end +end From ff88de81b5c0d99404c9ccb436e71ea2f8e08e08 Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Sat, 16 Mar 2024 09:13:38 +0500 Subject: [PATCH 095/121] Update test/test_ecc_syndromes.jl Co-authored-by: Stefan Krastanov --- test/test_ecc_syndromes.jl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/test_ecc_syndromes.jl b/test/test_ecc_syndromes.jl index 61b2eb8c8..1b80f3cca 100644 --- a/test/test_ecc_syndromes.jl +++ b/test/test_ecc_syndromes.jl @@ -9,7 +9,9 @@ codes = [ Steane7(), Shor9(), Perfect5(), - Cleve8(), Gottesman(3), Gottesman(5), + Cleve8(), + Gottesman(3), + Gottesman(5), CSS([0 1 1 0; 1 1 0 0], [1 1 1 1]), Toric(3,3), Toric(3,6), From 536f55cda9cd059729d3660be2928beea306b4b6 Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Sat, 16 Mar 2024 09:19:15 +0500 Subject: [PATCH 096/121] Update src/ecc/codes/gottesmancode.jl Co-authored-by: Stefan Krastanov --- src/ecc/codes/gottesmancode.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/src/ecc/codes/gottesmancode.jl b/src/ecc/codes/gottesmancode.jl index 6f7d5b0e7..461e33779 100644 --- a/src/ecc/codes/gottesmancode.jl +++ b/src/ecc/codes/gottesmancode.jl @@ -7,7 +7,6 @@ Key details for the [[8, 3, 3]] code when j = 3 using Stabilizer Formalism: Notes: - This implementation adopts the Gottesman Notation for the [[8, 3, 3]] stabilizer code as depicted in Table 3.3 on Page 22 on the Gottesman's PhD thesis. Additionally, for j = 4, our [[16, 10, 3]] stabilizer code stemming from QHamming(4) can be cross-verified from Table 8.1 on Page 91 as well [Gottesman1997](@cite). - The differences between [6506105](@cite), [Chao2017QuantumEC](@cite), and [Gottesman1997](@cite) primarily lie in the choice of stabilizer generators and their permutations for the [[8, 3, 3]] stabilizer code. -- The discrepancy in stabilizer generator representations underscores the flexibility within the stabilizer formalism, allowing for various valid choices and permutations, albeit with different notations and implementation details. """ struct Gottesman <: AbstractECC From c5c7d603e83f884090c570599ebb9880b34a2490 Mon Sep 17 00:00:00 2001 From: Fe-r-oz Date: Sat, 16 Mar 2024 09:21:25 +0500 Subject: [PATCH 097/121] resetting parameters to default --- test/test_ecc_decoder_all_setups.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_ecc_decoder_all_setups.jl b/test/test_ecc_decoder_all_setups.jl index 4b44b5bd7..389bb3e9d 100644 --- a/test/test_ecc_decoder_all_setups.jl +++ b/test/test_ecc_decoder_all_setups.jl @@ -83,7 +83,7 @@ end for c in codes for s in setups - e = evaluate_decoder(PyMatchingDecoder(c), s, 100000) + e = evaluate_decoder(PyMatchingDecoder(c), s, 10000) #@show c #@show s #@show e From 9e1cc0f5fb980c46df6ea44d149ad32ddd5a9e2f Mon Sep 17 00:00:00 2001 From: Fe-r-oz Date: Sat, 16 Mar 2024 09:55:54 +0500 Subject: [PATCH 098/121] adding separate Hx and Hz checks in Gottesman --- src/ecc/codes/gottesmancode.jl | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/ecc/codes/gottesmancode.jl b/src/ecc/codes/gottesmancode.jl index 461e33779..eb230e045 100644 --- a/src/ecc/codes/gottesmancode.jl +++ b/src/ecc/codes/gottesmancode.jl @@ -22,14 +22,14 @@ 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) - + Hx[1, :] .= true Hx[2, :] .= false - if c.j == 3 + if c.j == 3 for col in 1:cols Hx[3, col] = (col % 8 == 1 || col % 8 == 3 || col % 8 == 6) ? 0 : 1 end @@ -66,7 +66,7 @@ function parity_checks(c::Gottesman) end end end - + for a in 1:cols Hx[rows, a] = (a % 4 == 0) || (a % 4 == 1) ? 0 : 1 end @@ -74,7 +74,7 @@ function parity_checks(c::Gottesman) Hz[1, :] .= false Hz[2, :] .= true - + for i in 3:rows period = 2^(rows - i) for a in 1:cols @@ -83,9 +83,13 @@ function parity_checks(c::Gottesman) end extended_Hx = Matrix{Bool}(Hz) extended_Hz = Matrix{Bool}(Hx) - + num_rows = size(Hx, 1) - + fill_array = fill(UInt8(0), num_rows) Stabilizer(fill_array, extended_Hz, extended_Hx) -end \ No newline at end of file +end + +parity_checks_x(c::Gottesman) = c.Hx + +parity_checks_z(c::Gottesman) = c.Hz From 3e5d4a70b6211ccceef3ab1db154f22eac9c452a Mon Sep 17 00:00:00 2001 From: Fe-r-oz Date: Sat, 16 Mar 2024 10:25:49 +0500 Subject: [PATCH 099/121] Minor Modifications --- src/ecc/codes/gottesmancode.jl | 47 +++++++++++++++++----------------- 1 file changed, 23 insertions(+), 24 deletions(-) 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) From 035c00653afa027d87cc01d8eacc7eda2eee627d Mon Sep 17 00:00:00 2001 From: Fe-r-oz Date: Sat, 16 Mar 2024 10:29:40 +0500 Subject: [PATCH 100/121] minor modifications --- src/ecc/codes/gottesmancode.jl | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/ecc/codes/gottesmancode.jl b/src/ecc/codes/gottesmancode.jl index 2f849e38c..e024a8ca9 100644 --- a/src/ecc/codes/gottesmancode.jl +++ b/src/ecc/codes/gottesmancode.jl @@ -11,10 +11,8 @@ 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) + Hx = Matrix{Bool} + Hz = Matrix{Bool} 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) @@ -24,6 +22,9 @@ end code_n(c::Gottesman) = 2^c.j function parity_checks(c::Gottesman) + rows = c.j + 2 + cols = 2^c.j + extended_Hx = c.Hx extended_Hz = c.Hz From ffb91a95988154d98f6013bbbd279f6ca2025947 Mon Sep 17 00:00:00 2001 From: Fe-r-oz Date: Sat, 16 Mar 2024 10:34:41 +0500 Subject: [PATCH 101/121] minor modifications --- src/ecc/codes/gottesmancode.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ecc/codes/gottesmancode.jl b/src/ecc/codes/gottesmancode.jl index e024a8ca9..8f6ae8ff1 100644 --- a/src/ecc/codes/gottesmancode.jl +++ b/src/ecc/codes/gottesmancode.jl @@ -11,8 +11,8 @@ Notes: struct Gottesman <: AbstractECC j::Int - Hx = Matrix{Bool} - Hz = Matrix{Bool} + Hx::Matrix{Bool} + Hz::Matrix{Bool} 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) From fd0408cd68e340681445f106ef7d9bc76ed04bc1 Mon Sep 17 00:00:00 2001 From: Fe-r-oz Date: Sat, 16 Mar 2024 12:30:09 +0500 Subject: [PATCH 102/121] adding Hx and Hz checks in Gottesman --- src/ecc/codes/gottesmancode.jl | 48 +++++++++++++++++----------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/ecc/codes/gottesmancode.jl b/src/ecc/codes/gottesmancode.jl index 8f6ae8ff1..2e7049dfd 100644 --- a/src/ecc/codes/gottesmancode.jl +++ b/src/ecc/codes/gottesmancode.jl @@ -11,8 +11,6 @@ Notes: struct Gottesman <: AbstractECC j::Int - Hx::Matrix{Bool} - Hz::Matrix{Bool} 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) @@ -25,28 +23,28 @@ function parity_checks(c::Gottesman) rows = c.j + 2 cols = 2^c.j - extended_Hx = c.Hx - extended_Hz = c.Hz + Hx = falses(rows, cols) + Hz = falses(rows, cols) - extended_Hx[1, :] .= true - extended_Hx[2, :] .= false + Hx[1, :] .= true + Hx[2, :] .= false if c.j == 3 for col in 1:cols - extended_Hx[3, col] = (col % 8 == 1 || col % 8 == 3 || col % 8 == 6) ? 0 : 1 + Hx[3, col] = (col % 8 == 1 || col % 8 == 3 || col % 8 == 6) ? 0 : 1 end - extended_Hx[3, cols] = extended_Hx[3, cols] == 0 ? 1 : 0 + Hx[3, cols] = Hx[3, cols] == 0 ? 1 : 0 for col in 1:cols - extended_Hx[4, col] = (col % 4 == 1) || (col % 4 == 3) ? 0 : 1 + Hx[4, col] = (col % 4 == 1) || (col % 4 == 3) ? 0 : 1 end for a in 1:cols - extended_Hx[rows, a] = ((a % 4 == 0) || (a % 4 == 1) ? 0 : 1) ⊻ ((a % 8 == 5) || (a % 8 == 6)) + Hx[rows, a] = ((a % 4 == 0) || (a % 4 == 1) ? 0 : 1) ⊻ ((a % 8 == 5) || (a % 8 == 6)) end - extended_Hx[end, [end-1, end]] .= [0, 1] + Hx[end, [end-1, end]] .= [0, 1] else for a in 1:cols - extended_Hx[3, a] = (a == 0) || (a % 2 == 0) + Hx[3, a] = (a == 0) || (a % 2 == 0) end for row in 4:rows - 1 for col in 1:cols @@ -55,41 +53,43 @@ function parity_checks(c::Gottesman) n = 2^(c.j - k) if (col - 1) % (m + n) < m if col % 2 == 0 - extended_Hx[row, col] = 1 + Hx[row, col] = 1 else - extended_Hx[row, col] = 0 + Hx[row, col] = 0 end else if col % 2 == 0 - extended_Hx[row, col] = 0 + Hx[row, col] = 0 else - extended_Hx[row, col] = 1 + Hx[row, col] = 1 end end end end for a in 1:cols - extended_Hx[rows, a] = (a % 4 == 0) || (a % 4 == 1) ? 0 : 1 + Hx[rows, a] = (a % 4 == 0) || (a % 4 == 1) ? 0 : 1 end end - extended_Hz[1, :] .= false - extended_Hz[2, :] .= true + Hz[1, :] .= false + Hz[2, :] .= true for i in 3:rows period = 2^(rows - i) for a in 1:cols - extended_Hz[i, a] = div(a - 1, period) % 2 == 1 + Hz[i, a] = div(a - 1, period) % 2 == 1 end end - num_rows = size(extended_Hx, 1) + extended_Hx = Matrix{Bool}(Hz) + extended_Hz = Matrix{Bool}(Hx) + + num_rows = size(Hx, 1) fill_array = fill(UInt8(0), num_rows) Stabilizer(fill_array, extended_Hz, extended_Hx) end -parity_checks_x(c::Gottesman) = c.Hx - -parity_checks_z(c::Gottesman) = c.Hz +parity_checks_x(c::Gottesman) = stab_to_gf2(parity_checks(Gottesman()))[1:end:1,1:end÷2] +parity_checks_z(c::Gottesman) = stab_to_gf2(parity_checks(Gottesman()))[1:end,end÷2+1:end] From 1d1054834384cbe16fc10405daf059c57f82690f Mon Sep 17 00:00:00 2001 From: Fe-r-oz Date: Sat, 16 Mar 2024 12:53:04 +0500 Subject: [PATCH 103/121] utilizing stab_to_gf2 --- src/ecc/codes/gottesmancode.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ecc/codes/gottesmancode.jl b/src/ecc/codes/gottesmancode.jl index 2e7049dfd..f2624f31a 100644 --- a/src/ecc/codes/gottesmancode.jl +++ b/src/ecc/codes/gottesmancode.jl @@ -91,5 +91,5 @@ function parity_checks(c::Gottesman) Stabilizer(fill_array, extended_Hz, extended_Hx) end -parity_checks_x(c::Gottesman) = stab_to_gf2(parity_checks(Gottesman()))[1:end:1,1:end÷2] -parity_checks_z(c::Gottesman) = stab_to_gf2(parity_checks(Gottesman()))[1:end,end÷2+1:end] +parity_checks_x(c::Gottesman) = stab_to_gf2(parity_checks(Gottesman(c.j)))[1:end:1,1:end÷2] +parity_checks_z(c::Gottesman) = stab_to_gf2(parity_checks(Gottesman(c.j)))[1:end,end÷2+1:end] From 475fc80a9e4e3ea026c25f80a0ced780d8c4fc99 Mon Sep 17 00:00:00 2001 From: Fe-r-oz Date: Sat, 16 Mar 2024 13:26:00 +0500 Subject: [PATCH 104/121] Minor Modification --- test/test_ecc_decoder_all_setups.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_ecc_decoder_all_setups.jl b/test/test_ecc_decoder_all_setups.jl index 389bb3e9d..9592ee566 100644 --- a/test/test_ecc_decoder_all_setups.jl +++ b/test/test_ecc_decoder_all_setups.jl @@ -41,7 +41,7 @@ end @testset "belief prop decoders, good for small codes" begin codes = [ - Gottesman(3), + #Gottesman(3), ] noise = 0.001 From b3c8725e70972af0c1ce121f92205eaf20fd1378 Mon Sep 17 00:00:00 2001 From: Fe-r-oz Date: Sat, 16 Mar 2024 15:16:37 +0500 Subject: [PATCH 105/121] updating changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8bb53e67e..8b4756526 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ # News +## v0.8.23 - 2024-03-16 + +- Implemented the family of [[2^j, 2^j - j - 2, 3]] Gottesman codes, also known as [[2^j, 2^j - j - 2, 3]] quantum Hamming codes. + ## v0.8.22 - 2024-03-15 - Bump the `PyQDecoders` dependency, switching to `PythonCall` behind the scenes for reliability. From 43a24fb14997f726e6abc7e98db21a8808c04069 Mon Sep 17 00:00:00 2001 From: Fe-r-oz Date: Sat, 16 Mar 2024 15:21:59 +0500 Subject: [PATCH 106/121] resolving changelog conflicts --- CHANGELOG.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b4756526..8bb53e67e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,10 +6,6 @@ # News -## v0.8.23 - 2024-03-16 - -- Implemented the family of [[2^j, 2^j - j - 2, 3]] Gottesman codes, also known as [[2^j, 2^j - j - 2, 3]] quantum Hamming codes. - ## v0.8.22 - 2024-03-15 - Bump the `PyQDecoders` dependency, switching to `PythonCall` behind the scenes for reliability. From c00a0ed74085c83ccd2d75864ad3fd64f9cfab39 Mon Sep 17 00:00:00 2001 From: Fe-r-oz Date: Sat, 16 Mar 2024 15:29:00 +0500 Subject: [PATCH 107/121] undoing whitespaces --- test/test_ecc_encoding.jl | 2 +- test/test_throws.jl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_ecc_encoding.jl b/test/test_ecc_encoding.jl index c8f9e0ca7..bc2a06081 100644 --- a/test/test_ecc_encoding.jl +++ b/test/test_ecc_encoding.jl @@ -55,4 +55,4 @@ using QuantumClifford.ECC #println("$codeexpr, $(encodedₙ == algebraicₙ)") end -end \ No newline at end of file +end diff --git a/test/test_throws.jl b/test/test_throws.jl index 9aa678d58..724cc7de5 100644 --- a/test/test_throws.jl +++ b/test/test_throws.jl @@ -64,4 +64,4 @@ for m in [sMX,sMZ,sMY,sMRX,sMRZ,sMRY] @test_throws ArgumentError m(-1) @test_throws ArgumentError m(0,1) @test_throws ArgumentError m(-1,0) -end \ No newline at end of file +end From 074683ca11c74150251a540481b7d12a9ee7ebbb Mon Sep 17 00:00:00 2001 From: Fe-r-oz Date: Sat, 16 Mar 2024 15:37:26 +0500 Subject: [PATCH 108/121] removing whitespaces --- test/test_ecc.jl | 2 +- test/test_ecc_encoding.jl | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/test/test_ecc.jl b/test/test_ecc.jl index 93a728e41..9cc05edff 100644 --- a/test/test_ecc.jl +++ b/test/test_ecc.jl @@ -76,4 +76,4 @@ end @test isdegenerate(Steane7()) == false @test isdegenerate(Steane7(), 2) == true @test isdegenerate(Bitflip3()) == true -end \ No newline at end of file +end diff --git a/test/test_ecc_encoding.jl b/test/test_ecc_encoding.jl index bc2a06081..b5500133d 100644 --- a/test/test_ecc_encoding.jl +++ b/test/test_ecc_encoding.jl @@ -3,6 +3,7 @@ using QuantumClifford using QuantumClifford.ECC ## + @testset "encoding circuits - compare to algebraic construction of encoded state" begin # This test verifies that logical measurements on an encoded state match the physical pre-encoded state. # This test skips verifying the permutations of qubits during canonicalization are properly undone, @@ -26,6 +27,7 @@ using QuantumClifford.ECC :(Toric(8,8)), fill(:(random_stabilizer(5,7)), 100)... ] + code = eval(codeexpr) if undoperm==false # Pre-process the tableau to remove permutations and negative phases. From f39e8b399109097706f2068b3259a8a14b71e37b Mon Sep 17 00:00:00 2001 From: Feroz <93876775+Fe-r-oz@users.noreply.github.com> Date: Sat, 16 Mar 2024 17:47:17 +0500 Subject: [PATCH 109/121] Update test/test_ecc.jl Co-authored-by: Stefan Krastanov --- test/test_ecc.jl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/test_ecc.jl b/test/test_ecc.jl index 9cc05edff..5cecda473 100644 --- a/test/test_ecc.jl +++ b/test/test_ecc.jl @@ -8,7 +8,9 @@ codes = [ Steane7(), Shor9(), Perfect5(), - Cleve8(), Gottesman(3), Gottesman(5), + Cleve8(), + Gottesman(3), + Gottesman(5), CSS([0 1 1 0; 1 1 0 0], [1 1 1 1]), ] From 51fbc02e8929ac2d8660fff91a64332643054244 Mon Sep 17 00:00:00 2001 From: Fe-r-oz Date: Sat, 16 Mar 2024 19:15:42 +0500 Subject: [PATCH 110/121] minor modification --- src/ecc/codes/gottesmancode.jl | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/ecc/codes/gottesmancode.jl b/src/ecc/codes/gottesmancode.jl index f2624f31a..8c0eda3c6 100644 --- a/src/ecc/codes/gottesmancode.jl +++ b/src/ecc/codes/gottesmancode.jl @@ -90,6 +90,3 @@ function parity_checks(c::Gottesman) fill_array = fill(UInt8(0), num_rows) Stabilizer(fill_array, extended_Hz, extended_Hx) end - -parity_checks_x(c::Gottesman) = stab_to_gf2(parity_checks(Gottesman(c.j)))[1:end:1,1:end÷2] -parity_checks_z(c::Gottesman) = stab_to_gf2(parity_checks(Gottesman(c.j)))[1:end,end÷2+1:end] From f87161ab53ecf74f84a1814379fefd3761f29c3d Mon Sep 17 00:00:00 2001 From: Fe-r-oz Date: Sat, 16 Mar 2024 21:23:03 +0500 Subject: [PATCH 111/121] Implementation of non-CSS Gottesman codes aka quantum Hamming codes --- CHANGELOG.md | 3 +++ test/test_ecc_decoder_all_setups.jl | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8bb53e67e..87265ffcb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ # News +## v0.8.23 - 2024-03-16 +- Implemented the first family of non-CSS [[2^j, 2^j - j - 2, 3]] Gottesman codes, also known as [[2^j, 2^j - j - 2, 3]] quantum Hamming codes + ## v0.8.22 - 2024-03-15 - Bump the `PyQDecoders` dependency, switching to `PythonCall` behind the scenes for reliability. diff --git a/test/test_ecc_decoder_all_setups.jl b/test/test_ecc_decoder_all_setups.jl index 9592ee566..e51c53e41 100644 --- a/test/test_ecc_decoder_all_setups.jl +++ b/test/test_ecc_decoder_all_setups.jl @@ -41,7 +41,7 @@ end @testset "belief prop decoders, good for small codes" begin codes = [ - #Gottesman(3), + #Gottesman(3), Gottesman is a non-CSS code. BP works for CSS codes. ] noise = 0.001 From f07fd2cb570223cf71890ebf667995d0cba43b1e Mon Sep 17 00:00:00 2001 From: Fe-r-oz Date: Sat, 16 Mar 2024 21:30:24 +0500 Subject: [PATCH 112/121] Implementation of non-CSS Gottesman codes aka quantum Hamming codes --- CHANGELOG.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 87265ffcb..8bb53e67e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,9 +6,6 @@ # News -## v0.8.23 - 2024-03-16 -- Implemented the first family of non-CSS [[2^j, 2^j - j - 2, 3]] Gottesman codes, also known as [[2^j, 2^j - j - 2, 3]] quantum Hamming codes - ## v0.8.22 - 2024-03-15 - Bump the `PyQDecoders` dependency, switching to `PythonCall` behind the scenes for reliability. From 8831a55d1fb12e4f841afe73766e149bba081db2 Mon Sep 17 00:00:00 2001 From: Fe-r-oz Date: Sat, 16 Mar 2024 22:30:34 +0500 Subject: [PATCH 113/121] undoing whitespaces --- src/ecc/ECC.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ecc/ECC.jl b/src/ecc/ECC.jl index 060c65c4a..088b19d0b 100644 --- a/src/ecc/ECC.jl +++ b/src/ecc/ECC.jl @@ -335,4 +335,4 @@ include("codes/shorcode.jl") include("codes/clevecode.jl") include("codes/toric.jl") include("codes/gottesmancode.jl") -end #module \ No newline at end of file +end #module From 73fc7d2ba2aa813f6aba5ecae08795d2005934c4 Mon Sep 17 00:00:00 2001 From: Fe-r-oz Date: Sat, 16 Mar 2024 22:34:13 +0500 Subject: [PATCH 114/121] undoing whitespaces --- docs/src/references.bib | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/src/references.bib b/docs/src/references.bib index c3408f8e7..f65d0e245 100644 --- a/docs/src/references.bib +++ b/docs/src/references.bib @@ -227,11 +227,11 @@ @article{nahum2017quantum } % Key details about [[8, 3, 3]] stabilizer construction via alternative approach - + @article{6506105, author={Yu, Sixia and Bierbrauer, Jürgen and Dong, Ying and Chen, Qing and Oh, C. H.}, - journal={IEEE Transactions on Information Theory}, - title={All the Stabilizer Codes of Distance 3}, + journal={IEEE Transactions on Information Theory}, + title={All the Stabilizer Codes of Distance 3}, year={2013}, volume={59}, number={8}, @@ -250,4 +250,4 @@ @article{Chao2017QuantumEC 050502 }, url={https://api.semanticscholar.org/CorpusID:206314271} -} \ No newline at end of file +} From a753f32219b35e9698ddc23cddccfcded27f94ad Mon Sep 17 00:00:00 2001 From: Fe-r-oz Date: Sat, 16 Mar 2024 22:39:19 +0500 Subject: [PATCH 115/121] undoing whitespaces --- test/test_ecc_syndromes.jl | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/test_ecc_syndromes.jl b/test/test_ecc_syndromes.jl index 1b80f3cca..d9fe509db 100644 --- a/test/test_ecc_syndromes.jl +++ b/test/test_ecc_syndromes.jl @@ -19,8 +19,6 @@ codes = [ Toric(8,8), ] -## - function pframe_naive_vs_shor_syndrome(code) ecirc = naive_encoding_circuit(code) naive_scirc, naive_ancillaries = naive_syndrome_circuit(code) @@ -61,4 +59,4 @@ end for c in codes pframe_naive_vs_shor_syndrome(c) end -end \ No newline at end of file +end From e55dc19a0bf3d747a465542b3647913d373350ec Mon Sep 17 00:00:00 2001 From: Fe-r-oz Date: Sat, 16 Mar 2024 23:15:29 +0500 Subject: [PATCH 116/121] minor modification --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8bb53e67e..6a1b4b0d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ # News +## v0.8.23 - 2024-03-16 + +- Implemented the first family of non-CSS [[2^j, 2^j - j - 2, 3]] Gottesman codes, also known as [[2^j, 2^j - j - 2, 3]] quantum Hamming codes + ## v0.8.22 - 2024-03-15 - Bump the `PyQDecoders` dependency, switching to `PythonCall` behind the scenes for reliability. From 9a48cb270061c9f5129612bb487558a746c5e0d0 Mon Sep 17 00:00:00 2001 From: Stefan Krastanov Date: Sat, 16 Mar 2024 15:55:41 -0400 Subject: [PATCH 117/121] cleanup --- CHANGELOG.md | 9 +- docs/src/references.bib | 102 +++++++++--------- src/ecc/ECC.jl | 2 +- .../codes/{gottesmancode.jl => gottesman.jl} | 13 +-- test/test_ecc_decoder_all_setups.jl | 7 +- test/test_ecc_syndromes.jl | 2 + 6 files changed, 63 insertions(+), 72 deletions(-) rename src/ecc/codes/{gottesmancode.jl => gottesman.jl} (52%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 820e8a0db..7251584ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,14 +6,9 @@ # News -## v0.8.23 - 2024-03-16 - -- Implemented the first family of non-CSS [[2^j, 2^j - j - 2, 3]] Gottesman codes, also known as [[2^j, 2^j - j - 2, 3]] quantum Hamming codes - -## v0.8.22 - 2024-03-15 -** (Add details from remote branch changes for v0.8.21)** -## v0.8.21 - 2024-03-15 +## v0.8.21 - 2024-03-16 +- Implemented the Gottesman code family, also known as [[2^j, 2^j - j - 2, 3]] quantum Hamming codes. - Bump the `PyQDecoders` dependency, switching to `PythonCall` behind the scenes for reliability. - Bump the `LDPCDecoders` dependency. diff --git a/docs/src/references.bib b/docs/src/references.bib index f65d0e245..d968305ff 100644 --- a/docs/src/references.bib +++ b/docs/src/references.bib @@ -1,50 +1,3 @@ -@article{mackay2004sparse, - title={Sparse-graph codes for quantum error correction}, - author={MacKay, David JC and Mitchison, Graeme and McFadden, Paul L}, - journal={IEEE Transactions on Information Theory}, - volume={50}, - number={10}, - pages={2315--2330}, - year={2004}, - publisher={IEEE}, - doi={10.1109/TIT.2004.834737} -} - -@article{calderbank1998quantum, - title={Quantum error correction via codes over GF (4)}, - author={Calderbank, A Robert and Rains, Eric M and Shor, PM and Sloane, Neil JA}, - journal={IEEE Transactions on Information Theory}, - volume={44}, - number={4}, - pages={1369--1387}, - year={1998}, - publisher={IEEE}, - doi={10.1109/18.681315} -} - -@inproceedings{steane2007tutorial, - title={A tutorial on quantum error correction}, - author={Steane, Andrew M}, - booktitle={PROCEEDINGS-INTERNATIONAL SCHOOL OF PHYSICS ENRICO FERMI}, - volume={162}, - pages={1}, - year={2007}, - organization={IOS Press; Ohmsha; 1999}, - doi={10.3254/978-1-61499-018-5-1} -} - -@article{wilde2009logical, - title={Logical operators of quantum codes}, - author={Wilde, Mark M}, - journal={Physical Review A}, - volume={79}, - number={6}, - pages={062322}, - year={2009}, - publisher={APS}, - doi={10.1103/PhysRevA.79.062322} -} - % The basis of the tableaux algorithm @inproceedings{gottesman1998heisenberg, @@ -167,6 +120,18 @@ @article{hein2006entanglement year={2006} } +@article{wilde2009logical, + title={Logical operators of quantum codes}, + author={Wilde, Mark M}, + journal={Physical Review A}, + volume={79}, + number={6}, + pages={062322}, + year={2009}, + publisher={APS}, + doi={10.1103/PhysRevA.79.062322} +} + % Encoding circuits @article{cleve1997efficient, @@ -226,9 +191,44 @@ @article{nahum2017quantum year = {2017} } -% Key details about [[8, 3, 3]] stabilizer construction via alternative approach +% codes + +@article{mackay2004sparse, + title={Sparse-graph codes for quantum error correction}, + author={MacKay, David JC and Mitchison, Graeme and McFadden, Paul L}, + journal={IEEE Transactions on Information Theory}, + volume={50}, + number={10}, + pages={2315--2330}, + year={2004}, + publisher={IEEE}, + doi={10.1109/TIT.2004.834737} +} -@article{6506105, +@article{calderbank1998quantum, + title={Quantum error correction via codes over GF (4)}, + author={Calderbank, A Robert and Rains, Eric M and Shor, PM and Sloane, Neil JA}, + journal={IEEE Transactions on Information Theory}, + volume={44}, + number={4}, + pages={1369--1387}, + year={1998}, + publisher={IEEE}, + doi={10.1109/18.681315} +} + +@inproceedings{steane2007tutorial, + title={A tutorial on quantum error correction}, + author={Steane, Andrew M}, + booktitle={PROCEEDINGS-INTERNATIONAL SCHOOL OF PHYSICS ENRICO FERMI}, + volume={162}, + pages={1}, + year={2007}, + organization={IOS Press; Ohmsha; 1999}, + doi={10.3254/978-1-61499-018-5-1} +} + +@article{yu2013all, author={Yu, Sixia and Bierbrauer, Jürgen and Dong, Ying and Chen, Qing and Oh, C. H.}, journal={IEEE Transactions on Information Theory}, title={All the Stabilizer Codes of Distance 3}, @@ -240,7 +240,7 @@ @article{6506105 doi={10.1109/TIT.2013.2259138} } -@article{Chao2017QuantumEC, +@article{chao2018quantum, title={Quantum Error Correction with Only Two Extra Qubits.}, author={Rui Chao and Ben W Reichardt}, journal={Physical review letters}, @@ -250,4 +250,4 @@ @article{Chao2017QuantumEC 050502 }, url={https://api.semanticscholar.org/CorpusID:206314271} -} +} \ No newline at end of file diff --git a/src/ecc/ECC.jl b/src/ecc/ECC.jl index 088b19d0b..17c280862 100644 --- a/src/ecc/ECC.jl +++ b/src/ecc/ECC.jl @@ -334,5 +334,5 @@ include("codes/steanecode.jl") include("codes/shorcode.jl") include("codes/clevecode.jl") include("codes/toric.jl") -include("codes/gottesmancode.jl") +include("codes/gottesman.jl") end #module diff --git a/src/ecc/codes/gottesmancode.jl b/src/ecc/codes/gottesman.jl similarity index 52% rename from src/ecc/codes/gottesmancode.jl rename to src/ecc/codes/gottesman.jl index 8c0eda3c6..ab54c3196 100644 --- a/src/ecc/codes/gottesmancode.jl +++ b/src/ecc/codes/gottesman.jl @@ -1,18 +1,13 @@ -"""This class implements the family of [[2^j, 2^j - j - 2, 3]] Gottesman codes, also known as [[2^j, 2^j - j - 2, 3]] quantum Hamming codes, as described in Gottesman's 1997 PhD thesis on 'Stabilizer Codes and Quantum Error Correction' [Gottesman1997](@cite). +"""The family of `[[2ʲ, 2ʲ - j - 2, 3]]` Gottesman codes, also known as quantum Hamming codes, as described in [Gottesman's 1997 PhD thesis](@cite Gottesman1997). -Key details for the [[8, 3, 3]] code when j = 3 using Stabilizer Formalism: -- [6506105](@cite) utilizes an explicit construction method for the stabilizer generators. The remaining m generators, apart from Mx and Mz, are constructed using the check matrix [Hm|AmHm], where Hm = [c0, c1, ..., c^2m − 1]. Each column ck (for k = 0, 1, ..., 2^m − 1) represents a binary vector corresponding to the integer k. Also, Am refers to any invertible m × m matrix devoid of fixed points such that Am​.s ≠ 0 and Am.s ≠ s for all s ∈ F₂ᵐ. -- [Chao2017QuantumEC](@cite) introduces alternative stabilizer generators for the [[8, 3, 3]] code. It identifies permutations effective for all stabilizer generators except for X^⊗8 and Z^⊗8. However, these can be replaced with XXYZIYZI and ZZIXYIXY, respectively. The stabilizer generators are permuted to achieve desired properties, reflecting an alternative approach to constructing the stabilizer code. +You might be interested in consulting [yu2013all](@cite) and [chao2018quantum](@cite) as well. -Notes: -- This implementation adopts the Gottesman Notation for the [[8, 3, 3]] stabilizer code as depicted in Table 3.3 on Page 22 on the Gottesman's PhD thesis. Additionally, for j = 4, our [[16, 10, 3]] stabilizer code stemming from QHamming(4) can be cross-verified from Table 8.1 on Page 91 as well [Gottesman1997](@cite). -- The differences between [6506105](@cite), [Chao2017QuantumEC](@cite), and [Gottesman1997](@cite) primarily lie in the choice of stabilizer generators and their permutations for the [[8, 3, 3]] stabilizer code. +The ECC Zoo has an [entry for this family](https://errorcorrectionzoo.org/c/quantum_hamming) """ - struct Gottesman <: AbstractECC j::Int 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") + (j >= 3 && j < 21) || error("In `Gottesman(j)`, `j` must be ≥ 3 in order to obtain a valid code and < 21 to remain tractable") new(j) end end diff --git a/test/test_ecc_decoder_all_setups.jl b/test/test_ecc_decoder_all_setups.jl index e51c53e41..e23f3ed77 100644 --- a/test/test_ecc_decoder_all_setups.jl +++ b/test/test_ecc_decoder_all_setups.jl @@ -12,8 +12,8 @@ import LDPCDecoders Perfect5(), Cleve8(), Gottesman(3), - Gottesman(4), - #Gottesman(5), performs poorly + #Gottesman(4), bad threshold + #Gottesman(5), bad threshold ] noise = 0.001 @@ -31,7 +31,7 @@ import LDPCDecoders #@show c #@show s #@show e - @assert max(e...) < noise/3 + @assert max(e...) < noise/4 end end end @@ -41,7 +41,6 @@ end @testset "belief prop decoders, good for small codes" begin codes = [ - #Gottesman(3), Gottesman is a non-CSS code. BP works for CSS codes. ] noise = 0.001 diff --git a/test/test_ecc_syndromes.jl b/test/test_ecc_syndromes.jl index d9fe509db..e12fe7d0e 100644 --- a/test/test_ecc_syndromes.jl +++ b/test/test_ecc_syndromes.jl @@ -19,6 +19,8 @@ codes = [ Toric(8,8), ] +## + function pframe_naive_vs_shor_syndrome(code) ecirc = naive_encoding_circuit(code) naive_scirc, naive_ancillaries = naive_syndrome_circuit(code) From a2af3035ce46938682b6cc737c8011364897037a Mon Sep 17 00:00:00 2001 From: Stefan Krastanov Date: Sun, 17 Mar 2024 16:29:24 -0400 Subject: [PATCH 118/121] cleanup --- CHANGELOG.md | 2 +- docs/src/references.bib | 13 +++++- src/ecc/codes/gottesman.jl | 87 +++++++++----------------------------- test/runtests.jl | 1 + test/test_ecc_gottesman.jl | 21 +++++++++ 5 files changed, 55 insertions(+), 69 deletions(-) create mode 100644 test/test_ecc_gottesman.jl diff --git a/CHANGELOG.md b/CHANGELOG.md index 7251584ad..e323cdc94 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ # News -## v0.8.21 - 2024-03-16 +## v0.8.21 - 2024-03-17 - Implemented the Gottesman code family, also known as [[2^j, 2^j - j - 2, 3]] quantum Hamming codes. - Bump the `PyQDecoders` dependency, switching to `PythonCall` behind the scenes for reliability. diff --git a/docs/src/references.bib b/docs/src/references.bib index d968305ff..4bdfce7f9 100644 --- a/docs/src/references.bib +++ b/docs/src/references.bib @@ -250,4 +250,15 @@ @article{chao2018quantum 050502 }, url={https://api.semanticscholar.org/CorpusID:206314271} -} \ No newline at end of file +} + +@article{gottesman1996class, + title={Class of quantum error-correcting codes saturating the quantum Hamming bound}, + author={Gottesman, Daniel}, + journal={Physical Review A}, + volume={54}, + number={3}, + pages={1862}, + year={1996}, + publisher={APS} +} diff --git a/src/ecc/codes/gottesman.jl b/src/ecc/codes/gottesman.jl index ab54c3196..b23551882 100644 --- a/src/ecc/codes/gottesman.jl +++ b/src/ecc/codes/gottesman.jl @@ -1,4 +1,4 @@ -"""The family of `[[2ʲ, 2ʲ - j - 2, 3]]` Gottesman codes, also known as quantum Hamming codes, as described in [Gottesman's 1997 PhD thesis](@cite Gottesman1997). +"""The family of `[[2ʲ, 2ʲ - j - 2, 3]]` Gottesman codes, also known as quantum Hamming codes, as described in [Gottesman's 1997 PhD thesis](@cite Gottesman1997) and in [gottesman1996class](@cite). You might be interested in consulting [yu2013all](@cite) and [chao2018quantum](@cite) as well. @@ -15,73 +15,26 @@ 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) - - Hx[1, :] .= true - 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 - end - Hx[3, cols] = Hx[3, cols] == 0 ? 1 : 0 - for col in 1:cols - 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)) - end - Hx[end, [end-1, end]] .= [0, 1] - - else - for a in 1:cols - Hx[3, a] = (a == 0) || (a % 2 == 0) - end - for row in 4:rows - 1 - for col in 1:cols - k = row - 3 - m = 2^(c.j - k) - n = 2^(c.j - k) - if (col - 1) % (m + n) < m - if col % 2 == 0 - Hx[row, col] = 1 - else - Hx[row, col] = 0 - end - else - if col % 2 == 0 - Hx[row, col] = 0 - else - Hx[row, col] = 1 - end - end - end - end - - for a in 1:cols - Hx[rows, a] = (a % 4 == 0) || (a % 4 == 1) ? 0 : 1 - end + j = c.j + s = j+2 + n = 2^j + + H = zero(Stabilizer, s, n) + for i in 1:n + H[1, i] = (true, false) + H[2, i] = (false, true) end - - Hz[1, :] .= false - 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 + for i in 0:n-1 # column of H, corresponds to a single qubit error that is detectable) + Xⁱ = i + Zⁱ = i÷2 + jeven = j%2 == 0 + ieven = i%2 == 0 + if (jeven && ieven) || (!jeven && ieven && i < n÷2) || (!jeven && !ieven && i ≥ n÷2) + Zⁱ = ~Zⁱ + end + for b in 0:j-1 # which check to consider (row of H), also which bit to extract + H[s-b,i+1] = isone((Zⁱ>>b)&0x1), isone((Xⁱ>>b)&0x1) end end - - extended_Hx = Matrix{Bool}(Hz) - extended_Hz = Matrix{Bool}(Hx) - - num_rows = size(Hx, 1) - - fill_array = fill(UInt8(0), num_rows) - Stabilizer(fill_array, extended_Hz, extended_Hx) + H end diff --git a/test/runtests.jl b/test/runtests.jl index c26eaa33c..ef4dd4b94 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -62,6 +62,7 @@ end @doset "ecc_decoder_all_setups" @doset "ecc_encoding" @doset "ecc_syndromes" +@doset "ecc_gottesman" @doset "precompile" @doset "pauliframe" @doset "allocations" diff --git a/test/test_ecc_gottesman.jl b/test/test_ecc_gottesman.jl new file mode 100644 index 000000000..e290a87f4 --- /dev/null +++ b/test/test_ecc_gottesman.jl @@ -0,0 +1,21 @@ +using Test +using QuantumClifford +using QuantumClifford: mul_left! +using QuantumClifford.ECC +using QuantumClifford.ECC: AbstractECC + + +@testset "Gottesman codes should correct all single-qubit errors" begin + for j in 3:12 + H = parity_checks(Gottesman(j)) + syndromes = Set([]) # the set automatically removes repeated entries + for error_type in (single_x, single_y, single_z) + for bit_index in 1:nqubits(H) + syndrome = comm(H, error_type(nqubits(H), bit_index)) + @test any(==(0x1), syndrome) # checking the syndrome is not trivially zero + push!(syndromes, syndrome) + end + end + @test length(syndromes) == 3*nqubits(H) + end +end From e1a5a8de1c6635b6c4b0a61f45b586a03bdb2423 Mon Sep 17 00:00:00 2001 From: Stefan Krastanov Date: Sun, 17 Mar 2024 16:34:51 -0400 Subject: [PATCH 119/121] add refereces in markdown docs --- docs/src/references.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/src/references.md b/docs/src/references.md index db6d50331..80eff2a0b 100644 --- a/docs/src/references.md +++ b/docs/src/references.md @@ -28,6 +28,13 @@ For circuit construction routines (for stabilizer measurements for a given code) - [grassl2002algorithmic](@cite) - [grassl2011variations](@cite) +For code construction routines: +- [cleve1997efficient](@cite) +- [gottesman1996class](@cite) +- [Gottesman1997](@cite) +- [yu2013all](@cite) +- [chao2018quantum](@cite) + # References ```@bibliography From b47a8520102046f963754cecc40e599d804fc9af Mon Sep 17 00:00:00 2001 From: Stefan Krastanov Date: Sun, 17 Mar 2024 16:51:15 -0400 Subject: [PATCH 120/121] fix gottesman reference --- src/ecc/codes/gottesman.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ecc/codes/gottesman.jl b/src/ecc/codes/gottesman.jl index b23551882..cc6cc16a9 100644 --- a/src/ecc/codes/gottesman.jl +++ b/src/ecc/codes/gottesman.jl @@ -1,4 +1,4 @@ -"""The family of `[[2ʲ, 2ʲ - j - 2, 3]]` Gottesman codes, also known as quantum Hamming codes, as described in [Gottesman's 1997 PhD thesis](@cite Gottesman1997) and in [gottesman1996class](@cite). +"""The family of `[[2ʲ, 2ʲ - j - 2, 3]]` Gottesman codes, also known as quantum Hamming codes, as described in [Gottesman's 1997 PhD thesis](@cite gottesman1997stabilizer) and in [gottesman1996class](@cite). You might be interested in consulting [yu2013all](@cite) and [chao2018quantum](@cite) as well. From 96df6a83cf0671a08a1329db2664909e028cb867 Mon Sep 17 00:00:00 2001 From: Stefan Krastanov Date: Sun, 17 Mar 2024 18:06:58 -0400 Subject: [PATCH 121/121] fix gottesman reference --- docs/src/references.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/references.md b/docs/src/references.md index 80eff2a0b..8dde5910c 100644 --- a/docs/src/references.md +++ b/docs/src/references.md @@ -31,7 +31,7 @@ For circuit construction routines (for stabilizer measurements for a given code) For code construction routines: - [cleve1997efficient](@cite) - [gottesman1996class](@cite) -- [Gottesman1997](@cite) +- [gottesman1997stabilizer](@cite) - [yu2013all](@cite) - [chao2018quantum](@cite)