Skip to content

Commit

Permalink
Fix incorrect index permutation in graph generation
Browse files Browse the repository at this point in the history
Fixes #57 #57

This was not caught by tests because the tests were already
canonicalizing the tableaux.
Tests are now fixed too.
  • Loading branch information
Krastanov committed Jun 2, 2022
1 parent 7de2181 commit c83f85f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/graphs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Graphs
function graphstate!(stab::Stabilizer)
n = nqubits(stab)
stab, r, s, permx, permz = canonicalize_gott!(stab)
perm = invperm(permx[permz])
perm = permx[permz]
h_idx = [perm[i] for i in (r+1):n] # Qubits in which X ↔ Z is needed
ip_idx = [perm[i] for i in 1:n if stab[i,i]==(true,true)] # Qubits for which Y → X is needed
phase_flips = [perm[i] for i in 1:n if stab.phases[i]!=0x0]
Expand Down
18 changes: 16 additions & 2 deletions test/test_graphs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ function test_graphs()
@testset "Graph states" begin
for n in [1,test_sizes...]
s = random_stabilizer(n)
canonicalize_gott!(s)
g, h_idx, ip_idx, z_idx = graphstate(s)
gates = graph_gatesequence(h_idx, ip_idx, z_idx)
gate = graph_gate(h_idx, ip_idx, z_idx, nqubits(s))
Expand All @@ -15,7 +14,22 @@ function test_graphs()
for gate in vcat(gates...) apply!(s1, gate) end
@test canonicalize!(apply!(copy(s),c0)) == canonicalize!(s1) == canonicalize!(Stabilizer(g))
end
# one more check, done manually, to ensure we are testing for cases
# where canonicalize_gott! is causing index permutation
# (a few of the random cases already cover that)
s = S"- _XZ
+ _ZX
+ ZXZ"
g, h_idx, ip_idx, z_idx = graphstate(s)
gates = graph_gatesequence(h_idx, ip_idx, z_idx)
gate = graph_gate(h_idx, ip_idx, z_idx, nqubits(s))
c0 = one(CliffordOperator,nqubits(s))
for gate in vcat(gates...) apply!(tab(c0), gate) end
@test c0==gate
s1 = copy(s)
for gate in vcat(gates...) apply!(s1, gate) end
@test canonicalize!(apply!(copy(s),c0)) == canonicalize!(s1) == canonicalize!(Stabilizer(g))
end
end

test_graphs()
test_graphs()

0 comments on commit c83f85f

Please sign in to comment.