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

Incorrect matrix for ZXW circuit depending on W-spider orientation and vertex color #361

Open
semiclassical opened this issue Nov 11, 2024 · 1 comment
Labels
Priority: Medium Type: bug Something is not right

Comments

@semiclassical
Copy link

Consider the following ZXW circuit and its matrix as reported by ZXLive:

image

This diagram should correspond to the operator Z1+Z2=diag(2,0,0,-2), which the above matrix corroborates (up to a global scalar).

Now suppose we drag the 'head' of the W-spider so that it points to the left. This should not affect the spider's behavior, but the resulting matrix is different:

image

The boundary between these two cases seems to be whether the spider's head is on the left or right. In particular, the behavior of a 'vertical' W-spider is sensitive to small adjustments in the head's orientation.

The head being on the left also interacts oddly with the color change rule:

  • If both vertices are color-changed to be red within a Proof, then the matrix returns to the first (correct) example

  • If only the upper vertex is color-changed, the matrix is the second (incorrect) example

  • If only the lower vertex is color changed, a new incorrect matrix occurs:

image

@RazinShaikh RazinShaikh added Type: bug Something is not right Priority: Medium labels Nov 18, 2024
@RazinShaikh
Copy link
Collaborator

It's easier to see the problem with the following one. We should get the matrix for Hadamard (it's actually Had@X@X = Had)
image
But flipping the W orientation gives us X@Had@X:
image
The problem seems to be in the following block of code in pyzx but I can't figure out what the bug is.
https://github.com/zxcalc/pyzx/blob/a2775a2fec311485ec482e2a9c48eeb7b0922c80/pyzx/tensor.py#L173-L180

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority: Medium Type: bug Something is not right
Projects
None yet
Development

No branches or pull requests

2 participants