mod hvp¶
- module hvp¶
C API for Hessian-vector products of a potential handle.
// A Lanczos loop at one centre: k products, k + 1 force calls. rgpot_force_out_t centre = rgpot_force_out_create(); rgpot_potential_hvp_centre(pot, &input, ¢re); // 1 force call for (int i = 0; i < k; ++i) { rgpot_potential_hvp(pot, &input, q[i], 0.0, RGPOT_HVP_AUTO, hq); // 1 each // ... Lanczos recurrence on hq ... } rgpot_tensor_free(centre.forces);
See
crate::hvpfor the schemes and the centre cache.Functions
- unsafe extern C fn rgpot_potential_hvp(pot: *const rgpot_potential_t, input: *const rgpot_force_input_t, direction: *const f64, step: f64, scheme: i32, hv_out: *mut f64) -> rgpot_status_t¶
Write the Hessian-vector product
H directionat the geometry ofinputtohv_out.His the Hessian of the energy with respect to the3 * n_atomspositions.directionandhv_outhold3 * n_atomsdoubles laid out like the positions and must not overlap.schemeis argpot_hvp_scheme_tvalue:RGPOT_HVP_AUTO: the analytic callback when one is registered, otherwiseRGPOT_HVP_FORWARD.RGPOT_HVP_FORWARD:(F(x) - F(x + h u)) |v| / hwithu = v / |v|.F(x)comes from the handle’s cached centre when the positions, atomic numbers and cell carry the same bits as the last centre, sokproducts at one geometry makek + 1force calls. ErrorO(h).RGPOT_HVP_CENTRAL:(F(x - h u) - F(x + h u)) |v| / (2 h), two force calls, errorO(h^2).RGPOT_HVP_ANALYTIC: the registered callback;RGPOT_INVALID_PARAMETERwhen none is registered.
stepish, a length in the units of the positions; 0 selectsRGPOT_HVP_DEFAULT_STEP. A zero direction writes zeros without a call. A failing force callback’s status is returned with its ownrgpot_last_errormessage.Safety
NULL pointers, an unknown scheme, a non-positive step and overlapping buffers return
RGPOT_INVALID_PARAMETER. Otherwisepotmust be a live handle,inputmust point to a validrgpot_force_input_twhose tensors stay alive for the call, anddirectionandhv_outmust point to3 * n_atomsreadable and writable doubles.
- unsafe extern C fn rgpot_potential_hvp_centre(pot: *const rgpot_potential_t, input: *const rgpot_force_input_t, output: *mut rgpot_force_out_t) -> rgpot_status_t¶
Energy and forces at the geometry of
input, from the cached centre ofpotwhen it matches, otherwise from one force call that becomes the cached centre.output->forces` is set to a new owning
[n_atoms, 3]` tensor; free it with ``rgpot_tensor_free. A search that needs the centre forces calls this instead ofrgpot_potential_calculate, so the forward products at that centre share the evaluation.Safety
A NULL
pot,inputoroutputreturnsRGPOT_INVALID_PARAMETER. Otherwise the pointers followrgpot_potential_calculate.
- unsafe extern C fn rgpot_potential_hvp_counts(pot: *const rgpot_potential_t, out: *mut rgpot_hvp_counts_t) -> rgpot_status_t¶
Read the Hessian-vector counters of
potintoout.Safety
potmust be NULL or a live handle, andoutNULL or writable. NULL for either returnsRGPOT_INVALID_PARAMETER.
- unsafe extern C fn rgpot_potential_hvp_invalidate(pot: *const rgpot_potential_t)¶
Drop the cached centre of
pot.A centre is keyed on positions, atomic numbers and cell, not on the state behind the callback’s
user_data. Call this after changing that state at a fixed geometry. NULL is a no-op.Safety
potmust be NULL or a live handle.
- unsafe extern C fn rgpot_potential_reset_hvp_counts(pot: *const rgpot_potential_t)¶
Zero the Hessian-vector counters of
pot. The cached centre stays.Safety
potmust be NULL or a live handle. NULL is a no-op.
- unsafe extern C fn rgpot_potential_set_hvp_callback(pot: *const rgpot_potential_t, callback: Option<unsafe extern C fn (user_data:*mut c_void, input:*const rgpot_force_input_t, direction:*const f64, hv_out:*mut f64) -> rgpot_status_t>) -> rgpot_status_t¶
Register
callbackas the analytic Hessian-vector product ofpot, or clear it with NULL.The callback receives the
user_datathe handle was created with, so a potential object supplies its forces and its Hessian through one pointer. With a callback registered,RGPOT_HVP_AUTOproducts call it and make no force call.Safety
potmust be NULL or a live handle. A NULLpotreturnsRGPOT_INVALID_PARAMETER.callbackmust be safe to call with the handle’suser_datafor as long as it stays registered.