I was expecting Qiskit to do a upside down version of my unitary as it does for other unitary matrices of CNOT and Toffoli gates given in textbooks : if you convert a toffoli matrix from quantum computing textbooks(target 3rd and ctrl 1st,2nd) you will get an inverted version of it (target as q0 and ctrl as q1,q2).
So I hardcoded a unitary matrix and converted to gate then appended to qc. But the operator returns exactly the same matrix, so I wonder if my unitary is actually upside down but operator just shows flipped output ?
Hard coded matrix :
Operator output :
Code :
u = QuantumCircuit(qr)
u.unitary(UA, range(qr), label='U')
unitary = u.to_gate()
unitary.name = 'U'
mpl display :
qc = QuantumCircuit(qr)
qc.append(unitary, range(0, qr))
qc.draw("mpl", style='bw')
U = Operator( [[1,0,0,0], [0,1,0,0], [0,0,0,1], [0,0,1,0]])
then what it is implementing is actually the $CX_{q_1, q_0}$ . That is the controlled qubit is the $q_1$ and the target qubit is $q_0$. If you want to implement say $ CX_{q_0, q_1}$ then you need to input your unitary asOperator( [ [1,0,0,0], [0,0,0,1] [0,0,1,0], [0,1,0,0] ])
$\endgroup$