Search

Search papers and lessons

Equation of State Calculations by Fast Computing Machines

N. Metropolis, Arianna W. Rosenbluth, M. N. Rosenbluth et al. · 1953

The 1953 paper that introduced the Metropolis method: a random walk over particle positions that accepts or rejects each move so that the walk visits configurations with their Boltzmann weight.

On this page

  • Colour = topic mix
  • Probability
  • Calculus
  • Linear algebra
  • Sampling
  • Discrete math
  • Stochastic processes
  • Sign in to see your progress

TL;DR

In 1953 five authors at Los Alamos described a way to estimate the thermal properties of a dense fluid made of interacting molecules. Instead of averaging over random arrangements of the molecules, they run a random walk over arrangements in which each proposed move is accepted or rejected by a simple rule. The rule makes the walk spend time in each arrangement in proportion to its Boltzmann weight, so a plain average along the walk is the thermal average. They tested it on a two-dimensional system of hard disks and checked the result against known approximations.

Where you'll see it: molecular simulation of liquids and proteins, the sampling engine behind Bayesian statistics, and the Markov chain Monte Carlo methods used throughout machine learning.

The problem

Suppose you want the pressure of a liquid made of several hundred molecules at a fixed temperature. Statistical mechanics says that every arrangement of the molecules, every point in configuration space, has a weight that depends on its energy. For a system at temperature TT with energy EE, the weight of a state is proportional to e−E/kTe^{-E/kT}, where kk is Boltzmann's constant. This is the Canonical Ensemble picture. A thermal average of any quantity FF is

⟨F⟩=∫F(q) e−E(q)/kT dq∫e−E(q)/kT dq,\langle F\rangle = \frac{\int F(\mathbf{q})\, e^{-E(\mathbf{q})/kT}\, d\mathbf{q}}{\int e^{-E(\mathbf{q})/kT}\, d\mathbf{q}},

where q\mathbf{q} stands for the positions of all NN particles, so the integral runs over a 2N2N-dimensional space in two dimensions (or 3N3N in three). The energy splits into a kinetic part that depends on momenta and a potential part that depends on positions. The momentum part can be averaged analytically, which is why the paper only has to deal with positions.

A several-hundred-dimensional integral cannot be done on a grid. The obvious fix is Monte Carlo integration: pick random configurations and average. The paper points out why this fails for dense fluids. A random placement of hundreds of molecules almost always has two of them overlapping, which gives a huge energy and therefore a weight e−E/kTe^{-E/kT} that is essentially zero. Most of the samples contribute nothing, and the few that do dominate the answer with huge variance. What is needed is a way to visit the configurations that matter, the low-energy ones, far more often than the rest.

This is the same problem that Importance Sampling addresses by reweighting samples drawn from a convenient distribution. The paper takes a different route: it does not reweight at all. It builds a process whose visits already have the right frequencies.

Key idea

Replace the random configurations by a walk. Start from any arrangement, pick one particle, move it by a small random displacement, and decide whether to keep the move with one rule:

  • If the move lowers the energy, keep it.
  • If the move raises the energy by ΔE\Delta E, keep it with probability e−ΔE/kTe^{-\Delta E/kT}. Otherwise undo it.

Then count the current arrangement as a sample, whether or not the move was kept. This is a Metropolis Algorithm run on the space of configurations.

Think of a hiker on a landscape whose height is the energy. The hiker prefers to go downhill. Uphill steps are not forbidden; they are just less likely the steeper they are. Over a long walk the hiker spends time at each height in proportion to how many visits that height gets under the rule, and the rule is tuned so that the time spent at a point is proportional to e−E/kTe^{-E/kT}.

00.511.522.5300.20.40.60.81ΔE / kTprobability of accepting
  • acceptance probability
The uphill acceptance rule. A move that raises the energy by one kT is accepted about 37 percent of the time; a move that raises it by three kT only about 5 percent of the time.

The method

The box and the energy

The paper considers NN particles in a square of side LL. To avoid edge effects the square is treated as periodic: a particle leaving one side re-enters from the opposite side, and the distance between two particles is the shortest distance between one of them and any periodic image of the other. The paper uses this minimum distance rijr_{ij} and assumes the potential V(r)V(r) between two molecules falls off quickly, so only one image matters. The total energy is

E=12∑i≠jV(rij).E = \tfrac{1}{2}\sum_{i \neq j} V(r_{ij}).

The factor one half avoids counting each pair twice.

One move

A single step of the walk does the following for one particle ii.

  1. Propose a new position x′=xi+δ\mathbf{x}' = \mathbf{x}_i + \boldsymbol{\delta}, where each component of δ\boldsymbol{\delta} is a uniform random number between −δ-\delta and δ\delta. The new position is equally likely anywhere in a square of side 2δ2\delta around the old one. The maximum displacement δ\delta is a tunable number.
  2. Compute ΔE\Delta E, the change in energy caused by this one move. Only pairs involving particle ii change, so this is cheap.
  3. If ΔE≤0\Delta E \le 0, accept. If ΔE>0\Delta E > 0, draw a uniform random number uu between 0 and 1 and accept if u<e−ΔE/kTu \lt e^{-\Delta E/kT}.
  4. If the move was rejected, the particle stays where it was.

Whether the move was accepted or not, the resulting configuration is recorded as one sample. Forgetting to record the old configuration after a rejection is a classic bug, and the paper states explicitly that the initial configuration must be counted again after a forbidden move.

Why this samples the right distribution

The paper proves the rule works in two parts: the walk can reach any configuration from any other, which it calls ergodicity, and the flow of samples between any two states is balanced in the right way.

The second part is easiest to see with a symmetric proposal. Let π(s)∝e−E(s)/kT\pi(s) \propto e^{-E(s)/kT} be the target weight of configuration ss. Because the proposal is symmetric, the probability of proposing tt from ss equals the probability of proposing ss from tt. Call that probability qq. The Metropolis rule accepts the move from ss to tt with probability α(s,t)=min⁡(1,π(t)/π(s))\alpha(s,t) = \min\left(1, \pi(t)/\pi(s)\right). The flow of samples from ss to tt is therefore

π(s) q α(s,t)=q π(s)min⁡(1,π(t)π(s))=q min⁡(π(s),π(t)).\pi(s)\, q\, \alpha(s,t) = q\, \pi(s) \min\left(1, \frac{\pi(t)}{\pi(s)}\right) = q\, \min\left(\pi(s), \pi(t)\right).

The right-hand side is symmetric in ss and tt. So the flow from ss to tt equals the flow from tt to ss. This is the Detailed Balance condition, and a chain that satisfies it has π\pi as its stationary distribution. The paper reaches the same conclusion with a counting argument over an ensemble of systems: the number of systems moving from state rr to state ss must equal the number moving back, and that forces the ratio of populations to be e−(Es−Er)/kTe^{-(E_s - E_r)/kT}.

Notice that the normalising constant ∫e−E/kT dq\int e^{-E/kT}\, d\mathbf{q} never appears. Only ratios of weights are used, so the rule can be applied without knowing the total. That is why the method is practical in a space too large to normalise.

Hard disks

For the test case the paper uses rigid spheres in two dimensions. A pair of hard disks has energy zero when they do not overlap and infinite energy when they do. The energy change of a move is therefore either 00 or ∞\infty, the acceptance probability is 11 or 00, and the random number uu is not needed. A move is accepted exactly when it creates no overlap. The paper uses N=224N = 224 disks in a unit square, starting from a regular trigonal lattice.

Choosing the step size

The maximum displacement δ\delta has to be chosen with care. If δ\delta is too large, most proposed moves land on overlapping disks and are rejected, so the configuration hardly changes. If δ\delta is too small, almost every move is accepted but each one moves little, so the configuration changes slowly. In both cases the walk takes much longer to reach equilibrium. The paper sets δ\delta so that about half the moves are forbidden, which is a rule of thumb that appears in modern simulation codes too.

Pressure from the contacts

The paper does not compute the pressure directly from forces. It uses the virial theorem of Clausius, which relates the pressure to the average of the total force-times-distance product. For hard disks the virial term reduces to a single number: the density of other disks in contact with a given disk at the contact distance d0d_0, which the paper reads off the radial distribution function. The pressure then follows from an equation of state with one measured quantity. The paper's work is therefore to estimate that contact density accurately as a function of the area per disk.

Results

The paper expresses the equation of state through the dimensionless quantity (PA/NkT)−1(PA/NkT) - 1, where AA is the total area and A0A_0 is the area the disks would occupy in a close-packed arrangement. It compares three things: the Monte Carlo result, the free-volume theory of Wood, and a four-term virial expansion of the pressure in powers of the density.

A selection of the paper's table, with the Monte Carlo value first:

A/A0A/A_0Monte CarloFree volume theoryFour-term virial
1.326.436.725.35
1.802.932.942.68
4.040.6770.9900.667

Three findings matter.

  • Near close packing, where A/A0A/A_0 is small, the Monte Carlo result stays close to the free-volume theory, and the virial expansion falls well below it.
  • At large area, where A/A0A/A_0 is a few, the Monte Carlo result follows the four-term virial expansion, and the free-volume theory overshoots.
  • The paper reports no sign of a phase transition in the range of densities it covered.

The virial fit that the paper gives is

PANkT−1≈1.8138 x+2.5727 x2+3.179 x3+3.38 x4,x=A0A.\frac{PA}{NkT} - 1 \approx 1.8138\, x + 2.5727\, x^2 + 3.179\, x^3 + 3.38\, x^4, \qquad x = \frac{A_0}{A}.

Plugging in A/A0=4.04A/A_0 = 4.04 gives x≈0.2475x \approx 0.2475 and a value of about 0.6670.667, which matches the table. The paper's computing cost is also worth noting. One Monte Carlo cycle, in which every particle is moved once, took minutes on the MANIAC machine at Los Alamos, so each point on the pressure curve needed hours of running.

Why it mattered

The paper turned Monte Carlo from a way of estimating a small integral into a way of simulating a physical system. The acceptance rule it introduced is now called the Metropolis rule, and it is the basis of the Metropolis Algorithm. Hastings generalised it in 1970 to proposals that are not symmetric, which gives the Metropolis–Hastings algorithm used in statistics and machine learning today.

In chemistry and physics the method became the standard tool for simulating liquids, polymers, and magnetic systems at fixed temperature. In statistics the same idea, a walk whose visit frequencies match a target distribution, is the core of Markov Chain Monte Carlo. Any problem where a posterior or a Boltzmann-like distribution is known only up to a constant can use it, because the rule never needs the normalising constant.

Reading guide

Read the paper in this order, with these prerequisites in hand.

  1. The introduction. The question is the thermal average of a property for a fluid of interacting molecules. You need the idea of a Canonical Ensemble and of an average over states.
  2. The setup of the average. The energy is a sum over pairs, and the average is a ratio of integrals with weight e−E/kTe^{-E/kT}. Read Expected Value first if the ratio of integrals is unfamiliar.
  3. The move and the proof. This is the heart of the paper. Read Metropolis Algorithm for the rule, Detailed Balance for the balance argument, and Markov Chain for the idea of a walk with a stationary distribution. The uniform displacement is described in Uniform Distribution.
  4. The comparison with plain sampling. This is where the paper explains why random placement fails. Monte Carlo Method gives the background, and Importance Sampling shows the reweighting alternative that the paper avoids.
  5. The virial pressure. The paper's pressure formula uses the virial theorem and a contact density. Standard textbooks on liquids cover this; the graph has no node for it yet.
  6. The results. The averages along the walk are justified by the Law of Large Numbers. Check the table against the free-volume and virial formulas.
  7. The virial coefficients. Cluster integrals are a separate topic. You can skip it on a first read.

Check yourself

QuestionRecall: a proposed move lowers the energy of the system. Does the Metropolis rule accept it, reject it, or accept it with some probability?Show answer

It is always accepted. The rule accepts any move with ΔE≤0\Delta E \le 0 outright, because the ratio of target weights is at least one. Only uphill moves are accepted with a probability less than one.

QuestionA move raises the energy by ΔE=0.8 kT\Delta E = 0.8\,kT. What is the probability it is accepted?Show answer

The acceptance probability is e−0.8≈0.449e^{-0.8} \approx 0.449. The random number uu is drawn uniformly between 0 and 1, and the move is kept when uu is less than 0.449. So a little under half of such moves are kept.

QuestionWhy did the authors not simply place random configurations and weight each by e−E/kTe^{-E/kT}?Show answer

Dense configurations are almost always overlapping, which gives huge energies and weights close to zero. Most samples contribute nothing, and the estimate has very large variance. The walk instead spends its time in the configurations that have large weight, so each sample counts for something.

QuestionA run makes 1,000 proposed moves and accepts 400 of them. How many configurations are recorded as samples, and why?Show answer

Recorded samples number 1,000, one per proposed move, whether accepted or not. A rejected move leaves the configuration unchanged, but that unchanged configuration still has to be counted. Dropping the rejected steps would bias the average toward the configurations the walk leaves most easily.

QuestionIn the hard-disk case the energy change of any move is either 00 or ∞\infty. What does the Metropolis rule reduce to, and why does that simplify the simulation?Show answer

Moves that create no overlap have ΔE=0\Delta E = 0 and are accepted, and moves that create an overlap have ΔE=∞\Delta E = \infty and are rejected. No random number is needed, so the only computation per move is an overlap test against nearby disks.

Sources

Read the full paper

N. Metropolis, Arianna W. Rosenbluth, M. N. Rosenbluth et al., 1953.