Skip to content

Commit

Permalink
Surface code (QuantumSavory#246)
Browse files Browse the repository at this point in the history

---------

Co-authored-by: Stefan Krastanov <[email protected]>
  • Loading branch information
royess and Krastanov authored Mar 27, 2024
1 parent 7be5818 commit e051bd1
Show file tree
Hide file tree
Showing 10 changed files with 144 additions and 12 deletions.
8 changes: 3 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@

# News

## v0.9.2 - 2024-03-22

- Implemented the classical Reed-Muller code

## v0.9.1 - 2024-03-20
## v0.9.1 - dev

- Implemented `iscss` function to identify whether a given code is known to be a CSS (Calderbank-Shor-Steane) code.
- Implemented the classical Reed-Muller code
- Added the surface code to the ECC module.

## v0.9.0 - 2024-03-19

Expand Down
30 changes: 29 additions & 1 deletion docs/src/references.bib
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,34 @@ @article{gottesman1996class
publisher={APS}
}

@article{kitaev2003fault,
title = {Fault-tolerant quantum computation by anyons},
volume = {303},
issn = {00034916},
url = {https://linkinghub.elsevier.com/retrieve/pii/S0003491602000180},
doi = {10.1016/S0003-4916(02)00018-0},
abstract = {A two-dimensional quantum system with anyonic excitations can be considered as a quantum computer. Unitary transformations can be performed by moving the excitations around each other. Measurements can be performed by joining excitations in pairs and observing the result of fusion. Such computation is fault-tolerant by its physical nature.},
pages = {2--30},
number = {1},
journaltitle = {Annals of Physics},
shortjournal = {Annals of Physics},
author = {Kitaev, A.Yu.}
}

@article{fowler2012surface,
title = {Surface codes: Towards practical large-scale quantum computation},
volume = {86},
issn = {1050-2947, 1094-1622},
url = {https://link.aps.org/doi/10.1103/PhysRevA.86.032324},
doi = {10.1103/PhysRevA.86.032324},
shorttitle = {Surface codes},
pages = {032324},
number = {3},
journaltitle = {Physical Review A},
shortjournal = {Phys. Rev. A},
author = {Fowler, Austin G. and Mariantoni, Matteo and Martinis, John M. and Cleland, Andrew N.},
}

@article{muller1954application,
title={Application of Boolean algebra to switching circuit design and to error detection},
author={Muller, David E},
Expand Down Expand Up @@ -308,4 +336,4 @@ @book{djordjevic2021quantum
author={Djordjevic, Ivan B},
year={2021},
publisher={Academic Press}
}
}
2 changes: 2 additions & 0 deletions docs/src/references.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ For quantum code construction routines:
- [gottesman1997stabilizer](@cite)
- [yu2013all](@cite)
- [chao2018quantum](@cite)
- [kitaev2003fault](@cite)
- [fowler2012surface](@cite)

For classical code construction routines:
- [muller1954application](@cite)
Expand Down
3 changes: 2 additions & 1 deletion src/ecc/ECC.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export parity_checks, parity_checks_x, parity_checks_z, iscss,
RepCode,
CSS,
Shor9, Steane7, Cleve8, Perfect5, Bitflip3,
Toric, Gottesman,
Toric, Gottesman, Surface,
evaluate_decoder,
CommutationCheckECCSetup, NaiveSyndromeECCSetup, ShorSyndromeECCSetup,
TableDecoder,
Expand Down Expand Up @@ -345,5 +345,6 @@ include("codes/shorcode.jl")
include("codes/clevecode.jl")
include("codes/toric.jl")
include("codes/gottesman.jl")
include("codes/surface.jl")
include("codes/classical/reedmuller.jl")
end #module
60 changes: 60 additions & 0 deletions src/ecc/codes/surface.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
"""The planar surface code refers to the code [kitaev2003fault](@cite) in a 2D lattice with open boundaries.
Illustration of a 3×2 surface code, where qubits are located on the edges:
```
|---1--(Z)--2---|---3---|
| (X) 7 8 o
|---4---|---5---|---6---|
| o o o
| | | |
```
The surface code has open boundary conditions, unlike the toric code. To this end, we remove qubits (denoted by "o") and parity checks on the right and bottom sides.
Faces like `(1,4,7)` have X checks, and crosses like `(1,2,7)` have Z checks. Due to the removal of the bottom and right sides, we have some 3-qubit checks on the boundaries.
```jldoctest
julia> parity_checks(Surface(3,2))
+ X__X__X_
+ _X__X_XX
+ __X__X_X
+ ZZ____Z_
+ _ZZ____Z
+ ___ZZ_Z_
+ ____ZZ_Z
```
More information can be seen in [fowler2012surface](@cite).
"""
struct Surface <: AbstractECC
dx::Int
dz::Int
end

function iscss(::Type{Surface})
return true
end

code_n(c::Surface) = 2*c.dx*c.dz - c.dx -c.dz + 1

function parity_checks_xz(c::Surface)
tc = Toric(c.dx, c.dz)
hx, hz = parity_checks_xz(tc)
n = code_n(tc)
nchecks = c.dx*c.dz - 1
# remove qubits on the right and bottom sides from the toric code
removed_qubit_indices = vcat(
c.dx*(c.dz+1):c.dx:c.dx*(2*c.dz-1), # right side
c.dx*(2*c.dz-1)+1:2*c.dx*c.dz) # bottom side
qubit_indices = setdiff(1:n, removed_qubit_indices)
# also remove the checks on the right and bottom sides
x_check_indices = setdiff(1:nchecks, nchecks-c.dx+2:nchecks)
z_check_indices = setdiff(1:nchecks, c.dx:c.dx:nchecks)
hx[x_check_indices,qubit_indices], hz[z_check_indices,qubit_indices]
end

parity_checks_x(c::Surface) = parity_checks_xz(c)[1]
parity_checks_z(c::Surface) = parity_checks_xz(c)[2]

parity_checks(c::Surface) = parity_checks(CSS(parity_checks_xz(c)...))
27 changes: 26 additions & 1 deletion src/ecc/codes/toric.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,29 @@
"""The Toric code."""
"""The Toric code [kitaev2003fault](@cite).
Illustration of a 2x2 toric code, where qubits are located on the edges:
```
|--1-(Z)-2--|
| (X) 5 6
|--3--|--4--|
| 7 8
| | |
```
It is important to note that the toric code has periodic boundary conditions, which means that the top and bottom sides are essentially glued together, as are the left and right sides.
Faces like `(1,3,5,6)` have X checks, and crosses like `(1,2,5,7)` have Z checks.
```jldoctest
julia> parity_checks(Toric(2,2))
+ X_X_XX__
+ _X_XXX__
+ X_X___XX
+ ZZ__Z_Z_
+ ZZ___Z_Z
+ __ZZZ_Z_
```
"""
struct Toric <: AbstractECC
dx::Int
dz::Int
Expand Down
6 changes: 4 additions & 2 deletions test/test_ecc_decoder_all_setups.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import LDPCDecoders
Shor9(),
Perfect5(),
Cleve8(),
Gottesman(3),
Gottesman(3)
#Gottesman(4), bad threshold
#Gottesman(5), bad threshold
]
Expand Down Expand Up @@ -76,7 +76,9 @@ import LDPCDecoders
@testset "matching decoder, good as long as column weight of the code is limited" begin
codes = [
Toric(8,8),
Toric(9,9)
Toric(9,9),
Surface(8,8),
Surface(9,9)
]

noise = 0.01
Expand Down
4 changes: 4 additions & 0 deletions test/test_ecc_encoding.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ using QuantumClifford.ECC
:(Toric(3,6)),
:(Toric(6,4)),
:(Toric(8,8)),
:(Surface(3,3)),
:(Surface(3,6)),
:(Surface(6,4)),
:(Surface(8,8)),
fill(:(random_stabilizer(5,7)), 100)...
]

Expand Down
14 changes: 12 additions & 2 deletions test/test_ecc_iscss.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@ using QuantumClifford
using QuantumClifford.ECC
using QuantumClifford.ECC: AbstractECC

known_all_codes = [
Shor9(),
Steane7(),
Gottesman(3),
Cleve8(),
Perfect5(),
Toric(8,8),
Surface(8,8),
CSS([0 1 1 0; 1 1 0 0], [1 1 1 1]),
Bitflip3()
]

function is_css_matrix(H)
nrows, ncols = size(H)
for i in 1:nrows
Expand All @@ -17,8 +29,6 @@ function is_css_matrix(H)
return true
end

known_all_codes = [Shor9(), Steane7(), Gottesman(3), Cleve8(), Perfect5(), Toric(8,8), CSS([0 1 1 0; 1 1 0 0], [1 1 1 1]), Bitflip3()]

@testset "is CSS" begin
for code in known_all_codes
H = parity_checks(code)
Expand Down
2 changes: 2 additions & 0 deletions test/test_ecc_syndromes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ codes = [
Toric(3,6),
Toric(6,4),
Toric(8,8),
Surface(4,6),
Surface(8,8)
]

##
Expand Down

0 comments on commit e051bd1

Please sign in to comment.