Class DeepSpinBackend#
Defined in File DeepSpin.h
Inheritance Relationships#
Base Type#
public deepmd::DeepBaseModelBackend(Class DeepBaseModelBackend)
Derived Types#
public deepmd::DeepSpinPT(Class DeepSpinPT)public deepmd::DeepSpinTF(Class DeepSpinTF)
Class Documentation#
- class DeepSpinBackend : public deepmd::DeepBaseModelBackend#
Deep Potential.
Subclassed by deepmd::DeepSpinPT, deepmd::DeepSpinTF
Unnamed Group
- virtual void computew(std::vector<double> &ener, std::vector<double> &force, std::vector<double> &force_mag, std::vector<double> &virial, std::vector<double> &atom_energy, std::vector<double> &atom_virial, const std::vector<double> &coord, const std::vector<double> &spin, 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, magnetic force, virial, atomic energy, and atomic virial by using this DP with spin input.
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.
force_mag – [out] The magnetic 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.
spin – [in] The spins of atoms, [0, 0, 0] if no spin. 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> &force_mag, std::vector<float> &virial, std::vector<float> &atom_energy, std::vector<float> &atom_virial, const std::vector<float> &coord, const std::vector<float> &spin, 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> &force_mag, std::vector<double> &virial, std::vector<double> &atom_energy, std::vector<double> &atom_virial, const std::vector<double> &coord, const std::vector<double> &spin, 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, magnetic force, virial, atomic energy, and atomic virial by using this DP with spin input.
Note
The double precision interface is used by LAMMPS and AMBER.
- Parameters:
ener – [out] The system energy.
force – [out] The force on each atom.
force_mag – [out] The magnetic 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.
spin – [in] The spins of atoms, [0, 0, 0] if no spin. 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> &force_mag, std::vector<float> &virial, std::vector<float> &atom_energy, std::vector<float> &atom_virial, const std::vector<float> &coord, const std::vector<float> &spin, 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#
Public Functions
- inline DeepSpinBackend()#
DP constructor without initialization.
- inline virtual ~DeepSpinBackend()#
- DeepSpinBackend(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> &force_mag, std::vector<double> &virial, std::vector<double> &atom_energy, std::vector<double> &atom_virial, const std::vector<double> &coord, const std::vector<double> &spin, 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> &force_mag, std::vector<float> &virial, std::vector<float> &atom_energy, std::vector<float> &atom_virial, const std::vector<float> &coord, const std::vector<float> &spin, 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> &force_mag, std::vector<double> &virial, std::vector<double> &atom_energy, std::vector<double> &atom_virial, const std::vector<double> &coord, const std::vector<double> &spin, 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> &force_mag, std::vector<float> &virial, std::vector<float> &atom_energy, std::vector<float> &atom_virial, const std::vector<float> &coord, const std::vector<float> &spin, 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 std::vector<bool> get_use_spin() const#
Get the per-type use_spin flags.
- Returns:
A vector of booleans indicating which atom types have spin enabled. Empty if the backend does not provide this information.
- virtual void compute_canonical_graph_gpu(double *d_atom_energy, double *d_force, double *d_force_mag, 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 float *d_spin, const int nloc, const int nall_nodes, const std::int64_t edge_storage)#
GPU-resident compact canonical graph inference backend hook.
Given a device-resident dual-CSR graph and the per-node moment, write the per-atom energy, force, magnetic 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_ccneed not link PyTorch. See DeepSpin::compute_canonical_graph_gpu for the device pointer and graph contracts.
- virtual bool uses_canonical_graph_inference() const#
- virtual bool uses_native_spin_scheme() const#
Whether the backend serves the loaded artifact under the native spin scheme, in which the magnetic moment is a per-node descriptor input and the model carries no virtual atoms. Backends of the virtual-atom scheme inherit the negative default.
- virtual void computew(std::vector<double> &ener, std::vector<double> &force, std::vector<double> &force_mag, std::vector<double> &virial, std::vector<double> &atom_energy, std::vector<double> &atom_virial, const std::vector<double> &coord, const std::vector<double> &spin, const std::vector<int> &atype, const std::vector<double> &box, const std::vector<double> &fparam, const std::vector<double> &aparam, const bool atomic) = 0#