Skip to content

Commit

Permalink
use incident_edges instead of neighbours for correct fusion in basicr…
Browse files Browse the repository at this point in the history
…ules.py
  • Loading branch information
RazinShaikh committed Jun 29, 2024
1 parent eb04152 commit b110243
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
9 changes: 6 additions & 3 deletions pyzx/basicrules.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,12 @@ def fuse(g: BaseGraph[VT,ET], v1: VT, v2: VT) -> bool:
set_z_box_label(g, v1, get_z_box_label(g, v1) * get_z_box_label(g, v2))
else:
g.add_to_phase(v1, g.phase(v2))
for v3 in g.neighbors(v2):
if v3 != v1:
g.add_edge((v1,v3), edgetype=g.edge_type(g.edge(v2,v3)))
for e in g.incident_edges(v2):
source, target = g.edge_st(e)
other_vertex = source if source != v2 else target
if other_vertex == v1 and g.edge_type(e) == EdgeType.SIMPLE:
continue
g.add_edge((v1,other_vertex), edgetype=g.edge_type(e))
g.remove_vertex(v2)
return True

Expand Down
4 changes: 2 additions & 2 deletions pyzx/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ def spider(g: BaseGraph[VT,ET], matches: List[MatchSpiderType[VT]]) -> RewriteOu

# edges from the second vertex are transferred to the first
for e in g.incident_edges(v1):
edge_st = g.edge_st(e)
other_vertex = edge_st[0] if edge_st[1] == v1 else edge_st[1]
source, target = g.edge_st(e)
other_vertex = source if source != v1 else target
new_e = (v0, other_vertex)
if new_e not in etab: etab[new_e] = [0,0]
etab[new_e][g.edge_type(e)-1] += 1
Expand Down

0 comments on commit b110243

Please sign in to comment.