0
$\begingroup$

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:

enter image description here

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):

enter image description here

$\endgroup$
2

1 Answer 1

1
$\begingroup$

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) $$

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.