xnn.common.models.dispersion_fast.atm_cpu#

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

The reference (three_body_energy()) lists every triangle three times, once from each corner, as pairs of edges sharing a center, and evaluates them as separate tensor operations on gathered copies. On a CPU that is about twenty nanoseconds per triangle, an order of magnitude above the fused loops of the Fortran codes. Here the edges of every center are sorted by neighbor index and cut into tiles; a job is a pair of tiles of one center, and every pair of neighbors in it forms a triangle with the center. A triangle of three distinct atoms is evaluated once, from its smallest-index corner (a center pairs only neighbors of larger index), and a third of its energy goes to each of its atoms, which is the reference’s bookkeeping. A triangle with a repeated atom (two periodic images of one atom, or an image of the center) is evaluated from every corner with a third of its energy each, in a flat pass over those pairs. The tile and pair functions run compiled (torch.compile, the C++ and OpenMP code of inductor) on fixed batch shapes; their sources are marked dynamic, so a new atom or edge count does not compile again. The gradients (forces, stress, the dependence of C6 on the coordination numbers) are those of the compiled functions.

Module Attributes

TILE

the largest; a structure whose centers have fewer neighbors takes the smallest power of two (at least MIN_TILE) that holds them.

BATCH

Tile pairs per compiled call.

PAIRS

Repeated-atom pairs per compiled call.

EPS

Squared distances at or below this are coincident images (the reference's guard).

Functions

available()

torch.compile produces CPU code here (inductor and a C++ compiler); checked once.

three_body_direct(z, plan, v, r, c6_mat, ...)

The ATM energies per atom (N,) and their gradient without autograd: in the edge vectors (in the plan's edge order, (E, 3)) and in the coordination numbers (N,), through the pair C6 (dc6m[i, j] and dc6n[i, j]: the derivatives of c6_mat[i, j] in the coordination numbers of i and j).

three_body_energy_cpu(z, edge_index, ...[, plan])

Per-atom ATM energies (N,) in hartree: the values of three_body_energy() (same arguments) on the compiled tiles.

Classes

Plan(edge_index, n_atoms[, tile])

The tile-pair jobs and repeated-atom pairs of one edge list (sorted by center, then neighbor).