Skip to content

Fix grounds being dropped during composition and other operations #178

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

Merged
merged 1 commit into from
Nov 4, 2023
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
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