This is my code using qiskit below. I am not familiar with Unitarygate, so I tried to creat a cnot-gate.
from qiskit import QuantumCircuit
from qiskit.extensions import UnitaryGate
import numpy as np
matrix1 = [[1, 0, 0, 0],
[0, 1, 0, 0],
[0, 0, 0, 1],
[0, 0, 1, 0]]
gatecx = UnitaryGate(matrix1)
matrix2 = [[0,1],
[1,0]]
gatex = UnitaryGate(matrix2)
matrix3 = [[1/np.sqrt(2),1/np.sqrt(2)],
[1/np.sqrt(2),-1/np.sqrt(2)]]
gateh = UnitaryGate(matrix3)
circuit = QuantumCircuit(2,2)
circuit.append(gatex,[0])
circuit.append(gatecx,[0,1])
circuit.draw('mpl',scale=0.6)
I apply a x-gate to qubit0 first, then apply a cx-gate.
After running this code, qubit1 haven't be flipped. The result have shown that qubit0 is target-q and qubit1 is control-q. That is beyond comprehension!!
What make me confused is why qubit0 isn't control-qubit in code circuit.append(gatecx,[0,1])
?
Then I swapped the position of 0 and 1, circuit.append(gatecx,[1,0])
, qubit1 was flipped. Is the first position a control qubit?