zxlive icon indicating copy to clipboard operation
zxlive copied to clipboard

Fix pivot basic rewrite with new PyZX version

Open colltoaction opened this issue 1 year ago • 1 comments

This draft uncovers the issue with pivoting which I will solve next. cc @RazinShaikh. #256

Traceback (most recent call last):
  File "/home/mcoll/repos/github.com/colltoaction/zxlive/zxlive/rewrite_action.py", line 281, in do_rewrite
    node.rewrite_action.do_rewrite(self.proof_panel)
  File "/home/mcoll/repos/github.com/colltoaction/zxlive/zxlive/rewrite_action.py", line 114, in do_rewrite
    g, rem_verts = self.apply_rewrite(g, matches)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mcoll/repos/github.com/colltoaction/zxlive/zxlive/rewrite_action.py", line 129, in apply_rewrite
    etab, rem_verts, rem_edges, check_isolated_vertices = self.rule(g, matches)
                                                          ^^^^^^^^^^^^^^^^^^^^^
  File "/home/mcoll/repos/github.com/colltoaction/zxlive/zxlive/rewrite_data.py", line 117, in rule
    simplification(g)
  File "/home/mcoll/.local/lib/python3.11/site-packages/pyzx/simplify.py", line 109, in pivot_simp
    return simp(g, 'pivot_simp', match_pivot_parallel, pivot, matchf=matchf, quiet=quiet, stats=stats)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mcoll/.local/lib/python3.11/site-packages/pyzx/simplify.py", line 98, in simp
    g.remove_edges(rem_edges)
  File "/home/mcoll/.local/lib/python3.11/site-packages/pyzx/graph/multigraph.py", line 237, in remove_edges
    self.remove_edge(e)
  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 17 '24 21:07 colltoaction

some debugging points at

https://github.com/zxcalc/pyzx/blob/d81356b656ace618f4112266595d63415ac35dee/pyzx/rules.py#L683

check bialgebra

colltoaction avatar Jul 18 '24 15:07 colltoaction

@colltoaction Do you expect you will continue to work on this? Otherwise I'm gonna close it.

jvdwetering avatar Jan 30 '25 20:01 jvdwetering

Hi @jvdwetering! I just took another look at the issue. I changed the rule so that it uses simplify.pivot_simp with auto_simplify_parallel_edges=True and I got the following result:

image

Does it look in accordance to https://github.com/zxcalc/zxlive/issues/256#issuecomment-2247557548 to you?

colltoaction avatar Jan 31 '25 14:01 colltoaction

What was the graph that you started with? That one is not semantically equivalent to https://github.com/zxcalc/zxlive/issues/256#issuecomment-2231882306 Also, there were some errors reported with the auto-simplify, so that could be going on here as well: https://github.com/zxcalc/pyzx/issues/259

jvdwetering avatar Jan 31 '25 15:01 jvdwetering

  1. Open repro file repro-256.zxg.json
  2. Start derivation
  3. Select top two nodes
  4. Click Graph-like rules / pivot

colltoaction avatar Jan 31 '25 16:01 colltoaction

With the current version of ZXLive I get: image Which is semantically correct, it is just that the bottom two wires should dissapear. The version you get is semantically wrong, though given the changes you made to the code I don't understand why it is wrong.

jvdwetering avatar Jan 31 '25 16:01 jvdwetering

In your current implementation with pivot_simp it would also keep doing pivots on the whole graph, ignoring what you selected. It looks like in your diagram it might have applied the pivot twice, though it still looks wrong to me.

jvdwetering avatar Jan 31 '25 16:01 jvdwetering

I'll close this for now and hopefully find some time in the future

colltoaction avatar Feb 03 '25 15:02 colltoaction