Skip to content

Commit

Permalink
raise ValueError if toggle_edge is called with an invalid argument
Browse files Browse the repository at this point in the history
  • Loading branch information
boldar99 committed Jun 25, 2024
1 parent 5bdf6c2 commit aa4f9ee
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 10 additions & 2 deletions pyzx/graph/multigraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion pyzx/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit aa4f9ee

Please sign in to comment.