1
$\begingroup$

Given the following code:

from qiskit import QuantumCircuit
from qiskit.quantum_info import Statevector

qc = QuantumCircuit(2)

# This calculates what the state vector of our qubits would be
# after passing through the circuit 'qc'
ket = Statevector(qc)

# The code below writes down the state vector.
# Since it's the last line in the cell, the cell will display it as output
ket.draw()

when executed, will output:

Statevector([1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j] \n dims=(2, 2))

which is expected result, as per my understanding, as $|00\rangle = [1 0 0 0 ]$

But when we apply $x$-gate on qubit 0 as in:

qc.x(0)

ket = Statevector(qc)
ket.draw()

the output is:

Statevector([0.+0.j, 1.+0.j, 0.+0.j, 0.+0.j]\n dims=(2, 2))

which is not correct, as per my understanding, because applying the $x$-gate on first qubit will make the multi-qubit state $|10\rangle = [0 0 1 0]$, but the output of the above is $[0 1 0 0]$.

Please help me to understand this?

Also, here in the outputs dims=(2, 2)), shouldn't it be dims=(4, 1))?

$\endgroup$

1 Answer 1

4
$\begingroup$

Note that qiskit orders qubits oppositely from what you might have expected: it uses the "little endian" convention. This is explained in (slightly) greater detail in previous questions such as this one.

The dims function on statevector is not giving you the dimensions of the vector. It is giving you a list of the dimensions of the individual quantum systems. Here you have two qubits (i.e. each of dimension 2).

$\endgroup$
1
  • $\begingroup$ what about dimensions? shouldn't it be (4,1) instead of (2,2) ? $\endgroup$ Commented May 17, 2022 at 12:38

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.