xnn.krnn.models.sgdml.SGDML#

class xnn.krnn.models.sgdml.SGDML(species, sigma=10.0, kernel_order=2, use_symmetries=True, cutoff=1.0)[source]#

Bases: InteratomicPotential

Symmetrized gradient-domain machine-learning force field.

The model is tied to its molecule: every structure must list the elements of species in that order. It is filled by fit_sgdml() or loaded from an sGDML model file (load_sgdml_model()).

Parameters:
  • species (sequence of int or str) – The elements of the atoms, in order.

  • sigma (float, optional) – Length scale of the Matern kernel, by default 10.0.

  • kernel_order (int, optional) – n of the Matern order n + 1/2, by default 2.

  • use_symmetries (bool, optional) – Find the permutational symmetries of the molecule when fitting (sGDML), by default True; False gives GDML.

  • cutoff (float, optional) – Neighbour-list radius of the data pipeline; the model reads positions only. By default 1.0.

Variables:
  • train_desc (Tensor) – (M, D) descriptors of the training geometries.

  • train_weights (Tensor) – (M, D) force coefficients through the descriptor Jacobians.

  • energy_coef (Tensor) – (M,) energy coefficients (empty unless energies were part of the fit).

  • perms (Tensor) – (Q, N) atom permutations of the symmetry group.

  • c (std,) – Scale of the training forces and the integration constant.

  • lattice (Tensor) – (3, 3) cell (rows as vectors) of a periodic model, empty otherwise.

fit_options: Dict[str, object]#

options of fit_closed_form() (from the config)

fit_info: Dict[str, object]#

how the last fit was solved (the solver and, for the iterative one, its iterations and residual)

set_kernel(sigma, kernel_order=None)[source]#

Change the kernel (before fitting).

Parameters:
  • sigma (float)

  • kernel_order (int | None)

Return type:

None

set_permutations(perms)[source]#

Use the atom permutations perms (Q, N) as the symmetry group.

Return type:

None

receptive_field()[source]#

Unbounded: the energy reads every pair of atoms.

Return type:

float | None

geometry(data)[source]#

(B, N, 3) positions and (B, 3, 3) cells of the batch, in float64.

The cell is the structure’s when it is periodic, otherwise the model’s own (a model fitted in a cell); None for molecules.

Parameters:

data (AtomicGraph)

permuted_training_set()[source]#

(M, Q, D) training descriptors and weights under every permutation (cached).

set_use_fast(use_fast)[source]#

Choose the implementation of the kernel expansion.

Parameters:

use_fast (bool or str) – "auto" (the default): the fused kernels (xnn.krnn.fast.sgdml) where they are available and measured to be faster (a CUDA device, Triton, a batch above the size crossover of AUTO_POLICY, or AUTO_POLICY_TRAINING in training mode); True: wherever they are available; False: always the reference. The kernels give Hessians through the forces as the reference does.

Returns:

self.

Return type:

SGDML

uses_fast_path(x)[source]#

Whether the expansion of the descriptors x runs on the fused kernels.

Parameters:

x (Tensor)

Return type:

bool

energy_of_descriptors(x)[source]#

Energies (B,) of float64 descriptors (B, D).

Parameters:

x (Tensor)

Return type:

Tensor

forward(data)[source]#

Energy of each structure; the per-atom energies are its equal shares.

Parameters:

data (AtomicGraph)

Return type:

Dict[str, Tensor]

forms_forces(data)[source]#

Whether forward_direct() serves this evaluation: always in evaluation mode, unless the positions carry an autograd graph that the outputs must continue.

Parameters:

data (AtomicGraph)

Return type:

bool

forward_direct(data)[source]#

forward() with the forces "forces" and "virial" (dE / d(strain)) of the paper’s force predictor: the gradient of the expansion by the descriptors, formed with the energy, through the descriptor Jacobian. The outputs carry no autograd graph.

Parameters:

data (AtomicGraph)

Return type:

Dict[str, Tensor]

fit(graphs, **kwargs)[source]#

Fit to labelled structures (see fit_sgdml()).

Return type:

SGDML

fit_closed_form(train, validation=None)[source]#

The trainer’s fit: fit() with the options of the config (fit_options).

Return type:

SGDML

classmethod from_config(cfg)[source]#

Build from cfg.extra: species (one entry per atom, in order), sigma (a length scale, or several to choose from on the validation set when the trainer fits the model; by default 10 to 100 in steps of 10), kernel_order, use_symmetries, the fit options lam, energy_constraint, use_energy, solver, solver_tol, n_inducing and max_memory, or model_file (an sGDML model file to load); cfg.cutoff sizes the data pipeline’s graph.

Return type:

SGDML