xnn.common.deploy.step_graph.StepGraph#

class xnn.common.deploy.step_graph.StepGraph(model, cutoff, skin=1.0, margin=1.2, warmup=8, capture=True, compute_dtype=None, shorten=25, late_checks=False)[source]#

Bases: object

The steps of a molecular dynamics run, evaluated on a step plan.

Each call takes the structure of a step and returns the energy, the forces and, for a cell, the stress. The pair list is built with cutoff + skin and rebuilt when an atom has moved by more than half the skin. The plan holds margin times the pairs of its first list, so a rebuild refreshes it in place. The first warmup steps run with converged solves; then the solves run the largest count of the last two steps plus a quarter, and on a GPU the step is recorded as a CUDA graph and replayed from then on. A step whose solves did not converge in that length is evaluated again with converged solves, and the length raised above the one that failed. Every shorten steps the lengths are lowered to the largest count the solves needed in them plus a quarter, when that is shorter, and the step is recorded again: the dipole predictor keeps improving after the warm-up, and a length set then would be paid at every step. A failed length stops being a floor after four times shorten converged steps. The replayed step also tells whether an atom will pass half the skin within two more steps like the last; the pair list then still holds for the next step, and is built again at that step’s positions while it replays, on a second stream: in an orthorhombic cell the whole of it (a grid search), otherwise all but vesin’s neighbor list, found before the replay starts. A rebuild costs no second replay unless an atom moves further than predicted; a step evaluated again first takes its dipoles back out of the predictors.

The cell may change from step to step (constant-pressure dynamics). A changed cell brings the terms the plan keeps for it (the mesh influence functions, inverse cells and volumes) up to date in place before the step runs, so the recorded step follows it, and until the next pair list the rebuild test also counts how far the cell has moved the periodic images. The mesh and the Ewald coefficients stay those the plan was made with.

For multiple time step integrators (RESPA) a step evaluates a subset of the terms: terms="valence" the bonded terms of an inner step, terms="nonbonded" the rest (pairs, meshes, induction) of an outer step, which add up to the whole step. Both run on the one plan. The outer steps make every decision above (pair list, solve lengths, dipole predictor). An inner step decides nothing and reads nothing from the device: it replays its own recorded graph from its second call on, and its bonded vectors follow atoms wrapped back into the cell since the pair list was built. The first call of a run is an outer step.

With late_checks a replayed step returns before its status (pair list, convergence, iterations needed) reaches the host. The status is read during the next step, after that step’s replay is queued, so the device is not left idle while the host decides. The pair list is then built one step earlier. A step whose list turns out outdated or whose solves did not converge has already returned its results: it is counted in late_failures with a warning, and the step that reads it is evaluated as without late checks (rebuilt, or with longer solves). A step that rebuilds the pair list takes the new list behind its replay and leaves its status to the next step too, when the list is found on the device alone: a grid search, or with late checks every pair of a smaller orthorhombic cell (each edge over the list’s cutoff). A new list that does not hold (an atom wrapped back into the cell, more pairs than the plan holds) is built again in full by the next step. A step at which an atom is wrapped back into the cell is only seen to fail after it returned, so late checks suit integrators that do not wrap the positions. settle() reads the status of the last step of a run.

Parameters:
  • model (torch.nn.Module) – A ForceStressOutput around a model with step plans; it is put in evaluation mode.

  • cutoff (float) – The model’s neighbor-list cutoff in Angstrom.

  • skin (float, optional) – The margin of the pair list in Angstrom, by default 1.

  • margin (float, optional) – The capacity of the plan’s pair list relative to its first list, by default 1.2.

  • warmup (int, optional) – Steps with converged solves before the lengths are fixed, by default 8 (it also fills the history of the dipole predictor).

  • shorten (int, optional) – Steps between the checks that lower the lengths, by default 25; 0 keeps the lengths once fixed.

  • capture (bool, optional) – Record the step as a CUDA graph on a GPU, by default True.

  • compute_dtype (torch.dtype, optional) – The model’s dtype for a geometry kept in float64.

  • late_checks (bool, optional) – Read the status of a replayed step during the next step, by default False.

Raises:

ValueError – If the model has no step plans.

reset()[source]#

Forget the plan and the recorded graph (a new system).

Return type:

None

settle()[source]#

Read the status of the last step under late checks, as the next step would (a failed step is counted and warned about, and the next step rebuilds or solves longer).

Returns:

Whether the last step held (True without a step to read).

Return type:

bool