Skip to content
Current section
The Quantum Computing Enthusiast’s Hub
Saved
All sections

All sections

Saved
Skip Learn navigation
Encyclopedia
Topic

Qubit ordering and software conventions

The explicit mapping between labeled quantum systems, tensor factors, basis strings and array indices.

Also called endianness, bit ordering

Edition released Coverage: Overview · Technical
On this page

Definition and significance

Qubit ordering is a notation and data-interpretation convention. It does not change physics, but silently changing conventions can change which gate or measurement a calculation appears to describe. The encyclopedia uses q0 as the leftmost tensor factor in |q0 q1 ...>, unless an entry explicitly states otherwise.

Software may store qubit zero as the least significant bit of a basis-state index, draw it at the top of a circuit and display it at the right of a bitstring. Those three choices can coexist consistently. A diagram's vertical order is not automatically an array's tensor order.

Mechanism and mathematical treatment

For two qubits under the encyclopedia convention, |q0 q1>=|10> has index 2 and means q0=1,q1=0. Under a least-significant-q0 convention, the same labeled physical state has displayed string q1q0=01 and index 1. The vectors are related by a fixed permutation matrix.

An operator must undergo the corresponding basis transformation U_new=P U_old P dagger. Reordering only the statevector while retaining the original matrix is inconsistent. Measurement registers may add another mapping because qubits need not be measured into equally numbered classical bits.

Fully worked reference example

Start in |00> and apply X to labeled qubit q0. The encyclopedia vector is [0,0,1,0]. In Qiskit's common statevector convention the result is [0,1,0,0], with the string 01 when written q1q0. Both describe q0=1 and q1=0.

For a Bell state, [1/sqrt(2),0,0,1/sqrt(2)] looks identical under swapping the two qubits. It is therefore a poor sole test of ordering. An asymmetric state such as |10> or a CNOT with a specified unequal input is needed to expose a mistaken mapping.

Limitations and common misconceptions

Do not describe an SDK as simply “big endian” or “little endian” without naming the object: integers, statevectors, displayed strings and newer result containers can use different conventions. Pin the relevant documentation snapshot and record any explicit qubit_order argument.

Scientific relationships

Statevector indices and displayed strings require explicit mapping.

The declared qubit order fixes tensor factors in numerical output.

A three-qubit conversion that exposes every reversed index

For a state written in q0q1q2 order, the encyclopedia index is i=4q0+2q1+q2. A representation with q0 as the least significant bit uses j=q0+2q1+4q2. Thus the conversion permutation sends old indices 0,1,2,3,4,5,6,7 to new indices 0,4,2,6,1,5,3,7. The middle bit is unchanged, while the outer bits exchange significance.

Take the normalized real amplitude array [0,1,2,3,4,5,6,7]/sqrt(140). In the least-significant-q0 array order, it becomes [0,4,2,6,1,5,3,7]/sqrt(140). The normalization factor is sqrt(0^2+1^2+...+7^2)=sqrt(140). Unlike a Bell or GHZ state, this asymmetric vector reveals every nontrivial index movement.

An operator must be transformed with the same permutation: U_new=P U_old P dagger. For example, Z on labeled q0 is diag(1,1,1,1,-1,-1,-1,-1) in encyclopedia order, but diag(1,-1,1,-1,1,-1,1,-1) in the least-significant-q0 order. Applying the unconverted diagonal to the converted vector would measure or rotate a different labeled qubit.

Measurement mapping is another independent permutation

Suppose qubits are measured into classical bits by q0->c2, q1->c0 and q2->c1. For the physical labeled outcome q0q1q2=101, the classical values are c0=0,c1=1,c2=1. A displayed classical string in c2c1c0 order is therefore 110. Reversing the quantum bit string alone would give 101 and would not recover this result because the measurement wiring is not simple reversal.

The correct conversion is functional: read the named physical outcomes, assign them to their declared classical targets, then serialize those classical bits in the output format's documented order. If there are several classical registers, the serialization can include register grouping as well as bit order. A universal instruction to reverse every result string is therefore unsafe.

A complete result record can store the raw format together with an explicit ordered list of classical-bit identities. The scientific interpretation then maps those identities back through measurement wiring and any final logical layout. This is a data-contract requirement for interpreting an experiment or simulation, not a change in the underlying quantum state.

Routing introduces a logical-to-physical layer

Let logical L0 be stored at physical site 2, L1 at site 0 and L2 at site 1 after compilation. If the physical outcomes in site order are (1,0,1), the logical outcomes are (L0,L1,L2)=(1,1,0). This is separate from how an amplitude array orders physical sites. Combining layout and serialization without naming both maps can silently produce the wrong logical answer.

For a sampled observable Z_L0 X_L2, the requested physical measurement bases are Z on site 2 and X on site 1. A basis-change circuit generated from the initial layout would act on the wrong sites. The same issue appears when transforming a Hamiltonian observable alongside a routed circuit: the observable's qubit labels must follow the final mapping if the evaluation interface expects physical indices.

A useful consistency check is round-trip conversion. Convert a labeled basis assignment to the external representation, decode it back using the stored maps, and confirm that every label is recovered. This checks the mapping code but does not by itself validate that the external service actually used the claimed format. That latter contract must come from the specific API and version or result metadata.

Controlled operations and displayed orientation

In encyclopedia order, CNOT q0->q1 exchanges |10> and |11> while preserving |00> and |01>. In a two-qubit array whose basis labels are q1q0, the same labeled operation exchanges displayed strings 01 and 11. The matrix positions change, but control and target identities do not. Reversing the vertical order of a circuit drawing is yet another operation and need not relabel the underlying qubit objects.

For a simple asymmetric input q0q1=10, the correct output is 11. If the control and target were accidentally swapped, the output would remain 10. This basis test distinguishes orientation. A Bell preparation can fail to expose some ordering mistakes because its amplitude vector is invariant under exchanging the two qubits, which is why asymmetric tests are necessary.

Current official software documentation should be consulted for the particular statevector, integer, string and result-container conventions. The extension's calculations are independent of a software release and do not claim that every API in one ecosystem serializes every object identically. A reproducible executable example would pin its version and state the exact object being interpreted.

Sources

  • IBM Quantum · Documentation · quantum.cloud.ibm.com
    Verification scope

    Recorded source check ·

    Full ordering guide retrieved; statevector/integer/string conventions and explicit object-level result distinctions inspected.

    Conceptual reference semantics only. No code execution or universal backend support claim.

  • Google Quantum AI / Cirq · Documentation · quantumai.google
    Verification scope

    Recorded source check ·

    Simulation guide retrieved; explicit qubit_order semantics and distinction between state and measurement output inspected.

    Conceptual reference semantics only. No code execution or universal backend support claim.