From e43afd04005a96982bf1ceccd7c7f464bd230264 Mon Sep 17 00:00:00 2001 From: Martin Coll Date: Wed, 17 Jul 2024 17:56:31 -0300 Subject: [PATCH] Fix pivot basic rewrite with new PyZX version 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) --- zxlive/custom_rule.py | 7 ++----- zxlive/dialogs.py | 5 +---- zxlive/rewrite_action.py | 2 ++ zxlive/rule_panel.py | 15 ++++++--------- zxlive/vitem.py | 1 + 5 files changed, 12 insertions(+), 18 deletions(-) diff --git a/zxlive/custom_rule.py b/zxlive/custom_rule.py index 14f68e7b..5bffb15c 100644 --- a/zxlive/custom_rule.py +++ b/zxlive/custom_rule.py @@ -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 diff --git a/zxlive/dialogs.py b/zxlive/dialogs.py index 81bca9be..d069f5f1 100644 --- a/zxlive/dialogs.py +++ b/zxlive/dialogs.py @@ -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: diff --git a/zxlive/rewrite_action.py b/zxlive/rewrite_action.py index 4ca0c0d4..5d359f65 100644 --- a/zxlive/rewrite_action.py +++ b/zxlive/rewrite_action.py @@ -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 diff --git a/zxlive/rule_panel.py b/zxlive/rule_panel.py index dbc4cd66..d950ddee 100644 --- a/zxlive/rule_panel.py +++ b/zxlive/rule_panel.py @@ -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))) diff --git a/zxlive/vitem.py b/zxlive/vitem.py index 8e386be8..e704757d 100644 --- a/zxlive/vitem.py +++ b/zxlive/vitem.py @@ -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