For three qubits, I thought swapping the first and third qubit is equivalent to vertically flipping the circuit. However, performing one and then the other in Qiskit returns two different operators, despite the fact that the second should undo the first. My example circuit is the QFT on three qubits on which I am doing some analysis. Below is the circuit with no swap or reverse_bits.
N = 3
qr = QuantumRegister(N,'q')
cr = ClassicalRegister(N,'c')
qftCircuit = QuantumCircuit(qr,cr)
ct = TGate().control(1)
# Begin the QFT (with no swap or reverse_bits)
qftCircuit.h(0)
qftCircuit.cs(1,0)
qftCircuit.append(ct,[2,0])
qftCircuit.h(1)
qftCircuit.cs(2,1)
qftCircuit.h(2)
qftCircuit.draw('mpl')
Now when I get this circuit as an operator and compare it to the operator with the swaps, I can see that the circuit visually looks equivalent but they are not mathematically the same operator.(here sp
is Sympy just to display it nicely):
noswaps = quantum_info.Operator(qftCircuit).data
qftCircuit.swap(0,2)
qftCircuit = qftCircuit.reverse_bits()
qftCircuit.draw('mpl')
withswaps = quantum_info.Operator(qftCircuit).data
display(sp.Matrix(np.round(noswaps-withswaps,2)))
The question is why isn't this a matrix of zeros?