Skip to content

Commit aeb1545

Browse files
brohan-byteSai Rohan Reddy KondlapudiSai Rohan Reddy KondlapudiSai Rohan Reddy Kondlapudi
authored
Fix edge-case comparisons in VerifyOp (#586)
Co-authored-by: Sai Rohan Reddy Kondlapudi <rohan@mac.lan> Co-authored-by: Sai Rohan Reddy Kondlapudi <rohan@1x-nat-vl932-172-30-250-57.wireless.umass.edu> Co-authored-by: Sai Rohan Reddy Kondlapudi <rohan@umass-ssid-vl931-172-30-187-195.wireless.umass.edu>
1 parent 11dd3e5 commit aeb1545

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

src/misc_ops.jl

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,21 +128,25 @@ end
128128
struct VerifyOp <: AbstractOperation
129129
good_state::Stabilizer
130130
indices::AbstractVector{Int}
131-
VerifyOp(s,indices) = new(canonicalize_rref!(copy(stabilizerview(s)))[1],indices)
131+
function VerifyOp(s, indices)
132+
gs = canonicalize_rref!(copy(stabilizerview(s)))[1]
133+
r,n = size(gs)
134+
if(r!=n)
135+
throw(ArgumentError(lazy"""The argument you have provided for good_state is not a logical state within the codespace. Expected a pure $n - qubit stabilizer state (i.e. $n independent stabilizer generators on $n qubits), but good_state has only $r independent stabilizer generators."""))
136+
end
137+
return new(gs, indices)
138+
end
132139
end
133140

134141
# TODO this one needs more testing
135142
function applywstatus!(s::AbstractQCState, v::VerifyOp) # XXX It assumes the other qubits are measured or traced out
136143
# TODO QuantumClifford should implement some submatrix comparison
137-
r,n = size(v.good_state)
138-
if(r!=n)
139-
throw(ArgumentError("""The argument you have provided for good_state is not a logical state within the codespace. Expected a pure $n - qubit stabilizer state (i.e. $n independent stabilizer generators on $n qubits), but good_state has only $r independent stabilizer generators."""))
140-
end
141-
canonicalize_rref!(quantumstate(s),v.indices) # Document why rref is used
142-
sv = tab(s)
144+
sv = traceout!(copy(quantumstate(s)), setdiff(1:nqubits(s),v.indices))
145+
sv = stabilizerview(sv)
146+
canonicalize_rref!(sv, v.indices)
147+
sv = tab(sv)
143148
good_state = tab(v.good_state)
144149

145-
146150
for i in eachindex(good_state)
147151
(sv.phases[end-i+1]==good_state.phases[end-i+1]) || return s, false_success_stat
148152
for (j,q) in zip(eachindex(good_state),v.indices)

test/test_noisycircuits.jl

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -333,15 +333,11 @@
333333

334334
@testset "VerifyOp" begin
335335
using QuantumClifford.ECC: Steane7, parity_checks, naive_encoding_circuit
336+
using QuantumClifford: tensor
336337
@testset "Stabilizer passed as good_state is not a logical state" begin
337338
good_state = parity_checks(Steane7()) #passing in a code instead of a state within codespace
338-
verify = VerifyOp(good_state, 1:7)
339-
reg = Register(one(MixedDestabilizer,7),6) #dummy register to pass into applywstatus!
340-
339+
@test_throws ArgumentError VerifyOp(good_state, 1:7) #should throw an error since good_state isn't a logical state i.e. has only 6 stabilizer generators
341340

342-
@test_throws ArgumentError applywstatus!(reg, verify) #should throw an error since good_state isn't a logical state
343-
344-
345341
end
346342

347343
@testset "Accepts pure good_state argument" begin
@@ -358,6 +354,19 @@
358354
_, status = applywstatus!(reg, verify)
359355
@test status == true_success_stat
360356
end
357+
358+
@testset "handles sub-tableau with ancillas correctly " begin
359+
s = S"+ XXX__
360+
+ ZZ___
361+
+ Z_Z__
362+
- ZZ_Z_
363+
- _ZZ_Z"
364+
good_state = S"XXX ZZI IZZ"
365+
verify = VerifyOp(good_state, 1:3)
366+
_, status = applywstatus!(s, verify)
367+
@test status == true_success_stat #this test would have given a false_success_stat in the previous implementation of applywstatus! for VerifyOp
368+
369+
end
361370

362371

363372
end

0 commit comments

Comments
 (0)