zxlive icon indicating copy to clipboard operation
zxlive copied to clipboard

Update rewrites to work well with Multigraphs

Open boldar99 opened this issue 1 year ago • 7 comments

Basic rewrites that need to be fixed:

  • [x] Color change
  • [x] Fusion of multiple vertices
  • [x] Fusion sometimes with a mulit-edge
  • [x] Push Pauli
  • [x] Matching ID crashes ZXLive if one of the edges is a multi-edge
  • [x] Bialgebra
  • [x] Copy 0/pi spider
  • [x] Magic wand

boldar99 avatar Jun 22 '24 10:06 boldar99

These are mostly issues in PyZX so maybe you should create an issue there as well?

RazinShaikh avatar Jun 26 '24 16:06 RazinShaikh

Most basic rewrites are fixed now but a many others are still broken. We should fix the graph-like rules next:

  • [ ] local complementation
  • [ ] pivot (@colltoaction)
  • [ ] boundary pivot
  • [ ] gadget pivot
  • [ ] fuse phase gadget
  • [ ] supplementarity

For example, pivot incorrectly gives the following diagram with parallel edges

RazinShaikh avatar Jul 16 '24 21:07 RazinShaikh

Is that example incorrect? Do you want it to remove the parallel edges?

jvdwetering avatar Jul 21 '24 17:07 jvdwetering

It should remove parallel edges. The rightmost edge should be removed so that's also wrong.

RazinShaikh avatar Jul 23 '24 19:07 RazinShaikh

That edge only belongs to the neighbourset of the right-pivoted vertex, so that one should stay, right? I think these diagrams are semantically correct, just that you would want the pivot to actually complement the edge set, i.e. by applying some general Hopf rule afterwards.

jvdwetering avatar Jul 24 '24 10:07 jvdwetering

There is an exception unpacking a tuple that is suppressed during this rewrite.

  File "/home/mcoll/.local/lib/python3.11/site-packages/pyzx/graph/multigraph.py", line 240, in remove_edge
    s,t,ty = edge
    ^^^^^^
ValueError: not enough values to unpack (expected 3, got 2)

colltoaction avatar Jul 25 '24 20:07 colltoaction

Some discussion on how this can be implemented for the graph-like rewrites:

  • A graph-like rewrite should only match if the vertices it matches on form a simple graph. This is to prevent confusion about the intended behaviour when there are parallel edges between neighbours when doing for instance local complementation. In other words: graph-like rewrites only match to parts of the diagram that are graph-like, and by definition these do not have parallel edges.
  • A way to implement the correct rewrite is to to store the value of get_auto_simplify, and then set it to True for the duration of the rewrite, to automatically get rid of parallel edges.

jvdwetering avatar Jun 04 '25 15:06 jvdwetering