Transpiler pass for converting c_if
to if_test
#8601
Labels
type: feature request
New feature or request
c_if
to if_test
#8601
What should we add?
As developers, we want to transition away from
Instruction.condition
(via theInstruction{,Set}.c_if
methods) to remove unnecessary state fromInstruction
subclasses. Part of the backwards compatibility for this support can be a transpiler pass that converts instructions with non-None
conditions to instancesIfElseBlock
.This has two main benefits as a temporary measure:
Instruction
instances within the transpiler, without immediately needing to change the behaviour ofInstruction.c_if
, which is very hard to do within the deprecation policy.The first point is the justification for why this is useful to be in Terra (albeit not yet in the preset pass managers - the rest of the support for
IfElseBlock
is too shallow right now), and the second point is why we want this sooner rather than later.Potential further work: complex conditionals (e.g.
custom_gate.c_if()
) are likely to be expanded by the basis translator into many conditional gates all with the same condition. Ideally these would be transformed by this pass before basis translation so that they all appear in the sameIfElseBlock
, but right now the support for the control-flow operations in the rest of the transpiler (especially routing) is still being worked on. One could have a separate classical optimisation pass that runs during optimisation that collects runs of conditionals on the same condition into a singleIfElseBlock
. This might be moving Terra too far in the direction of classical optimisation, however, and may be better suited for other libraries.cc: @taalexander.
The text was updated successfully, but these errors were encountered: