Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix remove id for w #267

Merged
merged 1 commit into from
Aug 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading