Loading...
Searching...
No Matches
RgpotAdapter< RPot > Class Template Referencefinal

Wraps one rgpot kernel as an eOn Potential. More...

#include <RgpotAdapter.h>

Inheritance diagram for RgpotAdapter< RPot >:

Public Member Functions

template<class Cfg>
 RgpotAdapter (PotType ptype, const Parameters &params, const Cfg &cfg)
 Kernels construct in place from their config: several hold mutexes or other immovable state, so the adapter never copies or moves them.
 RgpotAdapter (PotType ptype, const Parameters &params)
 Kernels with no configuration surface default-construct in place.
void force (long N, const double *R, const int *atomicNrs, double *F, double *U, double *variance, const double *box) override
bool supportsBatchEvaluation () const noexcept override
 Reports whether the kernel serves a batch natively.
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) override
 Hands eOn's batch straight to the kernel.
bool isThreadSafe () const noexcept override
 Whether this potential's force() can be called from multiple threads on the SAME instance.
bool needsPerImageInstance () const noexcept override
 Whether NEB should create separate Potential instances per image for true parallel force evaluation.
const RPot & kernel () const noexcept
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 isSurrogate () const noexcept
 Whether this is a surrogate (GP) potential.
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.

Private Attributes

RPot pot_

Additional Inherited Members

Public Attributes inherited from eonc::Potential
std::atomic< size_t > forceCallCounter
Protected Attributes inherited from eonc::Potential
PotType ptype

Detailed Description

template<class RPot>
class RgpotAdapter< RPot >

Wraps one rgpot kernel as an eOn Potential.

force() passes eOn's flat arrays straight into the kernel's forceImpl — the layouts match field for field, including the row-major 3x3 box — bypassing rgpot's AtomMatrix wrapper and its optional result cache. Thread-sharing policy derives from the kernel's capability descriptor instead of per-type lists.

Definition at line 27 of file RgpotAdapter.h.

Constructor & Destructor Documentation

◆ RgpotAdapter() [1/2]

template<class RPot>
template<class Cfg>
RgpotAdapter< RPot >::RgpotAdapter ( PotType ptype,
const Parameters & params,
const Cfg & cfg )
inline

Kernels construct in place from their config: several hold mutexes or other immovable state, so the adapter never copies or moves them.

Definition at line 32 of file RgpotAdapter.h.

34 pot_(cfg) {}
Wraps one rgpot kernel as an eOn Potential.
PotType ptype
Definition Potential.h:25
Potential(PotType a_ptype)
Definition Potential.h:35

◆ RgpotAdapter() [2/2]

template<class RPot>
RgpotAdapter< RPot >::RgpotAdapter ( PotType ptype,
const Parameters & params )
inline

Kernels with no configuration surface default-construct in place.

Definition at line 37 of file RgpotAdapter.h.

39 pot_() {}

Member Function Documentation

◆ force()

template<class RPot>
void RgpotAdapter< RPot >::force ( long N,
const double * R,
const int * atomicNrs,
double * F,
double * U,
double * variance,
const double * box )
inlineoverridevirtual

Implements eonc::Potential.

Definition at line 41 of file RgpotAdapter.h.

42 {
43 rgpot::ForceInput in{static_cast<size_t>(N), R, atomicNrs, box};
44 rgpot::ForceOut out{F, 0.0, 0.0};
45 pot_.forceImpl(in, &out);
46 *U = out.energy;
47 if (variance != nullptr) {
48 *variance = out.variance;
49 }
50 }

◆ forceBatch()

template<class RPot>
void RgpotAdapter< RPot >::forceBatch ( long nSystems,
long nAtoms,
const double *const * positions,
const int *const * atomicNrs,
double *const * forces,
double * energies,
double * variances,
const double *const * boxes )
inlineoverridevirtual

Hands eOn's batch straight to the kernel.

eOn batches images of one system, so every system shares an atom count; rgpot allows them to differ, and filling nAtoms per system costs nothing and keeps the two contracts independent.

Calls forceBatchImpl rather than forceBatch for the same reason force() calls forceImpl: eOn owns caching, and routing through rgpot's cache would key the same geometry twice.

Reimplemented from eonc::Potential.

Definition at line 68 of file RgpotAdapter.h.

71 {
72 const auto n = static_cast<size_t>(nSystems);
75 in.reserve(n);
76 out.reserve(n);
77 for (size_t i = 0; i < n; ++i) {
78 in.push_back(rgpot::ForceInput{static_cast<size_t>(nAtoms), positions[i],
79 atomicNrs[i], boxes[i]});
80 out.push_back(rgpot::ForceOut{forces[i], 0.0, 0.0});
81 }
82
83 pot_.forceBatchImpl(
84 rgpot::ForceBatch{.nSystems = n, .in = in.data(), .out = out.data()});
85
86 for (size_t i = 0; i < n; ++i) {
87 energies[i] = out[i].energy;
88 if (variances != nullptr) {
89 variances[i] = out[i].variance;
90 }
93 }
94 }
static PotRegistry & get() noexcept
Process-lifetime singleton.
void on_force_call(PotType t) noexcept
std::atomic< size_t > forceCallCounter
Definition Potential.h:32

◆ isThreadSafe()

template<class RPot>
bool RgpotAdapter< RPot >::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 96 of file RgpotAdapter.h.

96 {
97 return pot_.caps().reentrancy == rgpot::Reentrancy::SharedInstance;
98 }

◆ kernel()

template<class RPot>
const RPot & RgpotAdapter< RPot >::kernel ( ) const
inlinenodiscardnoexcept

Definition at line 106 of file RgpotAdapter.h.

106{ return pot_; }

◆ needsPerImageInstance()

template<class RPot>
bool RgpotAdapter< RPot >::needsPerImageInstance ( ) const
inlinenodiscardoverridevirtualnoexcept

Whether NEB should create separate Potential instances per image for true parallel force evaluation.

When true, NEB calls makePotential() once per image instead of sharing one instance. Override in potentials that use internal mutexes (e.g. MetatomicPotential).

Reimplemented from eonc::Potential.

Definition at line 100 of file RgpotAdapter.h.

100 {
101 const auto caps = pot_.caps();
102 return caps.perImageInstances ||
104 }

◆ supportsBatchEvaluation()

template<class RPot>
bool RgpotAdapter< RPot >::supportsBatchEvaluation ( ) const
inlinenodiscardoverridevirtualnoexcept

Reports whether the kernel serves a batch natively.

rgpot answers every batch call, falling back to a per-system loop, so this asks the narrower question the eOn callers care about: is one batched call cheaper than N single ones? Only a native kernel makes it so.

Reimplemented from eonc::Potential.

Definition at line 56 of file RgpotAdapter.h.

56 {
57 return pot_.caps().batched;
58 }

Member Data Documentation

◆ pot_

template<class RPot>
RPot RgpotAdapter< RPot >::pot_
private

Definition at line 109 of file RgpotAdapter.h.


The documentation for this class was generated from the following file:
  • /home/runner/work/eOn/eOn/include/eon/potentials/RgpotAdapter/RgpotAdapter.h