From fddcdda73c9f01f9b630c43632c38fc9fc43e905 Mon Sep 17 00:00:00 2001 From: Xinyuan Liang <64718735+xuan112358@users.noreply.github.com> Date: Thu, 8 Aug 2024 22:16:20 +0800 Subject: [PATCH] Continue to move the deepks output files into the OUT folder (#4924) * 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 86113bac04c45948551aabdc11b81bfd0515850b. * add doc --- docs/advanced/input_files/input-main.md | 2 +- .../module_deepks/LCAO_deepks_interface.cpp | 5 +++++ .../module_deepks/LCAO_deepks_io.cpp | 21 ++++++++++++------- .../module_deepks/LCAO_deepks_io.h | 4 ++++ .../module_deepks/cal_gedm.cpp | 9 ++++---- .../get_dm_eig.py | 2 +- .../get_dm_eig.py | 2 +- .../603_NO_deepks_H2O_bandgap/get_dm_eig.py | 2 +- .../603_NO_deepks_H2O_v_delta_1/get_dm_eig.py | 2 +- .../603_NO_deepks_H2O_v_delta_2/get_dm_eig.py | 2 +- .../get_dm_eig.py | 2 +- tests/integrate/tools/catch_properties.sh | 6 +++--- 12 files changed, 38 insertions(+), 21 deletions(-) diff --git a/docs/advanced/input_files/input-main.md b/docs/advanced/input_files/input-main.md index 9fee956fd0..f03bdbc55e 100644 --- a/docs/advanced/input_files/input-main.md +++ b/docs/advanced/input_files/input-main.md @@ -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 diff --git a/source/module_hamilt_lcao/module_deepks/LCAO_deepks_interface.cpp b/source/module_hamilt_lcao/module_deepks/LCAO_deepks_interface.cpp index 4da2b4a523..d9ec97d9db 100644 --- a/source/module_hamilt_lcao/module_deepks/LCAO_deepks_interface.cpp +++ b/source/module_hamilt_lcao/module_deepks/LCAO_deepks_interface.cpp @@ -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 @@ -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( @@ -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); } } @@ -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 } } @@ -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 } } diff --git a/source/module_hamilt_lcao/module_deepks/LCAO_deepks_io.cpp b/source/module_hamilt_lcao/module_deepks/LCAO_deepks_io.cpp index 722ffb73be..d6e0c8bdfa 100644 --- a/source/module_hamilt_lcao/module_deepks/LCAO_deepks_io.cpp +++ b/source/module_hamilt_lcao/module_deepks/LCAO_deepks_io.cpp @@ -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 &d_tensor, + const std::string& out_dir, const int rank) { ModuleBase::TITLE("LCAO_deepks_io", "save_npy_d"); @@ -148,8 +149,8 @@ void LCAO_deepks_io::save_npy_d(const int nat, const long unsigned dshape[] = {static_cast(nat), static_cast(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); } } @@ -167,8 +168,8 @@ void LCAO_deepks_io::save_npy_d(const int nat, const long unsigned dshape[] = {static_cast(nat), static_cast(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); } } @@ -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"); @@ -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; } @@ -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"); @@ -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; } @@ -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"); @@ -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; } diff --git a/source/module_hamilt_lcao/module_deepks/LCAO_deepks_io.h b/source/module_hamilt_lcao/module_deepks/LCAO_deepks_io.h index 96f615ce44..d20a7bf113 100644 --- a/source/module_hamilt_lcao/module_deepks/LCAO_deepks_io.h +++ b/source/module_hamilt_lcao/module_deepks/LCAO_deepks_io.h @@ -71,6 +71,7 @@ void save_npy_d(const int nat, const int* inl_l, const bool deepks_equiv, const std::vector &d_tensor, + const std::string& out_dir, const int rank); void save_npy_gvx(const int nat, @@ -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, @@ -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); }; diff --git a/source/module_hamilt_lcao/module_deepks/cal_gedm.cpp b/source/module_hamilt_lcao/module_deepks/cal_gedm.cpp index ecebbd8483..417e67ec4e 100644 --- a/source/module_hamilt_lcao/module_deepks/cal_gedm.cpp +++ b/source/module_hamilt_lcao/module_deepks/cal_gedm.cpp @@ -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) { @@ -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 @@ -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; @@ -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()); } diff --git a/tests/deepks/602_NO_deepks_d_H2O_md_lda2pbe/get_dm_eig.py b/tests/deepks/602_NO_deepks_d_H2O_md_lda2pbe/get_dm_eig.py index 8bdf34720f..47542e2e8a 100644 --- a/tests/deepks/602_NO_deepks_d_H2O_md_lda2pbe/get_dm_eig.py +++ b/tests/deepks/602_NO_deepks_d_H2O_md_lda2pbe/get_dm_eig.py @@ -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)) diff --git a/tests/deepks/602_NO_deepks_d_H2O_scf_lda2pbe/get_dm_eig.py b/tests/deepks/602_NO_deepks_d_H2O_scf_lda2pbe/get_dm_eig.py index 8bdf34720f..47542e2e8a 100644 --- a/tests/deepks/602_NO_deepks_d_H2O_scf_lda2pbe/get_dm_eig.py +++ b/tests/deepks/602_NO_deepks_d_H2O_scf_lda2pbe/get_dm_eig.py @@ -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)) diff --git a/tests/deepks/603_NO_deepks_H2O_bandgap/get_dm_eig.py b/tests/deepks/603_NO_deepks_H2O_bandgap/get_dm_eig.py index 8bdf34720f..47542e2e8a 100644 --- a/tests/deepks/603_NO_deepks_H2O_bandgap/get_dm_eig.py +++ b/tests/deepks/603_NO_deepks_H2O_bandgap/get_dm_eig.py @@ -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)) diff --git a/tests/deepks/603_NO_deepks_H2O_v_delta_1/get_dm_eig.py b/tests/deepks/603_NO_deepks_H2O_v_delta_1/get_dm_eig.py index 8bdf34720f..47542e2e8a 100644 --- a/tests/deepks/603_NO_deepks_H2O_v_delta_1/get_dm_eig.py +++ b/tests/deepks/603_NO_deepks_H2O_v_delta_1/get_dm_eig.py @@ -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)) diff --git a/tests/deepks/603_NO_deepks_H2O_v_delta_2/get_dm_eig.py b/tests/deepks/603_NO_deepks_H2O_v_delta_2/get_dm_eig.py index 8bdf34720f..47542e2e8a 100644 --- a/tests/deepks/603_NO_deepks_H2O_v_delta_2/get_dm_eig.py +++ b/tests/deepks/603_NO_deepks_H2O_v_delta_2/get_dm_eig.py @@ -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)) diff --git a/tests/deepks/603_NO_deepks_SiO2_bandgap_multik/get_dm_eig.py b/tests/deepks/603_NO_deepks_SiO2_bandgap_multik/get_dm_eig.py index 8bdf34720f..47542e2e8a 100644 --- a/tests/deepks/603_NO_deepks_SiO2_bandgap_multik/get_dm_eig.py +++ b/tests/deepks/603_NO_deepks_SiO2_bandgap_multik/get_dm_eig.py @@ -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)) diff --git a/tests/integrate/tools/catch_properties.sh b/tests/integrate/tools/catch_properties.sh index e336150826..a2ee4a2185 100755 --- a/tests/integrate/tools/catch_properties.sh +++ b/tests/integrate/tools/catch_properties.sh @@ -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 @@ -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