From 22b28fc77435dc74268a952a3c1e30e016601d66 Mon Sep 17 00:00:00 2001 From: ydamour Date: Tue, 22 Mar 2022 10:49:39 +0100 Subject: [PATCH 1/8] csf fix segfault --- src/csf/sigma_vector.irp.f | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/csf/sigma_vector.irp.f b/src/csf/sigma_vector.irp.f index 4d409f50..beb827ba 100644 --- a/src/csf/sigma_vector.irp.f +++ b/src/csf/sigma_vector.irp.f @@ -52,10 +52,15 @@ ncfgpersomo = cfg_seniority_index(i+2) else k = 0 - do while(cfg_seniority_index(i+2+k) < ncfgpersomo) - k = k + 2 - ncfgpersomo = cfg_seniority_index(i+2+k) - enddo + if ((i+2+k) < size(cfg_seniority_index,1)) then + do while(cfg_seniority_index(i+2+k) < ncfgpersomo) + k = k + 2 + if ((i+2+k) >= size(cfg_seniority_index,1)) then + exit + endif + ncfgpersomo = cfg_seniority_index(i+2+k) + enddo + endif endif endif ncfg = ncfgpersomo - ncfgprev @@ -75,10 +80,15 @@ ncfgprev = cfg_seniority_index(i+2) else k = 0 - do while(cfg_seniority_index(i+2+k) < ncfgprev) - k = k + 2 - ncfgprev = cfg_seniority_index(i+2+k) - enddo + if ((i+2+k) < size(cfg_seniority_index,1)) then + do while(cfg_seniority_index(i+2+k) < ncfgprev) + k = k + 2 + if ((i+2+k) >= size(cfg_seniority_index,1)) then + exit + endif + ncfgprev = cfg_seniority_index(i+2+k) + enddo + endif endif enddo END_PROVIDER From 8a759e6a943ae3604dc0d7636c4a2bf9da6af03c Mon Sep 17 00:00:00 2001 From: ydamour Date: Thu, 24 Mar 2022 16:14:31 +0100 Subject: [PATCH 2/8] csf remove do while loops --- src/csf/sigma_vector.irp.f | 58 +++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 20 deletions(-) diff --git a/src/csf/sigma_vector.irp.f b/src/csf/sigma_vector.irp.f index beb827ba..026dd839 100644 --- a/src/csf/sigma_vector.irp.f +++ b/src/csf/sigma_vector.irp.f @@ -51,16 +51,24 @@ if(cfg_seniority_index(i+2) > ncfgpersomo) then ncfgpersomo = cfg_seniority_index(i+2) else - k = 0 - if ((i+2+k) < size(cfg_seniority_index,1)) then - do while(cfg_seniority_index(i+2+k) < ncfgpersomo) - k = k + 2 - if ((i+2+k) >= size(cfg_seniority_index,1)) then - exit - endif - ncfgpersomo = cfg_seniority_index(i+2+k) - enddo - endif + ! l = i+k+2 + ! Loop over l with a constraint to ensure that l <= size(cfg_seniority_index,1)-1 + ! Old version commented just below + do l = min(size(cfg_seniority_index,1)-1, i+2), size(cfg_seniority_index,1)-1, 2 + if (cfg_seniority_index(l) >= ncfgpersomo) then + ncfgpersomo = cfg_seniority_index(l) + endif + enddo + !k = 0 + !if ((i+2+k) < size(cfg_seniority_index,1)) then + ! do while(cfg_seniority_index(i+2+k) < ncfgpersomo) + ! k = k + 2 + ! if ((i+2+k) >= size(cfg_seniority_index,1)) then + ! exit + ! endif + ! ncfgpersomo = cfg_seniority_index(i+2+k) + ! enddo + !endif endif endif ncfg = ncfgpersomo - ncfgprev @@ -79,16 +87,26 @@ if(cfg_seniority_index(i+2) > ncfgprev) then ncfgprev = cfg_seniority_index(i+2) else - k = 0 - if ((i+2+k) < size(cfg_seniority_index,1)) then - do while(cfg_seniority_index(i+2+k) < ncfgprev) - k = k + 2 - if ((i+2+k) >= size(cfg_seniority_index,1)) then - exit - endif - ncfgprev = cfg_seniority_index(i+2+k) - enddo - endif + ! l = i+k+2 + ! Loop over l with a constraint to ensure that l <= size(cfg_seniority_index,1)-1 + ! Old version commented just below + do l = min(size(cfg_seniority_index,1)-1, i+2), size(cfg_seniority_index,1)-1, 2 + print*,'l' + if (cfg_seniority_index(l) >= ncfgprev) then + ncfgprev = cfg_seniority_index(l) + endif + print*,'ncfgprev', ncfgprev + enddo + !k = 0 + !if ((i+2+k) < size(cfg_seniority_index,1)) then + ! do while(cfg_seniority_index(i+2+k) < ncfgprev) + ! k = k + 2 + ! if ((i+2+k) >= size(cfg_seniority_index,1)) then + ! exit + ! endif + ! ncfgprev = cfg_seniority_index(i+2+k) + ! enddo + !endif endif enddo END_PROVIDER From bda895104242464d927be55e4b6a8426e23975c0 Mon Sep 17 00:00:00 2001 From: ydamour Date: Thu, 24 Mar 2022 16:18:51 +0100 Subject: [PATCH 3/8] remove print --- src/csf/sigma_vector.irp.f | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/csf/sigma_vector.irp.f b/src/csf/sigma_vector.irp.f index 026dd839..5aaba9a3 100644 --- a/src/csf/sigma_vector.irp.f +++ b/src/csf/sigma_vector.irp.f @@ -91,11 +91,9 @@ ! Loop over l with a constraint to ensure that l <= size(cfg_seniority_index,1)-1 ! Old version commented just below do l = min(size(cfg_seniority_index,1)-1, i+2), size(cfg_seniority_index,1)-1, 2 - print*,'l' if (cfg_seniority_index(l) >= ncfgprev) then ncfgprev = cfg_seniority_index(l) endif - print*,'ncfgprev', ncfgprev enddo !k = 0 !if ((i+2+k) < size(cfg_seniority_index,1)) then From 511a80e062213a76d2bc7aa7cf7179c74786de24 Mon Sep 17 00:00:00 2001 From: ydamour Date: Mon, 28 Mar 2022 20:08:35 +0200 Subject: [PATCH 4/8] add excitation energies in eV --- src/cis/cis.irp.f | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/cis/cis.irp.f b/src/cis/cis.irp.f index ab2294ad..f72197c2 100644 --- a/src/cis/cis.irp.f +++ b/src/cis/cis.irp.f @@ -62,6 +62,7 @@ subroutine run else call H_apply_cis endif + print*,'' print *, 'N_det = ', N_det print*,'******************************' print *, 'Energies of the states:' @@ -69,11 +70,13 @@ subroutine run print *, i, CI_energy(i) enddo if (N_states > 1) then - print*,'******************************' - print*,'Excitation energies ' + print*,'' + print*,'******************************************************' + print*,'Excitation energies (au) (eV)' do i = 2, N_states - print*, i ,CI_energy(i) - CI_energy(1) + print*, i ,CI_energy(i) - CI_energy(1), (CI_energy(i) - CI_energy(1))/0.0367502d0 enddo + print*,'' endif call ezfio_set_cis_energy(CI_energy) From e3e403692195d04e2c1e15546d9eea738eab909e Mon Sep 17 00:00:00 2001 From: ydamour Date: Tue, 5 Apr 2022 16:12:47 +0200 Subject: [PATCH 5/8] Fix psi_det_size --- src/determinants/determinants.irp.f | 43 +++++++++++++++-------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/src/determinants/determinants.irp.f b/src/determinants/determinants.irp.f index b8c8658f..eeadf779 100644 --- a/src/determinants/determinants.irp.f +++ b/src/determinants/determinants.irp.f @@ -77,28 +77,31 @@ BEGIN_PROVIDER [ integer, psi_det_size ] END_DOC PROVIDE ezfio_filename logical :: exists - if (mpi_master) then - call ezfio_has_determinants_n_det(exists) - if (exists) then - call ezfio_get_determinants_n_det(psi_det_size) - else - psi_det_size = 1 + psi_det_size = 1 + PROVIDE mpi_master + if (read_wf) then + if (mpi_master) then + call ezfio_has_determinants_n_det(exists) + if (exists) then + call ezfio_get_determinants_n_det(psi_det_size) + else + psi_det_size = 1 + endif + call write_int(6,psi_det_size,'Dimension of the psi arrays') endif - call write_int(6,psi_det_size,'Dimension of the psi arrays') + IRP_IF MPI_DEBUG + print *, irp_here, mpi_rank + call MPI_BARRIER(MPI_COMM_WORLD, ierr) + IRP_ENDIF + IRP_IF MPI + include 'mpif.h' + integer :: ierr + call MPI_BCAST( psi_det_size, 1, MPI_INTEGER, 0, MPI_COMM_WORLD, ierr) + if (ierr /= MPI_SUCCESS) then + stop 'Unable to read psi_det_size with MPI' + endif + IRP_ENDIF endif - IRP_IF MPI_DEBUG - print *, irp_here, mpi_rank - call MPI_BARRIER(MPI_COMM_WORLD, ierr) - IRP_ENDIF - IRP_IF MPI - include 'mpif.h' - integer :: ierr - call MPI_BCAST( psi_det_size, 1, MPI_INTEGER, 0, MPI_COMM_WORLD, ierr) - if (ierr /= MPI_SUCCESS) then - stop 'Unable to read psi_det_size with MPI' - endif - IRP_ENDIF - END_PROVIDER From e6d08356577968e79a81faa56dbbca83a4d62855 Mon Sep 17 00:00:00 2001 From: ydamour Date: Fri, 8 Apr 2022 17:21:03 +0200 Subject: [PATCH 6/8] fix error pt2 from det already in the wf --- src/cipsi/selection.irp.f | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/src/cipsi/selection.irp.f b/src/cipsi/selection.irp.f index d4d44c2d..2d8d34d5 100644 --- a/src/cipsi/selection.irp.f +++ b/src/cipsi/selection.irp.f @@ -195,7 +195,10 @@ subroutine select_singles_and_doubles(i_generator,hole_mask,particle_mask,fock_d integer :: l_a, nmax, idx integer, allocatable :: indices(:), exc_degree(:), iorder(:) - double precision, parameter :: norm_thr = 1.d-16 + + ! Removed to avoid introducing determinants already presents in the wf + !double precision, parameter :: norm_thr = 1.d-16 + allocate (indices(N_det), & exc_degree(max(N_det_alpha_unique,N_det_beta_unique))) @@ -215,10 +218,11 @@ subroutine select_singles_and_doubles(i_generator,hole_mask,particle_mask,fock_d i = psi_bilinear_matrix_rows(l_a) if (nt + exc_degree(i) <= 4) then idx = psi_det_sorted_order(psi_bilinear_matrix_order(l_a)) - if (psi_average_norm_contrib_sorted(idx) > norm_thr) then + ! Removed to avoid introducing determinants already presents in the wf + !if (psi_average_norm_contrib_sorted(idx) > norm_thr) then indices(k) = idx k=k+1 - endif + !endif endif enddo enddo @@ -242,10 +246,11 @@ subroutine select_singles_and_doubles(i_generator,hole_mask,particle_mask,fock_d idx = psi_det_sorted_order( & psi_bilinear_matrix_order( & psi_bilinear_matrix_transp_order(l_a))) - if (psi_average_norm_contrib_sorted(idx) > norm_thr) then + ! Removed to avoid introducing determinants already presents in the wf + !if (psi_average_norm_contrib_sorted(idx) > norm_thr) then indices(k) = idx k=k+1 - endif + !endif endif enddo enddo @@ -566,6 +571,7 @@ subroutine fill_buffer_double(i_generator, sp, h1, h2, bannedOrb, banned, fock_d double precision, external :: diag_H_mat_elem_fock double precision :: E_shift double precision :: s_weight(N_states,N_states) + logical, external :: is_in_wavefunction PROVIDE dominant_dets_of_cfgs N_dominant_dets_of_cfgs do jstate=1,N_states do istate=1,N_states @@ -830,6 +836,24 @@ subroutine fill_buffer_double(i_generator, sp, h1, h2, bannedOrb, banned, fock_d end select end do + ! To force the inclusion of determinants with a positive pt2 contribution + if (e_pert(istate) > 1d-8) then + w = -huge(1.0) + endif + +!!!BEGIN_DEBUG +! ! To check if the pt2 is taking determinants already in the wf +! if (is_in_wavefunction(det(N_int,1),N_int)) then +! print*, 'A determinant contributing to the pt2 is already in' +! print*, 'the wave function:' +! call print_det(det(N_int,1),N_int) +! print*,'contribution to the pt2 for the states:', e_pert(:) +! print*,'error in the filtering in' +! print*, 'cipsi/selection.irp.f sub: selecte_singles_and_doubles' +! print*, 'abort' +! call abort +! endif +!!!END_DEBUG integer(bit_kind) :: occ(N_int,2), n if (h0_type == 'CFG') then From 52c460367de1ba0e584d4668aca79fa9ec6549a1 Mon Sep 17 00:00:00 2001 From: ydamour Date: Mon, 11 Apr 2022 13:55:00 +0200 Subject: [PATCH 7/8] fix error pt2 --- src/cipsi/selection.irp.f | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/cipsi/selection.irp.f b/src/cipsi/selection.irp.f index 2d8d34d5..1317fcf3 100644 --- a/src/cipsi/selection.irp.f +++ b/src/cipsi/selection.irp.f @@ -834,12 +834,13 @@ subroutine fill_buffer_double(i_generator, sp, h1, h2, bannedOrb, banned, fock_d endif end select - end do - ! To force the inclusion of determinants with a positive pt2 contribution - if (e_pert(istate) > 1d-8) then - w = -huge(1.0) - endif + ! To force the inclusion of determinants with a positive pt2 contribution + if (e_pert(istate) > 1d-8) then + w = -huge(1.0) + endif + + end do !!!BEGIN_DEBUG ! ! To check if the pt2 is taking determinants already in the wf From 19185c06f4c39bbba3dd50d029f4acb8b52f1075 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Mon, 11 Apr 2022 23:55:17 +0200 Subject: [PATCH 8/8] Add cipsi_save.sh --- scripts/cipsi_save.sh | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 scripts/cipsi_save.sh diff --git a/scripts/cipsi_save.sh b/scripts/cipsi_save.sh new file mode 100644 index 00000000..a4d9b65e --- /dev/null +++ b/scripts/cipsi_save.sh @@ -0,0 +1,27 @@ +#!/bin/bash +# +# This script runs a CIPSI calculation as a sequence of single CIPSI iterations. +# After each iteration, the EZFIO directory is saved. +# +# Usage: cipsi_save [EZFIO_FILE] [NDET] +# +# Example: cipsi_save file.ezfio 10000 + +EZ=$1 +NDETMAX=$2 + +qp set_file ${EZ} +qp reset -d +qp set determinants read_wf true +declare -i NDET +NDET=1 +while [[ ${NDET} -lt ${NDETMAX} ]] +do + NDET=$(($NDET + $NDET)) + qp set determinants n_det_max $NDET + qp run fci > ${EZ}.out + NDET=$(qp get determinants n_det) + mv ${EZ}.out ${EZ}.${NDET}.out + cp -r ${EZ} ${EZ}.${NDET} +done +