xnn.ffnn.models.amoeba_kernels#

Fused Triton kernels of the AMOEBA and HIPPO nonbonded pair terms.

One program handles a block of pairs and keeps a pair’s whole arithmetic in registers: the distance, the derivative ladders of every radial kernel (xnn.ffnn.models.amoeba_ladders, evaluated in float64 as the eager path does), the multipole contractions, the switches. It writes the per-atom halves of the four pair energies, the direct- and polar-scaled permanent fields, the mutual ladder members of the induction and the exchange-polarization tensors with atomic adds, and the two mutual ladder members per pair. The eager functions of xnn.ffnn.models.amoeba (hippo_pair_block, _real_space_fields, exchange_polarization_tensor) define what is computed; these kernels compute the same numbers with the same scale factors and flags. The AMOEBA kernels (_amoeba_forward / _amoeba_backward) follow amoeba_pair_block and the buffered 14-7 term. The backward kernels are differentiable once more through the generated tangent and adjoint kernels of xnn.ffnn.models.amoeba_tangents (second derivatives, parameter gradients).

Imported only on CUDA devices, so that triton is needed only there.

Module Attributes

SPREAD_BLOCK

atoms per program and warps, one lane per stencil point

SPREAD_WARPS

atoms per program and warps, one lane per stencil point

Functions

adjoint(grid_a, coef_a, order_a, grid_b, ...)

The gradient (N, 3) with respect to the scaled coordinates of the two contractions sum_points grid[point] coef(point); the coefficient sets are (N, 10).

adjoint_cartesian(grid_a, set_a, order_a, ...)

adjoint() with Cartesian multipole sets (q, d, Q).

amoeba_pairs_backward(i_, k_, r_vec, scales, ...)

Launch the AMOEBA backward kernel: the gradients of sum(g_node * e_node) + sum(g_field_d * field_d) + sum(g_field_p * field_p) + sum(g_du * du) with respect to the pair vectors (M, 3), the charges (N,), dipoles (N, 3), quadrupoles (N, 3, 3) and site offsets (N, 3).

amoeba_pairs_forward(i_, k_, r_vec, scales, ...)

Launch the AMOEBA pair kernel.

amoeba_param_grad(i_, k_, r_vec, scales, ...)

The gradient (N, AMOEBA_NP) of the AMOEBA pair outputs' weighted sum with respect to the per-atom table (pairs_param_grad() for amoeba_pairs_forward()).

amoeba_scalar_table(coulomb, alpha_e, ...)

The float64 scalars of an AMOEBA evaluation (AMOEBA_SCALARS); vdw_window is the (taper, cutoff) of the van der Waals switch (zeros without one).

available()

Whether the kernels can run here (a CUDA device and Triton).

blocks_inverse(alpha, expol, mask)

alpha mask (I + K)^-1 (N, 3, 3) for the exchange-polarization tensors K (N, 3, 3) (_inverse3 of the eager path, one launch).

constants(device)

The float64 table of the ladder constants on device (made once).

gather(grid, w, start, batch, mesh, deriv)

(N, 10): the potential and its fractional derivatives up to deriv (0, 1 or 2).

gather_cartesian(grid, jac, w, start, batch, ...)

The potential (N,), its Cartesian gradient (N, 3) and Hessian (N, 3, 3) (zeros beyond deriv).

gather_field(grid, jac, w, start, batch, ...)

acc += coef d - grad(potential) in place: the mesh part of the field of the dipoles d (acc (N, 3) holds their real-space field) with the self-field coefficient coef; with the scalars guard of a conjugate-gradient iteration acc is left alone once the solve has converged.

mutual_backward(mu, lam, r_vec, du, i_, k_)

grad_r (M, 3) and grad_du (M, 2) of sum(lam * (T mu)) over the pairs (the products of the implicit backward of the induction); count and select as in pairs_forward() (the pairs not visited have zero ladders and get zero gradients).

mutual_field(mu, r_vec, du, i_, k_, N[, ...])

The real-space field (N, 3) of dipoles mu (N, 3) through the mutual ladders du (M, 2) of the pairs (mutual_field_real of the eager path), summed per atom over the compressed rows rows of pair_rows() (built here when not given); count as in pairs_forward().

pair_rows(i_, k_, N[, valid, sorted_i])

The compressed rows of the unique pairs (i, k) over the N atoms, for mutual_field(): every pair appears in the row of each of its atoms.

pairs_backward(i_, k_, r_vec, scales, keep, ...)

Launch the backward kernel: the gradients of sum(g_node * e_node) + sum(g_field_d * field_d) + sum(g_field_p * field_p) + sum(g_du * du) + sum(g_expol * expol) with respect to the pair vectors (M, 3) and the per-atom charges (N,), dipoles (N, 3) and quadrupoles (N, 3, 3).

pairs_forward(i_, k_, r_vec, scales, keep, ...)

Launch the pair kernel.

pairs_param_grad(i_, k_, r_vec, scales, ...)

The gradient (N, NP) of sum(g_node * e_node) + sum(g_field_d * field_d) + ... (the outputs of pairs_forward()) with respect to the per-atom parameter table, from the generated adjoint of the forward kernel (amoeba_tangents); the inputs are those of pairs_backward().

pcg_apply(p, field, inv_alpha, expol, mask, scal)

The operator on p (N, 3) given its field, accumulating sum(p * (A p)) into scal[0].

pcg_direction(p, z, scal_in, scal_out, bound)

The new direction in place and the next iteration's scalars (see _pcg_direction()).

pcg_scalars(rz)

The two scalar buffers (2, 6) of a solve, the first holding sum(r * z) of the start.

pcg_step(x, r, z, p, ap, diag, blocks, scal)

The update of x, r and z in place (see _pcg_step()).

plan_checks(pos, reference, last, converged, ...)

[outdated, due, converged, *needed] of a step plan as one float64 tensor from one kernel (see checks()), with last set to pos.

scalar_table(coulomb, alpha_e, alpha_p, ...)

The float64 scalars of an evaluation (SCALARS); windows maps "rep", "ct", "disp" to (taper, cutoff) pairs (zeros when the term has no switch), ewald_cutoffs holds the real-space cutoffs of the electrostatics and the dispersion.

select_pairs(active)

The pairs the kernels visit: the indices of the active ones (M,) in increasing order, followed by zeros up to M + 1 entries, and their number as an int32 tensor (1,), both on the device without a host read (a CUDA graph records them).

select_pairs_within(r, cutoff_sq[, valid])

The distances (M,) of the pair vectors r (M, 3) (no gradient) and select_pairs() of the pairs within the cutoff (r * r summed below cutoff_sq, a tensor of one entry in the precision of r) and valid (valid > 0): two kernels and one scan.

shift_cell_gradient(shift, g[, count])

sum_e shift[e] (x) g[e] (3, 3) in float64 over the pairs before count (all without it): the gradient of the image shifts' product with the one cell.

spline_tables(u, mesh, order)

The spline tables (N, 3, 4, P) (weights and three derivatives per axis) and the stencil starts (N, 3) of scaled fractional coordinates u (N, 3).

spread(c0, c1, c2, w, start, batch, mesh, ...)

The grid (groups, K1, K2, K3) of coefficients up to order (0, 1 or 2).

spread_cartesian(q, d, Q, jac, w, start, ...)

spread() of Cartesian multipoles with the structures' Jacobians jac (G, 3, 3); with the scalars guard of a conjugate-gradient iteration the grid stays zero once the solve has converged.

Classes

AmoebaPairs(*args, **kwargs)

The AMOEBA pair kernels as one autograd function (see HippoPairs): gradients with respect to the pair vectors, the per-atom multipoles and the van der Waals site offsets.

HippoPairs(*args, **kwargs)

The pair kernels as one autograd function: the forward kernel, and the backward kernel for the gradients with respect to the pair vectors and the per-atom multipoles (the other inputs get none: the class parameters are constants of an evaluation here, their gradients belong to the eager path of training).

MeshConvolution(*args, **kwargs)

The mesh potential of multipole sources at the atoms that carry them, differentiable with respect to the scaled coordinates, the components and the influence function.

MeshConvolutionCartesian(*args, **kwargs)

MeshConvolution on Cartesian multipoles q, d, Q with the Jacobians of the structures applied inside the kernels; returns the potential, its gradient and its Hessian at the atoms.

PairDifference(*args, **kwargs)

pos[k] - pos[i] (M, 3) of the pairs, plus shift @ cell of their image shifts (M, 3) with the one cell (3, 3) when given, computed in the precision of pos and stored in dtype (the model's) by one kernel, with the gradient scattered back to the atoms by one kernel (index_add serializes the adds of a list sorted by atom), over the compressed rows of the pairs (pair_rows()) when given.

PairScatter(*args, **kwargs)

The gradient of PairDifference with respect to the positions: g (M, 3) of the pairs added to their second atoms and subtracted from their first, (N, 3) in dtype, by one kernel (over the compressed rows when given; the pairs at or beyond count skipped).