Loading...
Searching...
No Matches
NestedEngineOracle.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// Copyright (c) gpridge developers
3// See LICENSE for details.
4
6
7namespace pot {
8
9std::string engineLibraryForSpecArm(const std::string& arm)
10{
11 if (arm == "uma") return "libuma_engine.so";
12 if (arm == "metatomic") return "libmetatomic_engine.so";
13 if (arm == "nwchem") return "libnwchem_engine.so";
14 if (arm == "cpmd") return "libcpmd_engine.so";
15 if (arm == "cp2k") return "libcp2k_engine.so";
16 if (arm == "lammps") return "liblammps_engine.so";
17 // builtin carries its own library path when it needs one, and the
18 // analytic potentials have no plugin at all.
19 return {};
20}
21
22std::unique_ptr<NestedEngineOracle> NestedEngineOracle::open(
23 const std::string& library, const std::vector<unsigned char>& config,
24 std::string& err)
25{
26 auto engine = EnginePotential::open(library, config, err);
27 if (!engine) return nullptr;
28 std::unique_ptr<NestedEngineOracle> self(new NestedEngineOracle());
29 self->engine_ = std::move(engine);
30 return self;
31}
32
34
35const std::string& NestedEngineOracle::library() const noexcept
36{
37 return engine_->library();
38}
39
41{
42 EnginePotential* engine = engine_.get();
43 return
44 [engine](long n_atoms, const double* positions, const int* atomic_nrs,
45 const double* box, double* energy, double* forces) -> int {
46 // Variance is not requested: the surrogate reports its own, and an
47 // oracle's uncertainty is not what the gate is measured in.
48 return engine->force(n_atoms, positions, atomic_nrs, box, forces,
49 energy, nullptr);
50 };
51}
52
53} // namespace pot
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, const double *box, double *forces, double *energy, double *variance)
static std::unique_ptr< EnginePotential > open(const std::string &library, const std::vector< unsigned char > &config, std::string &err, bool torch_cuda=false, int oracle_threads=1)
const std::string & library() const noexcept
ActiveGP::OracleFn asOracle()
Ground truth in the shape ActiveGP consumes.
NestedEngineOracle(const NestedEngineOracle &)=delete
static std::unique_ptr< NestedEngineOracle > open(const std::string &library, const std::vector< unsigned char > &config, std::string &err)
Potential wrappers and the batched oracle interface.
std::string engineLibraryForSpecArm(const std::string &arm)