Update rewrites to work well with Multigraphs
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
These are mostly issues in PyZX so maybe you should create an issue there as well?
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
Is that example incorrect? Do you want it to remove the parallel edges?
It should remove parallel edges. The rightmost edge should be removed so that's also wrong.
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.
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)
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 toTruefor the duration of the rewrite, to automatically get rid of parallel edges.