10
0
mirror of https://github.com/QuantumPackage/qp2.git synced 2024-07-08 12:26:01 +02:00

working on complex cipsi

This commit is contained in:
Kevin Gasperich 2020-03-03 17:48:46 -06:00
parent 17b9b423a9
commit 299243e2ce
8 changed files with 170 additions and 60 deletions

View File

@ -20,7 +20,7 @@ subroutine run_cipsi
logical :: has logical :: has
double precision :: relative_error double precision :: relative_error
PROVIDE H_apply_buffer_allocated PROVIDE h_apply_buffer_allocated
relative_error=PT2_relative_error relative_error=PT2_relative_error
@ -34,7 +34,7 @@ subroutine run_cipsi
call make_s2_eigenfunction call make_s2_eigenfunction
endif endif
if (is_complex) then if (is_complex) then
call diagonalize_CI_complex call diagonalize_ci_complex
else else
call diagonalize_CI call diagonalize_CI
endif endif
@ -94,13 +94,13 @@ subroutine run_cipsi
norm = 0.d0 norm = 0.d0
threshold_generators = 1.d0 threshold_generators = 1.d0
SOFT_TOUCH threshold_generators SOFT_TOUCH threshold_generators
if (is_complex) then ! if (is_complex) then
call zmq_pt2_complex(psi_energy_with_nucl_rep,pt2,relative_error,error, variance, & ! call zmq_pt2_complex(psi_energy_with_nucl_rep,pt2,relative_error,error, variance, &
norm, 0) ! Stochastic PT2 ! norm, 0) ! Stochastic PT2
else ! else
call zmq_pt2(psi_energy_with_nucl_rep,pt2,relative_error,error, variance, & call zmq_pt2(psi_energy_with_nucl_rep,pt2,relative_error,error, variance, &
norm, 0) ! Stochastic PT2 norm, 0) ! Stochastic PT2
endif ! endif
threshold_generators = threshold_generators_save threshold_generators = threshold_generators_save
SOFT_TOUCH threshold_generators SOFT_TOUCH threshold_generators
endif endif
@ -127,11 +127,12 @@ subroutine run_cipsi
n_det_before = N_det n_det_before = N_det
to_select = int(sqrt(dble(N_states))*dble(N_det)*selection_factor) to_select = int(sqrt(dble(N_states))*dble(N_det)*selection_factor)
to_select = max(N_states_diag, to_select) to_select = max(N_states_diag, to_select)
call zmq_selection(to_select, pt2, variance, norm)
if (is_complex) then if (is_complex) then
call zmq_selection_complex(to_select, pt2, variance, norm) ! call zmq_selection_complex(to_select, pt2, variance, norm)
PROVIDE psi_coef_complex PROVIDE psi_coef_complex
else else
call zmq_selection(to_select, pt2, variance, norm) ! call zmq_selection(to_select, pt2, variance, norm)
PROVIDE psi_coef PROVIDE psi_coef
endif endif
PROVIDE psi_det PROVIDE psi_det
@ -168,13 +169,13 @@ print *, (correlation_energy_ratio <= correlation_energy_ratio_max)
norm(:) = 0.d0 norm(:) = 0.d0
threshold_generators = 1d0 threshold_generators = 1d0
SOFT_TOUCH threshold_generators SOFT_TOUCH threshold_generators
if (is_complex) then ! if (is_complex) then
call zmq_pt2_complex(psi_energy_with_nucl_rep, pt2,relative_error,error,variance, & ! call zmq_pt2_complex(psi_energy_with_nucl_rep, pt2,relative_error,error,variance, &
norm,0) ! Stochastic PT2 ! norm,0) ! Stochastic PT2
else ! else
call ZMQ_pt2(psi_energy_with_nucl_rep, pt2,relative_error,error,variance, & call ZMQ_pt2(psi_energy_with_nucl_rep, pt2,relative_error,error,variance, &
norm,0) ! Stochastic PT2 norm,0) ! Stochastic PT2
endif ! endif
SOFT_TOUCH threshold_generators SOFT_TOUCH threshold_generators
endif endif
print *, 'N_det = ', N_det print *, 'N_det = ', N_det

View File

@ -63,11 +63,19 @@ logical function testTeethBuilding(minF, N)
norm = 0.d0 norm = 0.d0
double precision :: norm double precision :: norm
do i=N_det_generators,1,-1 if (is_complex) then
tilde_w(i) = psi_coef_sorted_gen(i,pt2_stoch_istate) * & do i=N_det_generators,1,-1
psi_coef_sorted_gen(i,pt2_stoch_istate) tilde_w(i) = cdabs(psi_coef_sorted_gen_complex(i,pt2_stoch_istate) * &
norm = norm + tilde_w(i) psi_coef_sorted_gen_complex(i,pt2_stoch_istate))
enddo norm = norm + tilde_w(i)
enddo
else
do i=N_det_generators,1,-1
tilde_w(i) = psi_coef_sorted_gen(i,pt2_stoch_istate) * &
psi_coef_sorted_gen(i,pt2_stoch_istate)
norm = norm + tilde_w(i)
enddo
endif
f = 1.d0/norm f = 1.d0/norm
tilde_w(:) = tilde_w(:) * f tilde_w(:) = tilde_w(:) * f
@ -126,11 +134,19 @@ subroutine ZMQ_pt2(E, pt2,relative_error, error, variance, norm, N_in)
integer(ZMQ_PTR), external :: new_zmq_to_qp_run_socket integer(ZMQ_PTR), external :: new_zmq_to_qp_run_socket
type(selection_buffer) :: b type(selection_buffer) :: b
PROVIDE psi_bilinear_matrix_columns_loc psi_det_alpha_unique psi_det_beta_unique if (is_complex) then
PROVIDE psi_bilinear_matrix_rows psi_det_sorted_order psi_bilinear_matrix_order PROVIDE psi_bilinear_matrix_columns_loc psi_det_alpha_unique psi_det_beta_unique
PROVIDE psi_bilinear_matrix_transp_rows_loc psi_bilinear_matrix_transp_columns PROVIDE psi_bilinear_matrix_rows psi_det_sorted_order psi_bilinear_matrix_order
PROVIDE psi_bilinear_matrix_transp_order psi_selectors_coef_transp psi_det_sorted PROVIDE psi_bilinear_matrix_transp_rows_loc psi_bilinear_matrix_transp_columns
PROVIDE psi_det_hii selection_weight pseudo_sym PROVIDE psi_bilinear_matrix_transp_order psi_selectors_coef_transp_complex psi_det_sorted
PROVIDE psi_det_hii selection_weight pseudo_sym
else
PROVIDE psi_bilinear_matrix_columns_loc psi_det_alpha_unique psi_det_beta_unique
PROVIDE psi_bilinear_matrix_rows psi_det_sorted_order psi_bilinear_matrix_order
PROVIDE psi_bilinear_matrix_transp_rows_loc psi_bilinear_matrix_transp_columns
PROVIDE psi_bilinear_matrix_transp_order psi_selectors_coef_transp psi_det_sorted
PROVIDE psi_det_hii selection_weight pseudo_sym
endif
if (h0_type == 'SOP') then if (h0_type == 'SOP') then
PROVIDE psi_occ_pattern_hii det_to_occ_pattern PROVIDE psi_occ_pattern_hii det_to_occ_pattern
@ -159,8 +175,15 @@ subroutine ZMQ_pt2(E, pt2,relative_error, error, variance, norm, N_in)
state_average_weight(pt2_stoch_istate) = 1.d0 state_average_weight(pt2_stoch_istate) = 1.d0
TOUCH state_average_weight pt2_stoch_istate selection_weight TOUCH state_average_weight pt2_stoch_istate selection_weight
PROVIDE nproc pt2_F mo_two_e_integrals_in_map mo_one_e_integrals pt2_w if (is_complex) then
PROVIDE psi_selectors pt2_u pt2_J pt2_R !todo: psi_selectors isn't linked to psi_selectors_coef anymore; should we provide both?
PROVIDE nproc pt2_F mo_two_e_integrals_in_map mo_one_e_integrals_complex pt2_w
PROVIDE psi_selectors pt2_u pt2_J pt2_R
else
PROVIDE nproc pt2_F mo_two_e_integrals_in_map mo_one_e_integrals pt2_w
PROVIDE psi_selectors pt2_u pt2_J pt2_R
endif
call new_parallel_job(zmq_to_qp_run_socket, zmq_socket_pull, 'pt2') call new_parallel_job(zmq_to_qp_run_socket, zmq_socket_pull, 'pt2')
integer, external :: zmq_put_psi integer, external :: zmq_put_psi
@ -242,6 +265,7 @@ subroutine ZMQ_pt2(E, pt2,relative_error, error, variance, norm, N_in)
double precision :: mem_collector, mem, rss double precision :: mem_collector, mem, rss
!todo: check memory allocation for complex
call resident_memory(rss) call resident_memory(rss)
mem_collector = 8.d0 * & ! bytes mem_collector = 8.d0 * & ! bytes
@ -751,10 +775,16 @@ END_PROVIDER
allocate(tilde_w(N_det_generators), tilde_cW(0:N_det_generators)) allocate(tilde_w(N_det_generators), tilde_cW(0:N_det_generators))
tilde_cW(0) = 0d0 tilde_cW(0) = 0d0
do i=1,N_det_generators if (is_complex) then
tilde_w(i) = psi_coef_sorted_gen(i,pt2_stoch_istate)**2 !+ 1.d-20 do i=1,N_det_generators
enddo tilde_w(i) = cdabs(psi_coef_sorted_gen_complex(i,pt2_stoch_istate))**2 !+ 1.d-20
enddo
else
do i=1,N_det_generators
tilde_w(i) = psi_coef_sorted_gen(i,pt2_stoch_istate)**2 !+ 1.d-20
enddo
endif
double precision :: norm double precision :: norm
norm = 0.d0 norm = 0.d0
@ -773,7 +803,7 @@ END_PROVIDER
pt2_n_0(1) = 0 pt2_n_0(1) = 0
do do
pt2_u_0 = tilde_cW(pt2_n_0(1)) pt2_u_0 = tilde_cW(pt2_n_0(1))
r = tilde_cW(pt2_n_0(1) + pt2_minDetInFirstTeeth) r = tilde_cW(pt2_n_0(1) + pt2_mindetinfirstteeth)
pt2_W_T = (1d0 - pt2_u_0) / dble(pt2_N_teeth) pt2_W_T = (1d0 - pt2_u_0) / dble(pt2_N_teeth)
if(pt2_W_T >= r - pt2_u_0) then if(pt2_W_T >= r - pt2_u_0) then
exit exit
@ -799,7 +829,7 @@ END_PROVIDER
endif endif
ASSERT(tooth_width > 0.d0) ASSERT(tooth_width > 0.d0)
do i=pt2_n_0(t)+1, pt2_n_0(t+1) do i=pt2_n_0(t)+1, pt2_n_0(t+1)
pt2_w(i) = tilde_w(i) * pt2_W_T / tooth_width pt2_w(i) = tilde_w(i) * pt2_w_t / tooth_width
end do end do
end do end do

View File

@ -21,7 +21,8 @@ subroutine run_selection_slave(thread,iproc,energy)
double precision :: pt2(N_states) double precision :: pt2(N_states)
double precision :: variance(N_states) double precision :: variance(N_states)
double precision :: norm(N_states) double precision :: norm(N_states)
!todo: check for providers that are now unlinked for real/complex
PROVIDE psi_bilinear_matrix_columns_loc psi_det_alpha_unique psi_det_beta_unique PROVIDE psi_bilinear_matrix_columns_loc psi_det_alpha_unique psi_det_beta_unique
PROVIDE psi_bilinear_matrix_rows psi_det_sorted_order psi_bilinear_matrix_order PROVIDE psi_bilinear_matrix_rows psi_det_sorted_order psi_bilinear_matrix_order
PROVIDE psi_bilinear_matrix_transp_rows_loc psi_bilinear_matrix_transp_columns PROVIDE psi_bilinear_matrix_transp_rows_loc psi_bilinear_matrix_transp_columns

View File

@ -758,7 +758,7 @@ subroutine fill_buffer_double(i_generator, sp, h1, h2, bannedOrb, banned, fock_d
if (.not.is_a_1h1p(det)) cycle if (.not.is_a_1h1p(det)) cycle
endif endif
Hii = diag_H_mat_elem_fock(psi_det_generators(1,1,i_generator),det,fock_diag_tmp,N_int) Hii = diag_h_mat_elem_fock(psi_det_generators(1,1,i_generator),det,fock_diag_tmp,N_int)
w = 0d0 w = 0d0

View File

@ -14,10 +14,17 @@ subroutine run_slave_cipsi
end end
subroutine provide_everything subroutine provide_everything
PROVIDE H_apply_buffer_allocated mo_two_e_integrals_in_map psi_det_generators psi_coef_generators psi_det_sorted_bit psi_selectors n_det_generators n_states generators_bitmask zmq_context N_states_diag if (is_complex) then
PROVIDE pt2_e0_denominator mo_num N_int ci_energy mpi_master zmq_state zmq_context PROVIDE H_apply_buffer_allocated mo_two_e_integrals_in_map psi_det_generators psi_coef_generators_complex psi_det_sorted_bit psi_selectors n_det_generators n_states generators_bitmask zmq_context N_states_diag
PROVIDE psi_det psi_coef threshold_generators state_average_weight PROVIDE pt2_e0_denominator mo_num N_int ci_energy mpi_master zmq_state zmq_context
PROVIDE N_det_selectors pt2_stoch_istate N_det selection_weight pseudo_sym PROVIDE psi_det psi_coef_complex threshold_generators state_average_weight
PROVIDE N_det_selectors pt2_stoch_istate N_det selection_weight pseudo_sym
else
PROVIDE H_apply_buffer_allocated mo_two_e_integrals_in_map psi_det_generators psi_coef_generators psi_det_sorted_bit psi_selectors n_det_generators n_states generators_bitmask zmq_context N_states_diag
PROVIDE pt2_e0_denominator mo_num N_int ci_energy mpi_master zmq_state zmq_context
PROVIDE psi_det psi_coef threshold_generators state_average_weight
PROVIDE N_det_selectors pt2_stoch_istate N_det selection_weight pseudo_sym
endif
end end
subroutine run_slave_main subroutine run_slave_main
@ -51,9 +58,15 @@ subroutine run_slave_main
zmq_to_qp_run_socket = new_zmq_to_qp_run_socket() zmq_to_qp_run_socket = new_zmq_to_qp_run_socket()
PROVIDE psi_det psi_coef threshold_generators state_average_weight mpi_master if (is_complex) then
PROVIDE zmq_state N_det_selectors pt2_stoch_istate N_det pt2_e0_denominator PROVIDE psi_det psi_coef_complex threshold_generators state_average_weight mpi_master
PROVIDE N_det_generators N_states N_states_diag pt2_e0_denominator mpi_rank PROVIDE zmq_state N_det_selectors pt2_stoch_istate N_det pt2_e0_denominator
PROVIDE N_det_generators N_states N_states_diag pt2_e0_denominator mpi_rank
else
PROVIDE psi_det psi_coef threshold_generators state_average_weight mpi_master
PROVIDE zmq_state N_det_selectors pt2_stoch_istate N_det pt2_e0_denominator
PROVIDE N_det_generators N_states N_states_diag pt2_e0_denominator mpi_rank
endif
IRP_IF MPI IRP_IF MPI
call MPI_BARRIER(MPI_COMM_WORLD, ierr) call MPI_BARRIER(MPI_COMM_WORLD, ierr)

View File

@ -36,7 +36,11 @@ subroutine run_stochastic_cipsi
if (s2_eig) then if (s2_eig) then
call make_s2_eigenfunction call make_s2_eigenfunction
endif endif
call diagonalize_ci if (is_complex) then
call diagonalize_ci_complex
else
call diagonalize_ci
endif
call save_wavefunction call save_wavefunction
call ezfio_has_hartree_fock_energy(has) call ezfio_has_hartree_fock_energy(has)
@ -60,7 +64,11 @@ subroutine run_stochastic_cipsi
if (s2_eig) then if (s2_eig) then
call make_s2_eigenfunction call make_s2_eigenfunction
endif endif
call diagonalize_CI if (is_complex) then
call diagonalize_ci_complex
else
call diagonalize_CI
endif
call save_wavefunction call save_wavefunction
endif endif
@ -84,8 +92,13 @@ subroutine run_stochastic_cipsi
pt2 = 0.d0 pt2 = 0.d0
variance = 0.d0 variance = 0.d0
norm = 0.d0 norm = 0.d0
call zmq_pt2(psi_energy_with_nucl_rep,pt2,relative_error,error, variance, & if (is_complex) then
norm, to_select) ! Stochastic PT2 and selection call zmq_pt2_complex(psi_energy_with_nucl_rep,pt2,relative_error,error, variance, &
norm, to_select) ! Stochastic PT2 and selection
else
call zmq_pt2(psi_energy_with_nucl_rep,pt2,relative_error,error, variance, &
norm, to_select) ! Stochastic PT2 and selection
endif
do k=1,N_states do k=1,N_states
rpt2(k) = pt2(k)/(1.d0 + norm(k)) rpt2(k) = pt2(k)/(1.d0 + norm(k))
@ -107,14 +120,22 @@ subroutine run_stochastic_cipsi
if (qp_stop()) exit if (qp_stop()) exit
! Add selected determinants ! Add selected determinants
call copy_H_apply_buffer_to_wf() call copy_h_apply_buffer_to_wf()
! call save_wavefunction ! call save_wavefunction
PROVIDE psi_coef if (is_complex) then
PROVIDE psi_coef_complex
else
PROVIDE psi_coef
endif
PROVIDE psi_det PROVIDE psi_det
PROVIDE psi_det_sorted PROVIDE psi_det_sorted
call diagonalize_CI if (is_complex) then
call diagonalize_ci_complex
else
call diagonalize_CI
endif
call save_wavefunction call save_wavefunction
call save_energy(psi_energy_with_nucl_rep, zeros) call save_energy(psi_energy_with_nucl_rep, zeros)
if (qp_stop()) exit if (qp_stop()) exit
@ -122,7 +143,11 @@ subroutine run_stochastic_cipsi
if (.not.qp_stop()) then if (.not.qp_stop()) then
if (N_det < N_det_max) then if (N_det < N_det_max) then
call diagonalize_CI if (is_complex) then
call diagonalize_ci_complex
else
call diagonalize_CI
endif
call save_wavefunction call save_wavefunction
call save_energy(psi_energy_with_nucl_rep, zeros) call save_energy(psi_energy_with_nucl_rep, zeros)
endif endif
@ -130,8 +155,13 @@ subroutine run_stochastic_cipsi
pt2(:) = 0.d0 pt2(:) = 0.d0
variance(:) = 0.d0 variance(:) = 0.d0
norm(:) = 0.d0 norm(:) = 0.d0
call ZMQ_pt2(psi_energy_with_nucl_rep, pt2,relative_error,error,variance, & if (is_complex) then
norm,0) ! Stochastic PT2 call zmq_pt2_complex(psi_energy_with_nucl_rep, pt2,relative_error,error,variance, &
norm,0) ! Stochastic PT2
else
call ZMQ_pt2(psi_energy_with_nucl_rep, pt2,relative_error,error,variance, &
norm,0) ! Stochastic PT2
endif
do k=1,N_states do k=1,N_states
rpt2(k) = pt2(k)/(1.d0 + norm(k)) rpt2(k) = pt2(k)/(1.d0 + norm(k))

View File

@ -17,6 +17,7 @@ subroutine ZMQ_selection(N_in, pt2, variance, norm)
N = max(N_in,1) N = max(N_in,1)
if (.True.) then if (.True.) then
!todo: some providers have becom unlinked for real/complex (det/coef); do these need to be provided?
PROVIDE pt2_e0_denominator nproc PROVIDE pt2_e0_denominator nproc
PROVIDE psi_bilinear_matrix_columns_loc psi_det_alpha_unique psi_det_beta_unique PROVIDE psi_bilinear_matrix_columns_loc psi_det_alpha_unique psi_det_beta_unique
PROVIDE psi_bilinear_matrix_rows psi_det_sorted_order psi_bilinear_matrix_order PROVIDE psi_bilinear_matrix_rows psi_det_sorted_order psi_bilinear_matrix_order
@ -105,9 +106,16 @@ subroutine ZMQ_selection(N_in, pt2, variance, norm)
f(:) = 1.d0 f(:) = 1.d0
if (.not.do_pt2) then if (.not.do_pt2) then
double precision :: f(N_states), u_dot_u double precision :: f(N_states), u_dot_u
do k=1,min(N_det,N_states) if (is_complex) then
f(k) = 1.d0 / u_dot_u(psi_selectors_coef(1,k), N_det_selectors) double precision :: u_dot_u_complex
enddo do k=1,min(N_det,N_states)
f(k) = 1.d0 / u_dot_u_complex(psi_selectors_coef_complex(1,k), N_det_selectors)
enddo
else
do k=1,min(N_det,N_states)
f(k) = 1.d0 / u_dot_u(psi_selectors_coef(1,k), N_det_selectors)
enddo
endif
endif endif
!$OMP PARALLEL DEFAULT(shared) SHARED(b, pt2, variance, norm) PRIVATE(i) NUM_THREADS(nproc_target+1) !$OMP PARALLEL DEFAULT(shared) SHARED(b, pt2, variance, norm) PRIVATE(i) NUM_THREADS(nproc_target+1)

View File

@ -1,14 +1,41 @@
------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------
current: current:
select_connected
select_singles_and_doubles (this should be separated real/complex)
spot_isinwf (same for real/complex)
splash_pq (separate real/complex)
get_d{0,1,2} (separate real/complex)
fill_buffer_double (separate real/complex)
fci fci
run_cipsi run_{,stochastic_}cipsi
zmq_pt2_complex everything okay except:
selection buffer? (val, mini)? zmq_pt2{,_complex} (todo: combine real/complex)
selection_slave_inproc selection buffer? (val, mini)?
zmq_selection_complex selection_slave_inproc
run_selection_slave
select_connected
pt2_slave_inproc
run_pt2_slave{,_large,_small}
select_connected
zmq_selection_complex
selection_collector
pull_selection_results
add_to_selection_buffer
selection_slave_inproc
run_selection_slave (has split for complex?)
select_connected
run_slave_cipsi run_slave_cipsi
run_stochastic_cipsi run_slave_main
change memory allocation for complex (first see how many arrays will need to change type)
run_pt2_slave (large/small?)
select_connected
selection_buffer:
if anything complex, need to change zmq calls
{push,pull}_pt2_results
------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------