Skip to content

Commit

Permalink
shor syndrome, classic xor, and pauli frame x measurement
Browse files Browse the repository at this point in the history
  • Loading branch information
amicciche committed Aug 23, 2023
1 parent cb1b591 commit f6b3917
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 3 deletions.
59 changes: 58 additions & 1 deletion src/ecc/ECC.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,71 @@ function naive_syndrome_circuit(parity_check_tableau, ancillary_index=1, bit_ind
naive_sc = AbstractOperation[]

for check in parity_check_tableau
naive_sc = append!(naive_sc,naive_ancillary_paulimeasurement(check, ancillary_index, bit_index))
append!(naive_sc,naive_ancillary_paulimeasurement(check, ancillary_index, bit_index))
ancillary_index +=1
bit_index +=1
end

return naive_sc
end

"""Circuit that measures the corresponding PauliOperator by Shor-style syndrome extraction, using qubits starting
at the `ancillary_index` and storing measurement results into classical bits starting at `bit_index`. The number
of ancillary and classical bits in the circuit returned is equal to the weight of the provided PauliOperator"""
function shor_ancillary_paulimeasurement(p::PauliOperator, ancillary_index=1, bit_index=1, cat=true)
init_ancil_index = ancillary_index
circuit = AbstractOperation[]
measurements = AbstractOperation[]
numQubits = nqubits(p)
for qubit in 1:numQubits
if p[qubit] == (1,0)
push!(circuit, sXCZ(qubit, numQubits + ancillary_index))
elseif p[qubit] == (0,1)
push!(circuit, sZCZ(qubit, numQubits + ancillary_index))
elseif p[qubit] == (1,1)
push!(circuit, sYCZ(qubit, numQubits + ancillary_index))

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

View check run for this annotation

Codecov / codecov/patch

src/ecc/ECC.jl#L89-L100

Added lines #L89 - L100 were not covered by tests
end
if p[qubit] != (0,0)
push!(measurements, sMRX(numQubits + ancillary_index, bit_index))
ancillary_index +=1
bit_index +=1

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

View check run for this annotation

Codecov / codecov/patch

src/ecc/ECC.jl#L102-L105

Added lines #L102 - L105 were not covered by tests
end
end
circuit = vcat(circuit,measurements)

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

View check run for this annotation

Codecov / codecov/patch

src/ecc/ECC.jl#L107-L108

Added lines #L107 - L108 were not covered by tests

if cat
cat_state_circuit = AbstractOperation[]
push!(cat_state_circuit, sHadamard(numQubits + init_ancil_index))
for i in (init_ancil_index+1):(ancillary_index -1)
push!(cat_state_circuit, sCNOT(numQubits + (i - 1), numQubits + i))
end
circuit = vcat(cat_state_circuit,circuit)

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

View check run for this annotation

Codecov / codecov/patch

src/ecc/ECC.jl#L110-L116

Added lines #L110 - L116 were not covered by tests
end

return circuit, ancillary_index, bit_index

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

View check run for this annotation

Codecov / codecov/patch

src/ecc/ECC.jl#L119

Added line #L119 was not covered by tests
end

function shor_syndrome_circuit(parity_check_tableau, ancillary_index=1, bit_index=1, cat=true)
shor_sc = AbstractOperation[]
xor_indices = []

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

View check run for this annotation

Codecov / codecov/patch

src/ecc/ECC.jl#L122-L124

Added lines #L122 - L124 were not covered by tests

for check in parity_check_tableau
circ, new_ancillary_index, new_bit_index = shor_ancillary_paulimeasurement(check, ancillary_index, bit_index, cat)
push!(xor_indices, collect(bit_index:new_bit_index-1))

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

View check run for this annotation

Codecov / codecov/patch

src/ecc/ECC.jl#L126-L128

Added lines #L126 - L128 were not covered by tests

append!(shor_sc, circ)
ancillary_index = new_ancillary_index
bit_index = new_bit_index
end

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

View check run for this annotation

Codecov / codecov/patch

src/ecc/ECC.jl#L130-L133

Added lines #L130 - L133 were not covered by tests

for indices in xor_indices
push!(shor_sc, QuantumClifford.ClassicalXOR(indices, bit_index))
bit_index += 1
end

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

View check run for this annotation

Codecov / codecov/patch

src/ecc/ECC.jl#L135-L138

Added lines #L135 - L138 were not covered by tests

return shor_sc

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

View check run for this annotation

Codecov / codecov/patch

src/ecc/ECC.jl#L140

Added line #L140 was not covered by tests
end

"""The distance of a code."""
function distance end

Expand Down
7 changes: 7 additions & 0 deletions src/misc_ops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,10 @@ function applywstatus!(s::AbstractQCState, v::VerifyOp) # XXX It assumes the oth
end

operatordeterminism(::Type{VerifyOp}) = DeterministicOperatorTrait()

"""Applies an XOR gate to classical bits. Currently only implemented for funcitonality with pauli frames."""
struct ClassicalXOR <: AbstractOperation
bits::Vector{Int} # the indices of the classical bits to be xored

Check warning on line 132 in src/misc_ops.jl

View check run for this annotation

Codecov / codecov/patch

src/misc_ops.jl#L132

Added line #L132 was not covered by tests
store::Int # the index of the classical bit that will store the results
end
ClassicalXOR(bits::NTuple, store::Int) = ClassicalXOR(collect(bits),store)

Check warning on line 135 in src/misc_ops.jl

View check run for this annotation

Codecov / codecov/patch

src/misc_ops.jl#L135

Added line #L135 was not covered by tests
22 changes: 20 additions & 2 deletions src/pauli_frames.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,25 @@ function apply!(f::PauliFrame, op::AbstractCliffordOperator)
return f
end

function apply!(frame::PauliFrame, op::sMZ) # TODO sMX, sMY
function apply!(frame::PauliFrame, xor::ClassicalXOR)
for f in eachindex(frame)
value = reduce(,frame.measurements[f,xor.bits])
frame.measurements[f, xor.store] = value
end

Check warning on line 64 in src/pauli_frames.jl

View check run for this annotation

Codecov / codecov/patch

src/pauli_frames.jl#L60-L64

Added lines #L60 - L64 were not covered by tests
end

function apply!(frame::PauliFrame, op::sMX) # TODO implement a faster direct version
op.bit == 0 && return frame
apply!(frame, sHadamard(op.qubit))
apply!(frame, sMZ(op.qubit, op.bit))

Check warning on line 70 in src/pauli_frames.jl

View check run for this annotation

Codecov / codecov/patch

src/pauli_frames.jl#L67-L70

Added lines #L67 - L70 were not covered by tests
end

function apply!(frame::PauliFrame, op::sMRX) # TODO implement a faster direct version
apply!(frame, sHadamard(op.qubit))
apply!(frame, sMRZ(op.qubit, op.bit))

Check warning on line 75 in src/pauli_frames.jl

View check run for this annotation

Codecov / codecov/patch

src/pauli_frames.jl#L73-L75

Added lines #L73 - L75 were not covered by tests
end

function apply!(frame::PauliFrame, op::sMZ) # TODO sMY, and faster sMX
op.bit == 0 && return frame
i = op.qubit
xzs = frame.frame.tab.xzs
Expand All @@ -75,7 +93,7 @@ function apply!(frame::PauliFrame, op::sMZ) # TODO sMX, sMY
return frame
end

function apply!(frame::PauliFrame, op::sMRZ) # TODO sMRX, sMRY
function apply!(frame::PauliFrame, op::sMRZ) # TODO sMRY, and faster sMRX
i = op.qubit
xzs = frame.frame.tab.xzs
T = eltype(xzs)
Expand Down

0 comments on commit f6b3917

Please sign in to comment.