GPRidge v1.0.0
GPR-accelerated saddle point searches on potential energy surfaces
☾
Toggle main menu visibility
Loading...
Searching...
No Matches
SketchedHessianH0.h
Go to the documentation of this file.
1
// SPDX-License-Identifier: MIT
2
// Copyright (c) gpridge developers
3
// See LICENSE for details.
4
5
/*
6
* SketchedHessianH0.h -- randomised Nystrom Hessian preconditioner for
7
* the chain L-BFGS H0 slot.
8
*
9
* Replaces the legacy scalar H0 = gamma * I in Nocedal's two-loop with
10
* a low-rank Nystrom approximation built from k Hessian-vector
11
* products at the current band position. Follows Frangella, Tropp, &
12
* Udell, "Randomized Nystrom Preconditioning", SIAM J. Matrix Anal.
13
* Appl. 44, 718 (2023), doi:10.1137/21M1466244.
14
*
15
* Distributed math layout for true strong scaling on the chain HvP
16
* phase (no duplicated work in the rate-limiting step):
17
*
18
* - The k-column Gaussian sketch Omega (n x k, splitmix64-seeded) is
19
* reproduced bit-identically on every rank from the same seed. No
20
* comm required to materialise it.
21
* - Each rank owns a disjoint slice of the k columns of Y = H Omega
22
* (= ceil(k / P) columns). It evaluates the k_local Hessian-vector
23
* products via a finite-difference probe on the chain force
24
* functor supplied to rebuild(). Per-column HvP is independent;
25
* this is the embarrassingly parallel phase.
26
* - One MPI_Allgather collects the per-rank Y_local stripes into a
27
* full Y on every rank (n * k doubles, sub-MB even for n in the
28
* thousands with k = 20).
29
* - Mid = Omega^T Y is a k x k matmul; computed locally and
30
* identically on every rank (k^3 operations, negligible vs the
31
* n*k HvP work).
32
* - LDLT factorisation of (Mid + delta I) is local. The 0.5 (Mid +
33
* Mid^T) symmetrisation absorbs the FD asymmetry.
34
*
35
* Apply: H_sketch^{-1} q ~= gamma * q + Omega * (Mid^{-1} (Omega^T q
36
* - gamma * Y^T q)). Pure local matrix-vector ops; the second-
37
* to-last step is the only n*k matmul (still local on full Omega
38
* because Omega is replicated).
39
*
40
* The Tikhonov shift gamma keeps the apply well-conditioned in
41
* directions outside the sketch range (Eq. 2.4 of Frangella-Tropp-Udell
42
* 2023); the legacy scalar L-BFGS H0 enters as the same gamma so the
43
* sketched H0 strictly extends the scalar default.
44
*
45
* References:
46
* - Frangella, Tropp, Udell. SIMAX 44, 718 (2023).
47
* doi:10.1137/21M1466244 -- the Nystrom precond. used here.
48
* - Wilson-Decius-Cross. Molecular Vibrations. Dover 1980.
49
* ISBN 9780486639413 -- F-G matrix used by callers to mass-weight
50
* the chain Hessian before passing the HvP functor in.
51
*/
52
53
#ifndef GPRIDGEIZATION_SKETCHEDHESSIANH0_H_
54
#define GPRIDGEIZATION_SKETCHEDHESSIANH0_H_
55
56
#include <Eigen/Dense>
57
#include <cstdint>
58
#include <functional>
59
60
#ifdef GPR_HAVE_MPI
61
#include <mpi.h>
62
#endif
63
64
namespace
gpr
{
65
namespace
optim
{
66
67
class
SketchedHessianH0
{
68
public
:
69
// Hessian-vector product functor: HvP(v) = H v, evaluated at the
70
// band position that is current when rebuild() is called. The
71
// caller is free to compute this via FD on a force functor, an
72
// analytic GP Hessian, or any other source.
73
using
HessianVectorProductFn
=
74
std::function<Eigen::VectorXd(
const
Eigen::VectorXd&)>;
75
76
// n_dof: chain dimension (3 * N_atoms * N_interior_images)
77
// sketch_rank: k, Nystrom rank. Typical 10-30; must satisfy
78
// 1 <= k <= n_dof.
79
// seed: splitmix64 seed for the Gaussian Omega. Reproducible
80
// across runs and ranks.
81
// tikhonov_eps: regulariser added to the diagonal of Mid before
82
// factorisation. 1e-10 by default; bigger when the
83
// HvP is noisy.
84
SketchedHessianH0
(
int
n_dof
,
int
sketch_rank
, uint64_t seed,
85
double
tikhonov_eps = 1e-10);
86
87
// Build the Nystrom factors from a fresh batch of HvPs. Columns of
88
// Y = H Omega are distributed across MPI_COMM_WORLD ranks; each
89
// rank evaluates ceil(k / P) HvPs and then participates in a
90
// single MPI_Allgather to assemble the full Y. If GPR_HAVE_MPI is
91
// off, this is purely local.
92
void
rebuild
(
const
HessianVectorProductFn
& hvp);
93
94
// Apply (Omega (Omega^T Y)^{-1} Omega^T + gamma_residual * I) q.
95
// gamma_residual is the legacy scalar L-BFGS H0; when set to the
96
// current Nocedal & Wright eq. 7.20 estimate, the sketched H0
97
// strictly extends the scalar default and never produces a step
98
// worse than the un-sketched chain L-BFGS.
99
[[nodiscard]] Eigen::VectorXd
apply
(
const
Eigen::VectorXd& q,
100
double
gamma_residual)
const
;
101
102
[[nodiscard]]
bool
ready
() const noexcept
103
{
104
return
ready_;
105
}
106
[[nodiscard]]
int
sketch_rank
() const noexcept
107
{
108
return
sketch_rank_;
109
}
110
[[nodiscard]]
int
n_dof
() const noexcept
111
{
112
return
n_dof_;
113
}
114
115
private
:
116
int
n_dof_;
117
int
sketch_rank_;
118
uint64_t seed_;
119
double
tikhonov_eps_;
120
bool
ready_ =
false
;
121
122
Eigen::MatrixXd Omega_;
// n_dof x sketch_rank, replicated
123
Eigen::MatrixXd Y_;
// n_dof x sketch_rank, replicated post-Allgather
124
Eigen::LDLT<Eigen::MatrixXd> mid_ldlt_;
// factors (Mid + eps I)
125
};
126
127
}
// namespace optim
128
}
// namespace gpr
129
130
#endif
// GPRIDGEIZATION_SKETCHEDHESSIANH0_H_
gpr::optim::SketchedHessianH0::ready
bool ready() const noexcept
Definition
SketchedHessianH0.h:102
gpr::optim::SketchedHessianH0::rebuild
void rebuild(const HessianVectorProductFn &hvp)
Definition
SketchedHessianH0.cpp:70
gpr::optim::SketchedHessianH0::sketch_rank
int sketch_rank() const noexcept
Definition
SketchedHessianH0.h:106
gpr::optim::SketchedHessianH0::HessianVectorProductFn
std::function< Eigen::VectorXd(const Eigen::VectorXd &)> HessianVectorProductFn
Definition
SketchedHessianH0.h:73
gpr::optim::SketchedHessianH0::apply
Eigen::VectorXd apply(const Eigen::VectorXd &q, double gamma_residual) const
Definition
SketchedHessianH0.cpp:131
gpr::optim::SketchedHessianH0::SketchedHessianH0
SketchedHessianH0(int n_dof, int sketch_rank, uint64_t seed, double tikhonov_eps=1e-10)
Definition
SketchedHessianH0.cpp:46
gpr::optim::SketchedHessianH0::n_dof
int n_dof() const noexcept
Definition
SketchedHessianH0.h:110
gpr::optim
Definition
ConsistentForceModel.h:13
gpr
Gaussian-process regression, kernels, priors, and the searches that run on the surrogate.
Definition
Macros.h:16
gpr
optimization
SketchedHessianH0.h
Generated by
1.17.0
Generated by
Doxygen 1.17.0
Analytics by
Antics
provided by
TurtleTech ehf