Qiskit / qiskit

Qiskit is an open-source SDK for working with quantum computers at the level of extended quantum circuits, operators, and primitives.
https://www.ibm.com/quantum/qiskit
Apache License 2.0
4.85k stars 2.29k forks source link

KAK decomposition produces unnecessary single-qubit gates #9315

Open ajavadia opened 1 year ago

ajavadia commented 1 year ago

Environment

What is happening?

Extra single-qubit gates are inserted during KAK decomposition (when they can just be removed).

For some reason this does not happen in euler_basis='U321' but happens in other euler_basis.

How can we reproduce the issue?

from qiskit.quantum_info.synthesis import TwoQubitBasisDecomposer
from qiskit.circuit.library import CXGate

decomposer = TwoQubitBasisDecomposer(CXGate(), euler_basis='U')
decomposer(CXGate().to_matrix()).draw()

It's just doing KAK on the CX gate in the CX basis. So it should just return CX itself.

However it returns this:

       ┌────────────┐     ┌───────────────┐
q12_0: ┤ U(0,-π,-π) ├──■──┤ U(0,-π/2,π/2) ├
       ├────────────┤┌─┴─┐└─┬────────────┬┘
q12_1: ┤ U(0,-π,-π) ├┤ X ├──┤ U(0,-π,-π) ├─
       └────────────┘└───┘  └────────────┘ 

This is technically correct but inefficient. Those U gates can all just be removed. If I change euler_basis='U321' then it works correctly and returns:


q13_0: ──■──
       ┌─┴─┐
q13_1: ┤ X ├
       └───┘

What should happen?

Those gates should not be inserted in the first place. They are hard to remove by subsequent passes as the transformation is not local.

Any suggestions?

No response

vtomole commented 1 year ago

Hey @ajavadia @levbishop ,

Just want to let ya'll know that we have run into this if that helps you figure out how to prioritize bug fixes.