Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Color codes support 1 #361

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

amicciche
Copy link
Member

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!

@Krastanov
Copy link
Member

related to #360

@Krastanov Krastanov self-requested a review September 26, 2024 16:46
Copy link
Member

@Krastanov Krastanov left a 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:

return true
end

"""From https://arxiv.org/abs/1108.5738 Fig. 2's caption:"""
Copy link
Member

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})
Copy link
Member

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
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment

Comment on lines +41 to +42
num_checks = (n-1)/2 |> Int
num_layers = (c.d-1)/2 |> Int
Copy link
Member

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)
Copy link
Member

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))
Copy link
Member

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"))
Copy link
Member

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"))
Copy link
Member

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
Copy link
Member

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")
Copy link
Member

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."""
Copy link
Member

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.

@Krastanov Krastanov marked this pull request as draft September 27, 2024 12:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants