Skip to content

Commit

Permalink
Fix pivot basic rewrite with new PyZX version
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
colltoaction committed Jul 17, 2024
1 parent bdc69bc commit e43afd0
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 18 deletions.
7 changes: 2 additions & 5 deletions zxlive/custom_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,8 @@ def filter_matchings_if_symbolic_compatible(matchings: list[Dict[VT, VT]], left:
for matching in matchings:
if len(matching) != len(left):
continue
try:
match_symbolic_parameters(matching, left, right)
new_matchings.append(matching)
except ValueError:
pass
match_symbolic_parameters(matching, left, right)
new_matchings.append(matching)
return new_matchings


Expand Down
5 changes: 1 addition & 4 deletions zxlive/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,7 @@ def save_diagram_dialog(graph: GraphT, parent: QWidget) -> Optional[tuple[str, F
file_path, selected_format = file_path_and_format

if selected_format in (FileFormat.QGraph, FileFormat.Json):
try:
graph.auto_detect_io()
except TypeError:
pass
graph.auto_detect_io()
data = graph.to_json()
elif selected_format == FileFormat.QASM:
try:
Expand Down
2 changes: 2 additions & 0 deletions zxlive/rewrite_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ def do_rewrite(self, panel: ProofPanel) -> None:

try:
g, rem_verts = self.apply_rewrite(g, matches)
except ValueError as ex:
raise ex
except Exception as ex:
show_error_msg('Error while applying rewrite rule', str(ex))
return
Expand Down
15 changes: 6 additions & 9 deletions zxlive/rule_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,9 @@ def add_edge(self, u: VT, v: VT) -> None:
self.update_io_labels(self.graph_scene)

def update_io_labels(self, scene: EditGraphScene) -> None:
try:
scene.g.auto_detect_io()
for v in scene.g.vertices():
if v in scene.g.inputs():
scene.vertex_map[v].phase_item.setPlainText("in-" + str(scene.g.inputs().index(v)))
elif v in scene.g.outputs():
scene.vertex_map[v].phase_item.setPlainText("out-" + str(scene.g.outputs().index(v)))
except TypeError:
return
scene.g.auto_detect_io()
for v in scene.g.vertices():
if v in scene.g.inputs():
scene.vertex_map[v].phase_item.setPlainText("in-" + str(scene.g.inputs().index(v)))
elif v in scene.g.outputs():
scene.vertex_map[v].phase_item.setPlainText("out-" + str(scene.g.outputs().index(v)))
1 change: 1 addition & 0 deletions zxlive/vitem.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def g(self) -> GraphT:

@property
def ty(self) -> VertexType:
# https://github.com/zxcalc/zxlive/pull/281
_ty: VertexType = self.g.type(self.v)
return _ty

Expand Down

0 comments on commit e43afd0

Please sign in to comment.