Skip to content
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

Add transpiler pass to optimize circuits with annotated operations #11475

Closed
alexanderivrii opened this issue Jan 2, 2024 · 2 comments
Closed
Assignees
Labels
type: feature request New feature or request
Milestone

Comments

@alexanderivrii
Copy link
Member

alexanderivrii commented Jan 2, 2024

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), 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

@alexanderivrii alexanderivrii added the type: feature request New feature or request label Jan 2, 2024
@alexanderivrii alexanderivrii added this to the 1.0.0 milestone Jan 2, 2024
@alexanderivrii alexanderivrii self-assigned this Jan 2, 2024
@ajavadia
Copy link
Member

ajavadia commented Jan 3, 2024

These are great.

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.

@mtreinish
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature request New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants