Fix Instruction.repeat
with conditionals (backport #11940)
#12499
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.This is an automatic backport of pull request #11940 done by Mergify.