The order (of the qubits) matters
Those programming using Quantum Computers will, eventually, come across this somewhat awkward observation when using the simulators or the real computers. The topic is often neglected by tutorials in quantum computing, and, to a certain extend, it is understandable that tutorials do not tackle it at first. In fact, if you are simply running operations on circuits in the machine, it will be hard to spot or bother about it. Nevertheless, it can cause a great deal of confusion and pain for those who are unaware or overlook it.
The problem, firstly addressed in the classical computers and now resurfacing with the quantum computers, is related to the order that qubits are organized on a sequence of qubits. Note that, when considering a sequence of qubits, and considering their significance in relation to the sequence, there are two ways to order them: either the qubit on the leftmost position of the sequence is considered the least significant qubit of the sequence, or the one in the rightmost position.
ok, but why this matters?
You will see, next, that it does!
Let me give an example using the CNOT gate depicted in the classical textbook from Nielsen and Chuang, Quantum Computation and Quantum Information. According to the book (page 178), the gate and its respective unitary operator, are as follow:
![]() |
CNOT Gate |
To demonstrate we actually have the same operator in both cases, lets use the code snippet below, and revert the qubit order in qiskit.
Another, more subtle example, is the partial trace. Assuming the code below intends to trace out the qubit B from svAB, returning the space vector for A.
The wrong assumption about the order of the qubits causes a very subtle bug in the code. The next code snippet takes into account the qubit ordering and traces out, correctly, the vector B.
Watch out for the ordering of qubits when implementing code. Textbooks and quantum platforms might use a different convention which can cause, at best, confusion when comparing results. In other cases, it can cause bugs in the circuit which are hard to spot!
Comments
Post a Comment