xnn.common.models.vibrations.hessian_vector_product#

xnn.common.models.vibrations.hessian_vector_product(model, data, v, create_graph=False)[source]#

The Hessian of the energy times a direction, H v, for every structure of a batch.

Parameters:
  • model (torch.nn.Module) – The potential (bare or wrapped in ForceStressOutput).

  • data (AtomicGraph) – The structures.

  • v (Tensor) – The direction of every atom (N, 3) (Angstrom), or K directions (K, N, 3), all from one evaluation of the model.

  • create_graph (bool, optional) – Keep the product differentiable (for a loss on curvatures, whose backward reaches the model’s parameters); default False.

Returns:

H v of the shape of v, in eV / Angstrom^2 times the unit of v; the structures of a batch do not couple.

Return type:

Tensor

Examples

The curvatures of a structure along modes u (K, N, 3) are u_k . H u_k:

hu = hessian_vector_product(model, graph, u, create_graph=True)
curvatures = (u * hu).sum((1, 2))