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

Hadamard cancellation rule #200

Open
wzpxq opened this issue Mar 6, 2024 · 4 comments
Open

Hadamard cancellation rule #200

wzpxq opened this issue Mar 6, 2024 · 4 comments

Comments

@wzpxq
Copy link

wzpxq commented Mar 6, 2024

Unless I am missing it there is no "Hadamard cancellation" implemented.

Consider the following graph:

g = zx.Graph() 

v0 = g.add_vertex(zx.VertexType.BOUNDARY, 0, 0)
v1 = g.add_vertex(zx.VertexType.H_BOX, 0, 1)
g.add_edge((v0, v1))
v2 = g.add_vertex(zx.VertexType.H_BOX, 0, 2)
g.add_edge((v1, v2))
v3 = g.add_vertex(zx.VertexType.BOUNDARY, 0, 3)
g.add_edge((v2, v3))

full_reduce, clifford_simp have no effect on it (nor did I find any other API that cancels the two Hadamards.

@wzpxq
Copy link
Author

wzpxq commented Mar 6, 2024

The same goes also for H_BOX next to an H-edge, btw:

g = zx.Graph() 

v0 = g.add_vertex(zx.VertexType.BOUNDARY, 0, 0)
v1 = g.add_vertex(zx.VertexType.H_BOX, 0, 1)
g.add_edge((v0, v1), zx.EdgeType.HADAMARD) 
v2 = g.add_vertex(zx.VertexType.BOUNDARY, 0, 2)
g.add_edge((v1, v2))

@dlyongemallo
Copy link
Contributor

full_reduce assumes that the input is a ZX-diagram, meaning it shouldn't have H_BOXes. I agree that this is confusing, and at some stage probably a conversion from H_BOX to Hadamard edges should happen. At the minimum, full_reduce should warn that the input is invalid.

See also #161 for some background.

@dnadlinger
Copy link

I also bumped into this as a first-time user of zxlive; lowering 2-ary H boxes sounds like a sensible pass to implement (and I agree, a warning for "invalid" inputs would have helped a lot in figuring out what is going on here!).

@wzpxq
Copy link
Author

wzpxq commented Apr 17, 2024

Thank you for the two replies.
So, as I have understood it, I simply have to call zx.hsimplify.from_hypergraph_form(g) to turn all H_BOXes into HADAMARD edges, before full_reduce can do its thing.
I tried it and it works.
But I suggest that if that H_BOX conversion will not be included into full_reduce that at least a new prominent API should be created that incorporates all simplifications to any graph.

dlyongemallo added a commit to dlyongemallo/pyzx that referenced this issue Apr 17, 2024
The function requires that the input is a ZX-diagram (i.e., no `H_BOX`es). See Quantomatic#161 and Quantomatic#200 for context.

Note: This does not guard `clifford_simp` or other simplification subroutines, which will still silently fail if there are `H_BOX`es. Putting a check into each subroutine would be redundant and expensive.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants