1

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))?

Mark Spinelli
  • 11,947
  • 2
  • 19
  • 65
Vinay Sharma
  • 509
  • 1
  • 12

1 Answers1

4

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).

DaftWullie
  • 57,689
  • 3
  • 46
  • 124