Skip to content

Lesson 7: Single-Qubit Gates and the Quantum Circuit Model

7.1 Learning Outcomes

By the end of this hour a student will be able to:

  1. Write the matrix of every standard single-qubit gate and state its action on the basis states.
  2. Explain why every quantum gate must be unitary and hence reversible.
  3. Read and construct quantum circuit diagrams, respecting the left-to-right time convention.
  4. Compose gates by matrix multiplication in the correct order.
  5. Apply the \(Z\)–\(Y\) decomposition and state the universality of \(\{H, T\}\) for single qubits.
  6. Relate each gate to a rotation of the Bloch sphere.

7.2 Why Gates Must Be Unitary

By Postulate 2, closed-system evolution is unitary. Three consequences that define the model:

  1. Reversibility. \(U^{-1} = U^\dagger\) always exists. There is no quantum AND gate that discards information; irreversible classical gates must be embedded in reversible ones (see the Toffoli gate in L08).
  2. Norm preservation. Probabilities continue to sum to 1 after every gate.
  3. Linearity. A gate is defined by its action on a basis, and extends linearly:

    \[ U\big(\alpha|0\rangle + \beta|1\rangle\big) = \alpha\,U|0\rangle + \beta\,U|1\rangle . \]

Do not read linearity as "the gate acts on each branch separately and we pick one." The two branches persist and later interfere.

7.3 The Standard Single-Qubit Gates

Pauli gates

\[ X = \begin{pmatrix}0&1\\1&0\end{pmatrix}, \quad Y = \begin{pmatrix}0&-i\\ i&0\end{pmatrix}, \quad Z = \begin{pmatrix}1&0\\0&-1\end{pmatrix} \]
Gate Action Bloch rotation Nickname
\(X\) \(\lvert 0\rangle \leftrightarrow \lvert 1\rangle\) \(\pi\) about \(\hat x\) bit flip, quantum NOT
\(Y\) \(\lvert 0\rangle \to i\lvert 1\rangle\), \(\lvert 1\rangle \to -i\lvert 0\rangle\) \(\pi\) about \(\hat y\) bit + phase flip
\(Z\) \(\lvert 0\rangle \to \lvert 0\rangle\), \(\lvert 1\rangle \to -\lvert 1\rangle\) \(\pi\) about \(\hat z\) phase flip

Note \(Y = iXZ\) and \(X^2 = Y^2 = Z^2 = I\): each Pauli is its own inverse.

Critical point about \(Z\). On \(|0\rangle\) or \(|1\rangle\) alone, \(Z\) does nothing observable (it only adds a global phase). On a superposition it is dramatic:

\[ Z|+\rangle = \tfrac{1}{\sqrt2}\big(|0\rangle - |1\rangle\big) = |-\rangle . \]

Phase gates are useless on basis states and essential on superpositions — this is why every algorithm begins with Hadamards.

The Hadamard gate

\[ H = \frac{1}{\sqrt2}\begin{pmatrix}1&1\\1&-1\end{pmatrix} \]
\[ H|0\rangle = |+\rangle, \quad H|1\rangle = |-\rangle, \quad H|+\rangle = |0\rangle, \quad H|-\rangle = |1\rangle \]

Properties: \(H = H^\dagger = H^{-1}\), so \(H^2 = I\). It is the basis-change gate between \(Z\) and \(X\), and satisfies the crucial conjugation identities

\[ HXH = Z, \qquad HZH = X, \qquad HYH = -Y . \]

The \(n\)-qubit Hadamard identity (used in every algorithm of Unit II):

\[ H^{\otimes n}|0\rangle^{\otimes n} = \frac{1}{\sqrt{2^n}}\sum_{x\in\{0,1\}^n} |x\rangle \]

and more generally

\[ H^{\otimes n}|x\rangle = \frac{1}{\sqrt{2^n}}\sum_{y\in\{0,1\}^n}(-1)^{x\cdot y}|y\rangle, \qquad x\cdot y = \bigoplus_j x_jy_j . \]

Proof of the general form. For one qubit, \(H|x\rangle = \frac{1}{\sqrt2}\sum_{y\in\{0,1\}}(-1)^{xy}|y\rangle\) (check \(x=0\) and \(x=1\) separately). Take the tensor product of \(n\) copies and note the phases add in the exponent. \(\blacksquare\)

Phase gates

\[ S = \begin{pmatrix}1&0\\0&i\end{pmatrix} = \sqrt{Z}, \qquad T = \begin{pmatrix}1&0\\0&e^{i\pi/4}\end{pmatrix} = \sqrt{S}, \qquad P(\lambda) = \begin{pmatrix}1&0\\0&e^{i\lambda}\end{pmatrix} \]

Relations: \(S^2 = Z\), \(T^2 = S\), \(T^4 = Z\), \(T^8 = I\). Bloch action: rotation about \(\hat z\) by \(\pi/2\), \(\pi/4\) and \(\lambda\) respectively.

The \(T\) gate is expensive. In fault-tolerant architectures \(H\), \(S\) and the CNOT (the Clifford gates) are cheap, but \(T\) requires magic-state distillation. Circuit cost in fault-tolerant quantum computing is quoted as \(T\)-count and \(T\)-depth.

Rotation gates

\[ R_x(\theta) = e^{-i\theta X/2} = \begin{pmatrix}\cos\frac{\theta}{2} & -i\sin\frac{\theta}{2}\\ -i\sin\frac{\theta}{2} & \cos\frac{\theta}{2}\end{pmatrix} \]
\[ R_y(\theta) = e^{-i\theta Y/2} = \begin{pmatrix}\cos\frac{\theta}{2} & -\sin\frac{\theta}{2}\\ \sin\frac{\theta}{2} & \cos\frac{\theta}{2}\end{pmatrix} \]
\[ R_z(\theta) = e^{-i\theta Z/2} = \begin{pmatrix}e^{-i\theta/2} & 0\\ 0 & e^{i\theta/2}\end{pmatrix} \]

\(R_y\) is real, which makes it the natural gate for encoding real-valued data in QML (Unit III).

Universal single-qubit gate (the \(U3\) / \(U\) gate).

\[ U(\theta,\phi,\lambda) = \begin{pmatrix} \cos\frac{\theta}{2} & -e^{i\lambda}\sin\frac{\theta}{2}\\ e^{i\phi}\sin\frac{\theta}{2} & e^{i(\phi+\lambda)}\cos\frac{\theta}{2}\end{pmatrix} \]

Every single-qubit unitary equals \(U(\theta,\phi,\lambda)\) up to a global phase. This is the gate that Qiskit's transpiler targets.

7.4 Decomposition and Universality

Theorem (\(Z\)–\(Y\) decomposition). Every single-qubit unitary \(U\) can be written

\[ U = e^{i\gamma} R_z(\beta)\, R_y(\delta)\, R_z(\alpha) \]

for real \(\gamma,\alpha,\beta,\delta\).

Sketch. \(U\) is unitary, so its rows are orthonormal; solving the resulting four equations for the three Euler angles plus a phase gives the decomposition, exactly as for \(SO(3)\) Euler angles. \(\blacksquare\)

Theorem (Solovay–Kitaev). The discrete set \(\{H, T\}\) generates a dense subgroup of \(SU(2)\). Any single-qubit unitary can be approximated to accuracy \(\epsilon\) using \(O\!\left(\log^{c}(1/\epsilon)\right)\) gates from \(\{H,T\}\), with \(c \approx 2\) (improvable to \(c\approx 1\)).

Consequence. \(\{H, T, \mathrm{CNOT}\}\) is a universal gate set for quantum computation. You do not need continuously tunable gates.

7.5 The Quantum Circuit Model

Reading a circuit

q0: ---[H]---*---[X]---[M]---
             |          |
q1: --------[X]---------|----
                        v
c : ====================o====

Symbols: [G] = gate G on that wire; * = control of a two-qubit gate; [X] joined to a * by a vertical bar = the target of a CNOT; [M] = measurement; ==== = a classical wire carrying the measured bit.

Conventions:

  • Wires are qubits, not physical wires. A horizontal line is one qubit's world-line.
  • Time flows left to right. Gates are applied in reading order.
  • A double line is a classical register carrying measurement results.
  • The number of wires never changes (no creating or destroying qubits mid-circuit).
  • Gates on disjoint qubits in the same column act simultaneously and commute.

The order trap

If the circuit is \(|\psi\rangle \to A \to B \to C\), the resulting state is

\[ |\psi_{\text{out}}\rangle = C\,B\,A\,|\psi\rangle . \]

Matrix order is the reverse of diagram order. This is the single most common examination error.

Circuit depth and width

  • Width = number of qubits.
  • Depth = number of time steps (layers of simultaneously executable gates).
  • On NISQ hardware, depth is limited by decoherence: if a gate takes \(t_g\) and coherence time is \(T_2\), the useful depth is roughly \(T_2/t_g\).

Useful gate identities

\[ HXH = Z, \quad HZH = X, \quad XZ = -ZX, \quad XYX = -Y \]
\[ S = T^2, \quad Z = S^2, \quad X = HZH, \quad Y = SXS^\dagger \]
\[ R_z(\theta) = e^{-i\theta/2}P(\theta) \quad(\text{differ by a global phase}) \]

7.6 Solved Problems

Problem 1 — Composing a gate sequence

A qubit starts in \(|0\rangle\). The circuit applies \(H\), then \(Z\), then \(H\). Find the final state both by tracking states and by multiplying matrices.

Solution.

State-tracking route.

\[ |0\rangle \xrightarrow{H} |+\rangle = \tfrac{1}{\sqrt2}(|0\rangle+|1\rangle) \]
\[ \xrightarrow{Z} \tfrac{1}{\sqrt2}(|0\rangle - |1\rangle) = |-\rangle \]
\[ \xrightarrow{H} |1\rangle \]

Matrix route. The overall unitary is \(U = H Z H\) (note the reversed order):

\[ HZH = \frac12\begin{pmatrix}1&1\\1&-1\end{pmatrix}\begin{pmatrix}1&0\\0&-1\end{pmatrix} \begin{pmatrix}1&1\\1&-1\end{pmatrix} \]
\[ = \frac12\begin{pmatrix}1&-1\\1&1\end{pmatrix}\begin{pmatrix}1&1\\1&-1\end{pmatrix} = \frac12\begin{pmatrix}0&2\\2&0\end{pmatrix} = \begin{pmatrix}0&1\\1&0\end{pmatrix} = X \]

So \(U|0\rangle = X|0\rangle = |1\rangle\) ✓.

Result: \(HZH = X\). The circuit is a NOT gate built from a phase flip sandwiched between Hadamards — the standard trick for converting phase information into amplitude information, used in every algorithm of Unit II.

Problem 2 — Effect of T on a superposition

Compute \(T|+\rangle\), express it in the Bloch picture, and find \(\Pr[0]\) and \(\Pr[+]\).

Solution.

\[ T|+\rangle = \begin{pmatrix}1&0\\0&e^{i\pi/4}\end{pmatrix}\frac{1}{\sqrt2}\begin{pmatrix}1\\1\end{pmatrix} = \frac{1}{\sqrt2}\begin{pmatrix}1\\ e^{i\pi/4}\end{pmatrix} \]
\[ = \frac{1}{\sqrt2}\left(|0\rangle + e^{i\pi/4}|1\rangle\right) \]

Bloch angles: \(\theta = \pi/2\) (equator), \(\varphi = \pi/4\). So

\[ (x,y,z) = \left(\cos\tfrac{\pi}{4},\ \sin\tfrac{\pi}{4},\ 0\right) = \left(\tfrac{1}{\sqrt2}, \tfrac{1}{\sqrt2}, 0\right) . \]
\[ \Pr[0] = \left|\tfrac{1}{\sqrt2}\right|^2 = \tfrac12 \qquad (\text{unchanged by }T) \]
\[ \Pr[+] = |\langle +|T|+\rangle|^2 = \left|\tfrac12(1 + e^{i\pi/4})\right|^2 \]
\[ = \tfrac14\left|(1+\cos\tfrac{\pi}{4}) + i\sin\tfrac{\pi}{4}\right|^2 = \tfrac14\left[(1.7071)^2 + (0.7071)^2\right] = \tfrac14[2.9142 + 0.5] = 0.8536 \]

Interpretation. \(T\) rotated the state 45° along the equator: \(Z\)-statistics are untouched, but \(X\)-statistics changed from certainty (1.0) to 0.854. Phase gates are invisible to \(Z\) measurement.

Problem 3 — Verifying a decomposition

Show that \(H = e^{i\pi/2} R_y(\pi/2) R_z(\pi)\) up to a global phase.

Solution.

\[ R_z(\pi) = \begin{pmatrix}e^{-i\pi/2} & 0\\ 0 & e^{i\pi/2}\end{pmatrix} = \begin{pmatrix}-i & 0 \\ 0 & i\end{pmatrix} = -i\begin{pmatrix}1&0\\0&-1\end{pmatrix} = -iZ \]
\[ R_y(\pi/2) = \begin{pmatrix}\cos\frac{\pi}{4} & -\sin\frac{\pi}{4}\\ \sin\frac{\pi}{4} & \cos\frac{\pi}{4}\end{pmatrix} = \frac{1}{\sqrt2}\begin{pmatrix}1 & -1\\ 1 & 1\end{pmatrix} \]

Multiply (right-most acts first, so compute \(R_y(\pi/2)\,R_z(\pi)\)):

\[ \frac{1}{\sqrt2}\begin{pmatrix}1&-1\\1&1\end{pmatrix}\cdot(-i)\begin{pmatrix}1&0\\0&-1\end{pmatrix} = \frac{-i}{\sqrt2}\begin{pmatrix}1 & 1\\ 1 & -1\end{pmatrix} = -i\,H \]

Therefore \(R_y(\pi/2)R_z(\pi) = -iH\), i.e.

\[ H = i\,R_y(\pi/2)R_z(\pi) = e^{i\pi/2}R_y(\pi/2)R_z(\pi) \ \checkmark \]

The prefactor \(e^{i\pi/2}\) is a global phase and is unobservable — which is exactly why hardware can implement \(H\) using only \(R_y\) and \(R_z\) pulses.

Problem 4 — Building an arbitrary state

Design a circuit that prepares \(|\psi\rangle = \frac{\sqrt3}{2}|0\rangle + \frac{1}{2}e^{i\pi/3}|1\rangle\) from \(|0\rangle\) using \(R_y\) and \(R_z\) (or a phase gate).

Solution. Read the Bloch angles off the target:

\[ \cos\frac{\theta}{2} = \frac{\sqrt3}{2} \Rightarrow \frac{\theta}{2} = \frac{\pi}{6} \Rightarrow \theta = \frac{\pi}{3}, \qquad \varphi = \frac{\pi}{3}. \]

Step 1 — set the polar angle with \(R_y(\theta)\) (real rotation, no phase introduced):

\[ R_y(\pi/3)|0\rangle = \cos\frac{\pi}{6}|0\rangle + \sin\frac{\pi}{6}|1\rangle = \frac{\sqrt3}{2}|0\rangle + \frac12|1\rangle . \]

Step 2 — set the azimuthal angle with \(P(\varphi)\):

\[ P(\pi/3)\left(\frac{\sqrt3}{2}|0\rangle + \frac12|1\rangle\right) = \frac{\sqrt3}{2}|0\rangle + \frac12 e^{i\pi/3}|1\rangle = |\psi\rangle \ \checkmark \]

Circuit: \(|0\rangle - [R_y(\pi/3)] - [P(\pi/3)] - |\psi\rangle\).

General recipe. Any single-qubit state is prepared by \(P(\varphi)R_y(\theta)|0\rangle\). This two-gate template is the basis of angle encoding in quantum machine learning (L26).

Problem 5 — Circuit identity and simplification

Simplify the circuit \(H - S - H - S - H\) acting on \(|0\rangle\), and identify the resulting gate up to global phase.

Solution. The overall unitary is \(U = H S H S H\) (reverse of diagram order — but note this product is palindromic, so order caution matters less here; we still multiply right to left).

Use \(HSH\) first. With \(S = \begin{pmatrix}1&0\\0&i\end{pmatrix}\):

\[ HSH = \frac12\begin{pmatrix}1&1\\1&-1\end{pmatrix}\begin{pmatrix}1&0\\0&i\end{pmatrix} \begin{pmatrix}1&1\\1&-1\end{pmatrix} = \frac12\begin{pmatrix}1& i\\ 1& -i\end{pmatrix}\begin{pmatrix}1&1\\1&-1\end{pmatrix} \]
\[ = \frac12\begin{pmatrix}1+i & 1-i\\ 1-i & 1+i\end{pmatrix} = \frac{1+i}{2}\begin{pmatrix}1 & -i\\ -i & 1\end{pmatrix} \]

using \(\frac{1-i}{1+i} = -i\). Recognise the bracket: \(\begin{pmatrix}1&-i\\-i&1\end{pmatrix} = \sqrt2\,R_x(\pi/2)\). So \(HSH = e^{i\pi/4}R_x(\pi/2) = \sqrt{X}\) up to phase.

Now $U = (HSH)\,S\,\underbrace{{}}_{} $ — writing \(U = H S H S H\), group as \((HSH)(SH)\):

\[ U = \frac{1+i}{2}\begin{pmatrix}1&-i\\-i&1\end{pmatrix} \cdot\begin{pmatrix}1&0\\0&i\end{pmatrix}\cdot\frac{1}{\sqrt2}\begin{pmatrix}1&1\\1&-1\end{pmatrix} \]
\[ SH = \frac{1}{\sqrt2}\begin{pmatrix}1&1\\ i&-i\end{pmatrix} \]
\[ U = \frac{1+i}{2\sqrt2}\begin{pmatrix}1&-i\\-i&1\end{pmatrix}\begin{pmatrix}1&1\\i&-i\end{pmatrix} = \frac{1+i}{2\sqrt2}\begin{pmatrix}1 - i\cdot i & 1 -i(-i)\\ -i + i & -i -i(-i)\end{pmatrix} \]
\[ = \frac{1+i}{2\sqrt2}\begin{pmatrix}2 & 0\\ 0 & -2i\end{pmatrix} = \frac{1+i}{\sqrt2}\begin{pmatrix}1 & 0\\ 0 & -i\end{pmatrix} = e^{i\pi/4}\begin{pmatrix}1&0\\0&e^{-i\pi/2}\end{pmatrix} \]

So \(U = e^{i\pi/4}\,S^\dagger\) — five gates collapse to one, up to an unobservable phase.

Acting on \(|0\rangle\): \(U|0\rangle = e^{i\pi/4}|0\rangle \simeq |0\rangle\).

Lesson. Circuit optimisation of exactly this kind is what a transpiler does automatically (L38), and it is why gate-count reduction is a first-class engineering concern on NISQ hardware.

7.7 Practice Problems

  1. Compute \(HYH\). [Ans: \(-Y\)]
  2. What is \(T^\dagger\) as a matrix, and what is \(T\,T^\dagger\)?
  3. Show \(S = P(\pi/2)\) and \(T = P(\pi/4)\).
  4. Design a circuit preparing \(\frac{1}{\sqrt2}(|0\rangle + i|1\rangle)\) from \(|0\rangle\) using two gates. [Ans: \(H\) then \(S\)]
  5. A circuit applies \(X\), then \(H\), then \(Z\) to \(|0\rangle\). Write the final state and the overall matrix. [Ans: state \(\propto|-\rangle\); matrix \(ZHX\)]
  6. Verify \(R_z(\theta_1)R_z(\theta_2) = R_z(\theta_1+\theta_2)\).
  7. Prove \(H^{\otimes 2}|01\rangle = \frac12(|00\rangle - |01\rangle + |10\rangle - |11\rangle)\) using the general Hadamard formula.
  8. Why is \(T\)-count a meaningful cost metric while \(H\)-count is not?

7.8 Summary

  • Every gate is a unitary matrix, so quantum computation is reversible.
  • \(X\) flips bits, \(Z\) flips phase, \(H\) creates superposition and converts phase ↔ amplitude, \(S\) and \(T\) apply partial phases.
  • \(H^{\otimes n}|0\rangle^{\otimes n}\) gives the uniform superposition over all \(2^n\) strings; \(H^{\otimes n}|x\rangle = 2^{-n/2}\sum_y(-1)^{x\cdot y}|y\rangle\).
  • In circuit diagrams time runs left to right, but matrix products are written right to left.
  • \(Z\)–\(Y\) decomposition writes any single-qubit unitary with three rotations; \(\{H,T,\text{CNOT}\}\) is universal (Solovay–Kitaev).
  • \(T\) gates dominate fault-tolerant cost; depth is limited by coherence time on NISQ devices.

Next lesson: L08 — Multi-qubit gates, entanglement and the Bell states.

Practise now: unit1-qubit-lab.html → Circuit Builder: drag gates onto a wire, watch the Bloch vector and state vector update, and read the accumulated unitary matrix.