Loading...
Searching...
No Matches
ActiveGP.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#ifndef GPR_POTENTIALS_ACTIVEGP_H_
6#define GPR_POTENTIALS_ACTIVEGP_H_
7
8#include <cstdint>
9#include <functional>
10#include <memory>
11#include <mutex>
12#include <vector>
13
14#include "gpr/neb/Session.h"
15
16namespace pot {
17
42 double sigma_lo_factor = 1.0;
44 double sigma_hi_factor = 20.0;
49 double certify_below_force = 0.0;
52 std::uint64_t refit_training_revisions = 5;
53};
54
55class ActiveGP {
56public:
59 using OracleFn = std::function<int(long n_atoms, const double* positions,
60 const int* atomic_nrs, const double* box,
61 double* energy, double* forces)>;
62
65 using AcquireHook = std::function<void(AcquireReason)>;
67 using ModelUpdateHook = std::function<void(std::uint64_t epoch)>;
68
70
71 ActiveGP(std::shared_ptr<gpr::neb::ActiveLearningSession> session,
72 OracleFn oracle, Config config = Config());
73
76 [[nodiscard]] std::uint64_t modelState() const noexcept;
77
79 [[nodiscard]] long trainingSize() const noexcept;
80
82 [[nodiscard]] long oracleCalls() const noexcept
83 {
84 return oracle_calls_;
85 }
86
88 {
89 on_acquire_ = std::move(hook);
90 }
92 {
93 on_model_update_ = std::move(hook);
94 }
95
98 int force(long n_atoms, const double* positions, const int* atomic_nrs,
99 double* forces, double* energy, double* variance,
100 const double* box);
101
107 int forceBatch(long n_systems, long n_atoms, const double* positions,
108 const int* atomic_nrs, double* forces, double* energies,
109 double* variances, const double* boxes);
110
112 void incorporate();
113
114private:
115 std::shared_ptr<gpr::neb::ActiveLearningSession> session_;
116 OracleFn oracle_;
117 Config config_;
118 AcquireHook on_acquire_;
119 ModelUpdateHook on_model_update_;
120 long oracle_calls_ = 0;
121 bool pending_incorporation_ = false;
122 mutable std::mutex mutex_;
123
125 void predict(long n_atoms, const double* positions, double* forces,
126 double* energy, double* variance);
127
129 int acquire(long n_atoms, const double* positions, const int* atomic_nrs,
130 const double* box, double* energy, double* forces,
131 AcquireReason reason, bool learn);
132
133 [[nodiscard]] double noiseSigma() const;
134};
135
136} // namespace pot
137
138#endif
ActiveLearningSession: shared GP + training data across GP-NEB and GP-Dimer phases.
AcquireReason
Fired when a point is delegated, before the oracle runs.
Definition ActiveGP.h:64
void setModelUpdateHook(ModelUpdateHook hook)
Definition ActiveGP.h:91
std::uint64_t modelState() const noexcept
Definition ActiveGP.cpp:22
ActiveGP(std::shared_ptr< gpr::neb::ActiveLearningSession > session, OracleFn oracle, Config config=Config())
Definition ActiveGP.cpp:13
ActiveGPConfig Config
Definition ActiveGP.h:69
void incorporate()
Host-requested incorporation boundary (the ABI hint channel).
Definition ActiveGP.cpp:94
std::function< void(std::uint64_t epoch)> ModelUpdateHook
Fired after an incorporation changed the surface.
Definition ActiveGP.h:67
int forceBatch(long n_systems, long n_atoms, const double *positions, const int *atomic_nrs, double *forces, double *energies, double *variances, const double *boxes)
Definition ActiveGP.cpp:181
std::function< int(long n_atoms, const double *positions, const int *atomic_nrs, const double *box, double *energy, double *forces)> OracleFn
Definition ActiveGP.h:59
int force(long n_atoms, const double *positions, const int *atomic_nrs, double *forces, double *energy, double *variance, const double *box)
Definition ActiveGP.cpp:107
long oracleCalls() const noexcept
Oracle calls made through this surrogate.
Definition ActiveGP.h:82
std::function< void(AcquireReason)> AcquireHook
Definition ActiveGP.h:65
long trainingSize() const noexcept
Training rows currently held.
Definition ActiveGP.cpp:27
void setAcquireHook(AcquireHook hook)
Definition ActiveGP.h:87
uint64_t epoch
Potential wrappers and the batched oracle interface.
double sigma_lo_factor
Delegate above this multiple of the likelihood noise sigma.
Definition ActiveGP.h:42
double sigma_hi_factor
Above this multiple the geometry is not learned from.
Definition ActiveGP.h:44
double certify_below_force
Definition ActiveGP.h:49
std::uint64_t refit_training_revisions
Definition ActiveGP.h:52