Skip to content

Commit

Permalink
improving bialgebra in editor_actions.py
Browse files Browse the repository at this point in the history
  • Loading branch information
RazinShaikh committed Jul 8, 2024
1 parent b8339e9 commit 014e74d
Showing 1 changed file with 8 additions and 43 deletions.
51 changes: 8 additions & 43 deletions pyzx/editor_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,26 +267,23 @@ def bialgebra(g: BaseGraph[VT,ET],
for e in g.incident_edges(v[i]):
source, target = g.edge_st(e)
other_vertex = source if source != v[i] else target
if other_vertex != v[j] or (multi_edge_found and i == 0):
if other_vertex != v[j] or multi_edge_found:
q = 0.4*g.qubit(other_vertex) + 0.6*g.qubit(v[i])
r = 0.4*g.row(other_vertex) + 0.6*g.row(v[i])
newv = g.add_vertex(g.type(v[j]), qubit=q, row=r)
g.set_phase(newv, g.phase(v[j]))
nhd[i].append(newv)
if other_vertex != v[j]:
if upair(newv, other_vertex) not in etab:
etab[upair(newv, other_vertex)] = [0, 0]
type_index = 0 if g.edge_type(e) == EdgeType.SIMPLE else 1
etab[upair(newv, other_vertex)][type_index] += 1
else:
if other_vertex == v[j]:
q = 0.4*g.qubit(v[i]) + 0.6*g.qubit(other_vertex)
r = 0.4*g.row(v[i]) + 0.6*g.row(other_vertex)
newv2 = g.add_vertex(g.type(v[i]), qubit=q, row=r)
nhd[j].append(newv2)
if upair(newv, newv2) not in etab:
etab[upair(newv, newv2)] = [0, 0]
etab[upair(newv, newv2)][0] += 1
elif other_vertex == v[j]:
other_vertex = newv2
if upair(newv, other_vertex) not in etab:
etab[upair(newv, other_vertex)] = [0, 0]
type_index = 0 if g.edge_type(e) == EdgeType.SIMPLE else 1
etab[upair(newv, other_vertex)][type_index] += 1
elif i == 0: # only add new vertex once
multi_edge_found = True

for n1 in nhd[0]:
Expand All @@ -301,38 +298,6 @@ def bialgebra(g: BaseGraph[VT,ET],
else: #g.type(w) == VertexType.H_BOX
t = VertexType.Z
g.scalar.add_power(g.vertex_degree(v1)-2)


# v is an X-spider, but w is either a Z-spider or an H-box
# t = g.type(w)
# multi_edge_found = False
# for e in g.incident_edges(v):
# source, target = g.edge_st(e)
# n = source if source != v else target
# if n == w and not multi_edge_found:
# multi_edge_found = True
# continue
# r = 0.6*g.row(v) + 0.4*g.row(n)
# q = 0.6*g.qubit(v) + 0.4*g.qubit(n)
# v2 = g.add_vertex(t,q,r)
# etab[upair(n,v2)] = [1,0] if g.edge_type(e) == EdgeType.SIMPLE else [0,1]
# new_verts.append(v2)
# if g.type(w) == VertexType.Z:
# t = VertexType.X
# g.scalar.add_power((g.vertex_degree(v)-2)*(g.vertex_degree(w)-2))
# else: #g.type(w) == VertexType.H_BOX
# t = VertexType.Z
# g.scalar.add_power(g.vertex_degree(v)-2)
# for e in g.incident_edges(w):
# source, target = g.edge_st(e)
# n = source if source != w else target
# if n == v: continue
# r = 0.6*g.row(w) + 0.4*g.row(n)
# q = 0.6*g.qubit(w) + 0.4*g.qubit(n)
# w2 = g.add_vertex(t,q,r)
# etab[upair(n,w2)] = [1,0] if g.edge_type(e) == EdgeType.SIMPLE else [0,1]
# for v2 in new_verts:
# etab[upair(w2,v2)] = [1,0]
return (etab, rem_verts, [], False)


Expand Down

0 comments on commit 014e74d

Please sign in to comment.