From 59ebee199f7abc59411d18fa1bea6db7abc88f11 Mon Sep 17 00:00:00 2001 From: Max Graml <78024843+MGraml@users.noreply.github.com> Date: Fri, 31 Jan 2025 11:18:35 +0100 Subject: [PATCH] BSE/RI-RPA: improve abort messages and fix bug for ERI_METHOD OS --- src/bse_full_diag.F | 14 ++++++++++++-- src/bse_util.F | 12 +++++++----- src/gw_utils.F | 5 ++++- src/mp2_eri.F | 8 +++----- src/mp2_integrals.F | 17 +++++++++++++++-- src/mp2_types.F | 1 + src/qs_environment.F | 3 +++ 7 files changed, 45 insertions(+), 15 deletions(-) diff --git a/src/bse_full_diag.F b/src/bse_full_diag.F index b0e0fc76f6..9a486e5dbd 100644 --- a/src/bse_full_diag.F +++ b/src/bse_full_diag.F @@ -475,7 +475,12 @@ CONTAINS ALLOCATE (Exc_ens(homo*virtual)) CALL choose_eigv_solver(fm_C, fm_eigvec_Z, Exc_ens, diag_info) - CPASSERT(diag_info == 0) + + IF (diag_info /= 0) THEN + CALL cp_abort(__LOCATION__, & + "Diagonalization of C=(A-B)^0.5 (A+B) (A-B)^0.5 failed in BSE") + END IF + ! C could have negative eigenvalues, since we do not explicitly check A+B ! for positive definiteness (would make another O(N^6) Diagon. necessary) ! Instead, we include a check here @@ -589,7 +594,12 @@ CONTAINS ALLOCATE (Exc_ens(homo*virtual)) CALL choose_eigv_solver(fm_A, fm_eigvec, Exc_ens, diag_info) - CPASSERT(diag_info == 0) + + IF (diag_info /= 0) THEN + CALL cp_abort(__LOCATION__, & + "Diagonalization of A failed in TDA-BSE") + END IF + CALL postprocess_bse(Exc_ens, fm_eigvec, mp2_env, qs_env, mo_coeff, & homo, virtual, homo_irred, unit_nr, .TRUE.) diff --git a/src/bse_util.F b/src/bse_util.F index d2c9dd8c2f..673705fd3a 100644 --- a/src/bse_util.F +++ b/src/bse_util.F @@ -154,7 +154,9 @@ CONTAINS ! calculate Trace(Log(Matrix)) as Log(DET(Matrix)) via cholesky decomposition CALL cp_fm_cholesky_decompose(matrix=fm_mat_Q_static_bse_gemm, n=dimen_RI, info_out=info_chol) - CPASSERT(info_chol == 0) + IF (info_chol /= 0) THEN + CALL cp_abort(__LOCATION__, 'Cholesky decomposition failed for static polarization in BSE') + END IF ! calculate [1+Q(i0)]^-1 CALL cp_fm_cholesky_invert(fm_mat_Q_static_bse_gemm) @@ -1542,7 +1544,7 @@ CONTAINS mp2_env%bse%num_print_exc > homo*virtual) THEN mp2_env%bse%num_print_exc = homo*virtual IF (unit_nr > 0) THEN - CALL cp_warn(__LOCATION__, & + CALL cp_hint(__LOCATION__, & "Keyword NUM_PRINT_EXC is either negative or too large. "// & "Printing all computed excitations.") END IF @@ -1558,7 +1560,7 @@ CONTAINS IF (mp2_env%bse%explicit_nto_list) THEN IF (mp2_env%bse%num_print_exc_ntos > 0) THEN IF (unit_nr > 0) THEN - CALL cp_warn(__LOCATION__, & + CALL cp_hint(__LOCATION__, & "Keywords NUM_PRINT_EXC_NTOS and STATE_LIST are both given in input. "// & "Overriding NUM_PRINT_EXC_NTOS.") END IF @@ -1574,7 +1576,7 @@ CONTAINS END DO IF (num_state_list_exceptions > 0) THEN IF (unit_nr > 0) THEN - CALL cp_warn(__LOCATION__, & + CALL cp_hint(__LOCATION__, & "STATE_LIST contains indices outside the range of included excitation levels. "// & "Ignoring these states.") END IF @@ -1619,7 +1621,7 @@ CONTAINS IF (mp2_env%bse%num_print_exc_descr < 0 .OR. & mp2_env%bse%num_print_exc_descr > mp2_env%bse%num_print_exc) THEN IF (unit_nr > 0) THEN - CALL cp_warn(__LOCATION__, & + CALL cp_hint(__LOCATION__, & "Keyword NUM_PRINT_EXC_DESCR is either negative or too large. "// & "Printing exciton descriptors up to NUM_PRINT_EXC.") END IF diff --git a/src/gw_utils.F b/src/gw_utils.F index 22bf49c260..012ebe89b2 100644 --- a/src/gw_utils.F +++ b/src/gw_utils.F @@ -362,7 +362,10 @@ CONTAINS DO ikind = 1, n_kind CALL get_qs_kind(qs_kind=qs_kind_set(ikind), basis_set=basis_set_a, & basis_type="RI_AUX") - CPASSERT(ASSOCIATED(basis_set_a)) + IF (.NOT. ASSOCIATED(basis_set_a)) THEN + CALL cp_abort(__LOCATION__, & + "At least one RI_AUX basis set was not explicitly invoked in &KIND-section.") + END IF END DO ALLOCATE (bs_env%i_RI_start_from_atom(n_atom)) diff --git a/src/mp2_eri.F b/src/mp2_eri.F index 68c317f383..7932ea9263 100644 --- a/src/mp2_eri.F +++ b/src/mp2_eri.F @@ -1320,11 +1320,9 @@ CONTAINS ! in the RI basis, there is only a single primitive Gaussian kpgf = 1 - IF (lc_max == 0) THEN - nc_start = 1 - ELSE - nc_start = ncoset(lc_max - 1) + 1 - END IF + ! ncoset is indexed by -1,..., ,5 + ! e.g. for pure s: lc_min = lc_max = 0, nc_start = 1 + nc_start = ncoset(lc_min - 1) + 1 nc_end = ncoset(lc_max) CALL coulomb3(la_max, npgfa, zeta(:), rpgfa(:), la_min, & diff --git a/src/mp2_integrals.F b/src/mp2_integrals.F index 49717a76e1..9b14d91ed8 100644 --- a/src/mp2_integrals.F +++ b/src/mp2_integrals.F @@ -334,8 +334,12 @@ CONTAINS END IF IF (do_bse) THEN - CPASSERT(my_do_gw) - CPASSERT(.NOT. do_im_time) + IF (.NOT. my_do_gw) THEN + CALL cp_abort(__LOCATION__, "BSE calculations require prior GW calculations.") + END IF + IF (do_im_time) THEN + CALL cp_abort(__LOCATION__, "BSE calculations are not implemented for low-scaling GW.") + END IF ! GPW integrals have to be implemented later IF (eri_method == do_eri_gpw) THEN CALL cp_abort(__LOCATION__, & @@ -539,6 +543,15 @@ CONTAINS (ri_metric%potential_type == do_potential_coulomb .OR. ri_metric%potential_type == do_potential_long) .OR. & eri_method == do_eri_os .AND. ri_metric%potential_type == do_potential_coulomb) THEN + ! Add a warning for automatically generated RI_AUX basis sets + ! Tend to be not sufficiently converged + IF (qs_env%mp2_env%ri_aux_auto_generated) THEN + CALL cp_warn(__LOCATION__, & + "At least one RI_AUX basis set was not explicitly invoked in &KIND-section. "// & + "Automatically RI-basis sets and ERI_METHOD OS tend to be not converged. "// & + "Consider specifying BASIS_SET RI_AUX explicitly with a sufficiently large basis.") + END IF + NULLIFY (mat_munu_local_L) ALLOCATE (mat_munu_local_L(my_group_L_size)) DO LLL = 1, my_group_L_size diff --git a/src/mp2_types.F b/src/mp2_types.F index a3e59bf4e0..b80b6ecb18 100644 --- a/src/mp2_types.F +++ b/src/mp2_types.F @@ -403,6 +403,7 @@ MODULE mp2_types TYPE(local_gemm_ctxt_type) :: local_gemm_ctx = local_gemm_ctxt_type() REAL(dp) :: e_gap = 0.0_dp, & e_range = 0.0_dp + LOGICAL :: ri_aux_auto_generated = .FALSE. END TYPE mp2_type TYPE integ_mat_buffer_type diff --git a/src/qs_environment.F b/src/qs_environment.F index 677a5ad44f..97d3c87e10 100644 --- a/src/qs_environment.F +++ b/src/qs_environment.F @@ -1011,6 +1011,9 @@ CONTAINS ! Generate a default basis CALL create_ri_aux_basis_set(ri_aux_basis_set, qs_kind, dft_control%auto_basis_ri_aux, basis_sort=sort_basis) CALL add_basis_set_to_container(qs_kind%basis_sets, ri_aux_basis_set, "RI_AUX") + ! Add a flag, which allows to check if the basis was generated + ! when applying ERI_METHOD OS to mp2, ri-rpa, gw etc + qs_env%mp2_env%ri_aux_auto_generated = .TRUE. END IF END DO END IF