-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Color codes support 1 #361
base: master
Are you sure you want to change the base?
Conversation
…ed by hand d=3,5,7,9, and 11
…e of the stabilizers for this code. A more complete commit will be coming in a few days
related to #360 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for submitting this, it is a very valuable addition!
There are few things to fix up:
- the CI failures (the spell checker and the changelog (you can just post the changelog update in a comment to avoid a merge conflict))
- a few style comments
- more substantially, this needs unit tests
- confirmations that
throw
happens in case in the future someone modifies the constructor ( in https://github.com/QuantumSavory/QuantumClifford.jl/blob/master/test/test_ecc_throws.jl ) - testing the properties of these codes by adding them in here: https://github.com/QuantumSavory/QuantumClifford.jl/blob/master/test/test_ecc_base.jl#L66 -- this file gets imported by other test files
- testing specifically their decoding with perfect matching decoders here https://github.com/QuantumSavory/QuantumClifford.jl/blob/master/test/test_ecc_decoder_all_setups.jl#L77 (if applicable)
- confirmations that
return true | ||
end | ||
|
||
"""From https://arxiv.org/abs/1108.5738 Fig. 2's caption:""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this docstring or turn it into a comment.
The way it is currently done, this will pop up in the documentation in the docstring for the general code_n
function, which does not seem to be the goal.
end | ||
|
||
"""Returns which qubits each stabilizer touches when given a parity check matrix. Useful for debugging/testing.""" | ||
function get_qubit_indices(matrix::Matrix{Bool}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be specific to color codes and it seems to be private. Change the name to reflect that, e.g. _colorcode_get_qubit_indices
Based on Fig. 2 of https://arxiv.org/abs/1108.5738""" | ||
function get_check_matrix(c::Triangular4_8_8) | ||
n = code_n(c) | ||
num_checks = (n-1)/2 |> Int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you know for a fact these will be integers, use ÷ not / (or div
if you do not like using unicode)
function get_check_matrix(c::Triangular4_8_8) | ||
n = code_n(c) | ||
num_checks = (n-1)/2 |> Int | ||
num_layers = (c.d-1)/2 |> Int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same comment
num_checks = (n-1)/2 |> Int | ||
num_layers = (c.d-1)/2 |> Int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
÷ (div), not /
return Stabilizer(vcat(matrix,zeros(Bool,num_checks,qubits)), vcat(zeros(Bool,num_checks,qubits), matrix)) | ||
end | ||
|
||
function get_check_matrix(c::Triangular6_6_6) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be a private helper meant to exist only for color codes. Change the name to reflect that (or just remove that function altogether and directly use parity_checks
)
matrix = get_check_matrix(c) | ||
|
||
num_checks, qubits = size(matrix) | ||
return Stabilizer(vcat(matrix,zeros(Bool,num_checks,qubits)), vcat(zeros(Bool,num_checks,qubits), matrix)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like it would be much simpler to do by writing something like parity_checks(CSS(matrix, matrix))
(as there is a general-purpose CSS type already in existence).
I am also leaning towards just putting the content of get_check_matrix
in here directly. The redirection seems unnecessary (especially if the simpler CSS(matrix,matrix)
expression is used)
d::Int | ||
function Triangular4_8_8(d) | ||
if d%2!=1 | ||
throw(DomainError("only odd distance trianglular color codes are allowed.\nRefer to https://arxiv.org/abs/1108.5738")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that it ends on a full stop, it seems like a sentence, so let's capitalize the first letter.
d::Int | ||
function Triangular6_6_6(d) | ||
if d%2!=1 | ||
throw(DomainError("only odd distance trianglular color codes are allowed.\nRefer to https://arxiv.org/abs/1108.5738")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that it ends on a full stop, it seems like a sentence, so let's capitalize the first letter.
abstract type TriangularCode <: ColorCode end | ||
|
||
"""Triangular code following the 4.8.8 tiling. Constructor take a distance d as input.""" | ||
struct Triangular4_8_8 <: TriangularCode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
darn, these underscores are a bit jarring... How about switching to Triangular488
- I know it will be weird if we ever implement patterns with double digits, but by then we might just have a more general-purpose constructor.
Same for the other code implemented here.
@@ -366,6 +366,7 @@ include("codes/gottesman.jl") | |||
include("codes/surface.jl") | |||
include("codes/concat.jl") | |||
include("codes/random_circuit.jl") | |||
include("codes/color_codes.jl") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, I forgot. The newly implemented codes should also be exported so that they are part of the public API of the library (see at the start of this file)
"""Planar color codes that encode a single logical qubit.""" | ||
abstract type TriangularCode <: ColorCode end | ||
|
||
"""Triangular code following the 4.8.8 tiling. Constructor take a distance d as input.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yet one more thing I forgot. This should have a [](@cite)
reference, that reference should be added to the bibtex file and to the listing of references in the "suggested readings" doc page.
This PR implements two infinite families of triangular planar color codes out of the three possible on triangular color codes, using https://arxiv.org/abs/1108.5738 as a main reference. I implemented the 4.8.8 and 6.6.6 tilings, for any odd distance the user may provide. A third possible tiling exists, however, to my knowledge, no relevant work has used the 4.6.12 tiling (perhaps weight 12 stabilizer checks seem a bit too difficult on a topological code?). Despite this, I'd be happy to add that functionality as well, if asked. I simply thought it would probably be a better use of time and resources to focus on other functionality before that code. Here is the error correction zoo page for the 4.6.12 code, and notice that according to its references, there hasn't been much mention of it in almost 15 years: https://errorcorrectionzoo.org/c/4612_color
Notably this PR addresses Step 1 and Step 2 of issue Color codes [$200], assuming that these two tilings of triangular color codes are sufficiently many. If not, I'd happily do some more reading and add more!