mirror of
https://github.com/QuantumPackage/qp2.git
synced 2024-12-22 11:33:29 +01:00
split the mo_optimization into mo_optimizatio_utils and mo_optimization
This commit is contained in:
parent
d7bf334fc0
commit
228796cff5
@ -3,3 +3,4 @@ selectors_full
|
||||
generators_cas
|
||||
two_body_rdm
|
||||
dav_general_mat
|
||||
mo_optimization
|
||||
|
@ -1,7 +1,3 @@
|
||||
two_body_rdm
|
||||
hartree_fock
|
||||
cipsi
|
||||
davidson_undressed
|
||||
mo_optimization_utils
|
||||
selectors_full
|
||||
generators_full
|
||||
utils_trust_region
|
||||
|
@ -2,87 +2,7 @@ program optimization
|
||||
|
||||
read_wf = .true. ! must be True for the orbital optimization !!!
|
||||
TOUCH read_wf
|
||||
call run_optimization
|
||||
call run_optimization_mos_CIPSI
|
||||
|
||||
end
|
||||
|
||||
subroutine run_optimization
|
||||
|
||||
implicit none
|
||||
|
||||
double precision :: e_cipsi, e_opt, delta_e
|
||||
double precision, allocatable :: Ev(:),PT2(:)
|
||||
integer :: nb_iter,i
|
||||
logical :: not_converged
|
||||
character (len=100) :: filename
|
||||
|
||||
PROVIDE psi_det psi_coef mo_two_e_integrals_in_map ao_pseudo_integrals
|
||||
allocate(Ev(N_states),PT2(N_states))
|
||||
|
||||
not_converged = .True.
|
||||
nb_iter = 0
|
||||
|
||||
! To start from the wf
|
||||
N_det_max = max(n_det,5)
|
||||
TOUCH N_det_max
|
||||
|
||||
open(unit=10, file=trim(ezfio_filename)//'/mo_optimization/result_opt')
|
||||
write(10,*) " Ndet E_cipsi E_opt Delta_e"
|
||||
call state_average_energy(e_cipsi)
|
||||
write(10,'(I10, 3F15.7)') n_det, e_cipsi, e_cipsi, 0d0
|
||||
close(10)
|
||||
|
||||
do while (not_converged)
|
||||
print*,''
|
||||
print*,'======================'
|
||||
print*,' Cipsi step:', nb_iter
|
||||
print*,'======================'
|
||||
print*,''
|
||||
print*,'********** cipsi step **********'
|
||||
! cispi calculation
|
||||
call run_stochastic_cipsi(Ev,PT2)
|
||||
|
||||
! State average energy after the cipsi step
|
||||
call state_average_energy(e_cipsi)
|
||||
|
||||
print*,''
|
||||
print*,'********** optimization step **********'
|
||||
! orbital optimization
|
||||
call run_orb_opt_trust_v2
|
||||
|
||||
! State average energy after the orbital optimization
|
||||
call state_average_energy(e_opt)
|
||||
|
||||
print*,''
|
||||
print*,'********** diff step **********'
|
||||
! Gain in energy
|
||||
delta_e = e_opt - e_cipsi
|
||||
print*, 'Gain in energy during the orbital optimization:', delta_e
|
||||
|
||||
open(unit=10, file=trim(ezfio_filename)//'/mo_optimization/result_opt', position='append')
|
||||
write(10,'(I10, 3F15.7)') n_det, e_cipsi, e_opt, delta_e
|
||||
close(10)
|
||||
|
||||
! Exit
|
||||
if (delta_e > 1d-12) then
|
||||
print*, 'WARNING, something wrong happened'
|
||||
print*, 'The gain (delta_e) in energy during the optimization process'
|
||||
print*, 'is > 0, but it must be < 0'
|
||||
print*, 'The program will exit'
|
||||
exit
|
||||
endif
|
||||
|
||||
if (n_det > n_det_max_opt) then
|
||||
print*, 'The number of determinants in the wf > n_det_max_opt'
|
||||
print*, 'The program will exit'
|
||||
exit
|
||||
endif
|
||||
|
||||
! To double the number of determinants in the wf
|
||||
N_det_max = int(dble(n_det * 2)*0.9)
|
||||
TOUCH N_det_max
|
||||
|
||||
nb_iter = nb_iter + 1
|
||||
enddo
|
||||
|
||||
end
|
||||
|
5
src/mo_optimization_utils/NEED
Normal file
5
src/mo_optimization_utils/NEED
Normal file
@ -0,0 +1,5 @@
|
||||
two_body_rdm
|
||||
hartree_fock
|
||||
cipsi
|
||||
davidson_undressed
|
||||
utils_trust_region
|
74
src/mo_optimization_utils/README.md
Normal file
74
src/mo_optimization_utils/README.md
Normal file
@ -0,0 +1,74 @@
|
||||
# Orbital optimization
|
||||
|
||||
## Methods
|
||||
Different methods are available:
|
||||
- full hessian
|
||||
```
|
||||
qp set orbital_optimization optimization_method full
|
||||
```
|
||||
- diagonal hessian
|
||||
```
|
||||
qp set orbital_optimization optimization_method diag
|
||||
```
|
||||
- identity matrix
|
||||
```
|
||||
qp set orbital_optimization optimization_method none
|
||||
```
|
||||
|
||||
After the optimization the ezfio contains the optimized orbitals
|
||||
|
||||
## For a fixed number of determinants
|
||||
To optimize the MOs for the actual determinants:
|
||||
```
|
||||
qp run orb_opt
|
||||
```
|
||||
|
||||
## For a complete optimization, i.e, with a larger and larger wave function
|
||||
To optimize the MOs with a larger and larger wave function:
|
||||
```
|
||||
qp run optimization
|
||||
```
|
||||
|
||||
The results are stored in the EZFIO in "mo_optimization/result_opt",
|
||||
with the following format:
|
||||
(1) (2) (3) (4)
|
||||
1: Number of determinants in the wf,
|
||||
2: Cispi energy before the optimization,
|
||||
3: Cipsi energy after the optimization,
|
||||
4: Energy difference between (2) and (3).
|
||||
|
||||
The optimization process if the following:
|
||||
- we do a first cipsi step to obtain a small number of determinants in the wf
|
||||
- we run an orbital optimization for this wf
|
||||
- we do a new cipsi step to double the number of determinants in the wf
|
||||
- we run an orbital optimization for this wf
|
||||
- ...
|
||||
- we do that until the energy difference between (2) and (3) is
|
||||
smaller than the targeted accuracy for the cispi (targeted_accuracy_cipsi in qp edit)
|
||||
or the wf is larger than a given size (n_det_max_opt in qp_edit)
|
||||
- after that you can reset your determinants (qp reset -d) and run a clean Cispi calculation
|
||||
|
||||
### End of the optimization
|
||||
You can choos the number of determinants after what the
|
||||
optimization will stop:
|
||||
```
|
||||
qp set orbital_optimization n_det_max_opt 1e5 # or any number
|
||||
```
|
||||
## Weight of the states
|
||||
You can change the weights of the differents states directly in qp edit.
|
||||
It will affect ths weights used in the orbital optimization.
|
||||
|
||||
# Tests
|
||||
To run the tests:
|
||||
```
|
||||
qp test
|
||||
```
|
||||
|
||||
# Org files
|
||||
The org files are stored in the directory org in order to avoid overwriting on user changes.
|
||||
The org files can be modified, to export the change to the source code, run
|
||||
```
|
||||
./TANGLE_org_mode.sh
|
||||
mv *.irp.f ../.
|
||||
```
|
||||
|
81
src/mo_optimization_utils/routine_opt_mos.irp.f
Normal file
81
src/mo_optimization_utils/routine_opt_mos.irp.f
Normal file
@ -0,0 +1,81 @@
|
||||
|
||||
subroutine run_optimization_mos_CIPSI
|
||||
|
||||
implicit none
|
||||
|
||||
double precision :: e_cipsi, e_opt, delta_e
|
||||
double precision, allocatable :: Ev(:),PT2(:)
|
||||
integer :: nb_iter,i
|
||||
logical :: not_converged
|
||||
character (len=100) :: filename
|
||||
|
||||
PROVIDE psi_det psi_coef mo_two_e_integrals_in_map ao_pseudo_integrals
|
||||
allocate(Ev(N_states),PT2(N_states))
|
||||
|
||||
not_converged = .True.
|
||||
nb_iter = 0
|
||||
|
||||
! To start from the wf
|
||||
N_det_max = max(n_det,5)
|
||||
TOUCH N_det_max
|
||||
|
||||
open(unit=10, file=trim(ezfio_filename)//'/mo_optimization/result_opt')
|
||||
write(10,*) " Ndet E_cipsi E_opt Delta_e"
|
||||
call state_average_energy(e_cipsi)
|
||||
write(10,'(I10, 3F15.7)') n_det, e_cipsi, e_cipsi, 0d0
|
||||
close(10)
|
||||
|
||||
do while (not_converged)
|
||||
print*,''
|
||||
print*,'======================'
|
||||
print*,' Cipsi step:', nb_iter
|
||||
print*,'======================'
|
||||
print*,''
|
||||
print*,'********** cipsi step **********'
|
||||
! cispi calculation
|
||||
call run_stochastic_cipsi(Ev,PT2)
|
||||
|
||||
! State average energy after the cipsi step
|
||||
call state_average_energy(e_cipsi)
|
||||
|
||||
print*,''
|
||||
print*,'********** optimization step **********'
|
||||
! orbital optimization
|
||||
call run_orb_opt_trust_v2
|
||||
|
||||
! State average energy after the orbital optimization
|
||||
call state_average_energy(e_opt)
|
||||
|
||||
print*,''
|
||||
print*,'********** diff step **********'
|
||||
! Gain in energy
|
||||
delta_e = e_opt - e_cipsi
|
||||
print*, 'Gain in energy during the orbital optimization:', delta_e
|
||||
|
||||
open(unit=10, file=trim(ezfio_filename)//'/mo_optimization/result_opt', position='append')
|
||||
write(10,'(I10, 3F15.7)') n_det, e_cipsi, e_opt, delta_e
|
||||
close(10)
|
||||
|
||||
! Exit
|
||||
if (delta_e > 1d-12) then
|
||||
print*, 'WARNING, something wrong happened'
|
||||
print*, 'The gain (delta_e) in energy during the optimization process'
|
||||
print*, 'is > 0, but it must be < 0'
|
||||
print*, 'The program will exit'
|
||||
exit
|
||||
endif
|
||||
|
||||
if (n_det > n_det_max_opt) then
|
||||
print*, 'The number of determinants in the wf > n_det_max_opt'
|
||||
print*, 'The program will exit'
|
||||
exit
|
||||
endif
|
||||
|
||||
! To double the number of determinants in the wf
|
||||
N_det_max = int(dble(n_det * 2)*0.9)
|
||||
TOUCH N_det_max
|
||||
|
||||
nb_iter = nb_iter + 1
|
||||
enddo
|
||||
|
||||
end
|
Loading…
Reference in New Issue
Block a user