2
$\begingroup$

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.

$\endgroup$

1 Answer 1

1
$\begingroup$

This is a common issue with Qiskit. Qiskit uses little endian encoding by default, that is, it considers the left most bit as the least significant bit, where as people usually subconsciously default to big endian encoding. To give you an example, 01 corresponds to 1 in big endian encoding, but in little endian it corresponds to 2. So technically the matrix you're getting is correct, there's just a mismatch between how you and Qiskit are interpreting the bit orderings. Take a look at the discussion here for more info. Hope this helps!

$\endgroup$
4
  • $\begingroup$ To account for this I consider the most significant bit the one in the bottom (when analyzing a Qiskit circuit). What I see now is that if you switch rows 1 and 2 (2nd and 3rd rows) and then columns 1 and 2 (2nd and 3rd columns) the Qiskit Matrix becomes the correct one. If you think in terms of the numbers in binary notation, "00" and "11" are the same either in little endian or big endian. On the other hand 01 becomes 10 and vice versa. In other words, your answer is correct. In any case, I will try my luck with the 3 qubits QFT circuit and see if this logic holds. Thanks for the answer! $\endgroup$ Commented Jul 14 at 19:16
  • $\begingroup$ Just one thing that it might needed to be corrected in your answer. If "01" corresponds to "2" in little endian than the right most bit is the most significant bit. In your answer I think you mentioned that little endian the left most bit is the most significant bit (and I think it is the reverse of that). $\endgroup$ Commented Jul 14 at 19:27
  • 1
    $\begingroup$ To close this question: I checked in the 3 qubits QFT and the results agree. To make it work, I exchanged rows and columns [1,3,4,6] by rows and columns [4,6,1,3] (in Qiskit's unitary matrix). This makes 001 become 101 and 011 become 110 (and vice versa). The results now they are the same. The standard QFT (as written in math books) and Qiskits results agree. Again, thanks for the explanation. $\endgroup$ Commented Jul 14 at 20:16
  • 1
    $\begingroup$ Glad this helped! And yes it should've said least significant, made the correction. $\endgroup$
    – Dani007
    Commented Jul 15 at 20:04

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.