# calculating the unitary of a circuit using Qiskit's simulator

i am trying to verify qiskit's get_unitary() result. this is my code:

from qiskit.visualization import array_to_latex
qc6 = QuantumCircuit(2)
qc6.h(1)
qc6.x(0)
qc6.cx(1,0)
qc6.draw()
qc6.save_unitary()
resultqc6 = sim.run(assemble(qc6)).result()
stateqc6 = resultqc6.get_unitary()
array_to_latex(stateqc6)


and here is the output matrix that i get:

but when i am trying to calculate the unitary matrix, i get a different result! can anyOne point out what am i doint wrong? this is how i do it : (H ⊗ X)(CNOT):

• Maybe this is related with Qiskit qubit order? qiskit.org/documentation/tutorials/circuits/… Dec 7, 2022 at 11:59
• @luciano i took that into consideration by (H tensor X) instead of (X tnsor H) Dec 7, 2022 at 12:14

## 1 Answer

You multiply gate matrices in reverse order of application in the circuit. To see this, notice that you add gates to the right of the initial state in a circuit, while you left-multiply matrices by the initial state vector.

In your case, you should be multiplying

$$(CNOT)(H \otimes X)$$