ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
KEDF_ML Class Reference

#include <kedf_ml.h>

Collaboration diagram for KEDF_ML:

Public Member Functions

 KEDF_ML ()
 
 ~KEDF_ML ()
 
void set_para (const int nx, const double dV, const double nelec, const double tf_weight, const double vw_weight, const double chi_p, const double chi_q, const std::vector< double > &chi_xi, const std::vector< double > &chi_pnl, const std::vector< double > &chi_qnl, const int &nkernel, const std::vector< int > &kernel_type, const std::vector< double > &kernel_scaling, const std::vector< double > &yukawa_alpha, const std::vector< std::string > &kernel_file, const bool &of_ml_gamma, const bool &of_ml_p, const bool &of_ml_q, const bool &of_ml_tanhp, const bool &of_ml_tanhq, const std::vector< int > &of_ml_gammanl, const std::vector< int > &of_ml_pnl, const std::vector< int > &of_ml_qnl, const std::vector< int > &of_ml_xi, const std::vector< int > &of_ml_tanhxi, const std::vector< int > &of_ml_tanhxi_nl, const std::vector< int > &of_ml_tanh_pnl, const std::vector< int > &of_ml_tanh_qnl, const std::vector< int > &of_ml_tanhp_nl, const std::vector< int > &of_ml_tanhq_nl, const std::string device_inpt, ModulePW::PW_Basis *pw_rho)
 
void set_device (std::string device_inpt)
 Set the device for ML KEDF.
 
double get_energy (const double *const *prho, ModulePW::PW_Basis *pw_rho)
 Get the energy of ML KEDF.
 
void ml_potential (const double *const *prho, ModulePW::PW_Basis *pw_rho, ModuleBase::matrix &rpotential)
 Get the potential of ML KEDF, and add it into rpotential.
 
void generateTrainData (const double *const *prho, ModulePW::PW_Basis *pw_rho, const double *veff)
 Generate training data for ML KEDF.
 
void localTest (const double *const *prho, ModulePW::PW_Basis *pw_rho)
 For test.
 
void NN_forward (const double *const *prho, ModulePW::PW_Basis *pw_rho, bool cal_grad)
 Interface to Neural Network forward.
 
void get_potential_ (const double *const *prho, ModulePW::PW_Basis *pw_rho, ModuleBase::matrix &rpotential)
 Calculate the Pauli potential of ML KEDF.
 
double potGammaTerm (int ir)
 
double potPTerm1 (int ir)
 
double potQTerm1 (int ir)
 
double potXiTerm1 (int ir)
 
double potTanhxiTerm1 (int ir)
 
double potTanhpTerm1 (int ir)
 
double potTanhqTerm1 (int ir)
 
void potGammanlTerm (const double *const *prho, ModulePW::PW_Basis *pw_rho, std::vector< double > &rGammanlTerm)
 
void potXinlTerm (const double *const *prho, ModulePW::PW_Basis *pw_rho, std::vector< double > &rXinlTerm)
 
void potTanhxinlTerm (const double *const *prho, ModulePW::PW_Basis *pw_rho, std::vector< double > &rTanhxinlTerm)
 
void potTanhxi_nlTerm (const double *const *prho, ModulePW::PW_Basis *pw_rho, std::vector< double > &rTanhxi_nlTerm)
 
void potPPnlTerm (const double *const *prho, ModulePW::PW_Basis *pw_rho, std::vector< double > &rPPnlTerm)
 
void potQQnlTerm (const double *const *prho, ModulePW::PW_Basis *pw_rho, std::vector< double > &rQQnlTerm)
 
void potTanhpTanh_pnlTerm (const double *const *prho, ModulePW::PW_Basis *pw_rho, std::vector< double > &rTanhpTanh_pnlTerm)
 
void potTanhqTanh_qnlTerm (const double *const *prho, ModulePW::PW_Basis *pw_rho, std::vector< double > &rTanhqTanh_qnlTerm)
 
void potTanhpTanhp_nlTerm (const double *const *prho, ModulePW::PW_Basis *pw_rho, std::vector< double > &rTanhpTanhp_nlTerm)
 
void potTanhqTanhq_nlTerm (const double *const *prho, ModulePW::PW_Basis *pw_rho, std::vector< double > &rTanhqTanhq_nlTerm)
 
void loadVector (std::string filename, std::vector< double > &data)
 
void dumpVector (std::string filename, const std::vector< double > &data)
 
void dumpTensor (std::string filename, const torch::Tensor &data)
 Dump the torch::Tensor into .npy file.
 
void dumpMatrix (std::string filename, const ModuleBase::matrix &data)
 Dump the matrix into .npy file.
 
void updateInput (const double *const *prho, ModulePW::PW_Basis *pw_rho)
 Update the desciptors for ML KEDF.
 
void init_data (const int &nkernel, const bool &of_ml_gamma, const bool &of_ml_p, const bool &of_ml_q, const bool &of_ml_tanhp, const bool &of_ml_tanhq, const std::vector< int > &of_ml_gammanl_, const std::vector< int > &of_ml_pnl, const std::vector< int > &of_ml_qnl, const std::vector< int > &of_ml_xi, const std::vector< int > &of_ml_tanhxi, const std::vector< int > &of_ml_tanhxi_nl, const std::vector< int > &of_ml_tanh_pnl, const std::vector< int > &of_ml_tanh_qnl, const std::vector< int > &of_ml_tanhp_nl, const std::vector< int > &of_ml_tanhq_nl)
 Initialize the data for ML KEDF, and generate the mapping between descriptor and kernel.
 
torch::Tensor get_data (std::string parameter, const int ikernel)
 Return the descriptors for ML KEDF.
 

Public Attributes

ModuleIO::Cal_MLKEDF_Descriptorscal_tool = nullptr
 
int nx = 0
 
int nx_tot = 0
 
double dV = 0.
 
const double cTF = 3.0/10.0 * std::pow(3*std::pow(M_PI, 2.0), 2.0/3.0) * 2
 
const double pqcoef = 1.0 / (4.0 * std::pow(3*std::pow(M_PI, 2.0), 2.0/3.0))
 
double ml_energy = 0.
 
double feg_net_F = 0.
 
double feg3_correct = 0.541324854612918
 
int ninput = 0
 
std::vector< double > gamma = {}
 
std::vector< double > p = {}
 
std::vector< double > q = {}
 
std::vector< std::vector< double > > gammanl = {}
 
std::vector< std::vector< double > > pnl = {}
 
std::vector< std::vector< double > > qnl = {}
 
std::vector< std::vector< double > > nablaRho = {}
 
std::vector< double > chi_xi = {1.0}
 
double chi_p = 1.
 
double chi_q = 1.
 
std::vector< std::vector< double > > xi = {}
 
std::vector< std::vector< double > > tanhxi = {}
 
std::vector< std::vector< double > > tanhxi_nl = {}
 
std::vector< double > tanhp = {}
 
std::vector< double > tanhq = {}
 
std::vector< double > chi_pnl = {1.0}
 
std::vector< double > chi_qnl = {1.0}
 
std::vector< std::vector< double > > tanh_pnl = {}
 
std::vector< std::vector< double > > tanh_qnl = {}
 
std::vector< std::vector< double > > tanhp_nl = {}
 
std::vector< std::vector< double > > tanhq_nl = {}
 
torch::DeviceType device_type = torch::kCPU
 
torch::Device device = torch::Device(torch::kCPU)
 
torch::Device device_CPU = torch::Device(torch::kCPU)
 
std::shared_ptr< NN_OFImplnn
 
double * enhancement_cpu_ptr = nullptr
 
double * gradient_cpu_ptr = nullptr
 
int nkernel = 1
 
bool ml_gamma = false
 
bool ml_p = false
 
bool ml_q = false
 
bool ml_tanhp = false
 
bool ml_tanhq = false
 
bool ml_gammanl = false
 
bool ml_pnl = false
 
bool ml_qnl = false
 
bool ml_xi = false
 
bool ml_tanhxi = false
 
bool ml_tanhxi_nl = false
 
bool ml_tanh_pnl = false
 
bool ml_tanh_qnl = false
 
bool ml_tanhp_nl = false
 
bool ml_tanhq_nl = false
 
std::vector< std::string > descriptor_type = {}
 
std::vector< int > kernel_index = {}
 
std::map< std::string, std::vector< int > > descriptor2kernel = {}
 
std::map< std::string, std::vector< int > > descriptor2index = {}
 
std::map< std::string, std::vector< bool > > gene_data_label = {}
 

Constructor & Destructor Documentation

◆ KEDF_ML()

KEDF_ML::KEDF_ML ( )
inline

◆ ~KEDF_ML()

KEDF_ML::~KEDF_ML ( )
inline

Member Function Documentation

◆ dumpMatrix()

void KEDF_ML::dumpMatrix ( std::string  filename,
const ModuleBase::matrix data 
)

Dump the matrix into .npy file.

Parameters
datamatrix
filenamefile name
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dumpTensor()

void KEDF_ML::dumpTensor ( std::string  filename,
const torch::Tensor &  data 
)

Dump the torch::Tensor into .npy file.

Parameters
datatorch::Tensor
filenamefile name
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dumpVector()

void KEDF_ML::dumpVector ( std::string  filename,
const std::vector< double > &  data 
)
Here is the caller graph for this function:

◆ generateTrainData()

void KEDF_ML::generateTrainData ( const double *const *  prho,
ModulePW::PW_Basis pw_rho,
const double *  veff 
)

Generate training data for ML KEDF.

Parameters
prhocharge density
wtKEDF_WT
tfKEDF_TF
pw_rhoPW_Basis
veffeffective potential
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_data()

torch::Tensor KEDF_ML::get_data ( std::string  parameter,
const int  ikernel 
)

Return the descriptors for ML KEDF.

Parameters
parameter"gamma", "p", "q", "tanhp", "tanhq", "gammanl", "pnl", "qnl", "xi", "tanhxi", "tanhxi_nl", "tanh_pnl", "tanh_qnl", "tanhp_nl", "tanhq_nl"
ikernelkernel index

◆ get_energy()

double KEDF_ML::get_energy ( const double *const *  prho,
ModulePW::PW_Basis pw_rho 
)

Get the energy of ML KEDF.

\[ E_{ML} = c_{TF} * \int{F(\rho) \rho^{5/3} dr} \]

Parameters
prhocharge density
pw_rhoPW_Basis
Returns
the energy of ML KEDF
Here is the call graph for this function:

◆ get_potential_()

void KEDF_ML::get_potential_ ( const double *const *  prho,
ModulePW::PW_Basis pw_rho,
ModuleBase::matrix rpotential 
)

Calculate the Pauli potential of ML KEDF.

Parameters
prhocharge density
pw_rhoPW_Basis
rpotentialrpotential => rpotential + V_{ML}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ init_data()

void KEDF_ML::init_data ( const int &  nkernel,
const bool &  of_ml_gamma,
const bool &  of_ml_p,
const bool &  of_ml_q,
const bool &  of_ml_tanhp,
const bool &  of_ml_tanhq,
const std::vector< int > &  of_ml_gammanl,
const std::vector< int > &  of_ml_pnl,
const std::vector< int > &  of_ml_qnl,
const std::vector< int > &  of_ml_xi,
const std::vector< int > &  of_ml_tanhxi,
const std::vector< int > &  of_ml_tanhxi_nl,
const std::vector< int > &  of_ml_tanh_pnl,
const std::vector< int > &  of_ml_tanh_qnl,
const std::vector< int > &  of_ml_tanhp_nl,
const std::vector< int > &  of_ml_tanhq_nl 
)

Initialize the data for ML KEDF, and generate the mapping between descriptor and kernel.

Parameters
nkernelnumber of kernels
of_ml_gammawhether to use gamma descriptor
of_ml_pwhether to use p descriptor
of_ml_qwhether to use q descriptor
of_ml_tanhpwhether to use tanhp descriptor
of_ml_tanhqwhether to use tanhq descriptor
of_ml_gammanlwhether to use gammanl descriptor
of_ml_pnlwhether to use pnl descriptor
of_ml_qnlwhether to use qnl descriptor
of_ml_xiwhether to use xi descriptor
of_ml_tanhxiwhether to use tanhxi descriptor
of_ml_tanhxi_nlwhether to use tanhxi_nl descriptor
of_ml_tanh_pnlwhether to use tanh_pnl descriptor
of_ml_tanh_qnlwhether to use tanh_qnl descriptor
of_ml_tanhp_nlwhether to use tanhp_nl descriptor
of_ml_tanhq_nlwhether to use tanhq_nl descriptor
Here is the caller graph for this function:

◆ loadVector()

void KEDF_ML::loadVector ( std::string  filename,
std::vector< double > &  data 
)
Here is the caller graph for this function:

◆ localTest()

void KEDF_ML::localTest ( const double *const *  pprho,
ModulePW::PW_Basis pw_rho 
)

For test.

Parameters
prhocharge density
pw_rhoPW_Basis
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ml_potential()

void KEDF_ML::ml_potential ( const double *const *  prho,
ModulePW::PW_Basis pw_rho,
ModuleBase::matrix rpotential 
)

Get the potential of ML KEDF, and add it into rpotential.

Parameters
prhocharge density
pw_rhoPW_Basis
rpotentialrpotential => rpotential + V_{ML}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ NN_forward()

void KEDF_ML::NN_forward ( const double *const *  prho,
ModulePW::PW_Basis pw_rho,
bool  cal_grad 
)

Interface to Neural Network forward.

Parameters
prhocharge density
pw_rhoPW_Basis
cal_gradwhether to calculate the gradient
Here is the call graph for this function:
Here is the caller graph for this function:

◆ potGammanlTerm()

void KEDF_ML::potGammanlTerm ( const double *const *  prho,
ModulePW::PW_Basis pw_rho,
std::vector< double > &  rGammanlTerm 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ potGammaTerm()

double KEDF_ML::potGammaTerm ( int  ir)
Here is the caller graph for this function:

◆ potPPnlTerm()

void KEDF_ML::potPPnlTerm ( const double *const *  prho,
ModulePW::PW_Basis pw_rho,
std::vector< double > &  rPPnlTerm 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ potPTerm1()

double KEDF_ML::potPTerm1 ( int  ir)
Here is the caller graph for this function:

◆ potQQnlTerm()

void KEDF_ML::potQQnlTerm ( const double *const *  prho,
ModulePW::PW_Basis pw_rho,
std::vector< double > &  rQQnlTerm 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ potQTerm1()

double KEDF_ML::potQTerm1 ( int  ir)
Here is the caller graph for this function:

◆ potTanhpTanh_pnlTerm()

void KEDF_ML::potTanhpTanh_pnlTerm ( const double *const *  prho,
ModulePW::PW_Basis pw_rho,
std::vector< double > &  rTanhpTanh_pnlTerm 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ potTanhpTanhp_nlTerm()

void KEDF_ML::potTanhpTanhp_nlTerm ( const double *const *  prho,
ModulePW::PW_Basis pw_rho,
std::vector< double > &  rTanhpTanhp_nlTerm 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ potTanhpTerm1()

double KEDF_ML::potTanhpTerm1 ( int  ir)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ potTanhqTanh_qnlTerm()

void KEDF_ML::potTanhqTanh_qnlTerm ( const double *const *  prho,
ModulePW::PW_Basis pw_rho,
std::vector< double > &  rTanhqTanh_qnlTerm 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ potTanhqTanhq_nlTerm()

void KEDF_ML::potTanhqTanhq_nlTerm ( const double *const *  prho,
ModulePW::PW_Basis pw_rho,
std::vector< double > &  rTanhqTanhq_nlTerm 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ potTanhqTerm1()

double KEDF_ML::potTanhqTerm1 ( int  ir)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ potTanhxi_nlTerm()

void KEDF_ML::potTanhxi_nlTerm ( const double *const *  prho,
ModulePW::PW_Basis pw_rho,
std::vector< double > &  rTanhxi_nlTerm 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ potTanhxinlTerm()

void KEDF_ML::potTanhxinlTerm ( const double *const *  prho,
ModulePW::PW_Basis pw_rho,
std::vector< double > &  rTanhxinlTerm 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ potTanhxiTerm1()

double KEDF_ML::potTanhxiTerm1 ( int  ir)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ potXinlTerm()

void KEDF_ML::potXinlTerm ( const double *const *  prho,
ModulePW::PW_Basis pw_rho,
std::vector< double > &  rXinlTerm 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ potXiTerm1()

double KEDF_ML::potXiTerm1 ( int  ir)
Here is the caller graph for this function:

◆ set_device()

void KEDF_ML::set_device ( std::string  device_inpt)

Set the device for ML KEDF.

Parameters
device_inpt"cpu" or "gpu"
Here is the caller graph for this function:

◆ set_para()

void KEDF_ML::set_para ( const int  nx,
const double  dV,
const double  nelec,
const double  tf_weight,
const double  vw_weight,
const double  chi_p,
const double  chi_q,
const std::vector< double > &  chi_xi,
const std::vector< double > &  chi_pnl,
const std::vector< double > &  chi_qnl,
const int &  nkernel,
const std::vector< int > &  kernel_type,
const std::vector< double > &  kernel_scaling,
const std::vector< double > &  yukawa_alpha,
const std::vector< std::string > &  kernel_file,
const bool &  of_ml_gamma,
const bool &  of_ml_p,
const bool &  of_ml_q,
const bool &  of_ml_tanhp,
const bool &  of_ml_tanhq,
const std::vector< int > &  of_ml_gammanl,
const std::vector< int > &  of_ml_pnl,
const std::vector< int > &  of_ml_qnl,
const std::vector< int > &  of_ml_xi,
const std::vector< int > &  of_ml_tanhxi,
const std::vector< int > &  of_ml_tanhxi_nl,
const std::vector< int > &  of_ml_tanh_pnl,
const std::vector< int > &  of_ml_tanh_qnl,
const std::vector< int > &  of_ml_tanhp_nl,
const std::vector< int > &  of_ml_tanhq_nl,
const std::string  device_inpt,
ModulePW::PW_Basis pw_rho 
)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ updateInput()

void KEDF_ML::updateInput ( const double *const *  prho,
ModulePW::PW_Basis pw_rho 
)

Update the desciptors for ML KEDF.

Parameters
prhocharge density
pw_rhoPW_Basis
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ cal_tool

ModuleIO::Cal_MLKEDF_Descriptors* KEDF_ML::cal_tool = nullptr

◆ chi_p

double KEDF_ML::chi_p = 1.

◆ chi_pnl

std::vector<double> KEDF_ML::chi_pnl = {1.0}

◆ chi_q

double KEDF_ML::chi_q = 1.

◆ chi_qnl

std::vector<double> KEDF_ML::chi_qnl = {1.0}

◆ chi_xi

std::vector<double> KEDF_ML::chi_xi = {1.0}

◆ cTF

const double KEDF_ML::cTF = 3.0/10.0 * std::pow(3*std::pow(M_PI, 2.0), 2.0/3.0) * 2

◆ descriptor2index

std::map<std::string, std::vector<int> > KEDF_ML::descriptor2index = {}

◆ descriptor2kernel

std::map<std::string, std::vector<int> > KEDF_ML::descriptor2kernel = {}

◆ descriptor_type

std::vector<std::string> KEDF_ML::descriptor_type = {}

◆ device

torch::Device KEDF_ML::device = torch::Device(torch::kCPU)

◆ device_CPU

torch::Device KEDF_ML::device_CPU = torch::Device(torch::kCPU)

◆ device_type

torch::DeviceType KEDF_ML::device_type = torch::kCPU

◆ dV

double KEDF_ML::dV = 0.

◆ enhancement_cpu_ptr

double* KEDF_ML::enhancement_cpu_ptr = nullptr

◆ feg3_correct

double KEDF_ML::feg3_correct = 0.541324854612918

◆ feg_net_F

double KEDF_ML::feg_net_F = 0.

◆ gamma

std::vector<double> KEDF_ML::gamma = {}

◆ gammanl

std::vector<std::vector<double> > KEDF_ML::gammanl = {}

◆ gene_data_label

std::map<std::string, std::vector<bool> > KEDF_ML::gene_data_label = {}

◆ gradient_cpu_ptr

double* KEDF_ML::gradient_cpu_ptr = nullptr

◆ kernel_index

std::vector<int> KEDF_ML::kernel_index = {}

◆ ml_energy

double KEDF_ML::ml_energy = 0.

◆ ml_gamma

bool KEDF_ML::ml_gamma = false

◆ ml_gammanl

bool KEDF_ML::ml_gammanl = false

◆ ml_p

bool KEDF_ML::ml_p = false

◆ ml_pnl

bool KEDF_ML::ml_pnl = false

◆ ml_q

bool KEDF_ML::ml_q = false

◆ ml_qnl

bool KEDF_ML::ml_qnl = false

◆ ml_tanh_pnl

bool KEDF_ML::ml_tanh_pnl = false

◆ ml_tanh_qnl

bool KEDF_ML::ml_tanh_qnl = false

◆ ml_tanhp

bool KEDF_ML::ml_tanhp = false

◆ ml_tanhp_nl

bool KEDF_ML::ml_tanhp_nl = false

◆ ml_tanhq

bool KEDF_ML::ml_tanhq = false

◆ ml_tanhq_nl

bool KEDF_ML::ml_tanhq_nl = false

◆ ml_tanhxi

bool KEDF_ML::ml_tanhxi = false

◆ ml_tanhxi_nl

bool KEDF_ML::ml_tanhxi_nl = false

◆ ml_xi

bool KEDF_ML::ml_xi = false

◆ nablaRho

std::vector<std::vector<double> > KEDF_ML::nablaRho = {}

◆ ninput

int KEDF_ML::ninput = 0

◆ nkernel

int KEDF_ML::nkernel = 1

◆ nn

std::shared_ptr<NN_OFImpl> KEDF_ML::nn

◆ nx

int KEDF_ML::nx = 0

◆ nx_tot

int KEDF_ML::nx_tot = 0

◆ p

std::vector<double> KEDF_ML::p = {}

◆ pnl

std::vector<std::vector<double> > KEDF_ML::pnl = {}

◆ pqcoef

const double KEDF_ML::pqcoef = 1.0 / (4.0 * std::pow(3*std::pow(M_PI, 2.0), 2.0/3.0))

◆ q

std::vector<double> KEDF_ML::q = {}

◆ qnl

std::vector<std::vector<double> > KEDF_ML::qnl = {}

◆ tanh_pnl

std::vector<std::vector<double> > KEDF_ML::tanh_pnl = {}

◆ tanh_qnl

std::vector<std::vector<double> > KEDF_ML::tanh_qnl = {}

◆ tanhp

std::vector<double> KEDF_ML::tanhp = {}

◆ tanhp_nl

std::vector<std::vector<double> > KEDF_ML::tanhp_nl = {}

◆ tanhq

std::vector<double> KEDF_ML::tanhq = {}

◆ tanhq_nl

std::vector<std::vector<double> > KEDF_ML::tanhq_nl = {}

◆ tanhxi

std::vector<std::vector<double> > KEDF_ML::tanhxi = {}

◆ tanhxi_nl

std::vector<std::vector<double> > KEDF_ML::tanhxi_nl = {}

◆ xi

std::vector<std::vector<double> > KEDF_ML::xi = {}

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