You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The idea is to add a transpiler pass that optimizes circuits with annotated operations.
Here is the list of possible optimizations that came up in various discussions:
Canonicalize modifiers. Convert the modifiers of an annotated operation into canonical form.
Example: consecutively applying inverse(), control(2), and inverse() is equivalent to applying control(2).
Remove annotations when possible.
Example: AnnotatedOperation(SwapGate(), [InverseModifier(), InverseModifier()]) is equivalent to SwapGate().
Recursively combine annotations.
Example: if g1 = AnnotatedOperation(g2, ControlModifier(2)) and g2 = AnnotatedOperation(SwapGate(), InverseModifier()), then we can replace g1 by AnnotatedOperation(SwapGate(), [InverseModifier(), ControlModifier(2)]).
Remove pairs of consecutive inverse gates.
This has several flavors. SGate() cancels out with SdgGate() but also with AnnotatedOperation(SGate(), InverseModifier) and also with AnnotatedOperation(SdgGate(), []). I am not sure this specific optimization should be a part of this transpiler pass, maybe it should be supported by InverseCancellation or the like.
Perform conjugate reduction.
A great example is a controlled QFT-based adder, which looks as follows: control-(QFT^{-1} -- U -- QFT). We saw in the past that Qiskit produces significantly sub-optimal decompositions. The circuit can be optimized to: QFT^{-1} -- control-U -- QFT, i.e. the control can be moved to the U-part only.
The pass probably needs to be recursive, descending into definitions of various gates.
Suggestions for additional optimizations are highly welcome
The text was updated successfully, but these errors were encountered:
I would add that most (any?) circuit optimizations that we do should be done while the gates are controlled by the same qubits. For example there is a pass to collapse a chain of gates: this should be done when those gates share the same control(s) too.
I'm going to close this as #11476 has merged now. If there are additional optimizations we want to enable in the pass, we can open a new issue to track those for future releases.
What should we add?
The idea is to add a transpiler pass that optimizes circuits with annotated operations.
Here is the list of possible optimizations that came up in various discussions:
Canonicalize modifiers. Convert the modifiers of an annotated operation into canonical form.
Example: consecutively applying
inverse()
,control(2)
, andinverse()
is equivalent to applyingcontrol(2)
.Remove annotations when possible.
Example:
AnnotatedOperation(SwapGate(), [InverseModifier(), InverseModifier()])
is equivalent toSwapGate()
.Recursively combine annotations.
Example: if
g1 = AnnotatedOperation(g2, ControlModifier(2))
andg2 = AnnotatedOperation(SwapGate(), InverseModifier())
, then we can replaceg1
byAnnotatedOperation(SwapGate(), [InverseModifier(), ControlModifier(2)])
.Remove pairs of consecutive inverse gates.
This has several flavors.
SGate()
cancels out withSdgGate()
but also withAnnotatedOperation(SGate(), InverseModifier)
and also withAnnotatedOperation(SdgGate(), [])
. I am not sure this specific optimization should be a part of this transpiler pass, maybe it should be supported byInverseCancellation
or the like.Perform conjugate reduction.
A great example is a controlled QFT-based adder, which looks as follows:
control-(QFT^{-1} -- U -- QFT)
. We saw in the past that Qiskit produces significantly sub-optimal decompositions. The circuit can be optimized to:QFT^{-1} -- control-U -- QFT
, i.e. the control can be moved to theU
-part only.The pass probably needs to be recursive, descending into
definitions
of various gates.Suggestions for additional optimizations are highly welcome
The text was updated successfully, but these errors were encountered: