Skip to content

copy _grounds in clone() and use other.is_ground(v) in tensor()#432

Merged
jvdwetering merged 1 commit intozxcalc:masterfrom
dlyongemallo:fix_missed_ground_ops
Apr 2, 2026
Merged

copy _grounds in clone() and use other.is_ground(v) in tensor()#432
jvdwetering merged 1 commit intozxcalc:masterfrom
dlyongemallo:fix_missed_ground_ops

Conversation

@dlyongemallo
Copy link
Copy Markdown
Contributor

Description

Cloned graphs lost their ground vertices because GraphS.clone() and Multigraph.clone() were not copying _grounds, and tensor() was checking g.is_ground(v) (the destination) instead of other.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

  • I have added/updated tests (for bugfixes, please include a regression test, for new features, include new tests either to an existing test file or a new file).
  • For new features: I have updated the documentation.
  • All the functions I added have a docstring parsable by sphinx (for a good example see pyzx.extract.extract_circuit).
  • I have added an entry to CHANGELOG.md describing my change.

Copilot AI review requested due to automatic review settings April 1, 2026 14:30
@dlyongemallo dlyongemallo marked this pull request as draft April 1, 2026 14:30
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes loss of “ground” vertices when duplicating or combining graphs, ensuring hybrid (grounded) structures survive clone() and tensor() operations.

Changes:

  • Copy _grounds in GraphS.clone() and Multigraph.clone() so cloned graphs preserve ground status.
  • Fix BaseGraph.tensor() to query other.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.

Comment thread tests/test_graph.py Outdated
@dlyongemallo dlyongemallo force-pushed the fix_missed_ground_ops branch from b1e66c2 to 0ce5166 Compare April 1, 2026 15:13
@dlyongemallo dlyongemallo marked this pull request as ready for review April 1, 2026 15:13
@jvdwetering jvdwetering merged commit 2312685 into zxcalc:master Apr 2, 2026
4 checks passed
@dlyongemallo dlyongemallo deleted the fix_missed_ground_ops branch April 2, 2026 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants