From db4fd5a453a0923a4a326409f3abc4f2cd6c1a59 Mon Sep 17 00:00:00 2001 From: dyzheng Date: Tue, 9 Jan 2024 10:46:01 +0800 Subject: [PATCH 1/2] Fix: bug of training force and stress with DeePKS (#3444) * Fix: bug of training force and stress with DeePKS * add test checklist for dm_eig.npy and grad_vx.npy and grad_vepsl.npy --- .../module_deepks/LCAO_deepks_pdm.cpp | 2 +- .../deepks/602_NO_deepks_d_H2O_scf_lda2pbe/INPUT | 3 ++- .../602_NO_deepks_d_H2O_scf_lda2pbe/get_dm_eig.py | 5 +++++ .../get_grad_vepsl.py | 5 +++++ .../get_grad_vx.py | 5 +++++ .../602_NO_deepks_d_H2O_scf_lda2pbe/result.ref | 11 +++++++---- .../603_NO_deepks_SiO2_bandgap_multik/INPUT | 4 ++-- .../get_dm_eig.py | 5 +++++ .../get_grad_vepsl.py | 5 +++++ .../get_grad_vx.py | 5 +++++ .../603_NO_deepks_SiO2_bandgap_multik/result.ref | 15 +++++++++------ 11 files changed, 51 insertions(+), 14 deletions(-) create mode 100644 tests/deepks/602_NO_deepks_d_H2O_scf_lda2pbe/get_dm_eig.py create mode 100644 tests/deepks/602_NO_deepks_d_H2O_scf_lda2pbe/get_grad_vepsl.py create mode 100644 tests/deepks/602_NO_deepks_d_H2O_scf_lda2pbe/get_grad_vx.py create mode 100644 tests/deepks/603_NO_deepks_SiO2_bandgap_multik/get_dm_eig.py create mode 100644 tests/deepks/603_NO_deepks_SiO2_bandgap_multik/get_grad_vepsl.py create mode 100644 tests/deepks/603_NO_deepks_SiO2_bandgap_multik/get_grad_vx.py diff --git a/source/module_hamilt_lcao/module_deepks/LCAO_deepks_pdm.cpp b/source/module_hamilt_lcao/module_deepks/LCAO_deepks_pdm.cpp index c6c56557a0..bf21360ebe 100644 --- a/source/module_hamilt_lcao/module_deepks/LCAO_deepks_pdm.cpp +++ b/source/module_hamilt_lcao/module_deepks/LCAO_deepks_pdm.cpp @@ -805,9 +805,9 @@ void LCAO_Deepks::cal_gdmx_k(const std::vector> key_tuple key_2(ibt2,dR2.x,dR2.y,dR2.z); for (int iw1l = 0; iw1l < row_indexes.size(); ++iw1l) { - std::vector nlm1 = this->nlm_save_k[iat][key_1][row_indexes[iw1l]][0]; for (int iw2l = 0; iw2l < col_indexes.size(); ++iw2l) { + std::vector nlm1 = this->nlm_save_k[iat][key_1][row_indexes[iw1l]][0]; std::vector> nlm2 = this->nlm_save_k[iat][key_2][col_indexes[iw2l]]; assert(nlm1.size()==nlm2[0].size()); diff --git a/tests/deepks/602_NO_deepks_d_H2O_scf_lda2pbe/INPUT b/tests/deepks/602_NO_deepks_d_H2O_scf_lda2pbe/INPUT index e83f234188..6694f2e12a 100644 --- a/tests/deepks/602_NO_deepks_d_H2O_scf_lda2pbe/INPUT +++ b/tests/deepks/602_NO_deepks_d_H2O_scf_lda2pbe/INPUT @@ -26,7 +26,8 @@ mixing_type broyden mixing_beta 0.4 #Parameters (6.File) -deepks_out_labels 0 +deepks_out_labels 1 deepks_scf 1 deepks_model model_lda_pbe_18.ptg cal_force 1 +cal_stress 1 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 new file mode 100644 index 0000000000..418c658dee --- /dev/null +++ b/tests/deepks/602_NO_deepks_d_H2O_scf_lda2pbe/get_dm_eig.py @@ -0,0 +1,5 @@ +import numpy +a=numpy.load('dm_eig.npy') +b=numpy.load('e_tot.npy') +c=numpy.load('e_base.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_grad_vepsl.py b/tests/deepks/602_NO_deepks_d_H2O_scf_lda2pbe/get_grad_vepsl.py new file mode 100644 index 0000000000..e6d1fccc40 --- /dev/null +++ b/tests/deepks/602_NO_deepks_d_H2O_scf_lda2pbe/get_grad_vepsl.py @@ -0,0 +1,5 @@ +import numpy +a=numpy.load('grad_vepsl.npy') +b=numpy.load('s_tot.npy') +c=numpy.load('s_base.npy') +print(numpy.sum(numpy.absolute(a))+numpy.sum(numpy.absolute(b))+numpy.sum(numpy.absolute(c))) diff --git a/tests/deepks/602_NO_deepks_d_H2O_scf_lda2pbe/get_grad_vx.py b/tests/deepks/602_NO_deepks_d_H2O_scf_lda2pbe/get_grad_vx.py new file mode 100644 index 0000000000..1cbc2f36a0 --- /dev/null +++ b/tests/deepks/602_NO_deepks_d_H2O_scf_lda2pbe/get_grad_vx.py @@ -0,0 +1,5 @@ +import numpy +a=numpy.load('grad_vx.npy') +b=numpy.load('f_tot.npy') +c=numpy.load('f_base.npy') +print(numpy.sum(numpy.absolute(a))+numpy.sum(numpy.absolute(b))+numpy.sum(numpy.absolute(c))) diff --git a/tests/deepks/602_NO_deepks_d_H2O_scf_lda2pbe/result.ref b/tests/deepks/602_NO_deepks_d_H2O_scf_lda2pbe/result.ref index 5a5b70e445..4eb979d9b1 100644 --- a/tests/deepks/602_NO_deepks_d_H2O_scf_lda2pbe/result.ref +++ b/tests/deepks/602_NO_deepks_d_H2O_scf_lda2pbe/result.ref @@ -1,4 +1,7 @@ -etotref -466.0342708510963 -etotperatomref -155.3447569504 -totalforceref 3.194930 -totaltimeref 2.7808 +etotref -466.0342709734276241 +etotperatomref -155.3447569911 +totalforceref 3.194893 +totalstressref 1.190505 +totaldes 2.319513 +deepks_e_dm -57.521935318566165 +totaltimeref 5.79 diff --git a/tests/deepks/603_NO_deepks_SiO2_bandgap_multik/INPUT b/tests/deepks/603_NO_deepks_SiO2_bandgap_multik/INPUT index 384ead0cc6..cef0bd1354 100644 --- a/tests/deepks/603_NO_deepks_SiO2_bandgap_multik/INPUT +++ b/tests/deepks/603_NO_deepks_SiO2_bandgap_multik/INPUT @@ -14,8 +14,8 @@ mixing_type broyden mixing_beta 0.400000 smearing_method gaussian smearing_sigma 0.020000 -cal_force 0 -cal_stress 0 +cal_force 1 +cal_stress 1 deepks_scf 1 deepks_out_labels 1 deepks_bandgap 1 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 new file mode 100644 index 0000000000..418c658dee --- /dev/null +++ b/tests/deepks/603_NO_deepks_SiO2_bandgap_multik/get_dm_eig.py @@ -0,0 +1,5 @@ +import numpy +a=numpy.load('dm_eig.npy') +b=numpy.load('e_tot.npy') +c=numpy.load('e_base.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_grad_vepsl.py b/tests/deepks/603_NO_deepks_SiO2_bandgap_multik/get_grad_vepsl.py new file mode 100644 index 0000000000..e6d1fccc40 --- /dev/null +++ b/tests/deepks/603_NO_deepks_SiO2_bandgap_multik/get_grad_vepsl.py @@ -0,0 +1,5 @@ +import numpy +a=numpy.load('grad_vepsl.npy') +b=numpy.load('s_tot.npy') +c=numpy.load('s_base.npy') +print(numpy.sum(numpy.absolute(a))+numpy.sum(numpy.absolute(b))+numpy.sum(numpy.absolute(c))) diff --git a/tests/deepks/603_NO_deepks_SiO2_bandgap_multik/get_grad_vx.py b/tests/deepks/603_NO_deepks_SiO2_bandgap_multik/get_grad_vx.py new file mode 100644 index 0000000000..1cbc2f36a0 --- /dev/null +++ b/tests/deepks/603_NO_deepks_SiO2_bandgap_multik/get_grad_vx.py @@ -0,0 +1,5 @@ +import numpy +a=numpy.load('grad_vx.npy') +b=numpy.load('f_tot.npy') +c=numpy.load('f_base.npy') +print(numpy.sum(numpy.absolute(a))+numpy.sum(numpy.absolute(b))+numpy.sum(numpy.absolute(c))) diff --git a/tests/deepks/603_NO_deepks_SiO2_bandgap_multik/result.ref b/tests/deepks/603_NO_deepks_SiO2_bandgap_multik/result.ref index 1f60a04e54..47437064f3 100644 --- a/tests/deepks/603_NO_deepks_SiO2_bandgap_multik/result.ref +++ b/tests/deepks/603_NO_deepks_SiO2_bandgap_multik/result.ref @@ -1,6 +1,9 @@ -etotref -1958.360872122988 -etotperatomref -326.3934786872 -totaldes 13.256026 -odelta 0.02699443518667366 -oprec 26.18202941954233 -totaltimeref 29.947 +etotref -1958.3608711386159484 +etotperatomref -326.3934785231 +totalforceref 33.057695 +totalstressref 279.260109 +totaldes 13.256025 +deepks_e_dm -224.21161147759534 +odelta 0.026994440153412902 +oprec 26.182031170349624 +totaltimeref 23.36 From 52622d518b4fff6d10e5ca2135783aed2670d614 Mon Sep 17 00:00:00 2001 From: zhuxuegang <121375968+Zhuxuegang2022@users.noreply.github.com> Date: Wed, 10 Jan 2024 09:51:35 +0800 Subject: [PATCH 2/2] Fix: the bug of garbled output (#3458) Co-authored-by: Zhao Tianqi --- source/module_elecstate/elecstate_print.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/module_elecstate/elecstate_print.cpp b/source/module_elecstate/elecstate_print.cpp index 1cc402ede5..9f4fc25d3b 100644 --- a/source/module_elecstate/elecstate_print.cpp +++ b/source/module_elecstate/elecstate_print.cpp @@ -315,7 +315,7 @@ void ElecState::print_etot(const bool converged, // std::cout << std::setiosflags(ios::showpos); if (scientific) { - std::cout << std::setiosflags(std::ios::scientific); + std::cout << std::scientific; } if (GlobalV::COLOUR)