mod hvp

module hvp

Hessian-vector products of a potential handle.

The product is H v, where H is the Hessian of the energy with respect to the 3N Cartesian positions and v is a direction laid out like the positions ([n_atoms, 3], row-major). A minimum-mode search (Lanczos, dimer) applies H to many directions at one geometry. With only a force callback each product is a difference of two force evaluations, and one of them is the centre the search has not moved from.

A handle keeps the forces of the last centre it evaluated, keyed on the bits of the positions, the atomic numbers and the cell. k forward products at one centre therefore cost k + 1 force calls instead of 2k. Another geometry, species list or cell is a new centre, and rgpot_potential_t::invalidate_hvp_centre drops the cached one when the potential itself changes. A potential that knows its Hessian registers a HessianVectorCallback and the products make no force call at all.

Scheme

Force calls per product

Error

RGPOT_HVP_FORWARD

1, plus 1 for each new centre

O(h)

RGPOT_HVP_CENTRAL

2

O(h^2)

RGPOT_HVP_ANALYTIC

0

that of the callback

h is the length of the displacement along the unit direction v / |v|, in the units of the positions. The difference is scaled back by |v|, so the product is homogeneous in |v|; the forward scheme is not linear in v, because its O(h) term keeps its sign when v does. Neither finite difference can be O(h^2) and cost one call per product: the forward error is (h / 2) T(u, u) |v|, with T the third derivative, and cancelling it takes the second evaluation that the central scheme makes.

Types

type HessianVectorCallback

Analytic Hessian-vector product of a potential.

The callback receives the user_data of the potential handle, the geometry, a direction of 3 * n_atoms doubles and room for as many doubles of output. It writes H direction to hv_out and returns RGPOT_SUCCESS, or an error status code. direction and hv_out do not overlap.

Variables

const RGPOT_HVP_DEFAULT_STEP: f64

Displacement length used when a caller passes a step of 0.

Enums

enum HvpError

Why a Hessian-vector request failed.

Invalid(String)

A malformed argument or callback result. C callers see RGPOT_INVALID_PARAMETER and this sentence in rgpot_last_error.

Callback(rgpot_status_t)

A callback returned this status. Its own rgpot_last_error message, if it set one, is left in place.

Implementations

impl HvpError

Functions

fn status(&self) -> rgpot_status_t

The status a C caller receives.

Traits implemented

impl std::fmt::Display for HvpError
impl std::error::Error for HvpError
enum rgpot_hvp_scheme_t

How a Hessian-vector product is computed.

RGPOT_HVP_AUTO

The analytic callback when one is registered, otherwise forward.

RGPOT_HVP_FORWARD

One displaced force call against the cached centre forces.

RGPOT_HVP_CENTRAL

Two displaced force calls, one on each side of the centre.

RGPOT_HVP_ANALYTIC

The registered callback. Refused when none is registered.

Implementations

impl rgpot_hvp_scheme_t

Functions

fn from_raw(raw: i32) -> Option<Self>

The scheme with this value, or None for a value the enum lacks.

Structs and Unions

struct HvpCentre

Energy, variance and forces (3 * n_atoms, row-major) at a centre.

energy: f64
variance: f64
forces: Vec<f64>
struct rgpot_hvp_counts_t

Work done by the Hessian-vector entry points of one handle.

products: u64

Products answered, a zero direction’s zero product included.

force_calls: u64

Force callback invocations made for products and centres.

centre_reused: u64

Requests answered from the cached centre without a force call.

analytic: u64

Products answered by the analytic callback.