xnn.ffnn.models.amoeba.StepPlan#

class xnn.ffnn.models.amoeba.StepPlan(skin=0.0, capacity=None)[source]#

Bases: object

What an evaluation of a structure decides on the host, recorded once and reused while the structure moves by small steps (molecular dynamics between rebuilds of the pair list): the image shifts of every bonded vector, the unique pairs of the neighbor list with their image shifts and scale factors, the layout of the Ewald sums and the polarizable atoms. An evaluation on a plan reads these instead of deciding them, so it waits for the device only in the convergence tests of the induced-dipole solve.

The pairs form a Verlet list: built with a neighbor list of cutoff + skin, they hold every pair within the cutoff until an atom has moved by more than half the skin (outdated()); the pairs beyond the cutoff and the padding up to a fixed capacity get zero weight.

solve_iterations, a dict from "forward" and "adjoint" to a number of iterations, makes those solves run exactly that long without reading the device (the counts of earlier steps are in solver_stats); converged then tells on the device whether every solve of the last evaluation and its backward pass converged, and needed holds, per phase in the order of SOLVE_PHASES, the iterations the last solve of that phase needed (zero for a phase that did not run). Build a plan with Amoeba.plan_step().

terms selects the terms an evaluation on the plan computes, for multiple time step integrators: "all" (default), "valence" (the bonded terms and the reference energies, without pairs, multipoles or solves) or "nonbonded" (the rest, the induction included). The two subsets add up to the whole energy, forces and stress. A valence evaluation follows atoms wrapped back into the cell since the pairs were found by whole lattice vectors, so it needs no check of the positions.

Parameters:
replaying()[source]#

Whether the plan is complete and evaluations read it.

Return type:

bool

outdated(pos)[source]#

Whether an atom at pos has moved by more than half the skin since the plan was built, as a boolean on the device (the pair list then misses pairs and the plan must be built again).

Parameters:

pos (Tensor) – Positions (N, 3).

Returns:

A boolean scalar.

Return type:

Tensor

due(pos, last, steps=1)[source]#

Whether an atom at pos will have moved by more than half the skin after steps more steps like the one from last, with one step to spare, as a boolean on the device: the pair list is still valid now and should be built again within steps steps.

Parameters:
  • pos (Tensor) – Positions (N, 3).

  • last (Tensor) – The positions of the step before (N, 3).

  • steps (int, optional) – The steps the pair list must still hold, by default 1 (it is built again before the next step).

Returns:

A boolean scalar.

Return type:

Tensor

checks(pos, last, steps=1)[source]#

outdated() and due() of pos with the solves’ convergence and needed iterations, as one float64 tensor [outdated, due, converged, *needed], and last set to pos after: one kernel on a GPU, so a recorded CUDA graph ends a step with one launch and its caller reads everything at once.

Parameters:
  • pos (Tensor) – Positions (N, 3).

  • last (Tensor) – The positions of the step before (N, 3), overwritten with pos.

  • steps (int, optional) – As in due(), by default 1.

Returns:

(3 + len(needed),), float64.

Return type:

Tensor

update(other, bonded=True)[source]#

Copy the pairs (with their rows), image shifts and reference positions of other, a plan of the same structure built later, into this plan’s tensors in place, so a CUDA graph recorded on this plan replays the new ones.

Parameters:
  • other (StepPlan) – The new plan.

  • bonded (bool, optional) – Copy the image shifts of the bonded vectors too (other recorded a whole evaluation), by default True.

Returns:

Whether every tensor matched in shape and was copied; nothing is copied otherwise.

Return type:

bool