class pot::EnginePotential

Overview

One instance owns one engine handle. More…

#include <gpr/potentials/EnginePotential.h>
 
class EnginePotential {
public:
    // construction
 
    EnginePotential(const EnginePotential&);
    ~EnginePotential();
 
    // methods
 
    static std::unique_ptr<EnginePotential> open(const std::string& library, const std::vector<unsigned char>& config, std::string& err, bool torch_cuda = false, int oracle_threads = 1);
    static PotentialWrapper wrap(std::shared_ptr<EnginePotential> engine);
    EnginePotential& operator=(const EnginePotential&);
    int force(long n_atoms, const double* positions, const int* atomic_nrs, const double* box, double* forces, double* energy, double* variance);
    bool hasBatch() const;
    int forceBatch(long n_systems, long n_atoms, const double* positions, const int* atomic_nrs, const double* boxes, double* forces, double* energies, double* variances);
    bool hasCallbacks() const;
    int setCallbacks(const RgpotEngineCallbacks& callbacks);
    bool hasHessianChecked() const;
    int hessianChecked(long n_atoms, const double* positions, std::size_t positions_len, const int* atomic_nrs, double* hessian_out, std::size_t hessian_len, const double* box);
    bool hasHessianActionChecked() const;
    int hessianActionChecked(long n_atoms, const double* positions, std::size_t positions_len, const int* atomic_nrs, const double* direction, std::size_t direction_len, double* hv_out, std::size_t hv_len, const double* box, unsigned long long* ops_out, double* scale_out);
    bool hasPredictionSupportedChecked() const;
    int predictionSupportedChecked(long n_atoms, const double* positions, std::size_t positions_len, const int* atomic_nrs, const double* box, int* supported_out);
    bool hasGprStats() const;
    int gprStats(RgpotEngineGprStats& stats_out) const;
    unsigned long long modelState() const;
    int hint(const std::vector<unsigned char>& message, std::string& err);
    EngineAbiStamp abiStamp() const;
    int caps(EngineCaps& out, std::string& err);
    int hvp(long n_atoms, const double* positions, const int* atomic_nrs, const double* direction, double* hv_out, const double* box, std::string& err);
    int taylorJet(long n_systems, long n_atoms, const double* positions, const int* atomic_nrs, const double* directions, long order, double* jet_out, EngineDerivativeReport* report, const double* boxes, std::string& err);
    int setCache(const char* path, std::string& err);
    int cacheCounts(std::uint64_t& computed, std::uint64_t& served, std::string& err);
    std::string lastError() const;
    bool unloadSafe() const;
    int abiVersion() const;
    int threadCount() const;
    void setThreadCount(int threads);
    const std::string& library() const;
    const std::string& resolvedPath() const;
    bool dead() const;
};

Detailed Documentation

One instance owns one engine handle. caps().reentrancy says whether the plugin allows concurrent calls on that handle. This host still uses one handle from one thread; a caller that evaluates from several threads opens one instance per thread.

Methods

static std::unique_ptr<EnginePotential> open(const std::string& library, const std::vector<unsigned char>& config, std::string& err, bool torch_cuda = false, int oracle_threads = 1)

Parameters:

library

path or soname handed to dlopen (RTLD_LOCAL).

config

capnp flat-array message for the engine’s params arm.

err

failure detail when construction returns nullptr.

torch_cuda

the engine evaluates on a CUDA device: load the libtorch_cuda runtime next to the libtorch_cpu the engine brought in before the engine is created. A torch engine links libtorch_cpu only, and the CUDA hooks register when libtorch_cuda is loaded.

oracle_threads

Evaluation thread count; at least one.

static PotentialWrapper wrap(std::shared_ptr<EnginePotential> engine)

Adapt a shared engine handle to the host’s potential interface. Positive statuses throw EngineError; negative statuses mark the handle dead and throw as well.

int force(long n_atoms, const double* positions, const int* atomic_nrs, const double* box, double* forces, double* energy, double* variance)

Energy and forces for one system. Returns the engine status; zero is success. variance may be null.

bool hasBatch() const

True when the engine exports rgpot_engine_force_batch.

int forceBatch(long n_systems, long n_atoms, const double* positions, const int* atomic_nrs, const double* boxes, double* forces, double* energies, double* variances)

Strided-uniform batch: n_systems systems of one composition. boxes holds 9 doubles per system.

bool hasCallbacks() const

True when the engine exports rgpot_engine_set_callbacks.

int setCallbacks(const RgpotEngineCallbacks& callbacks)

Register host callbacks for a learning engine.

bool hasHessianChecked() const

True when the engine exports rgpot_engine_hessian_checked.

int hessianChecked(long n_atoms, const double* positions, std::size_t positions_len, const int* atomic_nrs, double* hessian_out, std::size_t hessian_len, const double* box)

Extent-checked dense Hessian at one geometry.

bool hasHessianActionChecked() const

True when the engine exports rgpot_engine_hessian_action_checked.

int hessianActionChecked(long n_atoms, const double* positions, std::size_t positions_len, const int* atomic_nrs, const double* direction, std::size_t direction_len, double* hv_out, std::size_t hv_len, const double* box, unsigned long long* ops_out, double* scale_out)

Extent-checked Hessian-vector product with optional operation accounting.

bool hasPredictionSupportedChecked() const

True when the engine exports rgpot_engine_prediction_supported_checked.

int predictionSupportedChecked(long n_atoms, const double* positions, std::size_t positions_len, const int* atomic_nrs, const double* box, int* supported_out)

Extent-checked prediction-support query.

bool hasGprStats() const

True when the engine exports rgpot_engine_gpr_stats.

int gprStats(RgpotEngineGprStats& stats_out) const

Read learning-engine operation counters.

unsigned long long modelState() const

Monotone model-state counter; zero for an engine without one.

int hint(const std::vector<unsigned char>& message, std::string& err)

Send a runtime hint message; returns the engine status, or -1 when the engine exports no hint entry point.

EngineAbiStamp abiStamp() const

The stamp the plugin reported, or {1, 0, 1} when it exports none.

int caps(EngineCaps& out, std::string& err)

rgpot_engine_caps. Returns 3 when the plugin exports no caps symbol. jet_order is zero when the written size ends before that field.

int hvp(long n_atoms, const double* positions, const int* atomic_nrs, const double* direction, double* hv_out, const double* box, std::string& err)

Analytic Hessian-vector product. Returns 3 when the plugin does not export rgpot_engine_hvp or rgpot_engine_caps, or when analytic_hvp is clear. A negative status marks the handle dead.

int taylorJet(long n_systems, long n_atoms, const double* positions, const int* atomic_nrs, const double* directions, long order, double* jet_out, EngineDerivativeReport* report, const double* boxes, std::string& err)

Directional derivatives of the gradient up to order, one uniform batch. Returns 3 when the plugin exports no jet or caps symbol, or when order exceeds jet_order. A non-finite position, direction or cell, an order below 1, and a negative or non-finite report scale are status 1 and do not replace report. Inputs and output must not overlap.

int setCache(const char* path, std::string& err)

Attach a persistent result cache, or detach it when path is null. Returns 3 when the plugin exports no rgpot_engine_set_cache.

int cacheCounts(std::uint64_t& computed, std::uint64_t& served, std::string& err)

Kernel-computed and cache-served counts since the cache was attached. Returns 3 when the plugin exports no query, or when none is attached.

std::string lastError() const

Text of rgpot_engine_last_error, or empty when the plugin exports none or there is no message.

bool unloadSafe() const

True only when the stamp minor is at least 7 and rgpot_engine_unload_policy returns RGPOT_ENGINE_UNLOAD_SAFE.

int threadCount() const

OpenMP team requested explicitly by the host for every engine call.

const std::string& resolvedPath() const

Absolute path of the loaded object, from the dynamic loader.

bool dead() const

True once a negative status was returned: the handle is unusable.