I'm trying to reproduce in Qiskit the multiplicative form of the QFT for two qubits. It is similar to what is asked in Nielsen's QCQI book in Exercise 5.2 and Box 5.1. To check the results I'm printing the unitary transformation for the Qiskit circuit presented below:
import qiskit as qk
# Circuit definition
j1 = qk.QuantumRegister(1,'j1')
j2 = qk.QuantumRegister(1,'j2')
cr = qk.ClassicalRegister(1,"cr")
qc = qk.QuantumCircuit(j1,j2,cr)
qc.barrier()
qc.h(j1)
qc.cp(2*np.pi*(1/4),j2,j1,"R2")
qc.h(j2)
qc.swap(j1,j2)
qc.barrier()
# unitary transformation and circuit presentation
display(Operator(qc).data*2)
display(qc.draw('mpl'))
It seems to me that I followed all rules correctly, even putting the least significant qubit on top to match qiskit convention.
The problem is that the unitary transformation that I'm getting as a result is:
[[ 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j], [ 1.+0.j, 1.+0.j, -1.+0.j, -1.+0.j], [ 1.+0.j, -1.+0.j, 0.+1.j, -0.-1.j], [ 1.+0.j, -1.+0.j, -0.-1.j, 0.+1.j]]
And the correct matrix should be:
[[ 1.+0.j, 1.+0.j, 1.+0.j, 1.+0.j], [ 1.+0.j, 0.+1.j, -1.+0.j, 0.-1.j], [ 1.+0.j, -1.+0.j, 1.+0.j, -1.+0.j], [ 1.+0.j, 0.-1.j, -1.+0.j, 0.+1.j]])
I have been trying all day reproducing the result in Qiskit without any success. Any comments on what have I done wrong in my code? I have the feeling that I'm not using properly the cp (controlled phase) gate, but just cannot figure out what it could be.