10
0
mirror of https://github.com/LCPQ/quantum_package synced 2024-12-22 20:35:19 +01:00

Improved CASSD and FCI

This commit is contained in:
Anthony Scemama 2017-05-03 19:23:12 +02:00
parent c62302002e
commit 8288437ae6
4 changed files with 167 additions and 152 deletions

View File

@ -389,7 +389,12 @@ let get_task msg program_state rep_socket pair_socket =
let new_queue, task_id, task = let new_queue, task_id, task =
Queuing_system.pop_task ~client_id program_state.queue Queuing_system.pop_task ~client_id program_state.queue
in in
if (Queuing_system.number_of_queued new_queue = 0) then
let no_task =
Queuing_system.number_of_queued new_queue = 0
in
if no_task then
string_of_pub_state Waiting string_of_pub_state Waiting
|> ZMQ.Socket.send pair_socket |> ZMQ.Socket.send pair_socket
else else
@ -658,12 +663,17 @@ let run ~port =
in in
(** Debug input *) (** Debug input *)
Printf.sprintf "q:%d r:%d n:%d : %s\n%!" let () =
(Queuing_system.number_of_queued program_state.queue) if debug_env then
(Queuing_system.number_of_running program_state.queue) begin
(Queuing_system.number_of_tasks program_state.queue) Printf.sprintf "q:%d r:%d n:%d : %s\n%!"
(Message.to_string message) (Queuing_system.number_of_queued program_state.queue)
|> debug; (Queuing_system.number_of_running program_state.queue)
(Queuing_system.number_of_tasks program_state.queue)
(Message.to_string message)
|> debug
end
in
let new_program_state = let new_program_state =
try try

View File

@ -1,16 +1,23 @@
program fci_zmq program cassd_zmq
implicit none implicit none
integer :: i,j,k integer :: i,j,k
logical, external :: detEq
double precision, allocatable :: pt2(:) double precision, allocatable :: pt2(:)
integer :: degree integer :: degree
integer :: n_det_before, to_select
double precision :: threshold_davidson_in double precision :: threshold_davidson_in
allocate (pt2(N_states)) allocate (pt2(N_states))
double precision :: hf_energy_ref double precision :: hf_energy_ref
logical :: has logical :: has
pt2 = -huge(1.d0)
threshold_davidson_in = threshold_davidson
threshold_davidson = threshold_davidson_in * 100.d0
SOFT_TOUCH threshold_davidson
call diagonalize_CI
call save_wavefunction
call ezfio_has_hartree_fock_energy(has) call ezfio_has_hartree_fock_energy(has)
if (has) then if (has) then
call ezfio_get_hartree_fock_energy(hf_energy_ref) call ezfio_get_hartree_fock_energy(hf_energy_ref)
@ -18,15 +25,7 @@ program fci_zmq
hf_energy_ref = ref_bitmask_energy hf_energy_ref = ref_bitmask_energy
endif endif
pt2 = 1.d0
threshold_davidson_in = threshold_davidson
threshold_davidson = threshold_davidson_in * 100.d0
SOFT_TOUCH threshold_davidson
if (N_det > N_det_max) then if (N_det > N_det_max) then
call diagonalize_CI
call save_wavefunction
psi_det = psi_det_sorted psi_det = psi_det_sorted
psi_coef = psi_coef_sorted psi_coef = psi_coef_sorted
N_det = N_det_max N_det = N_det_max
@ -46,75 +45,78 @@ program fci_zmq
double precision :: E_CI_before(N_states) double precision :: E_CI_before(N_states)
integer :: n_det_before, to_select
print*,'Beginning the selection ...' print*,'Beginning the selection ...'
E_CI_before(1:N_states) = CI_energy(1:N_states) if (.True.) then ! Avoid pre-calculation of CI_energy
E_CI_before(1:N_states) = CI_energy(1:N_states)
endif
n_det_before = 0
double precision :: correlation_energy_ratio double precision :: correlation_energy_ratio
correlation_energy_ratio = 0.d0 correlation_energy_ratio = 0.d0
do while ( & if (.True.) then ! Avoid pre-calculation of CI_energy
(N_det < N_det_max) .and. & do while ( &
(maxval(abs(pt2(1:N_states))) > pt2_max) .and. & (N_det < N_det_max) .and. &
(correlation_energy_ratio <= correlation_energy_ratio_max) & (maxval(abs(pt2(1:N_states))) > pt2_max) .and. &
) (correlation_energy_ratio <= correlation_energy_ratio_max) &
)
correlation_energy_ratio = (CI_energy(1) - hf_energy_ref) / & correlation_energy_ratio = (CI_energy(1) - hf_energy_ref) / &
(E_CI_before(1) + pt2(1) - hf_energy_ref) (E_CI_before(1) + pt2(1) - hf_energy_ref)
correlation_energy_ratio = min(1.d0,correlation_energy_ratio) correlation_energy_ratio = min(1.d0,correlation_energy_ratio)
print *, 'N_det = ', N_det print *, 'N_det = ', N_det
print *, 'N_states = ', N_states print *, 'N_states = ', N_states
print*, 'correlation_ratio = ', correlation_energy_ratio print*, 'correlation_ratio = ', correlation_energy_ratio
do k=1, N_states do k=1, N_states
print*,'State ',k print*,'State ',k
print *, 'PT2 = ', pt2(k) print *, 'PT2 = ', pt2(k)
print *, 'E = ', CI_energy(k) print *, 'E = ', CI_energy(k)
print *, 'E(before)+PT2 = ', E_CI_before(k)+pt2(k) print *, 'E(before)+PT2 = ', E_CI_before(k)+pt2(k)
enddo
print *, '-----'
if(N_states.gt.1)then
print*,'Variational Energy difference'
do i = 2, N_states
print*,'Delta E = ',CI_energy(i) - CI_energy(1)
enddo
endif
if(N_states.gt.1)then
print*,'Variational + perturbative Energy difference'
do i = 2, N_states
print*,'Delta E = ',E_CI_before(i)+ pt2(i) - (E_CI_before(1) + pt2(1))
enddo
endif
E_CI_before(1:N_states) = CI_energy(1:N_states)
call ezfio_set_full_ci_zmq_energy(CI_energy(1))
n_det_before = N_det
to_select = N_det
to_select = max(N_det, to_select)
to_select = min(to_select, N_det_max-n_det_before)
call ZMQ_selection(to_select, pt2)
PROVIDE psi_coef
PROVIDE psi_det
PROVIDE psi_det_sorted
if (N_det == N_det_max) then
threshold_davidson = threshold_davidson_in
end if
call diagonalize_CI
call save_wavefunction
call ezfio_set_cas_sd_zmq_energy(CI_energy(1))
enddo enddo
print *, '-----' endif
if(N_states.gt.1)then
print*,'Variational Energy difference'
do i = 2, N_states
print*,'Delta E = ',CI_energy(i) - CI_energy(1)
enddo
endif
if(N_states.gt.1)then
print*,'Variational + perturbative Energy difference'
do i = 2, N_states
print*,'Delta E = ',E_CI_before(i)+ pt2(i) - (E_CI_before(1) + pt2(1))
enddo
endif
E_CI_before(1:N_states) = CI_energy(1:N_states)
call ezfio_set_cas_sd_zmq_energy(CI_energy(1))
n_det_before = N_det
to_select = 2*N_det
to_select = max(64-to_select, to_select)
to_select = min(to_select,N_det_max-n_det_before)
call ZMQ_selection(to_select, pt2)
PROVIDE psi_coef
PROVIDE psi_det
PROVIDE psi_det_sorted
if (N_det == N_det_max) then
threshold_davidson = threshold_davidson_in
SOFT_TOUCH threshold_davidson
endif
call diagonalize_CI
call save_wavefunction
call ezfio_set_cas_sd_zmq_energy(CI_energy(1))
enddo
if (N_det < N_det_max) then if (N_det < N_det_max) then
threshold_davidson = threshold_davidson_in threshold_davidson = threshold_davidson_in
SOFT_TOUCH threshold_davidson call diagonalize_CI
call diagonalize_CI call save_wavefunction
call save_wavefunction call ezfio_set_full_ci_zmq_energy(CI_energy(1))
call ezfio_set_cas_sd_zmq_energy(CI_energy(1))
endif endif
integer :: exc_max, degree_min integer :: exc_max, degree_min
@ -148,10 +150,8 @@ program fci_zmq
print *, 'E+PT2 = ', E_CI_before(k)+pt2(k) print *, 'E+PT2 = ', E_CI_before(k)+pt2(k)
print *, '-----' print *, '-----'
enddo enddo
call ezfio_set_cas_sd_zmq_energy_pt2(E_CI_before+pt2) call ezfio_set_cas_sd_zmq_energy_pt2(E_CI_before(1)+pt2(1))
endif endif
call save_wavefunction
call ezfio_set_cas_sd_zmq_energy(CI_energy(1))
call ezfio_set_cas_sd_zmq_energy_pt2(E_CI_before(1)+pt2(1)) call ezfio_set_cas_sd_zmq_energy_pt2(E_CI_before(1)+pt2(1))
end end

View File

@ -1,8 +1,6 @@
program fci_zmq program fci_zmq
implicit none implicit none
integer :: i,j,k integer :: i,j,k
logical, external :: detEq
double precision, allocatable :: pt2(:) double precision, allocatable :: pt2(:)
integer :: degree integer :: degree
integer :: n_det_before, to_select integer :: n_det_before, to_select
@ -12,6 +10,14 @@ program fci_zmq
double precision :: hf_energy_ref double precision :: hf_energy_ref
logical :: has logical :: has
pt2 = -huge(1.d0)
threshold_davidson_in = threshold_davidson
threshold_davidson = threshold_davidson_in * 100.d0
SOFT_TOUCH threshold_davidson
call diagonalize_CI
call save_wavefunction
call ezfio_has_hartree_fock_energy(has) call ezfio_has_hartree_fock_energy(has)
if (has) then if (has) then
call ezfio_get_hartree_fock_energy(hf_energy_ref) call ezfio_get_hartree_fock_energy(hf_energy_ref)
@ -19,14 +25,7 @@ program fci_zmq
hf_energy_ref = ref_bitmask_energy hf_energy_ref = ref_bitmask_energy
endif endif
pt2 = -huge(1.d0)
threshold_davidson_in = threshold_davidson
threshold_davidson = threshold_davidson_in * 100.d0
SOFT_TOUCH threshold_davidson
if (N_det > N_det_max) then if (N_det > N_det_max) then
call diagonalize_CI
call save_wavefunction
psi_det = psi_det_sorted psi_det = psi_det_sorted
psi_coef = psi_coef_sorted psi_coef = psi_coef_sorted
N_det = N_det_max N_det = N_det_max
@ -47,66 +46,71 @@ program fci_zmq
print*,'Beginning the selection ...' print*,'Beginning the selection ...'
E_CI_before(1:N_states) = CI_energy(1:N_states) if (.True.) then ! Avoid pre-calculation of CI_energy
E_CI_before(1:N_states) = CI_energy(1:N_states)
endif
n_det_before = 0 n_det_before = 0
double precision :: correlation_energy_ratio double precision :: correlation_energy_ratio
correlation_energy_ratio = 0.d0 correlation_energy_ratio = 0.d0
do while ( & if (.True.) then ! Avoid pre-calculation of CI_energy
(N_det < N_det_max) .and. & do while ( &
(maxval(abs(pt2(1:N_states))) > pt2_max) .and. & (N_det < N_det_max) .and. &
(correlation_energy_ratio <= correlation_energy_ratio_max) & (maxval(abs(pt2(1:N_states))) > pt2_max) .and. &
) (correlation_energy_ratio <= correlation_energy_ratio_max) &
)
correlation_energy_ratio = (CI_energy(1) - hf_energy_ref) / & correlation_energy_ratio = (CI_energy(1) - hf_energy_ref) / &
(E_CI_before(1) + pt2(1) - hf_energy_ref) (E_CI_before(1) + pt2(1) - hf_energy_ref)
correlation_energy_ratio = min(1.d0,correlation_energy_ratio) correlation_energy_ratio = min(1.d0,correlation_energy_ratio)
print *, 'N_det = ', N_det
print *, 'N_states = ', N_states
print*, 'correlation_ratio = ', correlation_energy_ratio
do k=1, N_states print *, 'N_det = ', N_det
print*,'State ',k print *, 'N_states = ', N_states
print *, 'PT2 = ', pt2(k) print*, 'correlation_ratio = ', correlation_energy_ratio
print *, 'E = ', CI_energy(k)
print *, 'E(before)+PT2 = ', E_CI_before(k)+pt2(k) do k=1, N_states
print*,'State ',k
print *, 'PT2 = ', pt2(k)
print *, 'E = ', CI_energy(k)
print *, 'E(before)+PT2 = ', E_CI_before(k)+pt2(k)
enddo
print *, '-----'
if(N_states.gt.1)then
print*,'Variational Energy difference'
do i = 2, N_states
print*,'Delta E = ',CI_energy(i) - CI_energy(1)
enddo
endif
if(N_states.gt.1)then
print*,'Variational + perturbative Energy difference'
do i = 2, N_states
print*,'Delta E = ',E_CI_before(i)+ pt2(i) - (E_CI_before(1) + pt2(1))
enddo
endif
E_CI_before(1:N_states) = CI_energy(1:N_states)
call ezfio_set_full_ci_zmq_energy(CI_energy(1))
n_det_before = N_det
to_select = N_det
to_select = max(N_det, to_select)
to_select = min(to_select, N_det_max-n_det_before)
call ZMQ_selection(to_select, pt2)
PROVIDE psi_coef
PROVIDE psi_det
PROVIDE psi_det_sorted
if (N_det == N_det_max) then
threshold_davidson = threshold_davidson_in
end if
call diagonalize_CI
call save_wavefunction
call ezfio_set_full_ci_zmq_energy(CI_energy(1))
enddo enddo
endif
print *, '-----'
if(N_states.gt.1)then
print*,'Variational Energy difference'
do i = 2, N_states
print*,'Delta E = ',CI_energy(i) - CI_energy(1)
enddo
endif
if(N_states.gt.1)then
print*,'Variational + perturbative Energy difference'
do i = 2, N_states
print*,'Delta E = ',E_CI_before(i)+ pt2(i) - (E_CI_before(1) + pt2(1))
enddo
endif
E_CI_before(1:N_states) = CI_energy(1:N_states)
call ezfio_set_full_ci_zmq_energy(CI_energy(1))
n_det_before = N_det
to_select = N_det
to_select = max(N_det, to_select)
to_select = min(to_select, N_det_max-n_det_before)
call ZMQ_selection(to_select, pt2)
PROVIDE psi_coef
PROVIDE psi_det
PROVIDE psi_det_sorted
if (N_det == N_det_max) then
threshold_davidson = threshold_davidson_in
end if
call diagonalize_CI
call save_wavefunction
call ezfio_set_full_ci_zmq_energy(CI_energy(1))
enddo
if (N_det < N_det_max) then if (N_det < N_det_max) then
threshold_davidson = threshold_davidson_in threshold_davidson = threshold_davidson_in
@ -139,16 +143,13 @@ program fci_zmq
print *, 'N_states = ', N_states print *, 'N_states = ', N_states
do k=1,N_states do k=1,N_states
print *, 'State', k print *, 'State', k
print *, 'PT2 = ', pt2 print *, 'PT2 = ', pt2(k)
print *, 'E = ', E_CI_before print *, 'E = ', E_CI_before(k)
print *, 'E+PT2 = ', E_CI_before+pt2 print *, 'E+PT2 = ', E_CI_before(k)+pt2(k)
print *, '-----' print *, '-----'
enddo enddo
call ezfio_set_full_ci_zmq_energy_pt2(E_CI_before(1)+pt2(1)) call ezfio_set_full_ci_zmq_energy_pt2(E_CI_before(1)+pt2(1))
endif endif
call save_wavefunction
call ezfio_set_full_ci_zmq_energy(CI_energy(1))
call ezfio_set_full_ci_zmq_energy_pt2(E_CI_before(1)+pt2(1)) call ezfio_set_full_ci_zmq_energy_pt2(E_CI_before(1)+pt2(1))
end end

View File

@ -535,7 +535,7 @@ subroutine new_parallel_job(zmq_to_qp_run_socket,name_in)
rc = f77_zmq_recv(zmq_to_qp_run_socket,message,510,0) rc = f77_zmq_recv(zmq_to_qp_run_socket,message,510,0)
message = trim(message(1:rc)) message = trim(message(1:rc))
if (message(1:2) /= 'ok') then if (message(1:2) /= 'ok') then
print *, message print *, trim(message(1:rc))
print *, 'Unable to start parallel job : '//name print *, 'Unable to start parallel job : '//name
stop 1 stop 1
endif endif
@ -565,6 +565,7 @@ subroutine zmq_set_running(zmq_to_qp_run_socket)
rc = f77_zmq_recv(zmq_to_qp_run_socket,message,510,0) rc = f77_zmq_recv(zmq_to_qp_run_socket,message,510,0)
message = trim(message(1:rc)) message = trim(message(1:rc))
if (message(1:2) /= 'ok') then if (message(1:2) /= 'ok') then
print *, trim(message(1:rc))
print *, 'Unable to set qp_run to Running' print *, 'Unable to set qp_run to Running'
stop 1 stop 1
endif endif
@ -718,6 +719,7 @@ subroutine add_task_to_taskserver(zmq_to_qp_run_socket,task)
rc = f77_zmq_recv(zmq_to_qp_run_socket, message, sze-1, 0) rc = f77_zmq_recv(zmq_to_qp_run_socket, message, sze-1, 0)
if (message(1:rc) /= 'ok') then if (message(1:rc) /= 'ok') then
print *, trim(message(1:rc))
print *, trim(task) print *, trim(task)
print *, 'Unable to add the next task' print *, 'Unable to add the next task'
stop -1 stop -1
@ -762,6 +764,7 @@ subroutine add_task_to_taskserver_recv(zmq_to_qp_run_socket)
character*(512) :: message character*(512) :: message
rc = f77_zmq_recv(zmq_to_qp_run_socket, message, 510, 0) rc = f77_zmq_recv(zmq_to_qp_run_socket, message, 510, 0)
if (message(1:rc) /= 'ok') then if (message(1:rc) /= 'ok') then
print *, trim(message(1:rc))
print *, 'Unable to add the next task' print *, 'Unable to add the next task'
stop -1 stop -1
endif endif
@ -790,6 +793,7 @@ subroutine task_done_to_taskserver(zmq_to_qp_run_socket, worker_id, task_id)
rc = f77_zmq_recv(zmq_to_qp_run_socket, message, 510, 0) rc = f77_zmq_recv(zmq_to_qp_run_socket, message, 510, 0)
if (trim(message(1:rc)) /= 'ok') then if (trim(message(1:rc)) /= 'ok') then
print *, trim(message(1:rc))
print *, 'Unable to send task_done message' print *, 'Unable to send task_done message'
stop -1 stop -1
endif endif