3
$\begingroup$

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.

Thank you in advance for your assistance!

enter image description here

$\endgroup$
2
  • 3
    $\begingroup$ Replace the control-rz gates with controlled-phase gates. $\endgroup$
    – diemilio
    Mar 6 at 20:53
  • 1
    $\begingroup$ Thank You so much! I solved $\endgroup$ Mar 7 at 18:25

1 Answer 1

1
$\begingroup$

@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

$\endgroup$
1
  • $\begingroup$ Thank you for making that clear. $\endgroup$ Mar 7 at 18:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.