# Qiskit TwoQubitBasisDecomposer - how to properly decompose gates?

I'm new with Qiskit and I'm struggling with creating my own controlled gates. I'm trying to create a ZYZ decomposition of a controlled unitary gate I created. I'm trying to use the method TwoQubitBasisDecomposer. Here is a piece of my code

U = Operator([[a,b],[c,d]]) #forms an unitary matrix

ucirc = QuantumCircuit(1)
ucirc.unitary(U,0)

c_ucirc = ucirc.control()

Ug = c_ucirc.to_gate()
UgZYZ = TwoQubitBasisDecomposer(Ug, euler_basis="ZYZ")
print(UgZYZ.basis)


When printing the basis Qiskit returns the equivalent two-qubit decomposed gate

However, I don't know how to actually get the gate itself to insert on other algorithms. How can I proceed? All methods within TwoQubitBasisDecomposer ask for a target. What is such a target?

The class TwoQubitBasisDecomposer decomposes 2-qubit unitaries using the minimum number of a 2-qubit basis gate of your choice. You pass this basis gate to the class constructor. In your code snippet, Ug is the basis gate that will be used to decompose the other unitaries.

Given a 2-qubit unitary G, you can decompose it as follows. Note that, TwoQubitBasisDecomposer implements __call__ so we can call its instance as a function.

# Here, we create a random 2-qubit unitary:
from qiskit.quantum_info.random import random_unitary
G = random_unitary(4).data

# Now, we decompose it using your decomposer:
circ = UgZYZ(G)
circ.draw('mpl')


• Thanks a lot! It did help me. Feb 11 at 13:24