Skip to content
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

Fix issue with deepcopy and builder API. #11669

Merged
merged 3 commits into from
Jan 31, 2024

Conversation

kevinhartman
Copy link
Contributor

@kevinhartman kevinhartman commented Jan 29, 2024

Summary

Fixes an issue with QuantumCircuit.__deepcopy__'s handling of the scope builder API introduced in #10977.

Details and comments

The _OuterCircuitScopeInterface instance held in QuantumCircuit._builder_api contains a reference to the outer circuit, which appears to be an issue when performing a deepcopy (we end up with a duplicated circuit inside the scope instance).

To fix this, we construct a new _OuterCircuitScopeInterface for the deep copy instead.

Resolves #11610

@kevinhartman kevinhartman added Changelog: None Do not include in changelog mod: circuit Related to the core of the `QuantumCircuit` class or the circuit library labels Jan 29, 2024
@kevinhartman kevinhartman added this to the 1.0.0 milestone Jan 29, 2024
@kevinhartman kevinhartman requested a review from a team as a code owner January 29, 2024 21:35
@qiskit-bot
Copy link
Collaborator

One or more of the the following people are requested to review this:

  • @Qiskit/terra-core

Copy link
Member

@jakelishman jakelishman left a comment

Choose a reason for hiding this comment

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

Ah thanks, yeah, it's obvious when you see it. Can we also add tests for shallow copy and pickle, here?

It'd be good to include some explicit assertions on exactly the clbits/cregs that should be present in both qc and qc2 after the deep copy/copy/pickle as well, to catch the potential failure case where both calls mutate both.

@coveralls
Copy link

coveralls commented Jan 29, 2024

Pull Request Test Coverage Report for Build 7731848487

Warning: This coverage report may be inaccurate.

We've detected an issue with your CI configuration that might affect the accuracy of this pull request's coverage report.
To ensure accuracy in future PRs, please see these guidelines.
A quick fix for this PR: rebase it; your next report should be accurate.

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • 205 unchanged lines in 30 files lost coverage.
  • Overall coverage increased (+0.1%) to 89.6%

Files with Coverage Reduction New Missed Lines %
qiskit/circuit/parametervector.py 1 93.33%
qiskit/circuit/tools/pi_check.py 1 91.15%
qiskit/primitives/containers/data_bin.py 1 96.97%
qiskit/primitives/statevector_sampler.py 1 99.09%
qiskit/exceptions.py 2 93.75%
qiskit/primitives/containers/estimator_pub.py 2 97.47%
qiskit/primitives/containers/sampler_pub.py 2 96.92%
qiskit/providers/backend.py 2 79.73%
qiskit/providers/models/backendstatus.py 2 74.07%
qiskit/transpiler/passes/basis/basis_translator.py 2 97.64%
Totals Coverage Status
Change from base Build 7702053542: 0.1%
Covered Lines: 59404
Relevant Lines: 66299

💛 - Coveralls

@kevinhartman
Copy link
Contributor Author

@jakelishman

Ah thanks, yeah, it's obvious when you see it. Can we also add tests for shallow copy and pickle, here?

It'd be good to include some explicit assertions on exactly the clbits/cregs that should be present in both qc and qc2 after the deep copy/copy/pickle as well, to catch the potential failure case where both calls mutate both.

Good idea(s)! Done in ba9a32c.

jakelishman
jakelishman previously approved these changes Jan 31, 2024
Copy link
Member

@jakelishman jakelishman left a comment

Choose a reason for hiding this comment

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

Thanks for finding this, and the fix!

@jakelishman
Copy link
Member

Wait sorry, I forgot I hadn't pushed the fix to the lint failure lol

Copy link
Member

@jakelishman jakelishman left a comment

Choose a reason for hiding this comment

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

That should keep pylint happy.

@jakelishman jakelishman enabled auto-merge January 31, 2024 20:14
@jakelishman jakelishman added this pull request to the merge queue Jan 31, 2024
Merged via the queue into Qiskit:main with commit 1c76bc8 Jan 31, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: None Do not include in changelog mod: circuit Related to the core of the `QuantumCircuit` class or the circuit library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

copy.deepcopy doesn't work on QuantumCircuit
4 participants