Skip to content

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:

\[ |0\rangle = \begin{pmatrix} 1 \\ 0 \end{pmatrix}, \quad |1\rangle = \begin{pmatrix} 0 \\ 1 \end{pmatrix} \]

The conjugate transpose (Hermitian adjoint) of a ket \(|\psi\rangle\) is a bra \(\langle\psi|\):

\[ \langle 0| = \begin{pmatrix} 1 & 0 \end{pmatrix}, \quad \langle 1| = \begin{pmatrix} 0 & 1 \end{pmatrix} \]

The inner product of two state vectors is written \(\langle\phi|\psi\rangle\). For orthonormal basis states:

\[ \langle 0|0\rangle = 1, \quad \langle 1|1\rangle = 1, \quad \langle 0|1\rangle = 0 \]

2. Quantum Superposition

A qubit can exist in a linear combination of basis states:

\[ |\psi\rangle = \alpha |0\rangle + \beta |1\rangle = \begin{pmatrix} \alpha \\ \beta \end{pmatrix} \]

where \(\alpha, \beta \in \mathbb{C}\) are probability amplitudes.

Normalization and the Born Rule

The state must satisfy the normalization condition:

\[ \langle\psi|\psi\rangle = |\alpha|^2 + |\beta|^2 = 1 \]

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)\):

\[ |\psi\rangle = \cos\left(\frac{\theta}{2}\right) |0\rangle + e^{i\phi} \sin\left(\frac{\theta}{2}\right) |1\rangle \]

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:

\[ r_x = \langle \psi | X | \psi \rangle = \sin\theta \cos\phi \]
\[ r_y = \langle \psi | Y | \psi \rangle = \sin\theta \sin\phi \]
\[ r_z = \langle \psi | Z | \psi \rangle = \cos\theta \]

Density Matrix and Mixed States

A general quantum state, whether pure or mixed, can be represented by a \(2 \times 2\) density matrix \(\rho\):

\[ \rho = \frac{1}{2} (I + r_x X + r_y Y + r_z Z) = \frac{1}{2} (I + \vec{r} \cdot \vec{\sigma}) \]

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:

\[ \hat{\rho} = \frac{1}{2} \begin{pmatrix} 1 + \langle Z \rangle & \langle X \rangle - i\langle Y \rangle \\ \langle X \rangle + i\langle Y \rangle & 1 - \langle Z \rangle \end{pmatrix} \]

4. Single-Qubit Unitary Gates

Quantum operations are represented by linear operators \(U\) acting on state vectors:

\[ |\psi'\rangle = U |\psi\rangle \]

To preserve state normalization (\(\langle\psi'|\psi'\rangle = \langle\psi|U^\dagger U|\psi\rangle = 1\)), every quantum gate must be unitary:

\[ U^\dagger U = U U^\dagger = I \]

Unitary evolution is completely reversible: \(U^{-1} = U^\dagger\).

The Pauli Gates

The Pauli operators form a basis for Hermitian \(2 \times 2\) matrices:

\[ 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} \]
  • 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:

\[ H = \frac{1}{\sqrt{2}} \begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix} \]

Applying \(H\):

\[ H|0\rangle = \frac{|0\rangle + |1\rangle}{\sqrt{2}} = |+\rangle \]
\[ H|1\rangle = \frac{|0\rangle - |1\rangle}{\sqrt{2}} = |-\rangle \]

Notice that \(H\) is Hermitian and self-inverse (\(H = H^\dagger = H^{-1}\)), so applying it twice returns \(|0\rangle\):

Applying H twice returns |0>

Phase Gates: S and T

Phase gates add relative phase to the \(|1\rangle\) component without changing measurement probabilities in the \(Z\)-basis:

\[ S = \begin{pmatrix} 1 & 0 \\ 0 & i \end{pmatrix} = \sqrt{Z}, \quad T = \begin{pmatrix} 1 & 0 \\ 0 & e^{i\pi/4} \end{pmatrix} = \sqrt{S} \]

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)