Linear Algebra

Linear Algebra in Quantum Mechanics and Quantum ML

IBM Quantum offers free access to a 127-qubit machine. Google Sycamore ran a computation in 200 seconds that a classical supercomputer would need 10,000 years for. This whole world is linear algebra over complex numbers: qubit as a vector, gate as a unitary matrix.

  • IBM Quantum: 127-qubit Eagle processor available through Qiskit - Python API + BLAS under the hood
  • VQE (Variational Quantum Eigensolver): minimize <psi|H|psi> - an eigenvalue problem
  • Quantum cryptography: BB84 - a protocol built on orthogonal quantum states
  • PennyLane: differentiable programming of quantum circuits with PyTorch autograd
  • Shor's algorithm: factoring via the quantum Fourier transform (a unitary matrix of size 2^n x 2^n)

**IBM Quantum gives free access to a 127-qubit quantum computer right now.** Google Sycamore performed in 200 seconds a calculation that would take a classical supercomputer 10,000 years. PennyLane and Qiskit let you run quantum circuits on real hardware or simulators with PyTorch-compatible autograd. This whole world runs on one foundation: linear algebra over complex numbers.

Quantum mechanics, stripped of physical mysticism, is a **dictionary**. *Qubit* = unit vector in $\mathbb{C}^2$. *Gate* = unitary matrix. *Measurement* = projection onto an eigenvector. *Entanglement* = a tensor product that does not factor. If you are already fluent in linear algebra, you have quantum computing 90 percent covered. This lesson supplies the remaining 10 percent: bra-ket notation and why complex numbers are essential here.

Qubit: a unit vector in C^2

A classical bit is 0 or 1. A ~qubit~{quantum bit - a vector |psi> in C^2 with |alpha|^2+|beta|^2=1} lives in **superposition**: |psi> = alpha|0> + beta|1>, with alpha and beta complex and |alpha|^2 + |beta|^2 = 1. The basis states |0> = (1, 0)^T and |1> = (0, 1)^T are just the standard basis of C^2.

Quantum gates = unitary matrices

Every operation on a qubit is multiplication by a ~unitary matrix~{U^dagger U = I, preserves the norm of the state vector}. The requirement U^dagger U = I is exactly what preserves the probabilities |alpha|^2 + |beta|^2 = 1: ||U*psi||^2 = ||psi||^2 = 1.

**The Pauli matrices** X, Y, Z are both Hermitian (H = H^dagger, observables) and unitary (U^dagger U = I, gates). Classical mechanics has no such object. Their eigenvalues are +/-1, the only possible measurement outcomes.

Measurement = projection onto an eigenvector

When you measure a qubit it 'collapses' onto an eigenvector of the observed operator. The probability is the squared modulus of the projection. This is not mysticism, it is a standard vector projection onto a basis:

Tensor product: multi-qubit systems

The state space of n qubits is the tensor product: C^2 (x) C^2 (x) ... (x) C^2 = C^(2^n). Two qubits live in C^4, three in C^8. In PyTorch `torch.kron(A, B)` computes the tensor product of matrices. This is the same operation as `np.kron`, and it is what assembles multi-qubit gates.

**Entanglement through matrix rank**: a two-qubit state (a, b, c, d) can be written as a 2x2 matrix [[a, b], [c, d]]. Rank 1 means the state is separable (a product of two qubits). Rank 2 means it is entangled. The Bell state [[0.707, 0], [0, 0.707]] has rank 2.

Quantum ML: VQE, QAOA, and variational circuits

**Variational Quantum Eigensolver (VQE)** is a hybrid quantum-classical algorithm. A quantum circuit prepares the parametric state |psi(theta)>, a classical optimizer minimizes <psi(theta)|H|psi(theta)>. It is literally a neural network whose layers are unitary matrices and whose loss is a quantum-mechanical expectation value.

**QAOA** (Quantum Approximate Optimization Algorithm) is the quantum analog of gradient descent for combinatorial optimization. The circuit alternates two unitary operators: e^(-i gamma C) (the problem Hamiltonian) and e^(-i beta B) (the mixing operator). These are matrix exponentials in action - the previous lesson at work.

**PennyLane** by Xanadu is PyTorch for quantum circuits. Quantum gates have autograd; you can run `loss.backward()` like in a regular neural network. Hybrid quantum-classical ML is no longer just theory: Zapata, QML.ai, 1QBit and others work in this space.

Quantum evolution = matrix exponential

Schrodinger's equation i hbar d|psi>/dt = H|psi>, with H a Hermitian Hamiltonian (H = H^dagger). Solution: |psi(t)> = e^(-i H t / hbar) |psi(0)>. This is the matrix exponential of an anti-Hermitian matrix (-iH). Because (-iH)^dagger = i H^dagger = i H = -(-iH), the matrix -iH is anti-Hermitian, and e^A for an anti-Hermitian A is unitary. Gates are just fixed snapshots of this evolution.

Practice: quantum gates

Qubit as a vector: states, gates, and unitary matrices

A qubit is a unit vector in $\mathbb{C}^2$: $|\psi\rangle = \alpha|0\rangle + \beta|1\rangle$, with $|\alpha|^2 + |\beta|^2 = 1$. The states $|0\rangle = (1,0)^\top$ and $|1\rangle = (0,1)^\top$ are the standard basis. A quantum gate is a unitary matrix $U$ ($U^\dagger U = I$), applied as $|\psi'\rangle = U|\psi\rangle$.

**Core gates (2x2 matrices):** - Pauli-X (NOT): $X = \begin{pmatrix}0&1\\1&0\end{pmatrix}$ - flips $|0\rangle \leftrightarrow |1\rangle$ - Hadamard: $H = \frac{1}{\sqrt{2}}\begin{pmatrix}1&1\\1&-1\end{pmatrix}$ - creates the superposition $H|0\rangle = \frac{|0\rangle+|1\rangle}{\sqrt{2}}$ - Phase: $S = \begin{pmatrix}1&0\\0&i\end{pmatrix}$ - phase rotation

A circuit as a matrix product

Gate composition

A circuit of $n$ gates $U_n, \ldots, U_1$ in sequence is a matrix product: $U_{\text{total}} = U_n \cdots U_1$. For a 5-qubit circuit of 20 gates: 20 matrix multiplications of size $32 \times 32$. Simulating $n$ qubits on a classical computer: $O(2^n)$ memory and time - precisely why quantum computers become interesting for $n > 50$.

Why must quantum gates be unitary matrices ($U^\dagger U = I$)?

A quantum state is a unit vector ($|\alpha|^2 + |\beta|^2 = 1$, probabilities sum to 1). A unitary matrix preserves the norm: $\langle\psi|U^\dagger U|\psi\rangle = \langle\psi|\psi\rangle = 1$. This is the physical requirement of probability conservation.

Entanglement, tensor products, and Quantum ML

A two-qubit state is a vector in $\mathbb{C}^4 = \mathbb{C}^2 \otimes \mathbb{C}^2$. Separable state: $|\psi\rangle = |\psi_1\rangle \otimes |\psi_2\rangle$. An entangled state does not factor as a tensor product: the Bell state $|\Phi^+\rangle = \frac{1}{\sqrt{2}}(|00\rangle + |11\rangle)$.

**Quantum ML (QML)**: variational quantum circuits (VQC) are parametric unitary matrices $U(\theta)$. Training: minimize $\langle\psi|H|\psi\rangle$ over $\theta$ via classical optimization. PennyLane (Xanadu) and Qiskit let you train such circuits with PyTorch-compatible autograd. Current status (2024): NISQ era, where noise still blocks an advantage over classical methods on most tasks.

VQE: ground state of a molecule

Quantum chemistry

VQE (Variational Quantum Eigensolver): find the smallest eigenvalue of the Hamiltonian $H$ of $H_2$. $H$ is a $4 \times 4$ Hermitian matrix (2 qubits). A parametric circuit $U(\theta)$ prepares $|\psi(\theta)\rangle$. We minimize $E(\theta) = \langle\psi(\theta)|H|\psi(\theta)\rangle$ - the variational principle for the lowest eigenvalue.

Why does simulating an $n$-qubit quantum system on a classical computer require $O(2^n)$ memory?

$\mathbb{C}^2 \otimes \mathbb{C}^2 \otimes \ldots \otimes \mathbb{C}^2 = \mathbb{C}^{2^n}$. An $n$-qubit state has $2^n$ complex amplitudes. At $n=50$: $2^{50} \approx 10^{15}$ complex numbers, around 16 petabytes. At $n=300$, more than the number of atoms in the universe.

The equal-superposition state (|+>): |+> = (1/sqrt(2))|0> + (1/sqrt(2))|1> = (1/sqrt(2), 1/sqrt(2))^T Probability of measuring 0: |1/sqrt(2)|^2 = 0.5 Probability of measuring 1: |1/sqrt(2)|^2 = 0.5 Normalization check: |alpha|^2 + |beta|^2 = 0.5 + 0.5 = 1 ok General qubit on the Bloch sphere: |psi> = cos(theta/2)|0> + e^(i phi) sin(theta/2)|1> theta in [0, pi], phi in [0, 2pi) -> Every qubit is a point on the unit sphere in R^3

GateMatrixActionML analog
X (NOT)[[0,1],[1,0]]|0> <-> |1> - quantum NOTFeature swap
H (Hadamard)[[1,1],[1,-1]]/sqrt(2)|0> -> |+> superpositionFourier basis / Walsh-Hadamard
Z (Phase flip)[[1,0],[0,-1]]Sign on |1>Reflection in R^2
RY(theta)[[cos theta/2, -sin theta/2],[sin theta/2, cos theta/2]]Rotation on the Bloch sphereParametric layer in a VQC

Observable: Z = [[1, 0], [0, -1]] Eigenvectors: |0> (for lambda=+1) and |1> (for lambda=-1) State: |psi> = alpha|0> + beta|1> Probability of getting +1: |<0|psi>|^2 = |alpha|^2 Probability of getting -1: |<1|psi>|^2 = |beta|^2 Expected value: <Z> = <psi|Z|psi> = |alpha|^2 * (+1) + |beta|^2 * (-1) = |alpha|^2 - |beta|^2 It is the scalar product with a matrix - the same formula used in least squares.

Let A = -iH, with H = H^dagger (Hermitian). Then A^dagger = (-iH)^dagger = i H^dagger = iH = -A (anti-Hermitian) Check: (e^A)^dagger * e^A = e^(A^dagger) * e^A = e^(-A) * e^A = e^(A - A) = e^0 = I -> e^A is unitary. Conclusion: quantum mechanics requires Hermitian Hamiltonians -> evolution is unitary -> probabilities are preserved. All of that follows from matrix exponential properties.

  • **System state**: unit vector in C^(2^n) for n qubits
  • **Quantum gate**: unitary matrix U with U^dagger U = I
  • **Measurement / observable**: Hermitian matrix H = H^dagger; result is an eigenvalue
  • **Entanglement**: coefficient matrix has rank > 1 (Schmidt rank)
  • **VQE / QAOA**: parametric unitaries plus classical optimization

Упражнения

  1. Why must quantum gates be unitary matrices? What physical principle is behind this? — The sum of probabilities = ||psi||^2 = 1 must be preserved after any operation; ||U psi||^2 = psi^dagger U^dagger U psi = psi^dagger I psi = ||psi||^2 only if U^dagger U = I; Unitarity = isometry in complex space: distances are preserved
  2. What is the difference between entanglement and superposition? How does matrix rank let you check it? — Superposition: a single qubit in alpha|0> + beta|1> - just a unit vector in C^2; Entanglement: a two-qubit state that cannot be decomposed as a product of two single-qubit states; Test: reshape (a,b,c,d) -> [[a,b],[c,d]], rank 1 = separable, rank 2 = entangled
  3. How is VQE related to a regular neural network? What plays the role of parameters and of the loss? — Parameters = angles in parametric gates RY(theta), RZ(phi), etc.; Loss = <psi(theta)|H|psi(theta)> - the expectation value of the Hamiltonian; Optimization is classical (COBYLA, Adam), the quantum circuit only evaluates the cost

Takeaways

  • **Qubit = unit vector in C^2**: |psi> = alpha|0> + beta|1>, |alpha|^2 + |beta|^2 = 1 - simply a normalization
  • **Quantum gate = unitary matrix U^dagger U = I** - preserves the norm, hence the probabilities
  • **Measurement = projection**: probability = squared modulus of the projection onto an eigenvector
  • **n qubits = a vector in C^(2^n)**: tensor product via np.kron, exponential growth of the state space
  • **Quantum evolution U(t) = e^(-iHt / hbar)**: matrix exponential of an anti-Hermitian matrix = unitary
  • **VQE / QAOA**: parametric unitaries plus classical optimization = Quantum ML today

Where to go next

Quantum computing is the endpoint of the linear algebra course. Under the hood are the same tools we started with.

  • Matrix functions — Quantum evolution e^(-iHt) is a special case of the matrix exponential
  • Tensor product — Multi-qubit systems are tensor products of C^2 spaces
  • Spectral graph theory — The graph Laplacian and quantum Hamiltonians share structural patterns across very different fields

Связанные уроки

  • qc-01
Linear Algebra in Quantum Mechanics and Quantum ML

0

1

Sign In