xnn.common.models.dispersion_fast#

Fast paths of the dispersion terms (D3, D4).

Profiled on periodic water boxes (5k-24k atoms, energy + forces + stress), the reference D4 spends its time in two places: the large-regime EEQ solve above about 10k atoms (85-90% of a step, nearly all of it recomputing structure factors in the conjugate-gradient loop) and the three-body ATM term below that and in molecular dynamics with the EEQ reuse (about 80% of a step); D3 spends it in its three-body term and in the dense (N, N) C6 matrix that term reads. The fast paths replace exactly those:

  • FastEEQSystem: the EEQ operator with factorized reciprocal phases (no trigonometry per product), a sparse real-space matrix, a fused molecular kernel and lockstep solves;

  • atm_energy(): the ATM energy and its first and second derivatives as fused Triton kernels, with the pair C6 from per-atom factors (no (N, N) matrix, so D3’s three-body term has no atom limit);

  • atm_cpu: on CPUs, the three-body term on compiled tiles (torch.compile), with an analytic gradient for d3_direct and d4_direct, which form the forces and stress of a standalone D3 or D4 term (D4: molecules) without autograd;

  • cpu: optional C++ / OpenMP kernels for the whole of D3 and for D4’s polarizabilities and two- and three-body terms, the loops of the Fortran codes (off by default, see xnn.common.models.cpu_extension).

They follow the use_fast convention of xnn.common.models.fast; the parameters, buffers and outputs of the modules are unchanged, except that the fast D3 paths do not form the dense "c6_matrix" output (it is returned empty, as above 20000 atoms; c6_matrix() computes it on request).

Module Attributes

AUTO_POLICY

minimum edges of the neighbor graph per GPU model.

AUTO_POLICY_CPU_KERNELS

AUTO_POLICY for a term whose optional C++ CPU kernels are on and apply (D3 and D4, cpu): on a CPU every size takes them

Modules

atm

The Axilrod-Teller-Muto three-body term of D3 and D4 as fused Triton kernels.

atm_cpu

The Axilrod-Teller-Muto three-body term on CPUs: dense per-center tiles, compiled.

atm_tangents

Derivatives of the Triton kernels of the D3 and D4 three-body term

coulomb

The molecular EEQ interaction erf(gamma_ij r_ij) / r_ij applied without storing it.

cpu

D3 and D4 on CPUs: optional C++ and OpenMP kernels (off by default, built on first use).

d3_direct

D3 on CPUs with its forces and stress formed without autograd, in PyTorch.

d4_direct

D4 on CPUs with its forces and stress formed without autograd, in PyTorch.

eeq

The large-regime EEQ operator, evaluated without trigonometry in the solver loop.