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 Instruction.repeat with conditionals (backport #11940) #12499

Merged
merged 1 commit into from
Jun 4, 2024

Conversation

mergify[bot]
Copy link
Contributor

@mergify mergify bot commented Jun 4, 2024

Summary

We can't put register conditionals within an Instruction.definition field; the data model of QuantumCircuit doesn't permit closing over registers from within definitions. This commit moves a condition to the outer Instruction that's returned.

Details and comments

Fix #11935
Fix #11936 (though note that #11761 would then be triggered for OQ3).

Important

As implemented, this commit isn't necessarily a completely valid transformation, but I'm putting it up in this form for a bit of discussion.

The point is that an instruction can in theory affect its own condition; consider a Measure().c_if(cr, value), where the measure instruction within the circuit is applied to a clbit that's in cr. To go further, consider the custom instruction whose definition is h q[0]; measure q[0] -> c[0]; - this is clearly not idempotent under a c-based condition (one could argue that the bare measure was, in the context of a noiseless abstract circuit, since the first measure would collapse the state).

Given that Instruction.repeat is only applied without a circuit context, and we're moving to remove Instruction.condition for these same sorts of reasons (in favour of IfElseOp), I think this is a transformation we can accept, though perhaps with additional documentation.


This is an automatic backport of pull request #11940 done by Mergify.

* Fix `Instruction.repeat` with conditionals

We can't put register conditionals within an `Instruction.definition`
field; the data model of `QuantumCircuit` doesn't permit closing over
registers from within definitions.  This commit moves a condition to the
outer `Instruction` that's returned.

* Avoid 'to_mutable' if not needed

* Add proviso on repeated conditionals in documentation

* Update wording in release note

Co-authored-by: Luciano Bello <[email protected]>

---------

Co-authored-by: Luciano Bello <[email protected]>
(cherry picked from commit 6ebb7aa)
@mergify mergify bot requested a review from a team as a code owner June 4, 2024 10:52
@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 Changelog: Bugfix Include in the "Fixed" section of the changelog mod: circuit Related to the core of the `QuantumCircuit` class or the circuit library affects extended support This issue (also) affects extended support labels Jun 4, 2024
@1ucian0 1ucian0 added this to the 0.46.2 milestone Jun 4, 2024
@coveralls
Copy link

Pull Request Test Coverage Report for Build 9365788968

Details

  • 11 of 11 (100.0%) changed or added relevant lines in 1 file are covered.
  • 12 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.001%) to 86.948%

Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/lex.rs 6 92.37%
crates/qasm2/src/parse.rs 6 97.61%
Totals Coverage Status
Change from base Build 9314544782: -0.001%
Covered Lines: 75008
Relevant Lines: 86268

💛 - Coveralls

@1ucian0 1ucian0 enabled auto-merge June 4, 2024 11:50
@1ucian0 1ucian0 added this pull request to the merge queue Jun 4, 2024
Merged via the queue into stable/0.46 with commit 4473bbe Jun 4, 2024
11 of 12 checks passed
@mergify mergify bot deleted the mergify/bp/stable/0.46/pr-11940 branch June 4, 2024 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects extended support This issue (also) affects extended support Changelog: Bugfix Include in the "Fixed" section of the 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.

4 participants