Skip to content

Commit b10feda

Browse files
brohan-byteSai Rohan Reddy Kondlapudi
andauthored
Added good_state validation for VerifyOp and included test for it (#557)
Co-authored-by: Sai Rohan Reddy Kondlapudi <[email protected]>
1 parent 8ea87a5 commit b10feda

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

src/misc_ops.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,15 @@ end
134134
# TODO this one needs more testing
135135
function applywstatus!(s::AbstractQCState, v::VerifyOp) # XXX It assumes the other qubits are measured or traced out
136136
# 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
137141
canonicalize_rref!(quantumstate(s),v.indices) # Document why rref is used
138142
sv = tab(s)
139143
good_state = tab(v.good_state)
144+
145+
140146
for i in eachindex(good_state)
141147
(sv.phases[end-i+1]==good_state.phases[end-i+1]) || return s, false_success_stat
142148
for (j,q) in zip(eachindex(good_state),v.indices)

test/test_noisycircuits.jl

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,4 +295,35 @@
295295
@test stabilizerview(r) == expectedFinalState
296296
end
297297
end
298+
299+
@testset "VerifyOp" begin
300+
using QuantumClifford.ECC: Steane7, parity_checks, naive_encoding_circuit
301+
@testset "Stabilizer passed as good_state is not a logical state" begin
302+
good_state = parity_checks(Steane7()) #passing in a code instead of a state within codespace
303+
verify = VerifyOp(good_state, 1:7)
304+
reg = Register(one(MixedDestabilizer,7),6) #dummy register to pass into applywstatus!
305+
306+
307+
@test_throws ArgumentError applywstatus!(reg, verify) #should throw an error since good_state isn't a logical state
308+
309+
310+
end
311+
312+
@testset "Accepts pure good_state argument" begin
313+
good_state = S"ZZI
314+
IZZ
315+
XXX" # passing in GHZ state as good_state argument since it exists within the repetition code's codespace
316+
verify = VerifyOp(good_state, 1:3)
317+
reg = Register(one(MixedDestabilizer,3),2)
318+
encoding = [sHadamard(1) , sCNOT(1,2) ,sCNOT(1,3) ] # encoding the register's state into a logical state within the repetition code's codespace
319+
for i in encoding
320+
apply!(reg, i)
321+
end
322+
323+
_, status = applywstatus!(reg, verify)
324+
@test status == true_success_stat
325+
end
326+
327+
328+
end
298329
end

0 commit comments

Comments
 (0)