Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clifford simp adds a phase of n*pi/2 #229

Closed
rafaelha opened this issue May 30, 2024 · 2 comments
Closed

Clifford simp adds a phase of n*pi/2 #229

rafaelha opened this issue May 30, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@rafaelha
Copy link
Contributor

rafaelha commented May 30, 2024

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
Copy link
Contributor Author

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
Copy link
Collaborator

I think this can now be closed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants