Clifford simp adds a phase of n*pi/2
Closed this issue · 2 comments
rafaelha commented
In the following code snippet, the two tensors differ by a phase of 1j. Running this for different seeds, I find that the phase of z
is either [1, 1j, -1, -1j].
import numpy as np
import random
import pyzx as zx
random.seed(1)
g1 = zx.generate.cliffordT(3, 20, p_t=0)
g2 = g1.copy()
zx.clifford_simp(g2) # Removing this line makes the assert pass
assert np.allclose(g1.to_tensor(), g2.to_tensor())
z = g1 + g2.adjoint()
zx.clifford_simp(z)
# print(z.to_tensor())
assert z.is_id()
assert z.scalar.to_number() == 1, f"scalar is {z.scalar.to_number()}"
# >> AssertionError: scalar is (-1.8369701987210297e-16-1j)
version: pyzx 0.8.0
rafaelha commented
Looking into this further, the problem was simply that BaseGraph.adjoint()
did not conjugate the phase. Adding the line
g.scalar.add_phase(- 2 * g.scalar.phase)
in BaseGraph.copy
fixed everything.
jvdwetering commented
I think this can now be closed?