1
$\begingroup$

I have a state psi as an ndarray of shape (2 ** 3,) s.t.

psi[0]= amplitude of 000

psi[1] = amplitude of 001.

So my qubit ordering is reversed w.r.t. qiskit's. To initialize the circuit correctly and apply the IQFT on the first 2 qubits from the left I tried the following code:

import qiskit as qt
from qiskit.aqua.circuits import FourierTransformCircuits as QFT

    circuit = qt.QuantumCircuit(3)
    circuit.initialize( psi, [i for i in reversed(circuit.qubits)])

    QFT.construct_circuit(circuit=circuit, qubits=circuit.qubits[:2], inverse=True)

    backend = qt.Aer.get_backend('statevector_simulator')
    final_state = qt.execute(circuit, backend, shots=1).result().get_statevector()

From the tests I've run, final_state is not what I expected: defining

exact = np.kron(IQFT_matrix(2),np.eye(2)).dot(state) with IQFT_matrix(2)= IQFT_matrix for 2 qubits.

np.testing.assert_array_almost_equal(final_state, exact)

fails. Can you please help me find the problem?

$\endgroup$
  • $\begingroup$ Bits order is reversed on IBM Q. The most significant bit is on the right. $\endgroup$ – Martin Vesely Mar 13 at 14:50
  • 1
    $\begingroup$ I know, that's why I initialized using reversed(circuit.qubits). Am I converting this the wrong way? I do not want to remap the state directly, since in future implementation the state will be many dimensional and I do not want to occupy tons of memory or perform a lot of operations on it. $\endgroup$ – simone Mar 13 at 14:53
0
$\begingroup$

There is the parameter do_swaps when you construct the fourier transform circuit.

do_swaps (bool): Boolean flag to specify if swaps should be included to align
                 the qubit order of input and output. The output qubits would
                 be in reversed order without the swaps.
|improve this answer|||||
$\endgroup$
  • $\begingroup$ Thanks for your help. I've tried using this flag but it does not solve the problem: 'final_state' differs from what I expected not only for index mapping, but for values too. $\endgroup$ – simone Mar 13 at 15:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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