pyzx icon indicating copy to clipboard operation
pyzx copied to clipboard

Hadamard cancellation rule

Open wzpxq opened this issue 11 months ago • 4 comments

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 avatar Mar 06 '24 12:03 wzpxq

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))

wzpxq avatar Mar 06 '24 12:03 wzpxq

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.

dlyongemallo avatar Mar 29 '24 09:03 dlyongemallo

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!).

dnadlinger avatar Apr 16 '24 17:04 dnadlinger

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.

wzpxq avatar Apr 17 '24 08:04 wzpxq