-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
#11940
Fix Instruction.repeat
with conditionals
#11940
Conversation
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.
One or more of the the following people are requested to review this:
|
Pull Request Test Coverage Report for Build 8171222509Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
releasenotes/notes/fix-instruction-repeat-conditional-dfe4d7ced54a7bb6.yaml
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fix looks good to me. I just have a small non-blocking comment on the release note.
releasenotes/notes/fix-instruction-repeat-conditional-dfe4d7ced54a7bb6.yaml
Outdated
Show resolved
Hide resolved
Co-authored-by: Luciano Bello <bel@zurich.ibm.com>
I've also updated the documentation of |
* 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 <bel@zurich.ibm.com> --------- Co-authored-by: Luciano Bello <bel@zurich.ibm.com>
* 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 <bel@zurich.ibm.com> --------- Co-authored-by: Luciano Bello <bel@zurich.ibm.com>
This seems (based on the presence of affected code) to affect |
@Mergifyio backport stable/0.46 |
✅ Backports have been created
|
* 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 <bel@zurich.ibm.com> --------- Co-authored-by: Luciano Bello <bel@zurich.ibm.com> (cherry picked from commit 6ebb7aa)
* 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 <bel@zurich.ibm.com> --------- Co-authored-by: Luciano Bello <bel@zurich.ibm.com> (cherry picked from commit 6ebb7aa) Co-authored-by: Jake Lishman <jake.lishman@ibm.com>
Summary
We can't put register conditionals within an
Instruction.definition
field; the data model ofQuantumCircuit
doesn't permit closing over registers from within definitions. This commit moves a condition to the outerInstruction
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 incr
. To go further, consider the custom instruction whose definition ish q[0]; measure q[0] -> c[0];
- this is clearly not idempotent under ac
-based condition (one could argue that the baremeasure
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 removeInstruction.condition
for these same sorts of reasons (in favour ofIfElseOp
), I think this is a transformation we can accept, though perhaps with additional documentation.