Now I got this code but it doesn't work and I'm kinda lost because I do not know if it's a mistake of the controlled Z-rotation (which we have to do using only Single Qubit Gates and CNOT) or if I misunderstood the inverse Fourier transformation and have to do something else.
#Implementation of the inverse QFT def inverse_QFT(n): qc = QuantumCircuit(n) pi = np.pi # do the rotations with for loops on the quantumregister q = (q[n-1],...,q,q) for j in range(n-1,-1,-1): #Hadamard on the jth qubit qc.h(j) for k in range(j-1,-1,-1): # The Controlled Z Rotations by theta theta = 2*pi / (2**(j-k)) qc.cx(j,k) qc.rz(-theta, j) qc.cx(j,k) qc.rz(theta, j) return qc
I wanted to add, that the code does work (so I get an output) but does not give me the right answer.
Edit: I changed the exponent from $k$ to $j-k$. But it still does not work.