# Unexpected Rotations in QFT Implementation with Qiskit vs. Expected Behavior in Quirk

I'm working on implementing the Quantum Fourier Transform (QFT) using Qiskit. I've encountered an issue where unexpected rotations occur in the presence of a Hadamard circuit, which contrasts with the expected behavior based on my simulations using Quirk. I suspect there might be a mistake in my Qiskit code, but I'm not certain about the source of the discrepancy.

Here's a detailed description of the problem:

In my Qiskit implementation of QFT, I observe rotations being applied in places where, theoretically, there shouldn't be any, especially after setting up the Hadamard gates for qubit initialization. To cross-reference my results, I used the Quirk quantum circuit simulator with a similar setup. Here's the Quirk circuit link, which does not exhibit the same unexpected rotations. I'm puzzled by the differences in the outcome between Qiskit and Quirk, as I expected the behavior of the QFT to be consistent across different platforms. Below is the relevant portion of my Qiskit code where I think the issue might be occurring:

def qft_inv(qc, a, b):
reverse(qc, a, b)
qc.barrier()
for i in range(a, b):
for j in range(i - 1, a - 1, -1):
theta = -np.pi / (2 ** (i - j))
qc.crz(theta, i, j)
visualize_on_bloch(qc)
qc.h(i)
qc.barrier()
visualize_on_bloch(qc)


I'm looking for insights on why my Qiskit implementation behaves differently from the Quirk simulation and whether there's something I'm missing or doing incorrectly in my code. Any suggestions on how to align my Qiskit implementation with the expected theoretical behavior observed in Quirk would be greatly appreciated.

• Replace the control-rz gates with controlled-phase gates. Mar 6 at 20:53
• Thank You so much! I solved Mar 7 at 18:25

@diemilio is right; you need to use controlled-phase gates.

Controlled-rz and controlled-phase are equivalent up to a global phase, which means they're interchangeable until you control them.

To see why through a simpler example, take the identity gate $$I = \begin{bmatrix}1 & 0 \\ 0 & 1 \end{bmatrix}$$, and another gate $$U = e^{i\theta}I = \begin{bmatrix}e^{i\theta} & 0 \\ 0 & e^{i\theta} \end{bmatrix}$$. Both $$I$$ and $$U$$ are equivalent up to global phase.

Controlled, these become

$$CI = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \\ \end{bmatrix} \;\;\text{and}\;\; CU = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & e^{i\theta} & 0 \\ 0 & 0 & 0 & e^{i\theta} \\ \end{bmatrix}$$

That is, $$CI$$ and $$CU$$ are not equivalent up to global phase. You can read more about global phase on IBM Quantum Learning

• Thank you for making that clear. Mar 7 at 18:27