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 AnnotatedOperation being modified during parameter assignment (backport #12869) #12872

Merged
merged 1 commit into from
Jul 31, 2024

Conversation

mergify[bot]
Copy link
Contributor

@mergify mergify bot commented Jul 31, 2024

Summary

Copying an annotated operation currently does not copy the underlying base_op. This leads to problems down the line, as we have multiple annotated operations referencing the same base_op, for example in parameter assignment. This PR copies the base_op upon copying the annotated operation to fix this problem.

Details and comments

No reno (yet), as this bug was probably mostly noticable in this release (1.2) which adds parameter handling to AnnotatedOperation.

Here's a minimal breaking example, which is fixed by this PR.

from qiskit.circuit import Parameter, QuantumCircuit
from qiskit.circuit.library import RYGate

theta = Parameter("theta")
ry = RYGate(theta)
qc = QuantumCircuit(5)
qc.append(ry.control(4, annotated=True), qc.qubits)
qc.assign_parameters([1.23])
print(qc)  # prints the circuit, which should be unmodified, with a bound parameter

qc.assign_parameters([1.23])  # fails as the parameter is already bound

This is an automatic backport of pull request #12869 done by [Mergify](https://mergify.com).

@mergify mergify bot requested a review from a team as a code owner July 31, 2024 16:53
@qiskit-bot
Copy link
Collaborator

Thank you for opening a new pull request.

Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient.

While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone.

One or more of the following people are relevant to this code:

  • @Qiskit/terra-core

@github-actions github-actions bot added the Changelog: None Do not include in changelog label Jul 31, 2024
@github-actions github-actions bot added this to the 1.2.0 milestone Jul 31, 2024
@mtreinish mtreinish enabled auto-merge July 31, 2024 16:59
@coveralls
Copy link

Pull Request Test Coverage Report for Build 10184376926

Details

  • 1 of 1 (100.0%) changed or added relevant line in 1 file are covered.
  • 17 unchanged lines in 3 files lost coverage.
  • Overall coverage decreased (-0.02%) to 89.829%

Files with Coverage Reduction New Missed Lines %
qiskit/transpiler/passes/synthesis/unitary_synthesis.py 2 88.39%
crates/qasm2/src/lex.rs 3 91.98%
crates/qasm2/src/parse.rs 12 96.23%
Totals Coverage Status
Change from base Build 10183294285: -0.02%
Covered Lines: 66432
Relevant Lines: 73954

💛 - Coveralls

@mtreinish mtreinish added this pull request to the merge queue Jul 31, 2024
Merged via the queue into stable/1.2 with commit a361f6c Jul 31, 2024
18 checks passed
@mergify mergify bot deleted the mergify/bp/stable/1.2/pr-12869 branch July 31, 2024 18:35
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants