Q&A-2How does gate application order in mathematical matrix composition correspond to temporal execution order in a quantum circuit diagram?
Answer
In quantum circuit diagrams, physical time advances strictly from left to right. When gate $A$ is placed before gate $B$ on the same qubit wire, $A$ executes first at $t_1$, followed by $B$ at $t_2$. In linear algebra, operations act on state vectors by matrix-vector multiplication: $|\psi'\rangle = U |\psi\rangle$. Because operators act on the ket directly to their right, successive application of $A$ followed by $B$ maps $|\psi\rangle \to B(A|\psi\rangle) = (BA)|\psi\rangle$. Thus, temporal left-to-right sequencing in a circuit diagram corresponds directly to right-to-left operator composition in matrix algebra: $U_{\text{total}} = U_n U_{n-1} \dots U_1$.
A second orthogonal ordering rule governs multi-qubit systems: tensor product spatial ordering. In standard textbook notation, qubit 0 is the most significant index (leftmost in the Kronecker product $q_0 \otimes q_1$). In Qiskit, qubit 0 is the least significant index (rightmost: $q_1 \otimes q_0$, Little Endian). When composing gates in parallel across multiple wires, $(A \otimes B)$ maps to wire spatial placement according to the endianness convention adopted by the runtime framework.
Worked Example: Non-Commuting 1-Qubit Sequence
Consider applying a Hadamard gate $H$ followed by a Pauli $X$ gate on wire $q_0$:
Circuit diagram (Time flows left to right):
t=1 t=2
q_0: ──[ H ]────[ X ]──-
Mathematical composition acting on input $|0\rangle$: $$U_{\text{total}} = X \cdot H$$
-
Matrix evaluation: $$H = \frac{1}{\sqrt{2}}\begin{pmatrix} 1 & 1 \ 1 & -1 \end{pmatrix}, \quad X = \begin{pmatrix} 0 & 1 \ 1 & 0 \end{pmatrix}$$ $$U_{\text{total}} = \begin{pmatrix} 0 & 1 \ 1 & 0 \end{pmatrix} \frac{1}{\sqrt{2}}\begin{pmatrix} 1 & 1 \ 1 & -1 \end{pmatrix} = \frac{1}{\sqrt{2}}\begin{pmatrix} 1 & -1 \ 1 & 1 \end{pmatrix}$$
If evaluated incorrectly as left-to-right matrix multiplication ($H \cdot X$): $$H \cdot X = \frac{1}{\sqrt{2}}\begin{pmatrix} 1 & 1 \ 1 & -1 \end{pmatrix} \begin{pmatrix} 0 & 1 \ 1 & 0 \end{pmatrix} = \frac{1}{\sqrt{2}}\begin{pmatrix} 1 & 1 \ -1 & 1 \end{pmatrix} \neq X \cdot H$$ Applying $X H |0\rangle$ yields $|+\rangle = \frac{|0\rangle + |1\rangle}{\sqrt{2}}$, whereas $H X |0\rangle = H |1\rangle = |-\rangle = \frac{|0\rangle - |1\rangle}{\sqrt{2}}$, which differs by an observable relative phase.
Comparison Table: Circuit vs Matrix Formalism
| Representation Dimension | Circuit Diagram Convention | Matrix Algebraic Representation | Common Failure Mode |
|---|---|---|---|
| Time Dimension | Left-to-right horizontal axes ($t_1 \to t_2$) | Right-to-left composition ($U_2 U_1$) | Multiplying matrices in script read order ($U_1 U_2$) |
| Space / Wire Dimension | Top-to-bottom qubit wires ($q_0, q_1, \dots$) | Kronecker product order ($q_n \otimes \dots \otimes q_0$ in Qiskit) | Inverting target/control or endianness transposition |
| Parallel Operations | Vertical alignment at same time slice | Tensor product ($A \otimes B$) | Treating parallel independent gates as sequential terms |
Curated: · Written: · Reviewed:
Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.