# Unitary to circuit in qiskit

I have a program that determine the unitary matrix of a unknown gate in a quantum circuit and then it checks in the standard gate list to get the name of unknown gate. It is guaranteed that unknown gate is some standard gate. Now the issue is if our unknown gate is ,say Hadamard gate, but we have a circuit with more than one qubit, then the matrix representation is tensor product of Hadamard and Identity gate. So , in such cases how to decompose the unitary matrix into a set of one or two qubit standard gates in qiskit?

• Does the standard gate list contain single-qubit gates only? And do you know the gate is applied to which qubit? Mar 23 at 8:30

Say that you have the following matrix for a single-qubit gate: $$\begin{bmatrix} 0.9689124214 & - 0.2474039604 i \\ - 0.2474039604 i & 0.9689124214 \\ \end{bmatrix}$$

First step is to create a QuantumCircuit with the gate in it:

from qiskit import QuantumCircuit
from qiskit.quantum_info import Operator

circuit = QuantumCircuit(1)
circuit.append(Operator([[0.96891242+0.j        , 0.        -0.24740396j],
[0.        -0.24740396j, 0.96891242+0.j        ]]), )


You can confirm that is correct by reversing the process like this:

from qiskit.visualization.array import array_to_latex
array_to_latex(Operator(circuit))


$$\begin{bmatrix} 0.9689124214 & - 0.2474039604 i \\ - 0.2474039604 i & 0.9689124214 \\ \end{bmatrix}$$

Now is synthesis time. This will depend a lot on your standard gate list. Take, for example, rotation gates:

from qiskit.transpiler.passes import UnitarySynthesis
result = UnitarySynthesis(basis_gates=['rx', 'ry', 'rz'])(circuit)
print(result)

   ┌─────────┐
q: ┤ Rx(0.5) ├
└─────────┘


You can confirm this result using Operators:

Operator(result) == Operator([[0.96891242+0.j        , 0.        -0.24740396j],
[0.        -0.24740396j, 0.96891242+0.j        ]])

True