Support simple IfElseOp conditionals in OpenQASM 2 export#14556
Conversation
With the removal of `Instruction.c_if` in Qiskitgh-13506, we lost the ability to export the sort of simple conditionals that OpenQASM 2 can represent. This restores the ability, for the subset of `IfElseOp` objects that OpenQASM 2 can represent. It is possible to make the exporter slightly more permissive in some cases, if desired/necessary.
|
One or more of the following people are relevant to this code:
|
Pull Request Test Coverage Report for Build 20142533553Details
💛 - Coveralls |
There was a problem hiding this comment.
Are register arrays supposed to throw up an error? Does the error OpenQASM 2 only supports register-equality conditions refer to that condition.
I do see this line but wanted clarification:
if isinstance(operation.condition, expr.Expr) or isinstance(
operation.condition[0], Clbit
)
Cryoris
left a comment
There was a problem hiding this comment.
1 question and 1 tiny comment otherwise LGTM
| if len(body.data) != 1: | ||
| # This could be relaxed in the future by "unrolling" the block and putting | ||
| # individual `if` conditions on each instruction. | ||
| raise QASM2ExportError( |
There was a problem hiding this comment.
It's stretching my memory, but were we previously able to do c_if on InstructionSets (i.e. multiple instructions) or do we have the same functionality as before if we only allow a single instruction?
There was a problem hiding this comment.
The old InstructionSet.c_if (which doesn't exist any more) used to set the .condition field individually, which corresponded to the OQ2 model (and this one) of only allowing if (<reg> == <val>) <gate>; - there's no blocks in OQ2.
Summary
With the removal of
Instruction.c_ifin gh-13506, we lost the ability to export the sort of simple conditionals that OpenQASM 2 can represent. This restores the ability, for the subset ofIfElseOpobjects that OpenQASM 2 can represent.It is possible to make the exporter slightly more permissive in some cases, if desired/necessary.
Details and comments
Fix #13848