copy _grounds in clone() and use other.is_ground(v) in tensor()#432
Merged
jvdwetering merged 1 commit intozxcalc:masterfrom Apr 2, 2026
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes loss of “ground” vertices when duplicating or combining graphs, ensuring hybrid (grounded) structures survive clone() and tensor() operations.
Changes:
- Copy
_groundsinGraphS.clone()andMultigraph.clone()so cloned graphs preserve ground status. - Fix
BaseGraph.tensor()to queryother.is_ground(v)when copying vertices from the source graph. - Add regression tests for clone/tensor ground preservation and document the fix in the changelog.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
tests/test_graph.py |
Adds regression tests for ground preservation in clone() and tensor(). |
pyzx/graph/multigraph.py |
Ensures _grounds is copied in Multigraph.clone(). |
pyzx/graph/graph_s.py |
Ensures _grounds is copied in GraphS.clone(). |
pyzx/graph/base.py |
Fixes tensor() to preserve ground status from the source graph (other). |
CHANGELOG.md |
Records the bugfix for clone() and tensor() ground handling. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
b1e66c2 to
0ce5166
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Cloned graphs lost their ground vertices because
GraphS.clone()andMultigraph.clone()were not copying_grounds, andtensor()was checkingg.is_ground(v)(the destination) instead ofother.is_ground(v)(the source) when copying. This change fixes both of these bugs.Related issue
N/A (but found this bug while working on #430)
Checklist
pyzx.extract.extract_circuit).