diff --git a/pyzx/graph/multigraph.py b/pyzx/graph/multigraph.py index 2a3d0b83..9d1e313d 100644 --- a/pyzx/graph/multigraph.py +++ b/pyzx/graph/multigraph.py @@ -34,6 +34,12 @@ def __init__(self, s: int=0, h: int=0, w_io: int=0): self.h = h self.w_io = w_io + def __repr__(self): + s = f"s={self.s}" if self.s else "" + h = f"h={self.h}" if self.h else "" + w_io = f"w_io={self.w_io}" if self.w_io else "" + return f"Edge({', '.join([s, h, w_io])})" + def add(self, s: int=0, h: int=0, w_io: int=0): self.s += s self.h += h @@ -348,9 +354,11 @@ def set_edge_type(self, edge, t): elif t == EdgeType.HADAMARD: e.add(h=1) else: e.add(w_io=1) - def toggle_edge_type(self, edge): - v1,v2 = edge + def toggle_edge_type(self, edge: Edge) -> None: + v1, v2 = edge e = self.graph[v1][v2] + if e.w_io: + raise ValueError(f'Cannot toggle {repr(e)}') e.h, e.s = e.s, e.h def type(self, vertex): diff --git a/pyzx/utils.py b/pyzx/utils.py index a7588af2..312cc32c 100644 --- a/pyzx/utils.py +++ b/pyzx/utils.py @@ -86,7 +86,7 @@ def toggle_edge(ty: EdgeType.Type) -> EdgeType.Type: return EdgeType.HADAMARD if ty == EdgeType.HADAMARD: return EdgeType.SIMPLE - return ty + raise ValueError(f'Cannot toggle {repr(ty)}') def phase_to_s(a: FractionLike, t:VertexType.Type=VertexType.Z) -> str: if isinstance(a, Fraction) or isinstance(a, int):