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

initial implementation of naive_encoding_circuit #184

Closed
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 143 additions & 0 deletions src/ecc/ECC.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using QuantumClifford
using QuantumClifford: AbstractOperation
using LinearAlgebra
import QuantumClifford: Stabilizer, MixedDestabilizer

abstract type AbstractECC end
Expand Down Expand Up @@ -398,4 +399,146 @@
include("./shorcode.jl")
include("./steanecode.jl")

"""A pedagogical example of a quantum error correcting [8,3] code used in [cleve1997efficient](@cite)."""
struct Cleve8 <: AbstractECC end

code_n(c::Cleve8) = 8

Check warning on line 405 in src/ecc/ECC.jl

View check run for this annotation

Codecov / codecov/patch

src/ecc/ECC.jl#L405

Added line #L405 was not covered by tests

parity_checks(c::Cleve8) = S"XXXXXXXX

Check warning on line 407 in src/ecc/ECC.jl

View check run for this annotation

Codecov / codecov/patch

src/ecc/ECC.jl#L407

Added line #L407 was not covered by tests
ZZZZZZZZ
XIXIZYZY
XIYZXIYZ
XZIYIYXZ"

function canonicalize_cleve97(checks::Stabilizer)
d, n = size(checks)
X0 = (checks |> stab_to_gf2)[:,1:n]'
Z0 = (checks |> stab_to_gf2)[:,n+1:2n]'

Check warning on line 416 in src/ecc/ECC.jl

View check run for this annotation

Codecov / codecov/patch

src/ecc/ECC.jl#L413-L416

Added lines #L413 - L416 were not covered by tests

# Now let's work on getting X1 and Z1
b = rank(X0)
amicciche marked this conversation as resolved.
Show resolved Hide resolved
r = d-b
k = n-d

Check warning on line 421 in src/ecc/ECC.jl

View check run for this annotation

Codecov / codecov/patch

src/ecc/ECC.jl#L419-L421

Added lines #L419 - L421 were not covered by tests

# First let's move the 0 columns to the left:
nullColumns = []
notNullColumns = []
for j in 1:d
if count(X0[:,j])==0 # TODO make sure this is condition -> null generator
push!(nullColumns, j)

Check warning on line 428 in src/ecc/ECC.jl

View check run for this annotation

Codecov / codecov/patch

src/ecc/ECC.jl#L424-L428

Added lines #L424 - L428 were not covered by tests
else
push!(notNullColumns, j)

Check warning on line 430 in src/ecc/ECC.jl

View check run for this annotation

Codecov / codecov/patch

src/ecc/ECC.jl#L430

Added line #L430 was not covered by tests
end
end

Check warning on line 432 in src/ecc/ECC.jl

View check run for this annotation

Codecov / codecov/patch

src/ecc/ECC.jl#L432

Added line #L432 was not covered by tests

# Reorder the generators/columns so 0 vectors are in front of X0:
column_order = vcat(nullColumns, notNullColumns)
X0_5 = X0[:, column_order]
Z0_5 = Z0[:, column_order]

Check warning on line 437 in src/ecc/ECC.jl

View check run for this annotation

Codecov / codecov/patch

src/ecc/ECC.jl#L435-L437

Added lines #L435 - L437 were not covered by tests

# Second let's perform Gaussian elimination to arrive at X1 and Z1
bank = []
for j in (r+1):(r+b)
i = 1
STOP = false
while !STOP
if X0_5[i, j] != 1
i+=1
if i > n
print("ERROR")
STOP = true

Check warning on line 449 in src/ecc/ECC.jl

View check run for this annotation

Codecov / codecov/patch

src/ecc/ECC.jl#L440-L449

Added lines #L440 - L449 were not covered by tests
end
else
STOP = true

Check warning on line 452 in src/ecc/ECC.jl

View check run for this annotation

Codecov / codecov/patch

src/ecc/ECC.jl#L452

Added line #L452 was not covered by tests
end
end
println(i)
push!(bank, i)
for a in (r+1):(r+b)
if a == j
continue

Check warning on line 459 in src/ecc/ECC.jl

View check run for this annotation

Codecov / codecov/patch

src/ecc/ECC.jl#L454-L459

Added lines #L454 - L459 were not covered by tests
end
if X0_5[i,a] == 1
X0_5[:,a] = (X0_5[:,j]+X0_5[:,a]).%2
Z0_5[:,a] = (Z0_5[:,j]+Z0_5[:,a]).%2

Check warning on line 463 in src/ecc/ECC.jl

View check run for this annotation

Codecov / codecov/patch

src/ecc/ECC.jl#L461-L463

Added lines #L461 - L463 were not covered by tests
end
end
end

Check warning on line 466 in src/ecc/ECC.jl

View check run for this annotation

Codecov / codecov/patch

src/ecc/ECC.jl#L465-L466

Added lines #L465 - L466 were not covered by tests

qubit_order = []
for i in 1:n
if i ∉ bank
push!(qubit_order, i)

Check warning on line 471 in src/ecc/ECC.jl

View check run for this annotation

Codecov / codecov/patch

src/ecc/ECC.jl#L468-L471

Added lines #L468 - L471 were not covered by tests
end
end
append!(qubit_order, bank)
println(qubit_order)

Check warning on line 475 in src/ecc/ECC.jl

View check run for this annotation

Codecov / codecov/patch

src/ecc/ECC.jl#L473-L475

Added lines #L473 - L475 were not covered by tests

X1 = X0_5[qubit_order, :]
Z1 = Z0_5[qubit_order, :]

Check warning on line 478 in src/ecc/ECC.jl

View check run for this annotation

Codecov / codecov/patch

src/ecc/ECC.jl#L477-L478

Added lines #L477 - L478 were not covered by tests

# Now begins the march towards X2 and Z2, starting with B'
r1 = rank(Z1[1:r+k,1:r])
r2 = r - r1
println("WARN: If r2 is greater than 0, this will not work. r2: ", r2)

Check warning on line 483 in src/ecc/ECC.jl

View check run for this annotation

Codecov / codecov/patch

src/ecc/ECC.jl#L481-L483

Added lines #L481 - L483 were not covered by tests

# TODO implement calculation of B' using the same alogirthm as above
# For the Cleve8 code r2 = 0, so X1= X2 and Z1 = Z2
X2 = X1; Z2 = Z1; # TODO this is generally wrong - see above comment.

Check warning on line 487 in src/ecc/ECC.jl

View check run for this annotation

Codecov / codecov/patch

src/ecc/ECC.jl#L487

Added line #L487 was not covered by tests

# Now time for the final steps before arriving at Xstar Zstar
B1 = Z2[1:k,1:r2+r1]

Check warning on line 490 in src/ecc/ECC.jl

View check run for this annotation

Codecov / codecov/patch

src/ecc/ECC.jl#L490

Added line #L490 was not covered by tests

XI = zeros(Bool, k , k)
for i in 1:k
XI[i,i] = 1
end
Xs = (vcat(XI, zeros(Bool,r2, k), B1', zeros(Bool, b, k)))
Zs = zeros(Bool, n, k)

Check warning on line 497 in src/ecc/ECC.jl

View check run for this annotation

Codecov / codecov/patch

src/ecc/ECC.jl#L492-L497

Added lines #L492 - L497 were not covered by tests

Xstar = hcat(Xs,X2)
Zstar = hcat(Zs,Z2)
return Xstar, Zstar, Stabilizer(X2',Z2') # TODO at some point unreorder the qubits

Check warning on line 501 in src/ecc/ECC.jl

View check run for this annotation

Codecov / codecov/patch

src/ecc/ECC.jl#L499-L501

Added lines #L499 - L501 were not covered by tests
end

""" The naive implementation of the encoding circuit by arXiv:quant-ph/9607030 """
function naive_encoding_circuit(checks::Stabilizer)
d, n = size(checks)
X0 = (checks |> stab_to_gf2)[:,1:n]'
b = rank(X0)
r = d-b
k = n-d

Check warning on line 510 in src/ecc/ECC.jl

View check run for this annotation

Codecov / codecov/patch

src/ecc/ECC.jl#L505-L510

Added lines #L505 - L510 were not covered by tests

Xstar, Zstar, standard_tab = canonicalize_cleve97(checks)
println(standard_tab)

Check warning on line 513 in src/ecc/ECC.jl

View check run for this annotation

Codecov / codecov/patch

src/ecc/ECC.jl#L512-L513

Added lines #L512 - L513 were not covered by tests

naive_ec = AbstractOperation[]
for i in (r+k+1):(r+k+b)
push!(naive_ec, sHadamard(i))
end

Check warning on line 518 in src/ecc/ECC.jl

View check run for this annotation

Codecov / codecov/patch

src/ecc/ECC.jl#L515-L518

Added lines #L515 - L518 were not covered by tests

for j in 1:n
if count(Xstar[:,j]) == 0 # Secondary generators are ignored
continue

Check warning on line 522 in src/ecc/ECC.jl

View check run for this annotation

Codecov / codecov/patch

src/ecc/ECC.jl#L520-L522

Added lines #L520 - L522 were not covered by tests
end
if Zstar[j,j]==1
push!(naive_ec, sZ(j))

Check warning on line 525 in src/ecc/ECC.jl

View check run for this annotation

Codecov / codecov/patch

src/ecc/ECC.jl#L524-L525

Added lines #L524 - L525 were not covered by tests
end
for i in 1:n
if i == j
continue

Check warning on line 529 in src/ecc/ECC.jl

View check run for this annotation

Codecov / codecov/patch

src/ecc/ECC.jl#L527-L529

Added lines #L527 - L529 were not covered by tests
end
if Xstar[i,j] == 1 && Zstar[i,j] == 0
push!(naive_ec, sZCX(j,i))
elseif Xstar[i,j] == 0 && Zstar[i,j] == 1
push!(naive_ec, sZCZ(j,i))
elseif Xstar[i,j] == 1 && Zstar[i,j] == 1
push!(naive_ec, sZCY(j,i))

Check warning on line 536 in src/ecc/ECC.jl

View check run for this annotation

Codecov / codecov/patch

src/ecc/ECC.jl#L531-L536

Added lines #L531 - L536 were not covered by tests
end
end
end

Check warning on line 539 in src/ecc/ECC.jl

View check run for this annotation

Codecov / codecov/patch

src/ecc/ECC.jl#L538-L539

Added lines #L538 - L539 were not covered by tests

return naive_ec, standard_tab

Check warning on line 541 in src/ecc/ECC.jl

View check run for this annotation

Codecov / codecov/patch

src/ecc/ECC.jl#L541

Added line #L541 was not covered by tests
end

end #module
Loading