diff --git a/src/graphs.jl b/src/graphs.jl index 39c9d60ca..5d006641c 100644 --- a/src/graphs.jl +++ b/src/graphs.jl @@ -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] diff --git a/test/test_graphs.jl b/test/test_graphs.jl index 37406b16e..71a4e6af5 100644 --- a/test/test_graphs.jl +++ b/test/test_graphs.jl @@ -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)) @@ -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() \ No newline at end of file +test_graphs()