=========== ``mod hvp`` =========== .. rust:module:: rgpot_core::hvp :index: 0 :vis: pub 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. .. rust:use:: rgpot_core::hvp :used_name: self .. rust:use:: rgpot_core :used_name: crate .. rust:use:: std::os::raw::c_void :used_name: c_void .. rust:use:: std::sync::atomic::AtomicU64 :used_name: AtomicU64 .. rust:use:: std::sync::atomic::Ordering :used_name: Ordering .. rust:use:: std::sync::Arc :used_name: Arc .. rust:use:: std::sync::Mutex :used_name: Mutex .. rust:use:: std::sync::MutexGuard :used_name: MutexGuard .. rust:use:: rgpot_core::eindir::rgpot_potential_t :used_name: rgpot_potential_t .. rust:use:: rgpot_core::eindir::validated_result :used_name: validated_result .. rust:use:: rgpot_core::status::rgpot_status_t :used_name: rgpot_status_t .. rust:use:: rgpot_core::tensor::copy_f64_tensor :used_name: copy_f64_tensor .. rust:use:: rgpot_core::tensor::copy_i32_tensor :used_name: copy_i32_tensor .. rust:use:: rgpot_core::tensor::rgpot_tensor_cpu_f64_2d :used_name: rgpot_tensor_cpu_f64_2d .. rust:use:: rgpot_core::tensor::rgpot_tensor_free :used_name: rgpot_tensor_free .. rust:use:: rgpot_core::types::rgpot_force_input_t :used_name: rgpot_force_input_t .. rust:use:: rgpot_core::types::rgpot_force_out_t :used_name: rgpot_force_out_t .. rubric:: Types .. rust:type:: rgpot_core::hvp::HessianVectorCallback :index: 0 :vis: pub :layout: [{"type":"keyword","value":"type"},{"type":"space"},{"type":"name","value":"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. .. rubric:: Variables .. rust:variable:: rgpot_core::hvp::RGPOT_HVP_DEFAULT_STEP :index: 0 :vis: pub :toc: const RGPOT_HVP_DEFAULT_STEP :layout: [{"type":"keyword","value":"const"},{"type":"space"},{"type":"name","value":"RGPOT_HVP_DEFAULT_STEP"},{"type":"punctuation","value":": "},{"type":"link","value":"f64","target":"f64"}] Displacement length used when a caller passes a step of 0. .. rubric:: Enums .. rust:enum:: rgpot_core::hvp::HvpError :index: 1 :vis: pub :layout: [{"type":"keyword","value":"enum"},{"type":"space"},{"type":"name","value":"HvpError"}] Why a Hessian-vector request failed. .. rust:struct:: rgpot_core::hvp::HvpError::Invalid :index: 2 :vis: pub :toc: Invalid :layout: [{"type":"name","value":"Invalid"},{"type":"punctuation","value":"("},{"type":"link","value":"String","target":"String"},{"type":"punctuation","value":")"}] A malformed argument or callback result. C callers see ``RGPOT_INVALID_PARAMETER`` and this sentence in ``rgpot_last_error``. .. rust:struct:: rgpot_core::hvp::HvpError::Callback :index: 2 :vis: pub :toc: Callback :layout: [{"type":"name","value":"Callback"},{"type":"punctuation","value":"("},{"type":"link","value":"rgpot_status_t","target":"rgpot_status_t"},{"type":"punctuation","value":")"}] A callback returned this status. Its own ``rgpot_last_error`` message, if it set one, is left in place. .. rubric:: Implementations .. rust:impl:: rgpot_core::hvp::HvpError :index: -1 :vis: pub :layout: [{"type":"keyword","value":"impl"},{"type":"space"},{"type":"link","value":"HvpError","target":"HvpError"}] :toc: impl HvpError .. rubric:: Functions .. rust:function:: rgpot_core::hvp::HvpError::status :index: -1 :vis: pub :layout: [{"type":"keyword","value":"fn"},{"type":"space"},{"type":"name","value":"status"},{"type":"punctuation","value":"("},{"type":"operator","value":"&"},{"type":"keyword","value":"self"},{"type":"punctuation","value":")"},{"type":"space"},{"type":"returns"},{"type":"space"},{"type":"link","value":"rgpot_status_t","target":"rgpot_status_t"}] The status a C caller receives. .. rubric:: Traits implemented .. rust:impl:: rgpot_core::hvp::HvpError::Display :index: -1 :vis: pub :layout: [{"type":"keyword","value":"impl"},{"type":"space"},{"type":"link","value":"std","target":"std"},{"type":"punctuation","value":"::"},{"type":"name","value":"fmt"},{"type":"punctuation","value":"::"},{"type":"name","value":"Display"},{"type":"space"},{"type":"keyword","value":"for"},{"type":"space"},{"type":"link","value":"HvpError","target":"HvpError"}] :toc: impl Display for HvpError .. rust:impl:: rgpot_core::hvp::HvpError::Error :index: -1 :vis: pub :layout: [{"type":"keyword","value":"impl"},{"type":"space"},{"type":"link","value":"std","target":"std"},{"type":"punctuation","value":"::"},{"type":"name","value":"error"},{"type":"punctuation","value":"::"},{"type":"name","value":"Error"},{"type":"space"},{"type":"keyword","value":"for"},{"type":"space"},{"type":"link","value":"HvpError","target":"HvpError"}] :toc: impl Error for HvpError .. rust:enum:: rgpot_core::hvp::rgpot_hvp_scheme_t :index: 1 :vis: pub :layout: [{"type":"keyword","value":"enum"},{"type":"space"},{"type":"name","value":"rgpot_hvp_scheme_t"}] How a Hessian-vector product is computed. .. rust:struct:: rgpot_core::hvp::rgpot_hvp_scheme_t::RGPOT_HVP_AUTO :index: 2 :vis: pub :toc: RGPOT_HVP_AUTO :layout: [{"type":"name","value":"RGPOT_HVP_AUTO"}] The analytic callback when one is registered, otherwise forward. .. rust:struct:: rgpot_core::hvp::rgpot_hvp_scheme_t::RGPOT_HVP_FORWARD :index: 2 :vis: pub :toc: RGPOT_HVP_FORWARD :layout: [{"type":"name","value":"RGPOT_HVP_FORWARD"}] One displaced force call against the cached centre forces. .. rust:struct:: rgpot_core::hvp::rgpot_hvp_scheme_t::RGPOT_HVP_CENTRAL :index: 2 :vis: pub :toc: RGPOT_HVP_CENTRAL :layout: [{"type":"name","value":"RGPOT_HVP_CENTRAL"}] Two displaced force calls, one on each side of the centre. .. rust:struct:: rgpot_core::hvp::rgpot_hvp_scheme_t::RGPOT_HVP_ANALYTIC :index: 2 :vis: pub :toc: RGPOT_HVP_ANALYTIC :layout: [{"type":"name","value":"RGPOT_HVP_ANALYTIC"}] The registered callback. Refused when none is registered. .. rubric:: Implementations .. rust:impl:: rgpot_core::hvp::rgpot_hvp_scheme_t :index: -1 :vis: pub :layout: [{"type":"keyword","value":"impl"},{"type":"space"},{"type":"link","value":"rgpot_hvp_scheme_t","target":"rgpot_hvp_scheme_t"}] :toc: impl rgpot_hvp_scheme_t .. rubric:: Functions .. rust:function:: rgpot_core::hvp::rgpot_hvp_scheme_t::from_raw :index: -1 :vis: pub :layout: [{"type":"keyword","value":"fn"},{"type":"space"},{"type":"name","value":"from_raw"},{"type":"punctuation","value":"("},{"type":"name","value":"raw"},{"type":"punctuation","value":": "},{"type":"link","value":"i32","target":"i32"},{"type":"punctuation","value":")"},{"type":"space"},{"type":"returns"},{"type":"space"},{"type":"link","value":"Option","target":"Option"},{"type":"punctuation","value":"<"},{"type":"link","value":"Self","target":"Self"},{"type":"punctuation","value":">"}] The scheme with this value, or ``None`` for a value the enum lacks. .. rubric:: Structs and Unions .. rust:struct:: rgpot_core::hvp::HvpCentre :index: 1 :vis: pub :toc: struct HvpCentre :layout: [{"type":"keyword","value":"struct"},{"type":"space"},{"type":"name","value":"HvpCentre"}] Energy, variance and forces (``3 * n_atoms``, row-major) at a centre. .. rust:variable:: rgpot_core::hvp::HvpCentre::energy :index: 2 :vis: pub :toc: energy :layout: [{"type":"name","value":"energy"},{"type":"punctuation","value":": "},{"type":"link","value":"f64","target":"f64"}] .. rust:variable:: rgpot_core::hvp::HvpCentre::variance :index: 2 :vis: pub :toc: variance :layout: [{"type":"name","value":"variance"},{"type":"punctuation","value":": "},{"type":"link","value":"f64","target":"f64"}] .. rust:variable:: rgpot_core::hvp::HvpCentre::forces :index: 2 :vis: pub :toc: forces :layout: [{"type":"name","value":"forces"},{"type":"punctuation","value":": "},{"type":"link","value":"Vec","target":"Vec"},{"type":"punctuation","value":"<"},{"type":"link","value":"f64","target":"f64"},{"type":"punctuation","value":">"}] .. rust:struct:: rgpot_core::hvp::rgpot_hvp_counts_t :index: 1 :vis: pub :toc: struct rgpot_hvp_counts_t :layout: [{"type":"keyword","value":"struct"},{"type":"space"},{"type":"name","value":"rgpot_hvp_counts_t"}] Work done by the Hessian-vector entry points of one handle. .. rust:variable:: rgpot_core::hvp::rgpot_hvp_counts_t::products :index: 2 :vis: pub :toc: products :layout: [{"type":"name","value":"products"},{"type":"punctuation","value":": "},{"type":"link","value":"u64","target":"u64"}] Products answered, a zero direction's zero product included. .. rust:variable:: rgpot_core::hvp::rgpot_hvp_counts_t::force_calls :index: 2 :vis: pub :toc: force_calls :layout: [{"type":"name","value":"force_calls"},{"type":"punctuation","value":": "},{"type":"link","value":"u64","target":"u64"}] Force callback invocations made for products and centres. .. rust:variable:: rgpot_core::hvp::rgpot_hvp_counts_t::centre_reused :index: 2 :vis: pub :toc: centre_reused :layout: [{"type":"name","value":"centre_reused"},{"type":"punctuation","value":": "},{"type":"link","value":"u64","target":"u64"}] Requests answered from the cached centre without a force call. .. rust:variable:: rgpot_core::hvp::rgpot_hvp_counts_t::analytic :index: 2 :vis: pub :toc: analytic :layout: [{"type":"name","value":"analytic"},{"type":"punctuation","value":": "},{"type":"link","value":"u64","target":"u64"}] Products answered by the analytic callback.