Skip to content
QFT.org

Search QFT.org

Enter a word or phrase.

    You can also browse the main navigation and chapter contents.

    A First Scalar-Field Simulation

    How much does a field at one site tell us about the field at its neighbor? In a free theory we can invert a matrix to answer this question. Adding a quartic interaction makes that inverse insufficient, but the finite Euclidean integral is still well defined. We will sample it with local field updates, first recover the free answer, and then measure how the interaction changes the correlation.

    The complete example runs on an 8×88\times8 periodic lattice. It includes the update, measurements, starting-state comparison and statistical error analysis. Its output is a calculation at one finite regulator; obtaining continuum physics requires the separate spacing and volume limits.

    Preparation: The dimensionless scalar lattice action and the meaning of a covariance matrix. The sampling probability and error estimate are developed below.

    The finite integral to be sampled

    Let n=(n0,n1)n=(n_0,n_1) label N0=N1=8N_0=N_1=8 sites in two Euclidean dimensions, with indices understood modulo eight. There are V=N0N1=64V=N_0N_1=64 real integration variables φn\varphi_n. This VV counts sites, whereas the physical Euclidean volume is a2Va^2V. Use

    SE[φ]=∑n[12∑μ=01(φn+μ^−φn)2+m^22φn2+λ^24φn4],m^2=1.S_E[\varphi]=\sum_n\left[ \frac12\sum_{\mu=0}^1(\varphi_{n+\hat\mu}-\varphi_n)^2 +\frac{\widehat m^2}{2}\varphi_n^2 +\frac{\widehat\lambda}{24}\varphi_n^4\right], \qquad \widehat m^2=1.

    Here m^2=a2m02\widehat m^2=a^2m_0^2 is the dimensionless bare mass coefficient and λ^=a2λ0\widehat\lambda=a^2\lambda_0 in two dimensions. We compare λ^=0\widehat\lambda=0 and 22, keeping every other parameter fixed. Neither m^\widehat m nor the quartic coefficient is an extracted physical mass or coupling.

    The probability density and observable mean are

    p(φ)=e−SE[φ]Z,Z=∫R64∏ndφn e−SE[φ],⟨O⟩=∫∏ndφn p(φ)O[φ].p(\varphi)=\frac{e^{-S_E[\varphi]}}{Z},\qquad Z=\int_{\mathbb R^{64}}\prod_n\mathrm d\varphi_n\,e^{-S_E[\varphi]},\qquad \langle O\rangle=\int\prod_n\mathrm d\varphi_n\,p(\varphi)O[\varphi].

    Both selected actions are strictly confining at large field and have finite ZZ. We need ratios of weights, so we never evaluate ZZ to update the configuration. The two Euclidean directions have equal spacing and identical periodic boundaries. A simulation sweep is an algorithmic time step, unrelated to either coordinate or to Lorentzian time evolution.

    Change one field, then decide whether to keep it

    Hold the neighbors of site nn fixed. Write its old value as xx, propose y=x+δy=x+\delta with δ\delta uniform on [−Δ,Δ][-\Delta,\Delta], and define the neighbor sum

    bn=∑μ=01(φn+μ^+φn−μ^).b_n=\sum_{\mu=0}^1(\varphi_{n+\hat\mu}+\varphi_{n-\hat\mu}).

    Every incident kinetic bond contributes to the action difference. Collecting their quadratic and linear terms gives

    ΔSE=(4+m^2)(xδ+δ22)−bnδ+λ^24[(x+δ)4−x4].\Delta S_E= (4+\widehat m^2)\left(x\delta+\frac{\delta^2}{2}\right) -b_n\delta +\frac{\widehat\lambda}{24}\left[(x+\delta)^4-x^4\right].

    Thus an update needs four neighbors, not a reevaluation of the full action. The companion checks this local expression against the full action difference for independently chosen test configurations and moves; the largest discrepancy in the recorded run is 3.8×10−143.8\times10^{-14}.

    The proposal is symmetric: the probability density of proposing yy from xx equals that of proposing xx from yy. Accept with probability

    A(x→y)=min⁡(1,e−ΔSE).A(x\to y)=\min(1,e^{-\Delta S_E}).

    To see why this works, multiply the forward proposal and acceptance by the old weight. The accepted probability flux is proportional to

    q(y∣x)min⁡(e−SE(x),e−SE(y)),q(y\mid x)\min(e^{-S_E(x)},e^{-S_E(y)}),

    which is unchanged on exchanging the configurations. This is detailed balance for this single-site update. Rejection leaves the old configuration in the sequence. Counting it again is necessary for the intended probability measure; deleting rejections biases the average. The original construction and this rejection issue are explained in Metropolis et al., §II, pp. 1088–1089.

    In code, use log(u) < -delta_action for a uniform u∈(0,1)u\in(0,1) instead of forming a potentially overflowing exponential. With Δ=1\Delta=1, the local calculation is:

    delta = proposal - old
    delta_action = (
        (4 + mass_squared) * (old * delta + delta**2 / 2)
        - neighbor_sum * delta
        + coupling * (proposal**4 - old**4) / 24
    )
    if np.log(rng.random()) < -delta_action:
        field[t, x] = proposal
    # Otherwise the old value remains. The sweep still advances.
    

    A sweep updates every site once. The executable groups sites by the parity of n0+n1n_0+n_1: all even sites, then all odd sites. On this even periodic lattice, sites of one parity have no nearest-neighbor bonds among themselves, so their conditional updates can be evaluated in parallel. After accepting even-site moves, recompute neighbors for the odd sites. Each half-sweep preserves the target; their ordered composition therefore preserves it, although the complete sweep need not itself obey detailed balance. This particular shortcut would fail without modification on an odd periodic extent or with interactions coupling sites within one parity.

    Repeated finite steps can reach arbitrary open regions of the field space, and rejections prevent compulsory alternation. These facts do not provide a useful numerical bound on equilibration time. A large acceptance fraction is also insufficient: proposals with an extremely small Δ\Delta almost always succeed while exploring very slowly.

    What to measure

    After each complete sweep, store the action per site, the mean field, and the translation- and direction-averaged two-point estimator

    Cr[φ]=12V∑n∑μ=01φnφn+rμ^,r=0,1,…,4.C_r[\varphi]=\frac{1}{2V}\sum_n\sum_{\mu=0}^1 \varphi_n\varphi_{n+r\hat\mu},\qquad r=0,1,\ldots,4.

    The exact field mean vanishes by φ↦−φ\varphi\mapsto-\varphi symmetry. We use the un-subtracted two-point estimator because that mean is known, rather than subtracting a noisy sample mean squared. This CrC_r averages two axes; it does not sum an entire spatial slice to project onto zero momentum. Consequently its decay generally contains more than one transfer energy even for the free theory. Fitting a single exponential at every separation would impose the wrong model, and periodic images matter near r=4r=4.

    At λ^=0\widehat\lambda=0, the action is 12φTKφ\tfrac12\varphi^TK\varphi with

    Knm=(4+m^2)δnm−∑μ=01(δm,n+μ^+δm,n−μ^).K_{nm}=(4+\widehat m^2)\delta_{nm} -\sum_{\mu=0}^1(\delta_{m,n+\hat\mu}+\delta_{m,n-\hat\mu}).

    The exact covariance is K−1K^{-1}. Equivalently, discrete Fourier modes give

    ⟨Cr⟩0=164∑j0,j1=07cos⁡(2πj1r/8)1+4sin⁡2(πj0/8)+4sin⁡2(πj1/8).\langle C_r\rangle_0= \frac1{64}\sum_{j_0,j_1=0}^7 \frac{\cos(2\pi j_1r/8)}{ 1+4\sin^2(\pi j_0/8)+4\sin^2(\pi j_1/8)}.

    The directional average has the same expectation by square-lattice symmetry. Direct matrix inversion and the Fourier covariance agree within 6.3×10−176.3\times10^{-17} in the companion. These are finite-lattice targets, including their periodic images; comparing with an infinite-volume continuum propagator instead would incorrectly blame legitimate regulator effects on the sampler.

    There is another useful exact check even with the quartic term. Integration by parts over a single real field gives

    0=∫∏mdφm ∂∂φn(φne−SE)⟹⟨φn∂SE∂φn⟩=1.0=\int\prod_m\mathrm d\varphi_m\, \frac{\partial}{\partial\varphi_n}(\varphi_n e^{-S_E}) \quad\Longrightarrow\quad \left\langle\varphi_n\frac{\partial S_E}{\partial\varphi_n}\right\rangle=1.

    The boundary term vanishes because of the positive quadratic or quartic large-field behavior. Sum over sites and split SE=S2+S4S_E=S_2+S_4 into its homogeneous quadratic and quartic pieces. Euler's identity yields

    2⟨S2⟩+4⟨S4⟩=V,⟨SE⟩V=12−⟨S4⟩V.2\langle S_2\rangle+4\langle S_4\rangle=V, \qquad \frac{\langle S_E\rangle}{V} =\frac12-\frac{\langle S_4\rangle}{V}.

    Only the free theory therefore has ⟨SE⟩/V=1/2\langle S_E\rangle/V=1/2. The program separately measures V−1∑nφn∂SE/∂φnV^{-1}\sum_n\varphi_n\partial S_E/\partial\varphi_n, called the Ward observable in its output, whose target is one in both cases. This check tests a relation among sampled moments, not the complete distribution.

    Equilibrate and estimate correlated errors

    The retained experiment uses seed 20261025 with NumPy's PCG64 generator and two SeedSequence children, one per action. Disjoint random draws drive 32 replicas of each action. Sixteen begin with every field zero; sixteen begin with every field +3+3. Each discards 2,048 sweeps, then retains all 16,384 subsequent measurements. The proposal half-width stays at Δ=1\Delta=1 throughout; no adaptation or seed selection is performed.

    Dispersed starts test whether a plausible-looking short history still remembers its initialization. For the free action, the first 64-sweep average of C1C_1 is about 0.05760.0576 from the zero starts and 1.02711.0271 from the +3+3 starts. Over the last 512 discarded sweeps the corresponding averages are 0.06590.0659 and 0.06600.0660. In the retained data, the largest difference between starting groups among the measured observables is 0.900.90 combined replica standard errors for the free theory and 2.942.94 for the interacting theory. The comparison supports the burn-in choice for these runs. Wolff, §1 explains how to check equilibration before applying stationary error formulas.

    Successive measurements share fields and are correlated. For one stationary observable history OsO_s, expanding the variance of its average gives

    Var⁡(O‾)=1M2∑s,t=1MCov⁡(Os,Ot).\operatorname{Var}(\overline O)=\frac1{M^2} \sum_{s,t=1}^M\operatorname{Cov}(O_s,O_t).

    Dropping all terms with s≠ts\ne t is the independent-sample approximation; it is unjustified merely because the program uses fresh random numbers for proposals. We instead group consecutive measurements into blocks. Let YrjY_{rj} be block jj's mean in replica rr, let BB be the number of blocks per replica, and let Y‾r\overline Y_r be that replica's overall mean. For RR independent replicas of equal length, the blocked standard-error estimate is

    σ^2=1R2B(B−1)∑r=1R∑j=1B(Yrj−Y‾r)2.\widehat\sigma^2= \frac{1}{R^2B(B-1)}\sum_{r=1}^R\sum_{j=1}^B (Y_{rj}-\overline Y_r)^2.

    This treats different blocks within a replica as approximately independent. Increase their length until the estimate stabilizes while keeping enough blocks. Blocks never cross replica boundaries. The binning derivation and its residual finite-block bias are discussed in Wolff, Appendix B, pp. 15–16; the more detailed autocorrelation article explains alternatives and slow-mode failures.

    For the free C1C_1, block lengths 1, 4, 16, 64 and 256 sweeps give standard errors 0.0000520.000052, 0.0000890.000089, 0.0001290.000129, 0.0001490.000149 and 0.0001510.000151. Treating every configuration as independent would underestimate the error by almost a factor of three. The interacting sequence gives 0.0000450.000045, 0.0000750.000075, 0.0001040.000104, 0.0001170.000117 and 0.0001190.000119. We quote the 256-sweep estimate, with 64 blocks per replica.

    The spread of the 32 complete replica means is a separate error estimate. For C1C_1 it gives 0.0001310.000131 and 0.0000820.000082 for the free and interacting cases. That finite-replica estimate is itself noisy; its difference from the blocked estimate is a reason to retain both diagnostics, not to report more digits of precision. The code also compares 1,024-, 4,096- and 8,192-sweep prefixes with the full run. For example, the free C1C_1 changes from 0.067270±0.0002570.067270\pm0.000257 at 4,096 sweeps to 0.067439±0.0001310.067439\pm0.000131 at 16,384, using replica errors for that comparison. The roughly halved error is consistent with inverse-square-root statistical scaling over those lengths. Prefixes are nested, so these two estimates are correlated.

    Results at one fixed lattice spacing and volume

    The results below use the full histories and 256-sweep blocked errors. All quantities are dimensionless, and uncertainties are estimated standard errors rather than rigorous bounds.

    ObservableExact free targetSampled freeSampled λ^=2\widehat\lambda=2
    ⟨SE⟩/V\langle S_E\rangle/V0.5000000.5000000.49937±0.000280.49937\pm0.000280.48656±0.000260.48656\pm0.00026
    ⟨C0⟩\langle C_0\rangle0.2541740.2541740.25370±0.000200.25370\pm0.000200.23573±0.000160.23573\pm0.00016
    ⟨C1⟩\langle C_1\rangle0.06771750.06771750.067439±0.0001510.067439\pm0.0001510.058104±0.0001190.058104\pm0.000119
    ⟨C2⟩\langle C_2\rangle0.02003140.02003140.019919±0.0001230.019919\pm0.0001230.015752±0.0000990.015752\pm0.000099
    Ward observable110.99873±0.000550.99873\pm0.000551.00003±0.000551.00003\pm0.00055

    The largest free discrepancy relative to a quoted blocked error is about 2.42.4; a correct noisy run need not place every exact answer inside a one-standard-error interval. The fixed four-standard-error diagnostics in the code use replica errors and all pass, but they remain probabilistic checks and the observables are correlated. The acceptance fractions are 0.59530.5953 and 0.59010.5901. Their closeness says little about the size of the physical interaction effect.

    The positive quartic term suppresses large field fluctuations, and the measured correlations decrease at every plotted separation. The plot shows the finite-lattice Gaussian prediction and the measured change; the gentle flattening near half the periodic extent is part of this geometry.

    The sampled free correlator follows the exact finite-lattice values, while the positive quartic interaction reduces correlations at separations zero through four.

    Axis-averaged CrC_r on the periodic 8×88\times8 lattice at m^2=1\widehat m^2=1. Circles and squares are Monte Carlo means for λ^=0\widehat\lambda=0 and 22; bars are 256-sweep blocked standard errors, sometimes smaller than the symbols. The black line joins the exact free values as a guide. The vertical axis is logarithmic; symbols are displaced slightly horizontally for visibility. No continuum or infinite-volume extrapolation is included.

    From the repository root, reproduce the calculation with Python 3 and NumPy:

    python3 examples/lattice-hamiltonian/lattice-fields/simulate.py
    

    The program writes simulation-results.json beside its source, including parameters, exact targets, block errors, starting-group checks and prefixes. plot_simulation.py additionally requires Matplotlib and regenerates the figure from that result. The retained run used Python 3.9.6 and NumPy 2.0.2. The scientific implementation is new; the source and selected output stay with the example so that changing the model requires an explicit new calculation.

    To turn propagation into an energy, first choose the spatial projection and the finite-time model. The finite-time spectral trace explains the backward term. The continuum mass calculation uses the same free action with spatial momentum zero at several spacings. The single interacting ensemble here measures a different correlator at one spacing.

    Summary

    A finite scalar simulation starts with a specified integration measure and action. A local Metropolis step samples that measure without knowing its normalization; a complete sweep and its rejected moves must be recorded consistently. Matrix inversion checks the free observable, integration by parts tests an interacting moment relation, and dispersed starts plus blocking expose different sources of error. These checks make a small finite-lattice result interpretable before addressing physical extrapolation or faster algorithms.

    Exercises

    An action difference at one site

    With m^2=1\widehat m^2=1, λ^=2\widehat\lambda=2, old field zero and four zero neighbors, propose y=1y=1. Find the action change and acceptance probability. Identify separately the kinetic, mass and quartic contributions.

    Solution

    The four incident bonds each acquire 1/21/2, so the kinetic contribution is 22. The mass term contributes 1/21/2 and the quartic term contributes 2/24=1/122/24=1/12. Therefore ΔSE=31/12\Delta S_E=31/12, and the acceptance probability is e−31/12≃0.0755e^{-31/12}\simeq0.0755. Counting only the two outgoing bonds would miss half the kinetic change: the two incoming bonds also contain the changed site.

    Why simultaneous updates need a condition

    Two neighboring sites have old values x,yx,y and proposed increments δx,δy\delta_x,\delta_y. Compare the exact change of their bond action 12(x−y)2\tfrac12(x-y)^2 with the sum of two local changes computed using the old neighbors. Explain the implication for a parallel update of all sites.

    Solution

    The exact change is

    (x−y)(δx−δy)+12δx2+12δy2−δxδy.(x-y)(\delta_x-\delta_y) +\frac12\delta_x^2+\frac12\delta_y^2 -\delta_x\delta_y.

    The sum of local changes with frozen old neighbors omits −δxδy-\delta_x\delta_y. Independent acceptance decisions based on those stale neighbors therefore do not generally preserve the intended coupled distribution. A single collective Metropolis proposal could use the full action change, or a sequential sweep could use already updated values. Our checkerboard implementation avoids the cross term because no bond joins two sites updated in the same half-sweep. Recompute the neighbors before the next parity.

    References

    • Metropolis, N., Rosenbluth, A. W., Rosenbluth, M. N., Teller, A. H., and Teller, E. (1953), “Equation of state calculations by fast computing machines,” The Journal of Chemical Physics 21, 1087–1092, doi:10.1063/1.1699114. The proposal, acceptance and retained-rejection discussion is in §II, pp. 1088–1089; institutional PDF copy.
    • Wolff, U., ALPHA Collaboration (2004), “Monte Carlo errors with less errors,” Computer Physics Communications 156, 143–153; erratum 176 (2007), 383, doi:10.1016/S0010-4655(03)00467-3, arXiv:hep-lat/0306017v4, PDF. We use §1's equilibration distinction and Appendix B's blocking analysis, not the paper's automatic autocorrelation-window implementation.

    Scrollable formula. Use Left and Right arrow keys to reveal hidden content.

    Scrollable table. Use Left and Right arrow keys to reveal hidden columns.

    Scrollable figure. Use Left and Right arrow keys to reveal hidden content.