Skip to content

Lesson 33: Quantum Boltzmann Machines

33.1 Learning Outcomes

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

  1. Recall the classical Boltzmann machine / RBM, its energy function and its training rule.
  2. Explain why classical training is hard (the intractable partition function) and how contrastive divergence works around it.
  3. Define the quantum Boltzmann machine with a transverse-field Hamiltonian.
  4. Derive the QBM gradient and explain the non-commutativity obstacle.
  5. Describe how quantum annealers are used to sample Boltzmann distributions, and assess the results honestly.

33.2 Classical Boltzmann Machines

Energy-based models

A Boltzmann machine is a generative model: a stochastic network of binary units \(\vec v\) (visible) and \(\vec h\) (hidden) with energy

\[ E(\vec v,\vec h) = -\sum_i a_iv_i - \sum_j b_jh_j - \sum_{i,j} w_{ij}v_ih_j \]

and probability given by the Boltzmann (Gibbs) distribution

\[ P(\vec v,\vec h) = \frac{e^{-E(\vec v,\vec h)}}{Z}, \qquad Z = \sum_{\vec v,\vec h} e^{-E(\vec v,\vec h)} . \]

\(Z\) is the partition function. Low-energy configurations are more probable, so training amounts to shaping the energy landscape so that the data sits in the valleys.

Restricted Boltzmann Machines (RBM)

Removing visible–visible and hidden–hidden connections leaves a bipartite graph, which makes the conditionals factorise:

\[ P(h_j = 1\mid\vec v) = \sigma\!\left(b_j + \sum_i w_{ij}v_i\right), \qquad P(v_i = 1\mid\vec h) = \sigma\!\left(a_i + \sum_j w_{ij}h_j\right) \]

with \(\sigma(x) = \frac{1}{1+e^{-x}}\). This enables block Gibbs sampling: update all hidden units in parallel, then all visible units.

The training rule

Maximise the log-likelihood \(\mathcal{L} = \sum_{\text{data}}\log P(\vec v)\). The gradient is

\[ \boxed{\ \frac{\partial\mathcal{L}}{\partial w_{ij}} = \underbrace{\big\langle v_ih_j\big\rangle_{\text{data}}}_{\text{positive phase}} - \underbrace{\big\langle v_ih_j\big\rangle_{\text{model}}}_{\text{negative phase}}\ } \]

The positive phase is easy — clamp \(\vec v\) to a data point and sample \(\vec h\).

The negative phase is hard — it requires sampling from the model's own equilibrium distribution, which needs \(Z\), a sum over \(2^{n}\) configurations.

Contrastive divergence (Hinton, 2002)

Instead of running the Gibbs chain to equilibrium, run it for \(k\) steps (usually \(k=1\)) starting from the data:

v0 = data point
h0 ~ P(h | v0)
v1 ~ P(v | h0)
h1 ~ P(h | v1)
grad w_ij  ~=  v0_i h0_j  -  v1_i h1_j

CD-1 is a biased approximation of the true gradient — it does not follow the gradient of any objective function exactly — yet it works remarkably well in practice, and it is what made deep belief networks feasible in 2006.

This is exactly the gap a quantum computer might fill. If a quantum device could sample the true Boltzmann distribution efficiently, the negative phase would be exact, removing CD's bias.

33.3 Quantum Boltzmann Machines

The Hamiltonian

Replace the classical energy function with a quantum Hamiltonian. Amin et al. (PRX, 2018):

\[ \boxed{\ H = -\sum_i \Gamma_i\,\sigma^{x}_{i} \;-\; \sum_i b_i\,\sigma^{z}_{i} \;-\; \sum_{i<j} w_{ij}\,\sigma^{z}_{i}\sigma^{z}_{j}\ } \]
Term Role
\(\sigma^z_i\), \(\sigma^z_i\sigma^z_j\) classical Ising energy — recovers the classical BM exactly
\(\sigma^x_i\) (transverse field) purely quantum — does not commute with \(\sigma^z\)

The quantum Gibbs state

\[ \rho = \frac{e^{-H}}{Z}, \qquad Z = \mathrm{Tr}\big(e^{-H}\big) \]

(Setting \(\beta = 1\) by absorbing temperature into \(H\).) Measuring the visible qubits in the \(Z\) basis gives

\[ P(\vec v) = \mathrm{Tr}\big(\Lambda_{\vec v}\,\rho\big), \qquad \Lambda_{\vec v} = |\vec v\rangle\langle\vec v|\otimes I_{\text{hidden}} . \]

Why the transverse field matters

If \(\Gamma_i = 0\), \(H\) is diagonal in the computational basis, \(\rho\) is a classical Gibbs distribution, and the QBM is a classical BM. Nothing is gained.

If \(\Gamma_i \ne 0\), then \([\sigma^x, \sigma^z] \ne 0\): the eigenstates of \(H\) are superpositions of computational basis states, and \(\rho\) has off-diagonal coherences. The model can then represent distributions no classical BM with the same connectivity can — this is the claimed expressivity advantage.

The non-commutativity obstacle

The classical derivation used

\[ \frac{\partial}{\partial\theta}\log\mathrm{Tr}\,e^{-H} = -\left\langle \frac{\partial H}{\partial\theta}\right\rangle . \]

This step requires \(\left[H, \frac{\partial H}{\partial\theta}\right] = 0\). For the \(b_i\) and \(w_{ij}\) parameters (which multiply \(\sigma^z\) terms) this fails once \(\Gamma\ne0\), and for \(\Gamma_i\) itself it fails too. The correct expression involves the Kubo–Mori integral

\[ \frac{\partial}{\partial\theta}\,\mathrm{Tr}\big(e^{-H}\big) = -\int_{0}^{1}\mathrm{Tr}\left(e^{-sH}\,\frac{\partial H}{\partial\theta}\,e^{-(1-s)H}\right)ds \]

which is not a simple expectation value and cannot be estimated by ordinary sampling.

Amin et al.'s workaround. Instead of maximising the log-likelihood, maximise a variational lower bound obtained from the Golden–Thompson inequality \(\mathrm{Tr}\,e^{A+B} \le \mathrm{Tr}\big(e^{A}e^{B}\big)\). The bound is differentiable by sampling, giving a trainable — if slightly weaker — objective.

The bound-based training rule

For visible-only (or bound-restricted) parameters, the gradient recovers the familiar form:

\[ \frac{\partial\mathcal{L}_{\text{bound}}}{\partial w_{ij}} = \big\langle \sigma^z_i\sigma^z_j\big\rangle_{\text{data-clamped}} - \big\langle \sigma^z_i\sigma^z_j\big\rangle_{\text{model}} \]

— structurally identical to the classical rule, but with expectations taken in the quantum Gibbs state.

33.4 Sampling: Where the Quantum Computer Enters

Three routes to sampling from \(\rho = e^{-H}/Z\):

Method Idea Status
Quantum annealing (D-Wave) anneal slowly; the device equilibrates with its cryogenic environment and returns approximately Boltzmann samples used in practice; effective temperature is uncontrolled
Gibbs state preparation algorithms based on quantum phase estimation or quantum Metropolis fault-tolerant era only
Variational (VarQITE) imaginary-time evolution with a parameterised circuit NISQ-compatible, approximate

The D-Wave route in practice

D-Wave hardware natively implements

\[ H(s) = A(s)\left(-\sum_i\sigma^x_i\right) + B(s)\left(\sum_i h_i\sigma^z_i + \sum_{i<j}J_{ij}\sigma^z_i\sigma^z_j\right) \]

which is exactly the QBM Hamiltonian form. Stopping the anneal early (a "reverse anneal" or a paused anneal) leaves a residual transverse field \(\Gamma \propto A(s)\), sampling from a quantum Boltzmann distribution.

Three practical problems.

  1. Unknown effective temperature. The device does not thermalise at the nominal fridge temperature; \(\beta_{\text{eff}}\) must be estimated per problem and drifts.
  2. Limited connectivity. The Chimera/Pegasus/Zephyr graphs are sparse. Dense \(w_{ij}\) requires minor embedding, in which one logical qubit becomes a chain of physical qubits — inflating qubit count and introducing chain-break errors.
  3. Not truly thermal. Real annealers exhibit freeze-out: the distribution stops evolving partway through the anneal, so the samples come from an intermediate, non-equilibrium distribution.

Reported results, honestly

  • Amin et al. (2018) trained small QBMs (fewer than 10 visible units) and found that a non-zero transverse field gave better log-likelihood than the classical equivalent on synthetic data.
  • Benedetti et al. (2017) trained an RBM on Bars-and-Stripes using a D-Wave sampler and matched classical CD, having first calibrated \(\beta_{\text{eff}}\) from the data.
  • No demonstration to date beats classical CD on a real-world dataset. The consistent finding is parity, not advantage — with the quantum route far slower in wall-clock time.

33.5 Solved Problems

Problem 1 — Boltzmann probabilities and the partition function

A 2-visible-unit BM has \(E(v_1,v_2) = -a_1v_1 - a_2v_2 - w\,v_1v_2\) with \(a_1 = 0.5\), \(a_2 = -0.3\), \(w = 1.0\). Compute \(Z\) and all four probabilities.

Solution.

Energies.

\[ E(0,0) = 0 \]
\[ E(1,0) = -0.5 \]
\[ E(0,1) = +0.3 \]
\[ E(1,1) = -0.5 + 0.3 - 1.0 = -1.2 \]

Boltzmann weights \(e^{-E}\).

\[ e^{0} = 1.0000 \]
\[ e^{0.5} = 1.6487 \]
\[ e^{-0.3} = 0.7408 \]
\[ e^{1.2} = 3.3201 \]

Partition function.

\[ Z = 1.0000 + 1.6487 + 0.7408 + 3.3201 = \mathbf{6.7097} \]

Probabilities.

\((v_1,v_2)\) \(E\) \(e^{-E}\) \(P\)
\((0,0)\) 0 1.0000 0.1490
\((1,0)\) \(-0.5\) 1.6487 0.2457
\((0,1)\) \(+0.3\) 0.7408 0.1104
\((1,1)\) \(\mathbf{-1.2}\) 3.3201 0.4948

Sum \(= 0.9999\) ✓.

Interpretation. The positive coupling \(w = 1\) makes \((1,1)\) by far the most likely — the units are correlated. Note that \(Z\) required summing \(2^{2} = 4\) terms; for 100 units it would be \(2^{100}\) terms, which is exactly why the negative phase is intractable.

Problem 2 — One step of contrastive divergence

An RBM has 2 visible and 1 hidden unit, \(w_{11} = 1.0\), \(w_{21} = -0.5\), \(a_1 = a_2 = 0\), \(b_1 = 0.2\). Perform one CD-1 step for the data point \(\vec v = (1,0)\).

Solution.

Positive phase — sample \(h\) given \(\vec v_0 = (1,0)\).

\[ P(h_1 = 1\mid\vec v_0) = \sigma\big(b_1 + w_{11}v_1 + w_{21}v_2\big) = \sigma(0.2 + 1.0 - 0) = \sigma(1.2) \]
\[ \sigma(1.2) = \frac{1}{1+e^{-1.2}} = \frac{1}{1+0.30119} = \mathbf{0.76852} \]

Say the sample gives \(h_0 = 1\).

Positive-phase statistics.

\[ \langle v_1h_1\rangle_{\text{data}} = 1\times1 = 1, \qquad \langle v_2h_1\rangle_{\text{data}} = 0\times1 = 0 \]

Negative phase — reconstruct \(\vec v_1\) given \(h_0 = 1\).

\[ P(v_1 = 1\mid h_0) = \sigma(a_1 + w_{11}h_1) = \sigma(1.0) = \frac{1}{1+e^{-1}} = \mathbf{0.73106} \]
\[ P(v_2 = 1\mid h_0) = \sigma(a_2 + w_{21}h_1) = \sigma(-0.5) = \frac{1}{1+e^{0.5}} = \mathbf{0.37754} \]

Say the samples give \(\vec v_1 = (1, 0)\).

Re-sample \(h\) given \(\vec v_1\). Identical to the positive phase: \(P = 0.76852\); say \(h_1 = 1\).

Negative-phase statistics.

\[ \langle v_1h_1\rangle_{\text{model}} = 1, \qquad \langle v_2h_1\rangle_{\text{model}} = 0 \]

Gradients.

\[ \Delta w_{11} \propto 1 - 1 = \mathbf{0}, \qquad \Delta w_{21} \propto 0 - 0 = \mathbf{0} \]

Interpretation. The reconstruction exactly matched the data, so there is nothing to learn from this sample — the model already assigns it high probability. This is the essence of CD: the gradient measures the discrepancy between the data and the model's reconstruction of it. When they agree, learning stops.

(In practice one averages over a minibatch; single-sample gradients are extremely noisy, and the stochastic sampling means a different draw of \(\vec v_1\) would have produced a non-zero gradient.)

Problem 3 — Transverse field and the ground state

A single-qubit QBM has \(H = -\Gamma\sigma^x - b\sigma^z\). Compute the eigenvalues, the ground state, and \(\langle\sigma^z\rangle\) in the Gibbs state, for \(\Gamma = 1\), \(b = 1\).

Solution.

\[ H = -\begin{pmatrix} b & \Gamma\\ \Gamma & -b\end{pmatrix} = -\begin{pmatrix}1 & 1\\ 1 & -1\end{pmatrix} \]

Eigenvalues. \(\det(H - \lambda I) = 0\) gives \(\lambda^{2} - (\Gamma^{2}+b^{2}) = 0\):

\[ \lambda = \pm\sqrt{\Gamma^2 + b^2} = \pm\sqrt2 = \pm1.41421 \]

Ground state (\(\lambda_- = -\sqrt2\)). Solve \((H + \sqrt2 I)|\psi\rangle = 0\):

\[ \begin{pmatrix}-1+\sqrt2 & -1\\ -1 & 1+\sqrt2\end{pmatrix}\begin{pmatrix}\alpha\\\beta\end{pmatrix} = 0 \]

From the first row: \(\beta = (\sqrt2 - 1)\alpha = 0.41421\alpha\). Normalising:

\[ |\psi_0\rangle = \frac{1}{\sqrt{1+0.41421^{2}}}\begin{pmatrix}1\\ 0.41421\end{pmatrix} = \begin{pmatrix}0.92388\\ 0.38268\end{pmatrix} \]

A superposition of \(|0\rangle\) and \(|1\rangle\) — impossible for a classical BM, whose states are always definite bit strings.

Gibbs state at \(\beta = 1\). In the eigenbasis, \(\rho = \frac{1}{Z}\mathrm{diag}(e^{\sqrt2}, e^{-\sqrt2})\):

\[ Z = e^{1.41421} + e^{-1.41421} = 4.11325 + 0.24316 = 4.35637 \]
\[ p_- = \frac{4.11325}{4.35641} = 0.94419, \qquad p_+ = 0.05582 \]

Expectation of \(\sigma^z\). The excited state is orthogonal to \(|\psi_0\rangle\): \(|\psi_1\rangle = (-0.38268,\ 0.92388)^T\).

\[ \langle\psi_0|\sigma^z|\psi_0\rangle = 0.92388^2 - 0.38268^2 = 0.85355 - 0.14645 = 0.70711 \]
\[ \langle\psi_1|\sigma^z|\psi_1\rangle = 0.14645 - 0.85355 = -0.70711 \]
\[ \langle\sigma^z\rangle = 0.94419(0.70711) + 0.05582(-0.70711) = \mathbf{0.62819} \]

Compare the classical case (\(\Gamma = 0\)). Then \(\langle\sigma^z\rangle = \tanh(b) = \tanh(1) = 0.76159\).

\[ \boxed{\ \text{The transverse field \emph{reduces} the magnetisation from } 0.762 \text{ to } 0.628.\ } \]

This is quantum fluctuation: the \(\sigma^x\) term drives transitions between \(|0\rangle\) and \(|1\rangle\), partially destroying the \(z\)-alignment. It is exactly the effect a QBM exploits — an extra, tunable source of "disorder" that has no classical analogue at the same temperature.

Problem 4 — Partition-function cost and why sampling is needed

Compute the cost of evaluating \(Z\) exactly for a fully connected BM with 20, 50 and 100 units. At \(10^{9}\) terms/second, how long does each take?

Solution.

\(Z = \sum_{\text{configs}} e^{-E}\) has \(2^{n}\) terms.

\(n\) \(2^{n}\) Time at \(10^{9}\)/s
20 \(1.05\times10^{6}\) 1.0 ms
50 \(1.13\times10^{15}\) 13 days
100 \(1.27\times10^{30}\) \(1.27\times10^{21}\) s = \(4\times10^{13}\) years

At 100 units — a tiny model by modern standards — exact evaluation exceeds the age of the universe by a factor of 3000.

Why sampling solves it. Estimating \(\langle v_ih_j\rangle_{\text{model}}\) needs only samples from \(P\), not \(Z\) itself. MCMC (Gibbs sampling) generates such samples with each step costing \(O(n^2)\) — polynomial. The catch is mixing time: the chain may need exponentially many steps to reach equilibrium if the energy landscape has deep, separated valleys.

This is precisely the gap a quantum annealer targets. Instead of a random walk that must climb out of valleys, quantum tunnelling can pass through barriers, potentially mixing faster. Whether this yields a genuine speed-up on realistic landscapes remains the central open question of quantum annealing (L35).

Problem 5 — Designing a QBM experiment on hardware

Design an experiment to test whether a QBM outperforms a classical RBM. Specify the dataset, architecture, hardware, controls and metrics — and predict the result.

Solution.

Dataset. Bars-and-Stripes on a \(4\times4\) grid: 16 visible units, 30 valid patterns out of \(2^{16} = 65536\). Small enough to compute the exact log-likelihood, which is essential for an honest comparison.

Architecture. 16 visible + 8 hidden units, fully connected between layers (RBM topology). Parameters: \(16\times8 + 16 + 8 = \mathbf{152}\).

Hardware. D-Wave Advantage. Minor embedding of a \(16\times8\) bipartite graph onto the Pegasus topology requires chains of ~4 physical qubits per logical qubit, so about 100 physical qubits.

The four arms of the experiment.

Arm Sampler Purpose
A Classical CD-1 the standard baseline
B Classical Gibbs, 1000 steps the "exact-sampling" ceiling
C D-Wave, \(\Gamma = 0\) (full anneal) tests the sampler, not quantumness
D D-Wave, \(\Gamma > 0\) (paused anneal) tests quantumness specifically

Arms C and D are the crucial pair. Comparing D against C isolates the effect of the transverse field, controlling for everything else about the hardware.

Critical calibration. Estimate \(\beta_{\text{eff}}\) for the annealer by fitting the observed energy histogram to a Boltzmann distribution. Without this, the comparison is meaningless — much of the early literature's apparent advantage came from an uncalibrated effective temperature.

Metrics.

  1. Exact log-likelihood on held-out data (computable at this size).
  2. KL divergence between the model and the true BAS distribution.
  3. Wall-clock time to reach a target log-likelihood — including embedding, programming and readout overhead, not just anneal time.
  4. Chain-break fraction — if above ~5 %, the embedding is unreliable and results are suspect.

Predicted outcome, stated in advance.

  • Arms A, B, C, D will reach comparable log-likelihoods, with B (exact Gibbs) marginally best.
  • Arm D may show a small improvement over C, consistent with Amin et al.'s finding that a transverse field helps modestly.
  • Arm A (classical CD-1) will win decisively on wall-clock time, by three to four orders of magnitude, because a D-Wave call carries ~10 ms of programming and readout overhead per sample batch while CD-1 runs in microseconds.

The honest conclusion to draw. QBMs are scientifically interesting — they demonstrate that a transverse field enriches the model class — but they are not yet practically competitive. The bottleneck is not the algorithm but the sampler: hardware overhead, uncontrolled effective temperature, limited connectivity and freeze-out. Designing the experiment with arms C and D, and calibrating \(\beta_{\text{eff}}\), is what separates a rigorous study from a press release.

33.6 Practice Problems

  1. For \(E(v) = -2v\), compute \(P(v=1)\) with one binary unit. [Ans: \(e^2/(1+e^2) = 0.881\)]
  2. Compute \(\sigma(0.5)\) and \(\sigma(-1.5)\). [Ans: 0.6225, 0.1824]
  3. Find the eigenvalues of \(H = -\Gamma\sigma^x - b\sigma^z\) for \(\Gamma = 0.5\), \(b = 2\). [Ans: \(\pm2.0616\)]
  4. Why does \([H,\partial H/\partial\theta]\ne0\) break the classical gradient derivation?
  5. How many terms in \(Z\) for a 30-unit BM? [Ans: \(1.07\times10^{9}\)]
  6. Compute \(\langle\sigma^z\rangle\) for a classical BM with \(b=0.8\), \(\Gamma=0\). [Ans: \(\tanh 0.8 = 0.6640\)]
  7. Name three practical problems with using a D-Wave device as a Boltzmann sampler.

33.7 Summary

  • A Boltzmann machine is an energy-based generative model with \(P \propto e^{-E}\); training needs \(\langle\cdot\rangle_{\text{data}} - \langle\cdot\rangle_{\text{model}}\), and the model term is intractable because \(Z\) sums \(2^n\) configurations.
  • Contrastive divergence replaces equilibrium sampling with a \(k\)-step chain — biased, but effective.
  • A QBM adds a transverse field \(-\Gamma\sum_i\sigma^x_i\), making \(H\) non-diagonal so the Gibbs state \(\rho = e^{-H}/Z\) carries coherences no classical BM can represent.
  • Non-commutativity breaks the standard gradient derivation; Amin et al. train a variational lower bound derived from the Golden–Thompson inequality instead.
  • Quantum annealers natively realise the QBM Hamiltonian and can be used as Boltzmann samplers, but suffer from unknown \(\beta_{\text{eff}}\), sparse connectivity requiring minor embedding, and freeze-out.
  • Honest status: a transverse field demonstrably enriches the model class on small synthetic problems, but no result beats classical CD on real data, and hardware overhead costs 3–4 orders of magnitude in wall-clock time.

Next lesson: L34 — The Quantum Approximate Optimization Algorithm (QAOA).

Practise now: unit3-qml-lab.html → Boltzmann Lab: set weights and biases, see the full energy table and Boltzmann distribution, sweep the transverse field \(\Gamma\) and watch \(\langle\sigma^z\rangle\) fall as quantum fluctuations grow.