Loading...
Searching...
No Matches
CatLearnPot Class Reference

#include <CatLearnPot.h>

Inheritance diagram for CatLearnPot:

Public Member Functions

 CatLearnPot (const Parameters &a_params)
void train_optimize (const MatrixXd &features, const MatrixXd &targets) override
void force (long nAtoms, const double *positions, const int *atomicNrs, double *forces, double *energy, double *variance, const double *box) override
bool isThreadSafe () const noexcept override
 Whether this potential's force() can be called from multiple threads on the SAME instance.
Public Member Functions inherited from eonc::SurrogatePotential
 SurrogatePotential (PotType a_ptype, const Parameters &a_params)
virtual ~SurrogatePotential ()=default
bool isSurrogate () const noexcept override
 Whether this is a surrogate (GP) potential.
std::tuple< double, AtomMatrix, double > get_ef_var (const AtomMatrix pos, const VectorXi atmnrs, const Matrix3d box)
Public Member Functions inherited from eonc::Potential
 Potential (PotType a_ptype)
 Potential (PotType a_ptype, const Parameters &)
 Potential (const Parameters &a_params)
virtual ~Potential ()
std::tuple< double, AtomMatrixget_ef (const AtomMatrix &pos, const VectorXi &atmnrs, const Matrix3d &box)
PotType getType () const
virtual bool requiresIsolatedMoleculeLayout () const noexcept
 True for molecular QM / non-PBC backends (NWChem socket, ASE ORCA/NWChem, …).
virtual bool isSharedInstanceThreadSafe () const noexcept
 Conservative gate for sharing one Potential instance across threads.
virtual bool needsPerImageInstance () const noexcept
 Whether NEB should create separate Potential instances per image for true parallel force evaluation.
virtual bool supportsBatchEvaluation () const noexcept
 Whether this potential supports batched evaluation of N systems in a single call.
virtual void forceBatch (long nSystems, long nAtoms, const double *const *positions, const int *const *atomicNrs, double *const *forces, double *energies, double *variances, const double *const *boxes)
 Evaluate forces for N systems in a single call.

Public Attributes

py::object m_gpmod
MatrixXd variance
Public Attributes inherited from eonc::Potential
std::atomic< size_t > forceCallCounter

Additional Inherited Members

Protected Attributes inherited from eonc::Potential
PotType ptype

Detailed Description

Definition at line 25 of file CatLearnPot.h.

Constructor & Destructor Documentation

◆ CatLearnPot()

CatLearnPot::CatLearnPot ( const Parameters & a_params)

Definition at line 16 of file CatLearnPot.cpp.

18 py::module_ sys = py::module_::import("sys");
19 py::exec(
20 std::format("sys.path.insert(0, {})", a_params.catlearn_options.path));
21
22 py::module_ gp_module = py::module_::import(
23 "catlearn.regression.gaussianprocess.calculator.mlmodel");
24
25 // Import the required modules
26 // GP Model
27 this->m_gpmod = gp_module.attr("get_default_model")(
28 "model"_a = a_params.catlearn_options.model);
29};
py::object m_gpmod
Definition CatLearnPot.h:38
struct eonc::Parameters::catlearn_options_t catlearn_options
SurrogatePotential(PotType a_ptype, const Parameters &a_params)

Member Function Documentation

◆ force()

void CatLearnPot::force ( long nAtoms,
const double * positions,
const int * atomicNrs,
double * forces,
double * energy,
double * variance,
const double * box )
overridevirtual

Implements eonc::Potential.

Definition at line 36 of file CatLearnPot.cpp.

38 {
39 MatrixXd features =
40 Eigen::Map<MatrixXd>(const_cast<double *>(positions), 1, nAtoms * 3);
41 py::tuple ef_and_unc = (this->m_gpmod.attr("predict")(
42 features, "get_variance"_a = true, "get_derivatives"_a = true));
43 auto ef_dat = ef_and_unc[0].cast<MatrixXd>();
44 auto vari = ef_and_unc[1].cast<MatrixXd>();
45 auto gradients = ef_dat.block(0, 1, 1, nAtoms * 3);
46 for (int idx = 0; idx < nAtoms; idx++) {
47 forces[3 * idx] = gradients(0, 3 * idx) * -1;
48 forces[3 * idx + 1] = gradients(0, 3 * idx + 1) * -1;
49 forces[3 * idx + 2] = gradients(0, 3 * idx + 2) * -1;
50 }
51 *variance = vari(0, 0); // energy variance only
52 *energy = ef_dat(0, 0);
53 return;
54}
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, eOnStorageOrder > MatrixXd
Definition Eigen.h:33
MatrixXd variance
Definition CatLearnPot.h:40

◆ isThreadSafe()

bool CatLearnPot::isThreadSafe ( ) const
inlinenodiscardoverridevirtualnoexcept

Whether this potential's force() can be called from multiple threads on the SAME instance.

Python-based potentials return false. Potentials with internal mutex (MetatomicPotential) return true but serialize internally – use needsPerImageInstance() to check if separate instances would enable true parallelism.

Reimplemented from eonc::Potential.

Definition at line 36 of file CatLearnPot.h.

36{ return false; }

◆ train_optimize()

void CatLearnPot::train_optimize ( const MatrixXd & features,
const MatrixXd & targets )
overridevirtual

Implements eonc::SurrogatePotential.

Definition at line 31 of file CatLearnPot.cpp.

31 {
32 m_gpmod.attr("optimize")(features, targets, py::arg("retrain") = true);
33 return;
34}

Member Data Documentation

◆ m_gpmod

py::object CatLearnPot::m_gpmod

Definition at line 38 of file CatLearnPot.h.

◆ variance

MatrixXd CatLearnPot::variance

Definition at line 40 of file CatLearnPot.h.


The documentation for this class was generated from the following files:
  • /home/runner/work/eOn/eOn/include/eon/potentials/CatLearnPot/CatLearnPot.h
  • /home/runner/work/eOn/eOn/client/potentials/CatLearnPot/CatLearnPot.cpp