Reproducing Caffarel's Zero-Variance Monte Carlo for STO integrals

Paper Reproductions

A research-note exercise in numerical reproducibility.

What this is

In 2019, Michel Caffarel published a paper (arXiv:1906.04515) showing that four-center two-electron repulsion integrals over Slater-type orbitals — long considered intractable except in special cases — could be computed by Monte Carlo to chemistry-relevant accuracy via three carefully-chosen variance reduction tricks. The headline application was a near-full-CI calculation on a cyanine model with 90 STO orbitals and 8.3 million unique integrals, which to my knowledge remains the most extensive molecular calculation done with pure STO basis (no Gaussian approximation for the four-center integrals).

The method part of that paper is a self-contained piece of work that doesn't require a supercomputer to validate: Caffarel publishes (in his Table III) ten specific four-center integrals over 1s, 2p, and 3d Slater orbitals, with reference values quoted to 10 decimal places. If you can reproduce those ten numbers, you have a working implementation of the method.

This is a clean reproduction of those ten integrals plus the qualitative content of Figure 1, with code small enough to read in an afternoon.

The estimator

Let

with a product of two Slater orbitals at possibly different centers and exponents.

A naive Monte Carlo estimator with Gaussian importance sampling has infinite variance for STO integrands: the integrand decays as but the Gaussian sampler decays as , so the ratio diverges in the tail. To get a finite-variance estimator Caffarel applies three tricks:

  1. Gaussian importance sampling sized to the orbital footprint — sample and map to the physical configuration as where is the Gaussian-product center for the -th electron and is the sum of orbital exponents.
  2. A coordinate transformation with , applied in the standard-normal preimage space. The Jacobian multiplies the estimator. For the variance becomes finite.
  3. A control variate built from the analytic STO-NG approximation: write where is the four-center ERI computed analytically with each Slater orbital replaced by an N-Gaussian fit, and is the residual integrand. As grows, and the variance vanishes.

The implementation is about 100 lines of NumPy.

Validation: Table III

The paper's Table III gives ten four-center ERIs at fixed asymmetric geometry , , , with exponents , , , . Caffarel reports these at , samples and reaches absolute errors in the to range.

I run at , — about 10000× fewer samples than Caffarel, but the implementation is correct so the slope is right.

Integral Caffarel reference error -units
0 2.1
1 0.5
2 0.6
2 2.1
2 0.6
3 1.5
3 0.3
4 1.1
4 1.8
5 0.3

Every entry agrees with Caffarel's published value within 0.3 to 2.1 sigmas. The errors are uniformly small in -units, which is the right calibration check: a correctly-implemented estimator should land within of the truth about 95% of the time.

The convergence figure for the row, swept over at several values of :

Convergence vs N for the (1s 1s | 1s 1s) integral at several n_g

Three panels: (left) the CV estimator approaches Caffarel's reference as for every ; (middle) the statistical error scales cleanly as — the Caffarel coordinate transform has done its job of bounding the variance; (right) at fixed large , increasing reduces the analytic Gaussian bias by orders of magnitude (red), and the CV correction brings the total error down to the MC noise floor (blue).

Figure 1: variance transition

Caffarel's Figure 1 plots the value of at single-center as a function of the coordinate-transform exponent , with . For the naive estimator has infinite variance; for it has finite variance and locks onto the exact value .

Caffarel Figure 1 reproduction: estimator value and variance vs coordinate-transform exponent nu

Left: naive estimator value (red) drifts wildly for , settles onto by . Right: statistical error in log scale falls by ~20× as goes from 0.1 to 1, then plateaus in the bounded-variance regime. The control variate (blue) adds another ~100× variance reduction.

What needed fixing

Three substantive bugs surfaced during the reproduction. Worth flagging because they are exactly the kind of slip that silently passes a single sanity test and fails on the broader sweep.

1. The 3D-vs-6D normalization on . The importance-sampling density is the six-dimensional standard normal , with . I had originally written , which is the 3D form for a single electron. The factor of appeared everywhere as a mysterious 16× error in the naive estimator until I checked it against an independent direct-MC implementation.

2. PySCF d-shell normalization. PySCF normalizes Cartesian Gaussian basis functions with a shell-uniform factor: for L=1, each of has unit self-overlap; for L=2, the diagonal have self-overlap while off-diagonal have . (This makes the d-shell sum to a clean form, but no individual cartesian d is normalized to 1.) Trying to match this analytically went badly. The fix: extract PySCF's actual normalization empirically from the overlap matrix mol.intor('int1e_ovlp_cart') and divide it out of the ERI tensor. Five lines of code; works for any L.

3. The cartesian Gaussian self-overlap formula had a error. The correct integral is

I had written the denominator as , missing the factor of . The error compounds as in the four-center ERI, which is why the L=2 integrals were off by a factor of 16 in .

All three are formula slips, not algorithmic mistakes — the kind of thing a careful person would write down on a whiteboard and probably get right, but typed at speed will likely get wrong. They were caught by working from the specific Caffarel published values back to the implementation, which is the honest way to find this class of bug.

What this isn't

This reproduction covers the single-integral test cases in Section III.A of the paper. The molecular calculations in Section III.B (Tables IV–VII: Hartree-Fock and near-FCI for Be, CH4, and cyanine) require wiring our integral generator into an SCF and CI driver. That's an additional day or so of work for the Be HF case (smallest), more for CH4, and the cyanine FCI is genuinely out of reach for a desktop reproduction — Caffarel ran it on 4800 cores for several hours.

The single-integral content here is, however, the self-contained method demonstration part of the paper. If you wanted to build something on top of Caffarel's ZVMC — for instance, a neural network surrogate that learns the residual across geometries to amortize the per-integral cost — the implementation here is the foundation you would use to generate training data.

Code

All ~400 lines of code are in caffarel_zvmc_repro/src/, released under MIT. The full table reproduction takes ~90 seconds on a single core; Figure 1 takes ~30 seconds.

Reference

Caffarel, M. (2019). Evaluating two-electron-repulsion integrals over arbitrary orbitals using Zero Variance Monte Carlo: Application to Full Configuration Interaction calculations with Slater-type orbitals. arXiv:1906.04515.