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

#include <CatLearnPot.h>

Inheritance diagram for CatLearnPot:

Public Member Functions

 CatLearnPot (const eonc::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)
 Production default: construction-scope registry, else PotRegistry::get().
 Potential (PotType a_ptype, IPotRegistry &registry)
 Test seam: injected registry, no process-default get() counters.
 Potential (PotType a_ptype, const Parameters &p)
 Potential (const Parameters &a_params)
virtual ~Potential ()
void force (std::span< const double > positions, std::span< const int > atomicNrs, std::span< double > forces, double *energy, double *variance, std::span< const double > box)
 C++ call site: size-checked view over the raw FFI force().
virtual void setFixedMask (long nAtoms, const double *isFixed)
 Optional frozen-atom mask (nAtoms*3, 1.0 = fixed).
std::tuple< double, AtomMatrix > get_ef (const AtomMatrix &pos, const VectorXi &atmnrs, const Matrix3d &box)
PotType getType () const
virtual double finiteCutoff () const noexcept
 Finite interaction range in position length units.
virtual bool requiresIsolatedMoleculeLayout () const noexcept
 True for molecular QM / non-PBC backends (NWChem socket, ASE ORCA/NWChem, …).
virtual unsigned layoutFlags () const noexcept
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 std::shared_ptr< Potential > clonePotential () const
 Independent instance that does not reload from disk.
virtual bool supportsBatchEvaluation () const noexcept
 Whether this potential supports batched evaluation of N systems in a single call.
virtual bool computesStress () const noexcept
 True when force() leaves a Cauchy stress that cauchyStress() can read until the next force() on this instance.
virtual Matrix3d cauchyStress () const
 Cauchy stress in eV/Angstrom^3.
virtual void forceBatchOwned (long nSystems, long nAtoms, const double *const *positions, const int *const *atomicNrs, double *const *forces, double *energies, double *variances, const double *const *boxes, const long *owners)
 Evaluate forces for 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)

Public Attributes

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

Additional Inherited Members

Public Types inherited from eonc::Potential
enum class  PotLayout : unsigned { InProcess = 1u << 0 , NeedsWorkingDirectory = 1u << 1 , Subprocess = 1u << 2 }
 How the pot is executed. Combine with bitwise or. More...
Protected Attributes inherited from eonc::Potential
PotType ptype

Detailed Description

Definition at line 24 of file CatLearnPot.h.

Constructor & Destructor Documentation

◆ CatLearnPot()

CatLearnPot::CatLearnPot ( const eonc::Parameters & a_params)

Definition at line 17 of file CatLearnPot.cpp.

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

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 38 of file CatLearnPot.cpp.

40 {
41 using namespace pybind11::literals;
42 (void)atomicNrs;
43 (void)box;
44 py::gil_scoped_acquire gil;
45 const Eigen::Map<const MatrixXd> features(positions, 1, nAtoms * 3);
46 py::tuple ef_and_unc = (this->m_gpmod.attr("predict")(
47 features, "get_variance"_a = true, "get_derivatives"_a = true));
48 auto ef_dat = ef_and_unc[0].cast<MatrixXd>();
49 auto vari = ef_and_unc[1].cast<MatrixXd>();
50 auto gradients = ef_dat.block(0, 1, 1, nAtoms * 3);
51 for (int idx = 0; idx < nAtoms; idx++) {
52 forces[3 * idx] = gradients(0, 3 * idx) * -1;
53 forces[3 * idx + 1] = gradients(0, 3 * idx + 1) * -1;
54 forces[3 * idx + 2] = gradients(0, 3 * idx + 2) * -1;
55 }
56 if (variance != nullptr) {
57 *variance = vari(0, 0); // energy variance only
58 }
59 *energy = ef_dat(0, 0);
60 return;
61}
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, eOnStorageOrder > MatrixXd
Definition Eigen.h:33

◆ 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 35 of file CatLearnPot.h.

35{ return false; }

◆ train_optimize()

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

Implements eonc::SurrogatePotential.

Definition at line 32 of file CatLearnPot.cpp.

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

Member Data Documentation

◆ m_gpmod

py::object CatLearnPot::m_gpmod

Definition at line 36 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