12

I've noticed that Q# favors Little Endian. Meaning that most operations are designed for this type of encoding. Is is it the same with Qiskit?

Sanchayan Dutta
  • 17,497
  • 7
  • 48
  • 110
Sorin Bolos
  • 611
  • 5
  • 11

3 Answers3

16

Qiskit uses little-endian for both classical bit ordering and qubit ordering.

For classical bits:

A 3-bit classical register creg with value abc has creg[0]=c, creg[1]=b, creg[2]=a.

For qubits:

The ordering is with respect to the tensor-product structure of the state space. So a 3-qubit quantum register qreg with wave-function $|\psi\rangle = |A\otimes B\otimes C\rangle = |ABC\rangle$ has qreg[0]$= |C\rangle$, qreg[1]$= |B\rangle$, qreg[2]$= |A\rangle$.

Similarly for representing unitary matrices of a circuit. $U = U_A \otimes U_B \otimes U_C = U_A U_B U_C$ would have $U_C$ acting on qreg[0], $U_B$ acting on qreg[1] and $U_A$ acting on qreg[2].

epelaez
  • 2,875
  • 1
  • 8
  • 31
cjwood
  • 1,221
  • 8
  • 9
2

Note that the bits are labelled from right to left. So cr[0] is the one to the furthest right, and so on. As an example of this, here's an 8 qubit circuit with a Pauli X on only the qubit numbered 7, which has its output stored to the bit numbered 7.

https://qiskit.org/textbook/ch-appendix/qiskit.html

Jack Woehr
  • 59
  • 4
1

Additionally, to put it for an example circuit:

enter image description here

RSW
  • 279
  • 1
  • 11
  • 2
    The example here is in fact the exact opposite definition. See @cjwood's answer above. In this 6 qubit example, the bit string would read 0 except for the 6th qubit which has the X gate: q_5 = 1. The ordering in the quantum state in little endian is $| q_5, q_4, q_3, q_2, q_1, q_0 \rangle$, so the bit string is $|100000\rangle$ – AJ Rasmusson Oct 21 '22 at 03:51