Skip to content

Commit c64492b

Browse files
royessKrastanov
andauthored
Concatenated quantum code (#289)
--------- Co-authored-by: Stefan Krastanov <[email protected]>
1 parent c1d115d commit c64492b

File tree

7 files changed

+70
-6
lines changed

7 files changed

+70
-6
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55

66
# News
77

8-
## v0.9.4 - dev
8+
## v0.9.4 - 2024-06-14
99

10+
- Addition of a constructor for concatenated quantum codes -- `Concat`.
11+
- Addition of multiple unexported classical code constructors.
1012
- Gate errors are now conveniently supported by the various ECC benchmark setups in the `ECC` module.
1113
- Remove printing of spurious debug info from the PyBP decoder.
1214
- Significant improvements to the low-level circuit compiler (the sumtype compactifier), leading to faster Pauli frame simulation of noisy circuits.

docs/src/references.bib

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,4 +378,11 @@ @book{error2024lin
378378
author={Lin, Shu and Costello, Daniel},
379379
year={2024},
380380
publisher={Pearson}
381-
}
381+
}
382+
383+
@article{knill1996concatenated,
384+
title={Concatenated quantum codes},
385+
author={Knill, Emanuel and Laflamme, Raymond},
386+
journal={arXiv preprint quant-ph/9608012},
387+
year={1996}
388+
}

docs/src/references.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ For quantum code construction routines:
3636
- [chao2018quantum](@cite)
3737
- [kitaev2003fault](@cite)
3838
- [fowler2012surface](@cite)
39+
- [knill1996concatenated](@cite)
3940

4041
For classical code construction routines:
4142
- [muller1954application](@cite)

src/ecc/ECC.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ using DocStringExtensions
88
using Combinatorics: combinations
99
using SparseArrays: sparse
1010
using Statistics: std
11-
using Nemo: ZZ, residue_ring, matrix, finite_field, GF, minpoly, coeff, lcm, FqPolyRingElem, FqFieldElem, is_zero, degree, defining_polynomial, is_irreducible
11+
using Nemo: ZZ, residue_ring, matrix, finite_field, GF, minpoly, coeff, lcm, FqPolyRingElem, FqFieldElem, is_zero, degree, defining_polynomial, is_irreducible
1212

1313
abstract type AbstractECC end
1414

@@ -19,7 +19,7 @@ export parity_checks, parity_checks_x, parity_checks_z, iscss,
1919
RepCode,
2020
CSS,
2121
Shor9, Steane7, Cleve8, Perfect5, Bitflip3,
22-
Toric, Gottesman, Surface,
22+
Toric, Gottesman, Surface, Concat,
2323
evaluate_decoder,
2424
CommutationCheckECCSetup, NaiveSyndromeECCSetup, ShorSyndromeECCSetup,
2525
TableDecoder,
@@ -49,6 +49,11 @@ function parity_checks_z(code::AbstractECC)
4949
throw(lazy"Codes of type $(typeof(code)) do not have separate X and Z parity checks, either because they are not a CSS code and thus inherently do not have separate checks, or because its separate checks are not yet implemented in this library.")
5050
end
5151

52+
53+
"""Check if the code is CSS.
54+
55+
Return `nothing` if unknown from the type.
56+
"""
5257
function iscss(::Type{T}) where T<:AbstractECC
5358
return false
5459
end
@@ -353,6 +358,7 @@ include("codes/clevecode.jl")
353358
include("codes/toric.jl")
354359
include("codes/gottesman.jl")
355360
include("codes/surface.jl")
361+
include("codes/concat.jl")
356362
include("codes/classical/reedmuller.jl")
357363
include("codes/classical/bch.jl")
358364
end #module

src/ecc/codes/concat.jl

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
"""
2+
`Concat(c₁, c₂)` is a code concatenation of two quantum codes [knill1996concatenated](@cite).
3+
4+
The inner code c₁ and the outer code c₂.
5+
The construction is the following: replace each qubit in code c₂ with logical qubits encoded by code c₁.
6+
The resulting code will have `n = n₁ × n₂` qubits and `k = k₁ × k₂` logical qubits.
7+
"""
8+
struct Concat <: AbstractECC
9+
c₁::AbstractECC
10+
c₂::AbstractECC
11+
end
12+
13+
function parity_checks(c::Concat)
14+
c₁ = c.c₁
15+
c₂ = c.c₂
16+
k₁ = code_k(c₁)
17+
n₁ = code_n(c₁)
18+
n₂ = code_n(c₂)
19+
s₁ = code_s(c₁)
20+
s₂ = code_s(c₂)
21+
inner_checks = Stabilizer(vcat([embed(n₁ * n₂, 1+(i-1)*n₁:i*n₁, parity_checks(c₁)[j]) for i in 1:n₂ for j in 1:s₁])) # parity checks of c₁ on each qubit of c₂
22+
h₂ = parity_matrix(c₂)
23+
phases₂ = phases(parity_checks(c₂))
24+
h_logx₁ = stab_to_gf2(logx_ops(c₁))
25+
phases_logx₁ = phases(logx_ops(c₁))
26+
h_logz₁ = stab_to_gf2(logz_ops(c₁))
27+
phases_logz₁ = phases(logz_ops(c₁))
28+
# parity checks of c₂ with qubits repalced with logical qubits of c₁
29+
outer_check_h = transpose(hcat([vcat(
30+
kron(h₂[i, 1:end÷2], h_logx₁[j, 1:end÷2]) .⊻ kron(h₂[i, end÷2+1:end], h_logz₁[j, 1:end÷2]), # X part
31+
kron(h₂[i, 1:end÷2], h_logx₁[j, end÷2+1:end]) .⊻ kron(h₂[i, end÷2+1:end], h_logz₁[j, end÷2+1:end]) # Z part
32+
) for i in 1:s₂ for j in 1:k₁]...))
33+
outer_check_phase = [UInt8(sum(h₂[i, 1:end÷2] * phases_logx₁[j]) + sum(h₂[i, end÷2+1:end] * phases_logz₁[j]) + phases₂[i]) & 0x3 for i in 1:s₂ for j in 1:k₁]
34+
outer_checks = Stabilizer(outer_check_phase, outer_check_h)
35+
vcat(inner_checks, outer_checks)
36+
end
37+
38+
code_n(c::Concat) = code_n(c.c₁) * code_n(c.c₂)
39+
40+
code_k(c::Concat) = code_k(c.c₁) * code_k(c.c₂)
41+
42+
function iscss(c::Concat)
43+
if iscss(c.c₁) && iscss(c.c₂)
44+
true
45+
end
46+
return nothing # if c.c₁ or c.c₂ are non-CSS; in this case, `Concat(c₁, c₂)` can still be CSS
47+
end

test/test_ecc_base.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ const code_instance_args = Dict(
99
Toric => [(3,3), (4,4), (3,6), (4,3), (5,5)],
1010
Surface => [(3,3), (4,4), (3,6), (4,3), (5,5)],
1111
Gottesman => [3, 4, 5],
12-
CSS => (c -> (parity_checks_x(c), parity_checks_z(c))).([Shor9(), Steane7(), Toric(4,4)])
12+
CSS => (c -> (parity_checks_x(c), parity_checks_z(c))).([Shor9(), Steane7(), Toric(4,4)]),
13+
Concat => [(Perfect5(), Perfect5()), (Perfect5(), Steane7()), (Steane7(), Cleve8()), (Toric(2,2), Shor9())],
1314
)
1415

1516
function all_testablable_code_instances(;maxn=nothing)

test/test_ecc_codeproperties.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ end
2222
@testset "is CSS" begin
2323
for code in all_testablable_code_instances()
2424
H = parity_checks(code)
25-
@test iscss(code) == is_css_matrix(H)
25+
@test iscss(code) in (is_css_matrix(H), nothing)
2626
end
2727
end
2828

0 commit comments

Comments
 (0)