Skip to content

Commit

Permalink
Continue to move the deepks output files into the OUT folder (#4924)
Browse files Browse the repository at this point in the history
* change the output dir of dm_eig.npy

* add doc for output dir of deepks files

* change the output file of v_delta_precalc, psialpha and gevdm

* Revert "add doc for output dir of deepks files"

This reverts commit 86113ba.

* add doc
  • Loading branch information
xuan112358 authored Aug 8, 2024
1 parent 4318ae0 commit fddcdda
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 21 deletions.
2 changes: 1 addition & 1 deletion docs/advanced/input_files/input-main.md
Original file line number Diff line number Diff line change
Expand Up @@ -1880,7 +1880,7 @@ Warning: this function is not robust enough for the current version. Please try

- **Type**: Boolean
- **Availability**: numerical atomic orbital basis
- **Description**: print energy and force labels and descriptors for DeePKS training
- **Description**: Print labels and descriptors for DeePKS training in OUT.${suffix}. The names of these files start with "deepks".
- **Note**: In `LCAO` calculation, the path of a numerical descriptor (an `orb` file) is needed to be specified under the `NUMERICAL_DESCRIPTOR` tag in the `STRU` file. For example:

```text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ void LCAO_Deepks_Interface::out_deepks_labels(const double& etot,
nlocal,
ld->des_per_atom,
ld->v_delta_precalc_tensor,
GlobalV::global_out_dir,
my_rank);
}
else if(deepks_v_delta==2)//v_delta_precalc storage method 2
Expand All @@ -163,6 +164,7 @@ void LCAO_Deepks_Interface::out_deepks_labels(const double& etot,
ld->inlmax,
ld->lmaxd,
ld->psialpha_tensor,
GlobalV::global_out_dir,
my_rank);

ld->prepare_gevdm(
Expand All @@ -173,6 +175,7 @@ void LCAO_Deepks_Interface::out_deepks_labels(const double& etot,
ld->inlmax,
ld->lmaxd,
ld->gevdm_tensor,
GlobalV::global_out_dir,
my_rank);
}
}
Expand Down Expand Up @@ -211,6 +214,7 @@ void LCAO_Deepks_Interface::out_deepks_labels(const double& etot,
ld->inl_l,
GlobalV::deepks_equiv,
ld->d_tensor,
GlobalV::global_out_dir,
my_rank); // libnpy needed
}
}
Expand Down Expand Up @@ -358,6 +362,7 @@ void LCAO_Deepks_Interface::out_deepks_labels(const double& etot,
ld->inl_l,
GlobalV::deepks_equiv,
ld->d_tensor,
GlobalV::global_out_dir,
GlobalV::MY_RANK); // libnpy needed
}
}
Expand Down
21 changes: 14 additions & 7 deletions source/module_hamilt_lcao/module_deepks/LCAO_deepks_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ void LCAO_deepks_io::save_npy_d(const int nat,
const int *inl_l,
const bool deepks_equiv,
const std::vector<torch::Tensor> &d_tensor,
const std::string& out_dir,
const int rank)
{
ModuleBase::TITLE("LCAO_deepks_io", "save_npy_d");
Expand All @@ -148,8 +149,8 @@ void LCAO_deepks_io::save_npy_d(const int nat,
const long unsigned dshape[] = {static_cast<unsigned long>(nat), static_cast<unsigned long>(des_per_atom)};
if (rank == 0)
{
//std::string file_dm_eig = GlobalV::global_out_dir + "dm_eig.npy";
std::string file_dm_eig = "dm_eig.npy";
std::string file_dm_eig = out_dir + "deepks_dm_eig.npy";
//std::string file_dm_eig = "dm_eig.npy";
npy::SaveArrayAsNumpy(file_dm_eig, false, 2, dshape, npy_des);
}
}
Expand All @@ -167,8 +168,8 @@ void LCAO_deepks_io::save_npy_d(const int nat,
const long unsigned dshape[] = {static_cast<unsigned long>(nat), static_cast<unsigned long>(des_per_atom)};
if (rank == 0)
{
//std::string file_dm_eig = GlobalV::global_out_dir + "dm_eig.npy";
std::string file_dm_eig = "dm_eig.npy";
std::string file_dm_eig = out_dir + "deepks_dm_eig.npy";
//std::string file_dm_eig = "dm_eig.npy";
npy::SaveArrayAsNumpy(file_dm_eig, false, 2, dshape, npy_des);
}
}
Expand Down Expand Up @@ -448,6 +449,7 @@ void LCAO_deepks_io::save_npy_v_delta_precalc(const int nat,
const int nlocal,
const int des_per_atom,
const torch::Tensor& v_delta_precalc_tensor,
const std::string& out_dir,
const int rank)
{
ModuleBase::TITLE("LCAO_deepks_io", "save_npy_v_delta_precalc");
Expand Down Expand Up @@ -484,7 +486,8 @@ void LCAO_deepks_io::save_npy_v_delta_precalc(const int nat,
}
}
}
npy::SaveArrayAsNumpy("v_delta_precalc.npy", false, 5, gshape, npy_v_delta_precalc);
const std::string file_vdpre = out_dir + "deepks_vdpre.npy";
npy::SaveArrayAsNumpy(file_vdpre, false, 5, gshape, npy_v_delta_precalc);
return;
}

Expand All @@ -495,6 +498,7 @@ void LCAO_deepks_io::save_npy_psialpha(const int nat,
const int inlmax,
const int lmaxd,
const torch::Tensor &psialpha_tensor,
const std::string& out_dir,
const int rank)
{
ModuleBase::TITLE("LCAO_deepks_io", "save_npy_psialpha");
Expand Down Expand Up @@ -529,7 +533,8 @@ void LCAO_deepks_io::save_npy_psialpha(const int nat,
}
}
}
npy::SaveArrayAsNumpy("psialpha.npy", false, 5, gshape, npy_psialpha);
const std::string file_psialpha = out_dir + "deepks_psialpha.npy";
npy::SaveArrayAsNumpy(file_psialpha, false, 5, gshape, npy_psialpha);
return;
}

Expand All @@ -538,6 +543,7 @@ void LCAO_deepks_io::save_npy_gevdm(const int nat,
const int inlmax,
const int lmaxd,
const torch::Tensor& gevdm_tensor,
const std::string& out_dir,
const int rank)
{
ModuleBase::TITLE("LCAO_deepks_io", "save_npy_gevdm");
Expand Down Expand Up @@ -574,7 +580,8 @@ void LCAO_deepks_io::save_npy_gevdm(const int nat,
}
}
}
npy::SaveArrayAsNumpy("grad_evdm.npy", false, 5, gshape, npy_gevdm);
const std::string file_gevdm = out_dir + "deepks_gevdm.npy";
npy::SaveArrayAsNumpy(file_gevdm, false, 5, gshape, npy_gevdm);
return;
}

Expand Down
4 changes: 4 additions & 0 deletions source/module_hamilt_lcao/module_deepks/LCAO_deepks_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ void save_npy_d(const int nat,
const int* inl_l,
const bool deepks_equiv,
const std::vector<torch::Tensor> &d_tensor,
const std::string& out_dir,
const int rank);

void save_npy_gvx(const int nat,
Expand Down Expand Up @@ -124,6 +125,7 @@ void save_npy_v_delta_precalc(const int nat,
const int nlocal,
const int des_per_atom,
const torch::Tensor& v_delta_precalc_tensor,
const std::string& out_dir,
const int rank);

void save_npy_psialpha(const int nat,
Expand All @@ -132,12 +134,14 @@ void save_npy_psialpha(const int nat,
const int inlmax,
const int lmaxd,
const torch::Tensor &psialpha_tensor,
const std::string& out_dir,
const int rank);

void save_npy_gevdm(const int nat,
const int inlmax,
const int lmaxd,
const torch::Tensor& gevdm_tensor,
const std::string& out_dir,
const int rank);
};

Expand Down
9 changes: 5 additions & 4 deletions source/module_hamilt_lcao/module_deepks/cal_gedm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "module_parameter/parameter.h"


inline void generate_py_files(const int lmaxd, const int nmaxd) {
inline void generate_py_files(const int lmaxd, const int nmaxd, const std::string &out_dir) {

if (GlobalV::MY_RANK != 0)
{
Expand All @@ -33,7 +33,7 @@ inline void generate_py_files(const int lmaxd, const int nmaxd) {

ofs << "basis = load_yaml('basis.yaml')['proj_basis']" << std::endl;
ofs << "model = torch.jit.load(sys.argv[1])" << std::endl;
ofs << "dm_eig = np.expand_dims(np.load('dm_eig.npy'),0)" << std::endl;
ofs << "dm_eig = np.expand_dims(np.load('" << out_dir << "dm_eig.npy'),0)" << std::endl;
ofs << "dm_eig = torch.tensor(dm_eig, "
"dtype=torch.float64,requires_grad=True)"
<< std::endl
Expand Down Expand Up @@ -75,9 +75,10 @@ void LCAO_Deepks::cal_gedm_equiv(const int nat) {
this->inl_l,
GlobalV::deepks_equiv,
this->d_tensor,
GlobalV::global_out_dir,
GlobalV::MY_RANK); // libnpy needed

generate_py_files(this->lmaxd, this->nmaxd);
generate_py_files(this->lmaxd, this->nmaxd, GlobalV::global_out_dir);

if (GlobalV::MY_RANK == 0) {
std::string cmd = "python cal_gedm.py " + PARAM.inp.deepks_model;
Expand All @@ -94,7 +95,7 @@ void LCAO_Deepks::cal_gedm_equiv(const int nat) {
this->E_delta,
GlobalV::MY_RANK);

std::string cmd = "rm -f cal_gedm.py basis.yaml";
std::string cmd = "rm -f cal_gedm.py basis.yaml ec.npy gedm.npy";
std::system(cmd.c_str());
}

Expand Down
2 changes: 1 addition & 1 deletion tests/deepks/602_NO_deepks_d_H2O_md_lda2pbe/get_dm_eig.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import numpy
a=numpy.load('dm_eig.npy')
a=numpy.load('OUT.autotest/deepks_dm_eig.npy')
b=numpy.load('OUT.autotest/deepks_etot.npy')
c=numpy.load('OUT.autotest/deepks_ebase.npy')
print(numpy.sum(numpy.absolute(a))+numpy.sum(b)+numpy.sum(c))
2 changes: 1 addition & 1 deletion tests/deepks/602_NO_deepks_d_H2O_scf_lda2pbe/get_dm_eig.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import numpy
a=numpy.load('dm_eig.npy')
a=numpy.load('OUT.autotest/deepks_dm_eig.npy')
b=numpy.load('OUT.autotest/deepks_etot.npy')
c=numpy.load('OUT.autotest/deepks_ebase.npy')
print(numpy.sum(numpy.absolute(a))+numpy.sum(b)+numpy.sum(c))
2 changes: 1 addition & 1 deletion tests/deepks/603_NO_deepks_H2O_bandgap/get_dm_eig.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import numpy
a=numpy.load('dm_eig.npy')
a=numpy.load('OUT.autotest/deepks_dm_eig.npy')
b=numpy.load('OUT.autotest/deepks_etot.npy')
c=numpy.load('OUT.autotest/deepks_ebase.npy')
print(numpy.sum(numpy.absolute(a))+numpy.sum(b)+numpy.sum(c))
2 changes: 1 addition & 1 deletion tests/deepks/603_NO_deepks_H2O_v_delta_1/get_dm_eig.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import numpy
a=numpy.load('dm_eig.npy')
a=numpy.load('OUT.autotest/deepks_dm_eig.npy')
b=numpy.load('OUT.autotest/deepks_etot.npy')
c=numpy.load('OUT.autotest/deepks_ebase.npy')
print(numpy.sum(numpy.absolute(a))+numpy.sum(b)+numpy.sum(c))
2 changes: 1 addition & 1 deletion tests/deepks/603_NO_deepks_H2O_v_delta_2/get_dm_eig.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import numpy
a=numpy.load('dm_eig.npy')
a=numpy.load('OUT.autotest/deepks_dm_eig.npy')
b=numpy.load('OUT.autotest/deepks_etot.npy')
c=numpy.load('OUT.autotest/deepks_ebase.npy')
print(numpy.sum(numpy.absolute(a))+numpy.sum(b)+numpy.sum(c))
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import numpy
a=numpy.load('dm_eig.npy')
a=numpy.load('OUT.autotest/deepks_dm_eig.npy')
b=numpy.load('OUT.autotest/deepks_etot.npy')
c=numpy.load('OUT.autotest/deepks_ebase.npy')
print(numpy.sum(numpy.absolute(a))+numpy.sum(b)+numpy.sum(c))
6 changes: 3 additions & 3 deletions tests/integrate/tools/catch_properties.sh
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ if ! test -z "$deepks_v_delta" && [ $deepks_v_delta == 1 ]; then
echo "totalh $totalh" >>$1
totalvdelta=`python3 get_v_delta.py`
echo "totalvdelta $totalvdelta" >>$1
totalvdp=`python3 get_sum_numpy.py v_delta_precalc.npy `
totalvdp=`python3 get_sum_numpy.py OUT.autotest/deepks_vdpre.npy `
echo "totalvdp $totalvdp" >> $1
fi

Expand All @@ -504,9 +504,9 @@ if ! test -z "$deepks_v_delta" && [ $deepks_v_delta == 2 ]; then
echo "totalh $totalh" >>$1
totalvdelta=`python3 get_v_delta.py`
echo "totalvdelta $totalvdelta" >>$1
total_psialpha=`python3 get_sum_numpy.py psialpha.npy `
total_psialpha=`python3 get_sum_numpy.py OUT.autotest/deepks_psialpha.npy `
echo "total_psialpha $total_psialpha" >> $1
total_gevdm=`python3 get_sum_numpy.py grad_evdm.npy `
total_gevdm=`python3 get_sum_numpy.py OUT.autotest/deepks_gevdm.npy `
echo "total_gevdm $total_gevdm" >> $1
fi

Expand Down

0 comments on commit fddcdda

Please sign in to comment.