Loading...
Searching...
No Matches
eonc::HostSurfacePotential Class Reference

#include <HostSurfacePotential.h>

Inheritance diagram for eonc::HostSurfacePotential:

Public Member Functions

 HostSurfacePotential (eon_relax_surface_fn fn, void *user, std::uint64_t epoch)
bool supportsBatchEvaluation () const noexcept override
 Whether this potential supports batched evaluation of N systems in a single call.
unsigned long long surfaceEpoch () const noexcept override
 Host-visible surface generation.
int lastStatus () const noexcept
void setEpoch (std::uint64_t epoch)
void bindPath (const std::vector< std::shared_ptr< Matter > > &path)
void bindBand (const std::vector< std::shared_ptr< Matter > > &path) override
 NEB calls this with the finished band before the first force evaluation, so a host surface can name each image.
bool forwardsStoredCell () const noexcept override
 A host that owns the cell reads the stored matrix.
void force (long nAtoms, const double *positions, const int *atomicNrs, double *forces, double *energy, double *variance, const double *box) override
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
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 double finiteCutoff () const noexcept
 Finite interaction range in position length units.
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 isThreadSafe () const noexcept
 Whether this potential's force() can be called from multiple threads on the SAME instance.
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 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 double hessianRange () const noexcept
 Distance beyond which every Hessian block between two atoms is exactly zero, in position length units.

Private Attributes

eon_relax_surface_fn fn_
void * user_
std::uint64_t epoch_ {0}
int last_ {0}
bool count_calls_ {true}
std::vector< std::shared_ptr< Matter > > path_

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

Definition at line 35 of file HostSurfacePotential.h.

Constructor & Destructor Documentation

◆ HostSurfacePotential()

eonc::HostSurfacePotential::HostSurfacePotential ( eon_relax_surface_fn fn,
void * user,
std::uint64_t epoch )
inline

Definition at line 37 of file HostSurfacePotential.h.

39 fn_{fn},
40 user_{user},
41 epoch_{epoch} {}
Potential(PotType a_ptype)
Production default: construction-scope registry, else PotRegistry::get().

Member Function Documentation

◆ bindBand()

void eonc::HostSurfacePotential::bindBand ( const std::vector< std::shared_ptr< Matter > > & path)
inlineoverridevirtual

NEB calls this with the finished band before the first force evaluation, so a host surface can name each image.

Reimplemented from eonc::Potential.

Definition at line 54 of file HostSurfacePotential.h.

54 {
55 bindPath(path);
56 }
void bindPath(const std::vector< std::shared_ptr< Matter > > &path)

◆ bindPath()

void eonc::HostSurfacePotential::bindPath ( const std::vector< std::shared_ptr< Matter > > & path)
inline

Definition at line 51 of file HostSurfacePotential.h.

51 {
52 path_ = path;
53 }
std::vector< std::shared_ptr< Matter > > path_

◆ force()

void eonc::HostSurfacePotential::force ( long nAtoms,
const double * positions,
const int * atomicNrs,
double * forces,
double * energy,
double * variance,
const double * box )
inlineoverridevirtual

Implements eonc::Potential.

Definition at line 61 of file HostSurfacePotential.h.

63 {
64 const double *posv[] = {positions};
65 const int *nrv[] = {atomicNrs};
66 double *frcv[] = {forces};
67 const double *boxv[] = {box};
68 double e{0};
69 double var{0};
70 count_calls_ = false;
71 forceBatch(1, nAtoms, posv, nrv, frcv, &e, &var, boxv);
72 count_calls_ = true;
73 if (energy) {
74 *energy = e;
75 }
76 if (variance) {
77 *variance = var;
78 }
79 }
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

◆ forceBatch()

void eonc::HostSurfacePotential::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

Reimplemented from eonc::Potential.

Definition at line 81 of file HostSurfacePotential.h.

84 {
85 if (!fn_) {
86 throw std::runtime_error("HostSurfacePotential: NULL surface");
87 }
88 const long npos = 3 * nAtoms * nSystems;
89 const long nbox = 9 * nSystems;
90 std::vector<double> pos(static_cast<size_t>(npos), 0.0);
91 std::vector<double> frc(static_cast<size_t>(npos), 0.0);
92 std::vector<double> box(static_cast<size_t>(nbox), 0.0);
93 std::vector<int32_t> z(static_cast<size_t>(nAtoms), 0);
94 std::vector<int64_t> ids(static_cast<size_t>(nSystems), 0);
95 if (atomicNrs && atomicNrs[0]) {
96 for (long a = 0; a < nAtoms; ++a) {
97 z[static_cast<size_t>(a)] = atomicNrs[0][a];
98 }
99 }
100 for (long s = 0; s < nSystems; ++s) {
101 int64_t id = EON_RELAX_IMAGE_NONE;
102 if (positions && positions[s]) {
103 for (size_t i = 0; i < path_.size(); ++i) {
104 if (path_[i] && path_[i]->getPositions().data() == positions[s]) {
105 id = static_cast<int64_t>(i);
106 break;
107 }
108 }
109 }
110 ids[static_cast<size_t>(s)] = id;
111 if (positions && positions[s]) {
112 for (long k = 0; k < 3 * nAtoms; ++k) {
113 pos[static_cast<size_t>(s * 3 * nAtoms + k)] = positions[s][k];
114 }
115 }
116 if (boxes && boxes[s]) {
117 for (long k = 0; k < 9; ++k) {
118 box[static_cast<size_t>(s * 9 + k)] = boxes[s][k];
119 }
120 }
121 }
122 std::vector<double> ebuf(static_cast<size_t>(nSystems), 0.0);
123 std::vector<double> vbuf(static_cast<size_t>(nSystems), 0.0);
124 std::uint64_t new_epoch = epoch_;
125 eon_relax_surface_request_t req{};
128 req.n_images = static_cast<int64_t>(nSystems);
129 req.n_atoms = static_cast<int64_t>(nAtoms);
130 req.positions = pos.data();
131 req.atomic_nrs = z.data();
132 req.boxes = box.data();
133 req.image_ids = ids.data();
134 req.energies = ebuf.data();
135 req.forces = frc.data();
136 req.variances = vbuf.data();
137 req.epoch_out = &new_epoch;
138 last_ = fn_(user_, &req);
139 if (last_ < 0) {
140 throw std::runtime_error("HostSurfacePotential: surface failed");
141 }
142 if (last_ > 0) {
143 throw SurfaceRecoverable(last_);
144 }
145 if (new_epoch != epoch_) {
146 epoch_ = new_epoch;
147 }
148 if (count_calls_) {
149 for (long s = 0; s < nSystems; ++s) {
151 }
152 }
153 for (long s = 0; s < nSystems; ++s) {
154 if (energies) {
155 energies[s] = ebuf[static_cast<size_t>(s)];
156 }
157 if (variances) {
158 variances[s] = vbuf[static_cast<size_t>(s)];
159 }
160 if (forces && forces[s]) {
161 for (long k = 0; k < 3 * nAtoms; ++k) {
162 forces[s][k] = frc[static_cast<size_t>(s * 3 * nAtoms + k)];
163 }
164 }
165 }
166 }
void recordForceCall() noexcept
Charge one evaluated geometry to this potential and its owning registry.
#define EON_RELAX_ABI_MAJOR
#define EON_RELAX_ABI_MINOR
#define EON_RELAX_IMAGE_NONE

◆ forwardsStoredCell()

bool eonc::HostSurfacePotential::forwardsStoredCell ( ) const
inlinenodiscardoverridevirtualnoexcept

A host that owns the cell reads the stored matrix.

Pots that infer periodic boundaries from a non-zero box keep seeing a zero box when the image is not periodic.

Reimplemented from eonc::Potential.

Definition at line 57 of file HostSurfacePotential.h.

57 {
58 return true;
59 }

◆ lastStatus()

int eonc::HostSurfacePotential::lastStatus ( ) const
inlinenodiscardnoexcept

Definition at line 49 of file HostSurfacePotential.h.

49{ return last_; }

◆ setEpoch()

void eonc::HostSurfacePotential::setEpoch ( std::uint64_t epoch)
inline

Definition at line 50 of file HostSurfacePotential.h.

50{ epoch_ = epoch; }

◆ supportsBatchEvaluation()

bool eonc::HostSurfacePotential::supportsBatchEvaluation ( ) const
inlinenodiscardoverridevirtualnoexcept

Whether this potential supports batched evaluation of N systems in a single call.

When true, callers (NEB, Dimer) should use forceBatch() instead of N individual force() calls for better GPU utilization.

Reimplemented from eonc::Potential.

Definition at line 43 of file HostSurfacePotential.h.

43 {
44 return true;
45 }

◆ surfaceEpoch()

unsigned long long eonc::HostSurfacePotential::surfaceEpoch ( ) const
inlinenodiscardoverridevirtualnoexcept

Host-visible surface generation.

A learning host increments this on every refit; Matter keys its energy and variance caches on the value so identical positions after a refit cannot return a stale energy or variance. Static pots stay 0.

Reimplemented from eonc::Potential.

Definition at line 46 of file HostSurfacePotential.h.

46 {
47 return epoch_;
48 }

Member Data Documentation

◆ count_calls_

bool eonc::HostSurfacePotential::count_calls_ {true}
private

Definition at line 173 of file HostSurfacePotential.h.

173{true};

◆ epoch_

std::uint64_t eonc::HostSurfacePotential::epoch_ {0}
private

Definition at line 171 of file HostSurfacePotential.h.

171{0};

◆ fn_

eon_relax_surface_fn eonc::HostSurfacePotential::fn_
private

Definition at line 169 of file HostSurfacePotential.h.

◆ last_

int eonc::HostSurfacePotential::last_ {0}
private

Definition at line 172 of file HostSurfacePotential.h.

172{0};

◆ path_

std::vector<std::shared_ptr<Matter> > eonc::HostSurfacePotential::path_
private

Definition at line 174 of file HostSurfacePotential.h.

◆ user_

void* eonc::HostSurfacePotential::user_
private

Definition at line 170 of file HostSurfacePotential.h.


The documentation for this class was generated from the following file: