-
Notifications
You must be signed in to change notification settings - Fork 49
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
Naive Implementation of the Encoding Circuit #154
Changes from 5 commits
7f5bfbb
36d8133
e6dbb95
05e3c56
cd05fff
365553a
14604eb
2a0c94f
460a131
8f6265a
2e568de
4cdd2a6
cee2e31
18d505e
abba3b2
1c345f8
9939e6a
88b6d4b
5b9b0ef
4db5e8e
00a1465
eb224c9
ed698f3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -88,10 +88,105 @@ function logz_ops(c::AbstractECC) | |||
logicalzview(MixedDest) | ||||
end | ||||
|
||||
# TODO implement isdegenerate | ||||
|
||||
""" Check if the code is degenerate or not.""" | ||||
function is_degenerate(c::AbstractECC) | ||||
tableau = stab_to_gf2(parity_checks(c)) | ||||
n = code_n(c) | ||||
dictionary = Set() | ||||
for column in 1:2*n | ||||
temp = tableau[:, column] | ||||
if temp in dictionary | ||||
return true | ||||
else | ||||
push!(dictionary, temp) | ||||
end | ||||
end | ||||
return false | ||||
end | ||||
|
||||
"""The rank of the bimatrix of a code.""" | ||||
function rank(c::AbstractECC) | ||||
destab_gott = MixedDestabilizer(parity_checks(c), undoperm=false) | ||||
bimat = stab_to_gf2(stabilizerview(destab_gott)) | ||||
rank = 0 | ||||
for i in 1:code_s(c) | ||||
if bimat[i, i] == 1 | ||||
rank +=1 | ||||
end | ||||
end | ||||
return rank | ||||
end | ||||
|
||||
"""The standardized logical tableau of a code by [PhysRevA.56.76](@cite)""" | ||||
function standard_tab_gott(c::AbstractECC) | ||||
n, s, k, r = code_n(c), code_s(c), code_k(c), rank(c) | ||||
# The standard form is | ||||
# I A1 A2 | B C1 C2 | ||||
# 0 0 0 | D I E | ||||
# and we augment the following third line (for logical qubits) | ||||
# 0 E^T I | 0 0 0 | ||||
# Then we apply the gates line by line bottom up in accordance with the formalisms here: arXiv:quant-ph/9607030 | ||||
standard_tab = stab_to_gf2(stabilizerview(MixedDestabilizer(parity_checks(c), undoperm=false))) | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. at some point you have to undo the permutations of columns, otherwise your qubits are now reindexed from what the user was expecting, and great amount of confusion can ensue There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also, check this function, it seems to be doing most of what you need. QuantumClifford.jl/src/QuantumClifford.jl Line 514 in 5ab1f0f
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nope, I am wrong, it does not do everything you need, but might be a useful inspiration for how to write your code in a more simple way |
||||
for i in 1: k | ||||
# can we use canonicalize_gott for the entire mixedDestabilizer? (i.e. the stab + log parts = n rows) | ||||
augment = zeros(Int8, (1, 2*n)) | ||||
for j in 1:n | ||||
if j > r && j <= n - k | ||||
augment[j] = standard_tab[j, 2*n-k+i] # the corresponding column of E in E^T | ||||
elseif j == n-k+i | ||||
augment[j] = 1 | ||||
end | ||||
end | ||||
standard_tab = vcat(standard_tab, augment) | ||||
end | ||||
# Flipping the table so it has the same format as the papercode | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just use |
||||
res = zeros(Int8, (n, 2n)) | ||||
for i in 1:n | ||||
for j in 1:n | ||||
res[i, j] = standard_tab[n+1-j, n+1-i] | ||||
end | ||||
for j in n+1:2*n | ||||
res[i,j] = standard_tab[2*n+1-j, n+1-i] | ||||
end | ||||
end | ||||
return res | ||||
end | ||||
|
||||
|
||||
""" The naive implementation of the encoding circuit by arXiv:quant-ph/9607030 """ | ||||
function naive_encoding_circuit(c::AbstractECC) | ||||
n, k, s, r = code_n(c), code_k(c), code_s(c), rank(c) | ||||
naive_ec = AbstractOperation[] | ||||
# Applying the hadamard gate to the last r qubits | ||||
for i in n: -1: n-r+1 | ||||
push!(naive_ec, sHadamard(i)) | ||||
end | ||||
|
||||
standard_tab = standard_tab_gott(c) | ||||
|
||||
for i in 1 : n | ||||
if standard_tab[i, i] ==1 | ||||
for j in 1:n | ||||
if j == i continue end | ||||
gate = (standard_tab[j, i], standard_tab[j, i+n]) | ||||
if gate == (1,0) | ||||
push!(naive_ec, sCNOT(j, i)) | ||||
elseif gate == (0,1) | ||||
push!(naive_ec, sXCZ(j, i)) | ||||
elseif gate == (1,1) | ||||
push!(naive_ec, sXCY(j, i)) | ||||
end | ||||
end | ||||
end | ||||
end | ||||
return naive_ec | ||||
end | ||||
|
||||
|
||||
include("./bitflipcode.jl") | ||||
include("./shorcode.jl") | ||||
include("./steanecode.jl") | ||||
include("./papercode.jl") | ||||
|
||||
end #module |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
struct Paper8 <: AbstractECC end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. May we rename this to I will test all of this later today and give comments |
||
|
||
code_n(c::Paper8) = 8 | ||
|
||
parity_checks(c::Paper8) = S"XXXXXXXX | ||
ZZZZZZZZ | ||
XIXIZYZY | ||
XIYZXIYZ | ||
XZIYIYXZ" |
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.
Could you document where is this from? Where did you find this algorithm?