Skip to content
QFT.org

Search QFT.org

Enter a word or phrase.

    You can also browse the main navigation and chapter contents.

    Variational Monte Carlo and the Local Energy

    A variational wavefunction has an energy above the ground-state energy, but a Monte Carlo estimate of that energy can lie below it. The first statement concerns an exact expectation value; the second concerns a random estimator. Confusing them can turn a statistical fluctuation into an apparent violation of the variational principle.

    We derive the local-energy estimator and its gradient, optimize a six-spin Hamiltonian with both enumeration and sampled gradients, and then measure the coverage of independent energy intervals. The Hilbert space is small enough to evaluate every claimed variational energy directly.

    Preparation: normalized state vectors, Pauli matrices, the variational principle and Monte Carlo errors.

    The exact variational statement

    Let HH be a Hermitian matrix for a specified finite regulator and let ψθ≠0\psi_\theta\ne0. With N=⟨ψ∣ψ⟩\mathcal N=\langle\psi|\psi\rangle,

    E(θ)=⟨ψ∣H∣ψ⟩N.E(\theta)=\frac{\langle\psi|H|\psi\rangle}{\mathcal N}.

    Expanding the normalized state in eigenvectors of the same Hamiltonian gives

    ∣Ψ⟩=∑ncn∣n⟩,E=∑n∣cn∣2En≥E0,∑n∣cn∣2=1.|\Psi\rangle=\sum_n c_n|n\rangle, \qquad E=\sum_n|c_n|^2E_n\ge E_0, \qquad \sum_n|c_n|^2=1.

    This inequality holds for every nonzero state, including an incompletely optimized neural state. It does not say that an optimizer found the best state in its ansatz, and it does not compare different lattice spacings, field cutoffs or boundary conditions. Those change the Hamiltonian or its approximation.

    A local energy whose mean is the energy

    In an orthonormal configuration basis, define

    p(s)=∣ψ(s)∣2N,Eloc(s)=(Hψ)(s)ψ(s)when ψ(s)≠0.p(s)=\frac{|\psi(s)|^2}{\mathcal N}, \qquad E_{\mathrm{loc}}(s)=\frac{(H\psi)(s)}{\psi(s)} \quad\text{when }\psi(s)\ne0.

    Then

    EpEloc=1N∑s:ψ(s)≠0ψ(s)∗(Hψ)(s)=E.\begin{aligned} \mathbb E_p E_{\mathrm{loc}} &=\frac1{\mathcal N} \sum_{s:\psi(s)\ne0}\psi(s)^*(H\psi)(s)\\ &=E. \end{aligned}

    The omitted configurations have zero contribution to this mean. For a complex state, individual local energies may be complex; Hermiticity makes the full mean real. The real part is an unbiased estimator of the energy, while a nonzero sampled imaginary mean can serve as a diagnostic. Our ground-state calculation below uses a real Hamiltonian and real positive amplitudes, so its local energies are real.

    If the state has full support,

    Ep∣Eloc−E∣2=∥(H−E)ψ∥2N=⟨H2⟩−E2.\mathbb E_p|E_{\mathrm{loc}}-E|^2 =\frac{\|(H-E)\psi\|^2}{\mathcal N} =\langle H^2\rangle-E^2.

    An exact eigenstate then has zero local-energy variance. At nodes this identity needs care: the left side misses any nonzero (Hψ)(s)(H\psi)(s) on a configuration with ψ(s)=0\psi(s)=0. Zero sampled local variance alone need not imply an eigenstate. Exercise 2 gives an exact counterexample.

    The mean and local-gradient formulation are described in Vicentini et al., §3.3, Eqs. (11)–(16). The support qualification is essential when rewriting direct state-vector formulas as Born averages.

    Estimate the energy of a product state

    Take six periodic Pauli spins and the normalized product state ∣+x⟩⊗6|+x\rangle^{\otimes6}. Its 64 amplitudes in the ZZ basis are equal. For the Hamiltonian H=−∑iZiZi+1−0.8∑iXiH=-\sum_i Z_i Z_{i+1}-0.8\sum_i X_i, a spin flip leaves the amplitude ratio in the local energy equal to one. One uniform draw of six independent signs therefore gives

    Eloc(s)=−4.8−∑i=05sisi+1,s6=s0.E_{\rm loc}(s)=-4.8-\sum_{i=0}^5s_i s_{i+1},\qquad s_6=s_0.

    Each bond has zero mean and unit variance. Two distinct bonds have zero covariance because their product contains at least one sign to the first power. Thus the exact energy is −4.8-4.8 and the local-energy variance is 66. Averaging BB independent configurations gives standard error 6/B\sqrt{6/B}. A draw with all spins aligned gives −10.8-10.8, even below the exact ground energy calculated below. The variational upper bound applies to the exact mean. This estimator is already usable before a parametrized wavefunction is introduced.

    Differentiate the normalized state, not just the numerator

    For a real parameter θi\theta_i, differentiation gives

    ∂iE=2Re⁡⟨∂iψ∣(H−E)∣ψ⟩N.\partial_i E =2\operatorname{Re} \frac{\langle\partial_i\psi|(H-E)|\psi\rangle}{\mathcal N}.

    The −E-E term comes from differentiating the norm. Introduce the force

    Fi=⟨∂iψ∣(H−E)∣ψ⟩N.F_i= \frac{\langle\partial_i\psi|(H-E)|\psi\rangle}{\mathcal N}.

    For a holomorphic complex parameterization, the Wirtinger derivative is ∂E/∂θi∗=Fi\partial E/\partial\theta_i^*=F_i; the gradient in a real parameter direction is 2Re⁡Fi2\operatorname{Re}F_i. These are different coordinate conventions, not conflicting factors.

    Where dividing by the amplitude is legitimate, put Oi(s)=∂iψ(s)/ψ(s)O_i(s)=\partial_i\psi(s)/\psi(s). Then

    Fi=Ep ⁣[Oi∗(Eloc−E)]=Cov⁡p(Oi,Eloc).F_i=\mathbb E_p\!\left[ O_i^*(E_{\mathrm{loc}}-E) \right] =\operatorname{Cov}_p(O_i,E_{\mathrm{loc}}).

    The complex conjugate is on OiO_i. At a moving node, ∂iψ\partial_i\psi can be nonzero where p=0p=0, so this covariance can miss a direct-gradient contribution. The retained implementation checks the direct formula first and uses ratios only for full-support real ground states.

    For BB independent samples, a centered estimate using the same samples for both means is

    F^i=1B−1∑b=1B(Oi(b)−O‾i)∗(Eloc(b)−E‾).\widehat F_i= \frac1{B-1}\sum_{b=1}^B (O_i^{(b)}-\overline O_i)^* (E_{\mathrm{loc}}^{(b)}-\overline E).

    The denominator B−1B-1 makes this covariance unbiased at a fixed state. Dividing by BB instead produces the factor (B−1)/B(B-1)/B. This does not make the entire nonlinear optimization unbiased, particularly when a sampled metric is inverted for stochastic reconfiguration.

    The six-spin reference problem

    Use periodic Pauli spins with six distinct bonds:

    H=−∑i=05ZiZi+1−0.8∑i=05Xi,Z6=Z0.H=-\sum_{i=0}^{5}Z_iZ_{i+1} -0.8\sum_{i=0}^{5}X_i, \qquad Z_6=Z_0.

    The coefficients multiply Pauli matrices, not Si=σi/2S_i=\sigma_i/2. Integer configurations run from 0 to 63, site 0 is the least significant bit, and si=1−2bit⁡is_i=1-2\operatorname{bit}_i. The local energy becomes

    Eloc(s)=−∑isisi+1−0.8∑iψ(s(i))ψ(s),E_{\mathrm{loc}}(s) =-\sum_i s_i s_{i+1} -0.8\sum_i\frac{\psi(s^{(i)})}{\psi(s)},

    where s(i)s^{(i)} flips spin ii. The diagonal interaction and the off-diagonal spin flips are both included; sampling only the diagonal term would optimize a different problem.

    The global flip F=∏iXiF=\prod_iX_i commutes with HH. For the trainable comparison use a restricted Boltzmann machine (RBM), a state obtained by summing auxiliary binary spins as in the derivation of its amplitudes. Its real amplitudes are projected with P+=(I+F)/2P_+=(I+F)/2 before normalization. The positive projection has full support. All 6464 basis states are retained in the exact diagonalization, which gives

    E0=−7.04880447500955.E_0=-7.04880447500955.

    An independent Kronecker-product assembly checks the bit-based matrix, and the J=0J=0 and g=0g=0 limits check its spectrum. The simple ∣+x⟩⊗6|+x\rangle^{\otimes6} state has energy −4.8-4.8. A uniform product state with ⟨Z⟩=cos⁡ϑ\langle Z\rangle=\cos\vartheta and ⟨X⟩=sin⁡ϑ\langle X\rangle=\sin\vartheta has

    Eprod6=−cos⁡2ϑ−0.8sin⁡ϑ.\frac{E_{\mathrm{prod}}}{6} =-\cos^2\vartheta-0.8\sin\vartheta.

    Its minimum occurs at sin⁡ϑ=0.4\sin\vartheta=0.4 and gives Eprod=−6.96E_{\mathrm{prod}}=-6.96. This product representative breaks global flip; it is a valid full-space variational comparator, not an exactly even state.

    Width, starting point and stopping condition

    Enumerated minimization uses hidden widths M=1,3,6M=1,3,6, with three fixed real starts at each width. Every parameter starts with standard deviation 0.050.05, using seed components (961025,10,M,k)(961025,10,M,k). The parameter count is 6+7M6+7M. Each fit uses analytic gradients and the same L-BFGS-B limits: 15001500 iterations, 40004000 function evaluations, relative objective tolerance 10−1410^{-14} and gradient tolerance 10−910^{-9}.

    The selected rows below expose the different outcomes; all nine fits and their parameters are retained.

    Width and startE−E0E-E_0Var⁡(H)\operatorname{Var}(H)Stopping reason
    M=1M=1, start 02.876×10−22.876\times10^{-2}0.13530.1353relative objective change
    M=3M=3, start 03.070×10−53.070\times10^{-5}3.123×10−43.123\times10^{-4}iteration cap
    M=3M=3, start 13.065×10−53.065\times10^{-5}3.113×10−43.113\times10^{-4}relative objective change
    M=3M=3, start 24.24×10−124.24\times10^{-12}3.70×10−113.70\times10^{-11}relative objective change
    M=6M=6, start 03.73×10−123.73\times10^{-12}3.77×10−113.77\times10^{-11}relative objective change

    The three M=1M=1 starts give nearly the same energy. The three M=6M=6 energy excesses range from 3.73×10−123.73\times10^{-12} to 5.29×10−115.29\times10^{-11}. In particular, the different M=3M=3 outcomes show that a larger observed error can be an optimization failure rather than insufficient width.

    None of the nine fits meets the independently evaluated 10−910^{-9} gradient criterion. Eight report success because the relative objective change is small; one reaches the iteration cap. For example, the designated M=6M=6, start-0 state has gradient infinity norm 2.08×10−72.08\times10^{-7} despite its very accurate energy. This distinction follows the actual SciPy 1.13.1 L-BFGS-B stopping rules.

    Correlations provide an additional check. Define

    X‾=16∑i⟨Xi⟩,Cd=16∑i⟨ZiZi+d⟩.\overline X=\frac16\sum_i\langle X_i\rangle, \qquad C_d=\frac16\sum_i\langle Z_iZ_{i+d}\rangle.
    StateX‾\overline XC1C_1C3C_3
    exact ground0.48385885030.48385885030.78771366560.78771366560.74510908000.7451090800
    M=1M=1, start 00.45953894440.45953894440.80237655810.80237655810.78266912670.7826691267
    M=3M=3, start 00.48385113300.48385113300.78771472340.78771472340.74519053410.7451905341
    M=6M=6, start 00.48385885320.48385885320.78771366330.78771366330.74510910840.7451091084

    Network width varies here while the Hilbert space and Hamiltonian stay fixed. The continuous scalar example separately varies its field representation. No six-spin result establishes thermodynamic or continuum convergence.

    Optimizing with actual sampled gradients

    To isolate gradient noise, start every trajectory from the same M=3M=3, start-0 initial parameters. Ordinary gradient descent makes 10001000 updates with learning rate 0.030.03 for the first 500500 and 0.010.01 thereafter; an update-norm cap of 0.20.2 is declared in advance. Each stochastic update uses 512512 fresh independent Born samples. Eight replicas use independent seed streams; paired SR comparisons use the same uniform streams with their own evolving distributions.

    The sampler constructs the complete 6464-state probability table and draws from its CDF. This is genuine stochastic estimation but an exponentially costly small-system sampling method. Enumeration eliminates Markov-chain autocorrelation at this size.

    The enumerated ordinary-gradient trajectory ends at −7.0301387437-7.0301387437. The eight sampled trajectories have mean direct energy −7.0301146742-7.0301146742 and between-replica standard deviation 9.97×10−49.97\times10^{-4}. That deviation describes optimizer variation, not the uncertainty of an energy estimate for one fixed state. The fixed schedule has not reached the accurate enumerated L-BFGS-B solution. The SR comparison changes the update geometry while retaining the same sample count and schedule.

    Independent energy intervals and their coverage

    Freeze replica 0 from ordinary gradients and from each of two shifted-SR methods. For each fixed state, generate 512512 independent validation batches at n=256n=256 and n=2048n=2048. These samples were not used to optimize or select the states. Form the conventional normal interval

    E^±1.959964 sElocn,\widehat E\pm1.959964\,\frac{s_{E_{\mathrm{loc}}}}{\sqrt n},

    and test whether it contains that state's directly evaluated E(θ)E(\theta). The normal approximation is being tested, not assumed to provide exact finite-sample coverage.

    Fixed training methodValidation sizeCovered batches out of 51295% interval for coverage
    gradient256256481481[0.915,0.958][0.915,0.958]
    gradient20482048482482[0.917,0.960][0.917,0.960]
    SR, shift 10−310^{-3}256256489489[0.933,0.971][0.933,0.971]
    SR, shift 10−310^{-3}20482048485485[0.924,0.965][0.924,0.965]
    SR, shift 10−210^{-2}256256491491[0.938,0.974][0.938,0.974]
    SR, shift 10−210^{-2}20482048487487[0.929,0.968][0.929,0.968]

    The last column is an exact binomial Clopper–Pearson interval for the coverage probability in this repeated-batch experiment. It is separate from each energy interval. All six intervals contain 0.950.95; 512512 trials do not establish exact nominal coverage or validity for another state or sampler.

    For the shift-10−310^{-3} state, 253253 of the 512512 size-256256 energy estimates fall below the exact ground energy. The state's direct energy is nevertheless −7.0487278184>E0-7.0487278184>E_0. Its energy excess is small compared with the single-batch estimator standard deviation, approximately 0.001740.00174. The noisy estimates do not inherit the variational inequality.

    All nine enumerated RBM energy errors by hidden width and independent energy-interval coverage for three fixed trained states at two validation sample sizes.

    Left: direct variational energy excesses for all fixed starts, with the M=3M=3 iteration-cap result retained. Right: independent coverage estimates with binomial 95% intervals. These bars quantify the finite coverage experiment; they are neither optimizer error bars nor energy uncertainties.

    The companion directory examples/computational-qft/neural-quantum-states/ retains all models, stopping statuses, trajectories and coverage estimates. Its default verification modes evaluate saved states without optimizing or resampling. Reproduction writes to explicit new outputs.

    Summary

    VMC separates three objects: the exact energy of a chosen state, the random local-energy estimate, and the optimizer that changes the state. Enumeration makes those distinctions measurable in this example. Accurate energies do not certify a requested gradient tolerance, sampled energies need not obey a variational bound, and node-sensitive identities must be checked before replacing direct derivatives by logarithmic ratios.

    Exercises

    1. Recover the normalization term and the complex factor

    Starting from E=ψ†Hψ/(ψ†ψ)E=\psi^\dagger H\psi/(\psi^\dagger\psi), derive its variation for a real parameter. Then suppose ψ\psi is holomorphic in complex parameters. Identify the Wirtinger derivatives and the gradients in the real and imaginary parts of one parameter.

    Solution

    For an arbitrary variation,

    δE=δψ†(H−E)ψ+ψ†(H−E)δψN=2Re⁡δψ†(H−E)ψN.\delta E= \frac{\delta\psi^\dagger(H-E)\psi+ \psi^\dagger(H-E)\delta\psi}{\mathcal N} =2\operatorname{Re} \frac{\delta\psi^\dagger(H-E)\psi}{\mathcal N}.

    For real θi\theta_i, substitute δψ=∂iψ δθi\delta\psi=\partial_i\psi\,\delta\theta_i to obtain ∂iE=2Re⁡Fi\partial_iE=2\operatorname{Re}F_i. In holomorphic coordinates zi=xi+iyiz_i=x_i+iy_i, δE=∑i(Fiδzi∗+Fi∗δzi)\delta E=\sum_i(F_i\delta z_i^*+F_i^*\delta z_i). Hence

    ∂E∂zi∗=Fi,∂E∂zi=Fi∗,∂E∂xi=2Re⁡Fi,∂E∂yi=2Im⁡Fi.\frac{\partial E}{\partial z_i^*}=F_i, \qquad \frac{\partial E}{\partial z_i}=F_i^*, \qquad \frac{\partial E}{\partial x_i}=2\operatorname{Re}F_i, \qquad \frac{\partial E}{\partial y_i}=2\operatorname{Im}F_i.

    Dropping the derivative of the denominator would omit −E-E and give a gradient that changes under an irrelevant rescaling of the state.

    2. A moving node hides both a gradient and a variance

    Let H=XH=X and Ψθ=(1,θ)T/1+θ2\Psi_\theta=(1,\theta)^T/\sqrt{1+\theta^2} with real θ\theta. At θ=0\theta=0, compare the direct energy derivative, projective tangent norm and quantum energy variance with estimates that use only configurations of nonzero Born probability.

    Solution

    Directly,

    E(θ)=2θ1+θ2,E′(0)=2.E(\theta)=\frac{2\theta}{1+\theta^2}, \qquad E'(0)=2.

    At zero, Ψ=(1,0)T\Psi=(1,0)^T and ∂θΨ=(0,1)T\partial_\theta\Psi=(0,1)^T. The derivative is already orthogonal to the state, so its projective norm squared is 1. Since H2=IH^2=I and E=0E=0, the quantum variance is also 1.

    The Born sampler visits only the first component. Its local energy is (HΨ)0/Ψ0=0(H\Psi)_0/\Psi_0=0, and its log derivative is 0. A covariance assembled only from that one event therefore returns zero gradient, zero tangent metric and zero local-energy variance. The missing second component has ∂θΨ1=1\partial_\theta\Psi_1=1 and (HΨ)1=1(H\Psi)_1=1 even though its probability is zero. Direct state-vector formulas include these contributions. More samples from the same support cannot repair their omission.

    References

    • G. Carleo and M. Troyer, “Solving the Quantum Many-Body Problem with Artificial Neural Networks,” Science 355, 602–606 (2017), doi:10.1126/science.aag2302, arXiv:1606.02318v1. Ground-state optimization and Appendix C.
    • SciPy developers, SciPy 1.13.1 Manual: L-BFGS-B options. Relative-objective, gradient and iteration stopping rules used in the retained fits.
    • F. Vicentini et al., “NetKet 3: Machine Learning Toolbox for Many-Body Quantum Systems,” SciPost Physics Codebases 7 (2022), doi:10.21468/SciPostPhysCodeb.7, arXiv:2112.10526v2. Sections 3.3 and 4.1, Eqs. (11)–(16) and (26)–(31), and the nodal qualification in §3.5, footnote 14.

    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.