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>
requires (!std::is_base_of_v<eonc::IPluginLoader, std::remove_cvref_t<Cfg>>)
 RgpotAdapter (eonc::PotType ptype, const eonc::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.
template<class Cfg>
requires (!std::is_base_of_v<eonc::IPluginLoader, std::remove_cvref_t<Cfg>>)
 RgpotAdapter (eonc::PotType ptype, const eonc::Parameters &params, const Cfg &cfg, eonc::IPluginLoader &loader)
 Test seam: injected loader, no process-default search-path mutation.
 RgpotAdapter (eonc::PotType ptype, const eonc::Parameters &params)
 Kernels with no configuration surface default-construct in place.
 RgpotAdapter (eonc::PotType ptype, const eonc::Parameters &params, eonc::IPluginLoader &loader)
 Test seam: injected loader, no process-default search-path mutation.
 RgpotAdapter (eonc::PotType ptype, const eonc::Parameters &params, RPot &&kernel)
 Take a pre-built kernel (ExprPot and other move-only constructors).
 RgpotAdapter (eonc::PotType ptype, const eonc::Parameters &params, RPot &&kernel, eonc::IPluginLoader &loader)
 Test seam: injected loader, no process-default search-path mutation.
void force (long N, const double *R, const int *atomicNrs, double *F, double *U, double *variance, const double *box) override
bool computesStress () const noexcept override
 True when force() leaves a Cauchy stress that cauchyStress() can read until the next force() on this instance.
Matrix3d cauchyStress () const override
 Cauchy stress from the last force() that reported one.
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 requiresIsolatedMoleculeLayout () const noexcept override
 Kernels that do not implement periodic boundaries must not have their coordinates wrapped.
bool needsPerImageInstance () const noexcept override
 Whether NEB should create separate Potential instances per image for true parallel force evaluation.
bool isSharedInstanceThreadSafe () const noexcept override
 Conservative gate for sharing one Potential instance across threads.
const RPot & kernel () const noexcept
double hessianRange () const noexcept override
 Hessian block range from HessianRangeOf<RPot>, not from whether the kernel happens to have a cutoff field.
Public Member Functions inherited from eonc::Potential
void recordForceCall () noexcept
 Charge one evaluated geometry to this potential and its owning registry.
IPotRegistry & registry () const noexcept
 The registry this potential charges its force calls to.
 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 unsigned long long surfaceEpoch () const noexcept
 Host-visible surface generation.
virtual double finiteCutoff () const noexcept
 Finite interaction range in position length units.
virtual bool isSurrogate () const noexcept
 Whether this is a surrogate (GP) potential.
virtual unsigned layoutFlags () const noexcept
virtual std::shared_ptr< Potential > clonePotential () const
 Independent instance that does not reload from disk.
virtual void bindBand (const std::vector< std::shared_ptr< Matter > > &)
 NEB calls this with the finished band before the first force evaluation, so a host surface can name each image.
virtual bool forwardsStoredCell () const noexcept
 A host that owns the cell reads the stored matrix.
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.

Private Member Functions

void finishConstruct (const eonc::Parameters &params)
void validateCaps () const
void storeStress (const rgpot::ForceOut &out)

Private Attributes

RPot pot_
eonc::IPluginLoader & loader_
Matrix3d stress_ {Matrix3d::Zero()}
bool haveStress_ {false}

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...
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 32 of file RgpotAdapter.h.

Constructor & Destructor Documentation

◆ RgpotAdapter() [1/6]

template<class RPot>
template<class Cfg>
requires (!std::is_base_of_v<eonc::IPluginLoader, std::remove_cvref_t<Cfg>>)
RgpotAdapter< RPot >::RgpotAdapter ( eonc::PotType ptype,
const eonc::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.

Production: process-default PluginLoader.

Definition at line 39 of file RgpotAdapter.h.

Wraps one rgpot kernel as an eOn Potential.
RgpotAdapter(eonc::PotType ptype, const eonc::Parameters &params, const Cfg &cfg)
Kernels construct in place from their config: several hold mutexes or other immovable state,...
PotType ptype
Definition Potential.h:47

◆ RgpotAdapter() [2/6]

template<class RPot>
template<class Cfg>
requires (!std::is_base_of_v<eonc::IPluginLoader, std::remove_cvref_t<Cfg>>)
RgpotAdapter< RPot >::RgpotAdapter ( eonc::PotType ptype,
const eonc::Parameters & params,
const Cfg & cfg,
eonc::IPluginLoader & loader )
inline

Test seam: injected loader, no process-default search-path mutation.

Definition at line 45 of file RgpotAdapter.h.

49 }
eonc::IPluginLoader & loader_
void finishConstruct(const eonc::Parameters &params)

◆ RgpotAdapter() [3/6]

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

Kernels with no configuration surface default-construct in place.

Definition at line 52 of file RgpotAdapter.h.

◆ RgpotAdapter() [4/6]

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

Test seam: injected loader, no process-default search-path mutation.

Definition at line 58 of file RgpotAdapter.h.

◆ RgpotAdapter() [5/6]

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

Take a pre-built kernel (ExprPot and other move-only constructors).

Definition at line 65 of file RgpotAdapter.h.

const RPot & kernel() const noexcept

◆ RgpotAdapter() [6/6]

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

Test seam: injected loader, no process-default search-path mutation.

Definition at line 70 of file RgpotAdapter.h.

Member Function Documentation

◆ cauchyStress()

template<class RPot>
Matrix3d RgpotAdapter< RPot >::cauchyStress ( ) const
inlinenodiscardoverridevirtual

Cauchy stress from the last force() that reported one.

sigma = (1/V) dE/dε, eV/Angstrom^3.

Reimplemented from eonc::Potential.

Definition at line 95 of file RgpotAdapter.h.

95 {
96 if (!haveStress_) {
97 throw std::logic_error("rgpot kernel did not return a stress tensor");
98 }
99 return stress_;
100 }
Matrix3d stress_

◆ computesStress()

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

True when force() leaves a Cauchy stress that cauchyStress() can read until the next force() on this instance.

Reimplemented from eonc::Potential.

Definition at line 89 of file RgpotAdapter.h.

89 {
90 return haveStress_;
91 }

◆ finishConstruct()

template<class RPot>
void RgpotAdapter< RPot >::finishConstruct ( const eonc::Parameters & params)
inlineprivate

Definition at line 182 of file RgpotAdapter.h.

182 {
183 loader_.add_config_paths(params.potential_options().potentialsPath);
184 validateCaps();
185 }
void validateCaps() const

◆ 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 77 of file RgpotAdapter.h.

78 {
79 rgpot::ForceInput in{static_cast<size_t>(N), R, atomicNrs, box};
80 rgpot::ForceOut out{F, 0.0, 0.0};
81 pot_.forceImpl(in, &out);
82 *U = out.energy;
83 if (variance != nullptr) {
84 *variance = out.variance;
85 }
87 }
void storeStress(const rgpot::ForceOut &out)

◆ 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 118 of file RgpotAdapter.h.

121 {
122 const auto n = static_cast<size_t>(nSystems);
125 in.reserve(n);
126 out.reserve(n);
127 for (size_t i = 0; i < n; ++i) {
128 in.push_back(rgpot::ForceInput{static_cast<size_t>(nAtoms), positions[i],
129 atomicNrs[i], boxes[i]});
130 out.push_back(rgpot::ForceOut{forces[i], 0.0, 0.0});
131 }
132
133 pot_.forceBatchImpl(
134 rgpot::ForceBatch{.nSystems = n, .in = in.data(), .out = out.data()});
135
136 haveStress_ = false;
137 for (size_t i = 0; i < n; ++i) {
138 energies[i] = out[i].energy;
139 if (variances != nullptr) {
140 variances[i] = out[i].variance;
141 }
142 if (out[i].has_stress) {
143 storeStress(out[i]);
144 }
146 }
147 }
void recordForceCall() noexcept
Charge one evaluated geometry to this potential and its owning registry.

◆ hessianRange()

template<class RPot>
double RgpotAdapter< RPot >::hessianRange ( ) const
inlinenodiscardoverridevirtualnoexcept

Hessian block range from HessianRangeOf<RPot>, not from whether the kernel happens to have a cutoff field.

0 leaves coloring off.

Reimplemented from eonc::Potential.

Definition at line 177 of file RgpotAdapter.h.

177 {
179 }
double acceptedHessianRange(double range) noexcept
Drop a non-positive or non-finite range so coloring stays off.

◆ isSharedInstanceThreadSafe()

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

Conservative gate for sharing one Potential instance across threads.

Defaults to isThreadSafe(); backends whose state lives outside the wrapper instance (global/common-block Fortran entry points) override this to false on their own classes.

Reimplemented from eonc::Potential.

Definition at line 166 of file RgpotAdapter.h.

166 {
167 if (pot_.caps().reentrancy != rgpot::Reentrancy::SharedInstance) {
168 return false;
169 }
171 }
virtual bool isSharedInstanceThreadSafe() const noexcept
Conservative gate for sharing one Potential instance across threads.
Definition Potential.h:167

◆ 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 149 of file RgpotAdapter.h.

149 {
150 return pot_.caps().reentrancy == rgpot::Reentrancy::SharedInstance;
151 }

◆ kernel()

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

Definition at line 173 of file RgpotAdapter.h.

173{ 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 160 of file RgpotAdapter.h.

160 {
161 const auto caps = pot_.caps();
162 return caps.perImageInstances ||
164 }

◆ requiresIsolatedMoleculeLayout()

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

Kernels that do not implement periodic boundaries must not have their coordinates wrapped.

A free cluster with an atom on the cell face is torn by that wrap on the first optimizer step.

Reimplemented from eonc::Potential.

Definition at line 156 of file RgpotAdapter.h.

156 {
157 return !pot_.caps().periodic;
158 }

◆ storeStress()

template<class RPot>
void RgpotAdapter< RPot >::storeStress ( const rgpot::ForceOut & out)
inlineprivate

Definition at line 197 of file RgpotAdapter.h.

197 {
198 haveStress_ = out.has_stress != 0;
199 if (!haveStress_) {
200 return;
201 }
202 for (int row = 0; row < 3; ++row) {
203 for (int col = 0; col < 3; ++col) {
204 stress_(row, col) = out.stress[row * 3 + col];
205 }
206 }
207 }

◆ 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 106 of file RgpotAdapter.h.

106 {
107 return pot_.caps().batched;
108 }

◆ validateCaps()

template<class RPot>
void RgpotAdapter< RPot >::validateCaps ( ) const
inlineprivate

Definition at line 187 of file RgpotAdapter.h.

187 {
188 const auto caps = pot_.caps();
189 using R = rgpot::Reentrancy;
190 if (caps.reentrancy != R::SharedInstance &&
191 caps.reentrancy != R::PerInstance &&
192 caps.reentrancy != R::ProcessSerial) {
193 throw std::runtime_error("rgpot kernel advertised an unknown reentrancy");
194 }
195 }

Member Data Documentation

◆ haveStress_

template<class RPot>
bool RgpotAdapter< RPot >::haveStress_ {false}
private

Definition at line 212 of file RgpotAdapter.h.

212{false};

◆ loader_

template<class RPot>
eonc::IPluginLoader& RgpotAdapter< RPot >::loader_
private

Definition at line 210 of file RgpotAdapter.h.

◆ pot_

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

Definition at line 209 of file RgpotAdapter.h.

◆ stress_

template<class RPot>
Matrix3d RgpotAdapter< RPot >::stress_ {Matrix3d::Zero()}
private

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