Quantum States and Gates¶
This guide introduces the mathematical foundations of single-qubit quantum states, Dirac bra-ket notation, and unitary quantum gates.
Tutorial Signposts: - Getting Started: Tutorial 0: Getting Started (GitHub) - Single-Qubit Superposition: Tutorial 1: Superposition (GitHub) - Parameterized Rotations: Tutorial 6: Custom Gates (GitHub)
1. The Qubit and Dirac Notation¶
In classical computation, the fundamental unit of information is the bit, which takes a definite value of either \(0\) or \(1\). In quantum computation, the fundamental unit is the quantum bit or qubit.
A qubit lives in a 2-dimensional complex Hilbert space \(\mathbb{C}^2\). Using Dirac notation, the standard computational basis states are written as column vectors:
The conjugate transpose (Hermitian adjoint) of a ket \(|\psi\rangle\) is a bra \(\langle\psi|\):
The inner product of two state vectors is written \(\langle\phi|\psi\rangle\). For orthonormal basis states:
2. Quantum Superposition¶
A qubit can exist in a linear combination of basis states:
where \(\alpha, \beta \in \mathbb{C}\) are probability amplitudes.
Normalization and the Born Rule¶
The state must satisfy the normalization condition:
According to the Born rule, measuring a qubit in the computational basis yields: - Outcome \(0\) with probability \(P(0) = |\alpha|^2 = |\langle 0|\psi\rangle|^2\) - Outcome \(1\) with probability \(P(1) = |\beta|^2 = |\langle 1|\psi\rangle|^2\)
Upon measurement, the state collapses into the observed eigenstate (\(|0\rangle\) or \(|1\rangle\)).
3. The Bloch Sphere and State Geometry¶
Because global phase factors (\(e^{i\gamma}|\psi\rangle\)) are not physically observable, any pure single-qubit state can be parameterized by two real angles \(\theta \in [0, \pi]\) and \(\phi \in [0, 2\pi)\):
This maps every pure state to a point on the surface of a unit sphere in \(\mathbb{R}^3\), known as the Bloch sphere: - The north pole (\(\theta = 0\)) corresponds to \(|0\rangle\). - The south pole (\(\theta = \pi\)) corresponds to \(|1\rangle\). - The equator (\(\theta = \pi/2\)) contains equal-superposition states such as \(|+\rangle\) (\(\phi = 0\)), \(|-\rangle\) (\(\phi = \pi\)), \(|+i\rangle\) (\(\phi = \pi/2\)), and \(|-i\rangle\) (\(\phi = 3\pi/2\)).
Bloch Vector Coordinates¶
The Cartesian coordinates of the Bloch vector \(\vec{r} = (r_x, r_y, r_z)\) are the expectation values of the three Pauli operators:
Density Matrix and Mixed States¶
A general quantum state, whether pure or mixed, can be represented by a \(2 \times 2\) density matrix \(\rho\):
where \(\vec{\sigma} = (X, Y, Z)\) is the vector of Pauli matrices.
The length of the Bloch vector determines the purity of the state: - Pure States: \(|\vec{r}|^2 = r_x^2 + r_y^2 + r_z^2 = 1\). The state lies on the surface of the Bloch sphere (\(\text{Tr}(\rho^2) = 1\)). - Mixed States: \(|\vec{r}|^2 < 1\). The state lies inside the Bloch sphere (\(\text{Tr}(\rho^2) < 1\)). - Maximally Mixed State: \(\vec{r} = (0, 0, 0)\), corresponding to \(\rho = \frac{1}{2} I\) and purity \(\text{Tr}(\rho^2) = 1/2\).
Quantum State Tomography¶
Because density matrices are linear combinations of Pauli operators, an unknown single-qubit state can be reconstructed by measuring its expectation values along the \(X\), \(Y\), and \(Z\) axes:
4. Single-Qubit Unitary Gates¶
Quantum operations are represented by linear operators \(U\) acting on state vectors:
To preserve state normalization (\(\langle\psi'|\psi'\rangle = \langle\psi|U^\dagger U|\psi\rangle = 1\)), every quantum gate must be unitary:
Unitary evolution is completely reversible: \(U^{-1} = U^\dagger\).
The Pauli Gates¶
The Pauli operators form a basis for Hermitian \(2 \times 2\) matrices:
- Pauli-X (NOT) flips \(|0\rangle \leftrightarrow |1\rangle\).
- Pauli-Z (Phase Flip) leaves \(|0\rangle\) unchanged and flips the phase of \(|1\rangle\): \(Z|1\rangle = -|1\rangle\).
- Pauli-Y combines bit and phase flips with a complex factor: \(Y = i X Z\).
The Hadamard Gate¶
The Hadamard gate \(H\) creates equal superpositions from computational basis states:
Applying \(H\):
Notice that \(H\) is Hermitian and self-inverse (\(H = H^\dagger = H^{-1}\)), so applying it twice returns \(|0\rangle\):

Phase Gates: S and T¶
Phase gates add relative phase to the \(|1\rangle\) component without changing measurement probabilities in the \(Z\)-basis:
5. Implementation in quantum-emotion¶
In quantum-emotion, state registers and gates use Python matrix multiplication @:
from quantum_emotion import KetState, BraState, Hadamard, PauliX, PauliZ
# Initialize qubit in |0>
psi0 = KetState(N=1)
# Apply Hadamard: |0> -> |+>
psi_plus = Hadamard(wires=0) @ psi0
print("State vector:", psi_plus.eval())
# Check inner product <+|0> = 1/sqrt(2)
bra_plus = psi_plus.conj
overlap = bra_plus @ psi0
print("Overlap <+|0>:", overlap)