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
5.1k stars 2.34k forks source link

UnitarySynthesis ignores basis_gates argument for >= 3 qubit unitaries #11849

Open kevinsung opened 7 months ago

kevinsung commented 7 months ago

Environment

What is happening?

I create a circuit with a 3-qubit UnitaryGate. I use UnitarySynthesis and pass a CZ gate basis. It gets synthesized down to CX instead of CZ.

How can we reproduce the issue?

from qiskit import QuantumCircuit, QuantumRegister
from qiskit.circuit.library import UnitaryGate
from qiskit.quantum_info import random_unitary
from qiskit.transpiler import PassManager
from qiskit.transpiler.passes import UnitarySynthesis

qubits = QuantumRegister(3, name="q")
circuit = QuantumCircuit(qubits)
a, b, c = qubits
circuit.append(UnitaryGate(random_unitary(8)), [a, b, c])

pass_manager = PassManager(
    [
        UnitarySynthesis(basis_gates=["cz", "id", "rz", "sx", "x"]),
    ]
)
transpiled = pass_manager.run(circuit)
transpiled.draw("mpl")

image

What should happen?

Should be synthesized down to CZ as requested.

Any suggestions?

No response

mtreinish commented 7 months ago

The default synthesis plugin used by UnitarySynthesis relies on the Quantum Shannon Decomposition module in qiskit.synthesis (https://github.com/Qiskit/qiskit/blob/main/qiskit/synthesis/unitary/qsd.py) for unitaries of > 2 qubits. It currently doesn't look at any basis gates or target constraints.

At the pass level I'm not sure we can always guarantee the output synthesis is going to respect the basis_gates or target arguments as different synthesis plugins can explicitly ignore the arguments. But I think we should look at fixing this for the default plugin though because it does advertise it does respect the basis gates and target, and this issue would potentially break the synthesis translation stage plugin too.