Skip to content

Commit

Permalink
Merge pull request #178 from ABorgna/fix/dropped-grounds
Browse files Browse the repository at this point in the history
Fix grounds being dropped during composition and other operations
  • Loading branch information
jvdwetering authored Nov 4, 2023
2 parents 18388ca + bd9f7ae commit a4a1be9
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions pyzx/graph/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,8 @@ def compose(self, other: 'BaseGraph') -> None:
w = self.add_vertex(other.type(v),
phase=other.phase(v),
qubit=other.qubit(v),
row=offset + other.row(v))
row=offset + other.row(v),
ground=other.is_ground(v))
if v in other._vdata: self._vdata[w] = other._vdata[v]
vtab[v] = w
for e in other.edges():
Expand Down Expand Up @@ -361,11 +362,12 @@ def merge(self, other: 'BaseGraph') -> Tuple[List[VT],List[ET]]:
rs = other.rows()
qs = other.qubits()
phase = other.phases()
grounds = other.grounds()

vert_map = dict()
edges = []
for v in other.vertices():
w = self.add_vertex(ty[v],qs[v],rs[v],phase[v])
w = self.add_vertex(ty[v],qs[v],rs[v],phase[v],v in grounds)
vert_map[v] = w
for e in other.edges():
s,t = other.edge_st(e)
Expand All @@ -382,12 +384,13 @@ def subgraph_from_vertices(self,verts: List[VT]) -> 'BaseGraph':
rs = self.rows()
qs = self.qubits()
phase = self.phases()
grounds = self.grounds()

edges = [self.edge(v,w) for v in verts for w in verts if self.connected(v,w)]

vert_map = dict()
for v in verts:
w = g.add_vertex(ty[v],qs[v],rs[v],phase[v])
w = g.add_vertex(ty[v],qs[v],rs[v],phase[v],v in grounds)
vert_map[v] = w
for e in edges:
s,t = self.edge_st(e)
Expand Down

0 comments on commit a4a1be9

Please sign in to comment.