Class DeepPotBackend#

Inheritance Relationships#

Base Type#

Derived Types#

Class Documentation#

class DeepPotBackend : public deepmd::DeepBaseModelBackend#

Deep Potential.

Subclassed by deepmd::DeepPotJAX, deepmd::DeepPotPD, deepmd::DeepPotPT, deepmd::DeepPotTF

Unnamed Group

virtual void computew(std::vector<double> &ener, std::vector<double> &force, std::vector<double> &virial, std::vector<double> &atom_energy, std::vector<double> &atom_virial, const std::vector<double> &coord, const std::vector<int> &atype, const std::vector<double> &box, const std::vector<double> &fparam, const std::vector<double> &aparam, const bool atomic) = 0#

Evaluate the energy, force, virial, atomic energy, and atomic virial by using this DP.

Note

The double precision interface is used by i-PI, ABACUS, and CP2k.

Parameters:
  • ener[out] The system energy.

  • force[out] The force on each atom.

  • virial[out] The virial.

  • atom_energy[out] The atomic energy.

  • atom_virial[out] The atomic virial.

  • coord[in] The coordinates of atoms. The array should be of size nframes x natoms x 3.

  • atype[in] The atom types. The list should contain natoms ints.

  • box[in] The cell of the region. The array should be of size nframes x 9.

  • fparam[in] The frame parameter. The array can be of size : nframes x dim_fparam. dim_fparam. Then all frames are assumed to be provided with the same fparam.

  • aparam[in] The atomic parameter The array can be of size : nframes x natoms x dim_aparam. natoms x dim_aparam. Then all frames are assumed to be provided with the same aparam.

  • atomic[in] Request atomic energy and virial if atomic is true.

virtual void computew(std::vector<double> &ener, std::vector<float> &force, std::vector<float> &virial, std::vector<float> &atom_energy, std::vector<float> &atom_virial, const std::vector<float> &coord, const std::vector<int> &atype, const std::vector<float> &box, const std::vector<float> &fparam, const std::vector<float> &aparam, const bool atomic) = 0#

Unnamed Group

virtual void computew(std::vector<double> &ener, std::vector<double> &force, std::vector<double> &virial, std::vector<double> &atom_energy, std::vector<double> &atom_virial, const std::vector<double> &coord, const std::vector<int> &atype, const std::vector<double> &box, const int nghost, const InputNlist &inlist, const int &ago, const std::vector<double> &fparam, const std::vector<double> &aparam, const bool atomic) = 0#

Evaluate the energy, force, virial, atomic energy, and atomic virial by using this DP.

Note

The double precision interface is used by LAMMPS and AMBER.

Parameters:
  • ener[out] The system energy.

  • force[out] The force on each atom.

  • virial[out] The virial.

  • atom_energy[out] The atomic energy.

  • atom_virial[out] The atomic virial.

  • coord[in] The coordinates of atoms. The array should be of size nframes x natoms x 3.

  • atype[in] The atom types. The list should contain natoms ints.

  • box[in] The cell of the region. The array should be of size nframes x 9.

  • nghost[in] The number of ghost atoms.

  • lmp_list[in] The input neighbour list.

  • ago[in] Update the internal neighbour list if ago is 0.

  • fparam[in] The frame parameter. The array can be of size : nframes x dim_fparam. dim_fparam. Then all frames are assumed to be provided with the same fparam.

  • aparam[in] The atomic parameter The array can be of size : nframes x natoms x dim_aparam. natoms x dim_aparam. Then all frames are assumed to be provided with the same aparam.

  • atomic[in] Request atomic energy and virial if atomic is true.

virtual void computew(std::vector<double> &ener, std::vector<float> &force, std::vector<float> &virial, std::vector<float> &atom_energy, std::vector<float> &atom_virial, const std::vector<float> &coord, const std::vector<int> &atype, const std::vector<float> &box, const int nghost, const InputNlist &inlist, const int &ago, const std::vector<float> &fparam, const std::vector<float> &aparam, const bool atomic) = 0#

Unnamed Group

virtual void computew_mixed_type(std::vector<double> &ener, std::vector<double> &force, std::vector<double> &virial, std::vector<double> &atom_energy, std::vector<double> &atom_virial, const int &nframes, const std::vector<double> &coord, const std::vector<int> &atype, const std::vector<double> &box, const std::vector<double> &fparam, const std::vector<double> &aparam, const bool atomic) = 0#

Evaluate the energy, force, and virial with the mixed type by using this DP.

Note

At this time, no external program uses this interface.

Parameters:
  • ener[out] The system energy.

  • force[out] The force on each atom.

  • virial[out] The virial.

  • atom_energy[out] The atomic energy.

  • atom_virial[out] The atomic virial.

  • nframes[in] The number of frames.

  • coord[in] The coordinates of atoms. The array should be of size nframes x natoms x 3.

  • atype[in] The atom types. The array should be of size nframes x natoms.

  • box[in] The cell of the region. The array should be of size nframes x 9.

  • fparam[in] The frame parameter. The array can be of size : nframes x dim_fparam. dim_fparam. Then all frames are assumed to be provided with the same fparam.

  • aparam[in] The atomic parameter The array can be of size : nframes x natoms x dim_aparam. natoms x dim_aparam. Then all frames are assumed to be provided with the same aparam.

  • atomic[in] Request atomic energy and virial if atomic is true.

virtual void computew_mixed_type(std::vector<double> &ener, std::vector<float> &force, std::vector<float> &virial, std::vector<float> &atom_energy, std::vector<float> &atom_virial, const int &nframes, const std::vector<float> &coord, const std::vector<int> &atype, const std::vector<float> &box, const std::vector<float> &fparam, const std::vector<float> &aparam, const bool atomic) = 0#

Public Functions

inline DeepPotBackend()#

DP constructor without initialization.

inline virtual ~DeepPotBackend()#
DeepPotBackend(const std::string &model, const int &gpu_rank = 0, const std::string &file_content = "")#

DP constructor with initialization.

Parameters:
  • model[in] The name of the frozen model file.

  • gpu_rank[in] The GPU rank. Default is 0.

  • file_content[in] The content of the model file. If it is not empty, DP will read from the string instead of the file.

virtual void init(const std::string &model, const int &gpu_rank = 0, const std::string &file_content = "") = 0#

Initialize the DP.

Parameters:
  • model[in] The name of the frozen model file.

  • gpu_rank[in] The GPU rank. Default is 0.

  • file_content[in] The content of the model file. If it is not empty, DP will read from the string instead of the file.

inline virtual int dim_chg_spin() const#

Get dimension of charge/spin condition inputs. Returns 0 for backends that do not support charge/spin conditioning.

inline virtual void set_charge_spin(const std::vector<double> &charge_spin)#

Fix the charge/spin condition served for the rest of the run.

An override is needed only where the condition has to be folded into state that is built ahead of the evaluations using it, as in a compressed model whose tables are specialized to one condition. A backend that reads the condition as an ordinary per-call input has nothing to install, so the default is a no-op rather than an error: the condition still reaches such a backend on every evaluation, through the charge_spin argument of computew(). The request is refused only by a model that carries no charge/spin conditioning at all, which no route can honour.

Parameters:

charge_spin[in] The condition, of length dim_chg_spin().

inline virtual void computew(std::vector<double> &ener, std::vector<double> &force, std::vector<double> &virial, std::vector<double> &atom_energy, std::vector<double> &atom_virial, const std::vector<double> &coord, const std::vector<int> &atype, const std::vector<double> &box, const std::vector<double> &fparam, const std::vector<double> &aparam, const std::vector<double> &charge_spin, const bool atomic)#
inline virtual void computew(std::vector<double> &ener, std::vector<float> &force, std::vector<float> &virial, std::vector<float> &atom_energy, std::vector<float> &atom_virial, const std::vector<float> &coord, const std::vector<int> &atype, const std::vector<float> &box, const std::vector<float> &fparam, const std::vector<float> &aparam, const std::vector<double> &charge_spin, const bool atomic)#
inline virtual void computew(std::vector<double> &ener, std::vector<double> &force, std::vector<double> &virial, std::vector<double> &atom_energy, std::vector<double> &atom_virial, const std::vector<double> &coord, const std::vector<int> &atype, const std::vector<double> &box, const int nghost, const InputNlist &inlist, const int &ago, const std::vector<double> &fparam, const std::vector<double> &aparam, const std::vector<double> &charge_spin, const bool atomic)#
inline virtual void computew(std::vector<double> &ener, std::vector<float> &force, std::vector<float> &virial, std::vector<float> &atom_energy, std::vector<float> &atom_virial, const std::vector<float> &coord, const std::vector<int> &atype, const std::vector<float> &box, const int nghost, const InputNlist &inlist, const int &ago, const std::vector<float> &fparam, const std::vector<float> &aparam, const std::vector<double> &charge_spin, const bool atomic)#
inline virtual void computew_mixed_type(std::vector<double> &ener, std::vector<double> &force, std::vector<double> &virial, std::vector<double> &atom_energy, std::vector<double> &atom_virial, const int &nframes, const std::vector<double> &coord, const std::vector<int> &atype, const std::vector<double> &box, const std::vector<double> &fparam, const std::vector<double> &aparam, const std::vector<double> &charge_spin, const bool atomic)#
inline virtual void computew_mixed_type(std::vector<double> &ener, std::vector<float> &force, std::vector<float> &virial, std::vector<float> &atom_energy, std::vector<float> &atom_virial, const int &nframes, const std::vector<float> &coord, const std::vector<int> &atype, const std::vector<float> &box, const std::vector<float> &fparam, const std::vector<float> &aparam, const std::vector<double> &charge_spin, const bool atomic)#
virtual void compute_edges_gpu(double *d_atom_energy, double *d_force, double *d_atom_virial, const double *d_coord, const int *d_atype, const int *d_edge_index, const double *d_edge_vec, const int nloc, const int nedge)#

GPU-resident edge inference backend hook.

Given device-resident edge tensors, write the per-atom energy, force, and virial back to the device output pointers. The PyTorch Exportable backend overrides this; every other backend inherits the throwing default. The signature is torch-free so the dispatcher stays backend-agnostic and libdeepmd_cc need not link PyTorch. See DeepPot::compute_edges_gpu for the device pointer, graph, and communication contracts.

virtual void compute_edges_gpu(double *d_atom_energy, double *d_force, double *d_atom_virial, const double *d_coord, const int *d_atype, const int *d_edge_index, const double *d_edge_vec, const int nloc, const int nedge, const std::vector<double> &fparam, const std::vector<double> &aparam, const int nall_nodes, const InputNlist *comm_nlist)#
virtual void compute_edges_gpu(double *d_atom_energy, double *d_force, double *d_atom_virial, const double *d_coord, const int *d_atype, const int *d_edge_index, const float *d_edge_vec, const int nloc, const int nedge, const std::vector<double> &fparam, const std::vector<double> &aparam, const int nall_nodes, const InputNlist *comm_nlist)#
virtual void compute_canonical_graph_gpu(double *d_atom_energy, double *d_force, double *d_atom_virial, const std::int64_t *d_atype, const std::uint32_t *d_source, const float *d_edge_vec, const std::int64_t *d_destination_row_ptr, const std::int64_t *d_source_row_ptr, const std::uint32_t *d_source_order, const int nloc, const int nall_nodes, const std::int64_t edge_storage)#
virtual bool supports_device_edge_inference() const#
virtual bool uses_fp32_edge_vectors() const#
virtual bool uses_canonical_graph_inference() const#

Public Static Functions

static inline void require_addressable_charge_spin(const std::vector<double> &charge_spin)#

Reject a charge/spin condition no embedding table can address.

A descriptor embeds the condition by gathering one row of a charge table and one row of a multiplicity table, whose geometry belongs to the feature rather than to any one descriptor. Neither the gather nor the compiled kernel bounds-checks the row, so a value outside a table reads past it and a fractional value is truncated onto a neighbouring row, both of which answer for a state the caller never asked for. The bounds mirror deepmd/utils/charge_state.py, which holds the same contract for the Python boundaries.

Both tests are relational rather than equalities, which keeps them exact and lets a NaN, which compares false against everything, fall out of the range test rather than through it.

Parameters:

charge_spin[in] The condition, as {charge, multiplicity}.