2

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(2np.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.

1 Answers1

1

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!

Dani007
  • 595
  • 2
  • 12