Skip to content

Commit

Permalink
Merge pull request #267 from RazinShaikh/remove-id-w
Browse files Browse the repository at this point in the history
fix remove id for w
  • Loading branch information
jvdwetering committed Aug 16, 2024
2 parents 0a001f7 + 70d38f5 commit 81ebc5f
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions pyzx/basicrules.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ def check_remove_id(g: BaseGraph[VT,ET], v: VT) -> bool:
return False

def remove_id(g: BaseGraph[VT,ET], v: VT) -> bool:
if vertex_is_w(g.type(v)):
return remove_id_w(g, v)
if not check_remove_id(g, v):
return False

Expand All @@ -243,4 +245,21 @@ def remove_id(g: BaseGraph[VT,ET], v: VT) -> bool:

return True

def check_remove_id_w(g: BaseGraph[VT,ET], v: VT) -> bool:
w_in, w_out = get_w_io(g, v)
if g.vertex_degree(w_out) == 2:
return True
return False

def remove_id_w(g: BaseGraph[VT,ET], v: VT) -> bool:
if not check_remove_id_w(g, v):
return False
w_in, w_out = get_w_io(g, v)
v1 = [n for n in g.neighbors(w_out) if n != w_in][0]
v2 = [n for n in g.neighbors(w_in) if n != w_out][0]
g.add_edge((v1,v2), edgetype=EdgeType.SIMPLE
if g.edge_type(g.edge(w_out, v1)) == g.edge_type(g.edge(w_in, v2))
else EdgeType.HADAMARD)
g.remove_vertex(w_in)
g.remove_vertex(w_out)
return True

0 comments on commit 81ebc5f

Please sign in to comment.