xnn.common.models.dispersion_fast.d3_direct#

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

The reference (DFTD3) gets its forces and stress from an autograd pass through every tensor operation of the evaluation. Here the derivatives are written out: the coordination numbers with their slope per edge, the Gaussian reference weights with their slope in the coordination number, the pair C6 with their derivatives in both coordination numbers, the pair energies with their slope in the distance, and the three-body term from the compiled tiles of atm_cpu with their gradient (three_body_direct()). The derivatives through the C6 collect on the coordination numbers, which carry them to the edges; the edge gradient gives the forces and the strain derivative (the stress). Evaluation only: the outputs carry no autograd graph.

Molecules up to DENSE_ATOMS atoms take the dense path (d3_dense()): the same derivatives over every pair i < j and every triangle of atoms, in one call compiled with torch.compile, which leaves no per-call work in Python beyond the call itself.

Module Attributes

DIRECT_TILE

Neighbors per tile of the three-body term for molecules (fastest at 81 and 375 atoms on one and eight threads).

CELL_TILE

Neighbors per tile for cells (their centers have many neighbors, which fill large tiles).

DENSE_ATOMS

Most atoms of a molecule for the dense path (every pair and triangle of atoms in one compiled call).

DENSE_BATCH_ATOMS

Most atoms of a batch of several molecules for the dense paths.

SERIAL_ATOMS

thread start-up would cost more than it saves).

DENSE_OPTIONS

Inductor options of the dense paths' compiled calls.

Functions

d3_dense(term, data)

d3_direct() for a batch of molecules over every pair and triangle of atoms, in one compiled call: the outputs of evaluate_direct().

d3_direct(term, data)

D3 of a batched graph with its forces, no autograd: the energies per atom and per structure (B, 3) (total, two-body, three-body; eV), the features (N, 2) (coordination number, homoatomic C6), the forces (N, 3) (eV / A) and dE / d(strain) (B, 3, 3) (eV).

dense_applies(data, limit)

Whether the dense paths serve data: one molecule of at most limit atoms or a batch of molecules of at most DENSE_BATCH_ATOMS (the pairs and triangles across its molecules are computed and dropped), and torch.compile produces CPU code here.

molecules(data)

Whether no structure of data is a cell.

prepared(term, setting, tables, tensors, ...)

The key of setting(term) in registry and tables(term) of the dense path, cached on the term while its buffers or parameters tensors stay the same tensors at the same versions and its attributes plain the same.