57#include "./base/base_uses.f90"
63 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'pao_main'
78 CHARACTER(len=*),
PARAMETER :: routinen =
'pao_init'
85 IF (.NOT. ls_scf_env%do_pao)
RETURN
87 CALL timeset(routinen, handle)
89 pao => ls_scf_env%pao_env
90 CALL get_qs_env(qs_env=qs_env, input=input, matrix_s=matrix_s)
100 CALL timestop(handle)
112 CHARACTER(len=*),
PARAMETER :: routinen =
'pao_optimization_start'
119 IF (.NOT. ls_scf_env%do_pao)
RETURN
121 CALL timeset(routinen, handle)
123 pao => ls_scf_env%pao_env
124 ls_mstruct => ls_scf_env%ls_mstruct
129 pao%matrix_P_ready = .false.
132 IF (.NOT. pao%constants_ready)
THEN
137 pao%constants_ready = .true.
143 IF (.NOT. pao%matrix_X_ready)
THEN
146 IF (len_trim(pao%restart_file) > 0)
THEN
148 ELSE IF (
SIZE(pao%ml_training_set) > 0)
THEN
150 ELSE IF (
ALLOCATED(pao%models))
THEN
155 pao%matrix_X_ready = .true.
156 ELSE IF (
SIZE(pao%ml_training_set) > 0)
THEN
158 ELSE IF (
ALLOCATED(pao%models))
THEN
161 IF (pao%iw > 0)
WRITE (pao%iw, *)
"PAO| reusing matrix_X from previous optimization"
172 CALL dbcsr_create(ls_mstruct%matrix_A, template=pao%matrix_Y)
174 CALL dbcsr_create(ls_mstruct%matrix_B, template=pao%matrix_Y)
178 CALL pao_calc_ab(pao, qs_env, ls_scf_env, gradient=.false.)
180 CALL timestop(handle)
192 LOGICAL,
INTENT(OUT) :: pao_is_done
194 CHARACTER(len=*),
PARAMETER :: routinen =
'pao_update'
196 INTEGER :: handle, icycle
197 LOGICAL :: cycle_converged, do_mixing, should_stop
198 REAL(kind=
dp) :: energy, penalty
203 IF (.NOT. ls_scf_env%do_pao)
THEN
208 ls_mstruct => ls_scf_env%ls_mstruct
209 pao => ls_scf_env%pao_env
211 IF (.NOT. pao%matrix_P_ready)
THEN
213 pao%matrix_P_ready = .true.
216 IF (pao%max_pao == 0)
THEN
221 IF (pao%need_initial_scf)
THEN
222 pao_is_done = .false.
223 pao%need_initial_scf = .false.
224 IF (pao%iw > 0)
WRITE (pao%iw, *)
"PAO| Performing initial SCF optimization."
228 CALL timeset(routinen, handle)
231 do_mixing = pao%mixing /= 1.0_dp .AND. pao%istep > 1
233 CALL dbcsr_copy(matrix_x_mixing, pao%matrix_X)
236 cycle_converged = .false.
242 pao%istep = pao%istep + 1
244 IF (pao%iw > 0)
WRITE (pao%iw,
"(A,I9,A)")
" PAO| ======================= Iteration: ", &
245 pao%istep,
" ============================="
251 IF (pao%linesearch%starts)
THEN
254 CALL pao_calc_ab(pao, qs_env, ls_scf_env, gradient=.true., penalty=penalty)
261 CALL dbcsr_copy(pao%matrix_X_orig, pao%matrix_X)
265 IF (cycle_converged)
THEN
266 pao_is_done = icycle < 3
267 IF (pao_is_done .AND. pao%iw > 0)
WRITE (pao%iw, *)
"PAO| converged after ", pao%istep,
" steps :-)"
273 IF (icycle >= pao%max_cycles)
THEN
274 IF (pao%iw > 0)
WRITE (pao%iw, *)
"PAO| CG not yet converged after ", icycle,
" cylces."
275 pao_is_done = .false.
279 IF (mod(icycle, pao%write_cycles) == 0) &
284 CALL external_control(should_stop,
"PAO", start_time=qs_env%start_time, target_time=qs_env%target_time)
285 IF (should_stop .OR. pao%istep >= pao%max_pao)
THEN
286 cpwarn(
"PAO not converged!")
292 CALL linesearch_step(pao%linesearch, energy=energy, slope=pao%norm_G**2)
294 IF (pao%linesearch%step_size < 1e-9_dp) cpabort(
"PAO gradient is wrong.")
296 CALL dbcsr_copy(pao%matrix_X, pao%matrix_X_orig)
297 CALL dbcsr_add(pao%matrix_X, pao%matrix_D, 1.0_dp, pao%linesearch%step_size)
302 CALL dbcsr_add(pao%matrix_X, matrix_x_mixing, pao%mixing, 1.0_dp - pao%mixing)
304 IF (pao%iw > 0)
WRITE (pao%iw, *)
"PAO| Recalculating energy after mixing."
311 CALL timestop(handle)
323 LOGICAL,
INTENT(IN) :: pao_is_done
325 CHARACTER(len=*),
PARAMETER :: routinen =
'pao_post_scf'
329 IF (.NOT. ls_scf_env%do_pao)
RETURN
330 IF (.NOT. pao_is_done)
RETURN
332 CALL timeset(routinen, handle)
340 IF (ls_scf_env%calculate_forces)
CALL pao_add_forces(qs_env, ls_scf_env)
342 CALL timestop(handle)
352 CHARACTER(len=*),
PARAMETER :: routinen =
'pao_optimization_end'
358 IF (.NOT. ls_scf_env%do_pao)
RETURN
360 pao => ls_scf_env%pao_env
361 ls_mstruct => ls_scf_env%ls_mstruct
363 CALL timeset(routinen, handle)
375 CALL timestop(handle)
collects all references to literature in CP2K as new algorithms / method are included from literature...
integer, save, public schuett2018
subroutine, public dbcsr_copy(matrix_b, matrix_a, name, keep_sparsity, keep_imaginary)
...
subroutine, public dbcsr_set(matrix, alpha)
...
subroutine, public dbcsr_release(matrix)
...
subroutine, public dbcsr_add(matrix_a, matrix_b, alpha_scalar, beta_scalar)
...
subroutine, public dbcsr_reserve_diag_blocks(matrix)
Reserves all diagonal blocks.
Routines to handle the external control of CP2K.
subroutine, public external_control(should_stop, flag, globenv, target_time, start_time, force_check)
External manipulations during a run : when the <PROJECT_NAME>.EXIT_$runtype command is sent the progr...
Types needed for a linear scaling quickstep SCF run based on the density matrix.
Defines the basic variable types.
integer, parameter, public dp
A generic framework to calculate step lengths for 1D line search.
subroutine, public linesearch_finalize(this)
Finzalize line search machinery.
subroutine, public linesearch_init(this, section, label)
Initialize linesearch from given input section.
subroutine, public linesearch_reset(this)
Reset line search to initial state.
subroutine, public linesearch_step(this, energy, slope)
Calculate step length of next line search step.
Machine interface based on Fortran 2003 and POSIX.
real(kind=dp) function, public m_walltime()
returns time from a real-time clock, protected against rolling early/easily
Routines for reading and writing restart files.
subroutine, public pao_write_restart(pao, qs_env, energy)
Writes restart file.
subroutine, public pao_write_ks_matrix_csr(qs_env, ls_scf_env)
writing the KS matrix (in terms of the PAO basis) in csr format into a file
subroutine, public pao_write_s_matrix_csr(qs_env, ls_scf_env)
writing the overlap matrix (in terms of the PAO basis) in csr format into a file
subroutine, public pao_read_restart(pao, qs_env)
Reads restart file.
Main module for the PAO method.
subroutine, public pao_post_scf(qs_env, ls_scf_env, pao_is_done)
Calculate PAO forces and store density matrix for future ASPC extrapolations.
subroutine, public pao_update(qs_env, ls_scf_env, pao_is_done)
Called after the SCF optimization, updates the PAO basis.
subroutine, public pao_init(qs_env, ls_scf_env)
Initialize the PAO environment.
subroutine, public pao_optimization_end(ls_scf_env)
Finish a PAO optimization run.
subroutine, public pao_optimization_start(qs_env, ls_scf_env)
Start a PAO optimization run.
Methods used by pao_main.F.
subroutine, public pao_build_orthogonalizer(pao, qs_env)
Constructs matrix_N and its inverse.
subroutine, public pao_build_core_hamiltonian(pao, qs_env)
Creates the matrix_H0 which contains the core hamiltonian.
subroutine, public pao_guess_initial_p(pao, qs_env, ls_scf_env)
Provide an initial guess for the density matrix.
subroutine, public pao_test_convergence(pao, ls_scf_env, new_energy, is_converged)
Test whether the PAO optimization has reached convergence.
subroutine, public pao_add_forces(qs_env, ls_scf_env)
Calculate the forces contributed by PAO.
subroutine, public pao_check_trace_ps(ls_scf_env)
Ensure that the number of electrons is correct.
subroutine, public pao_init_kinds(pao, qs_env)
Initialize qs kinds.
subroutine, public pao_build_matrix_x(pao, qs_env)
Creates the matrix_X.
subroutine, public pao_check_grad(pao, qs_env, ls_scf_env)
Debugging routine for checking the analytic gradient.
subroutine, public pao_print_atom_info(pao)
Prints a one line summary for each atom.
subroutine, public pao_store_p(qs_env, ls_scf_env)
Stores density matrix as initial guess for next SCF optimization.
subroutine, public pao_build_selector(pao, qs_env)
Build rectangular matrix to converert between primary and PAO basis.
subroutine, public pao_calc_energy(pao, qs_env, ls_scf_env, energy)
Calculate the pao energy.
subroutine, public pao_build_diag_distribution(pao, qs_env)
Creates new DBCSR distribution which spreads diagonal blocks evenly across ranks.
Main module for PAO Machine Learning.
subroutine, public pao_ml_init(pao, qs_env)
Initializes the learning machinery.
subroutine, public pao_ml_predict(pao, qs_env)
Fills paomatrix_X based on machine learning predictions.
Module for equivariant PAO-ML based on PyTorch.
subroutine, public pao_model_predict(pao, qs_env)
Fills paomatrix_X based on machine learning predictions.
Optimizers used by pao_main.F.
subroutine, public pao_opt_init(pao)
Initialize the optimizer.
subroutine, public pao_opt_finalize(pao)
Finalize the optimizer.
subroutine, public pao_opt_new_dir(pao, icycle)
Calculates the new search direction.
Front-End for any PAO parametrization.
subroutine, public pao_param_initial_guess(pao, qs_env)
Fills matrix_X with an initial guess.
subroutine, public pao_param_init(pao, qs_env)
Initialize PAO parametrization.
subroutine, public pao_calc_ab(pao, qs_env, ls_scf_env, gradient, penalty, forces)
Takes current matrix_X and calculates the matrices A and B.
subroutine, public pao_param_finalize(pao)
Finalize PAO parametrization.
Types used by the PAO machinery.
subroutine, public get_qs_env(qs_env, atomic_kind_set, qs_kind_set, cell, super_cell, cell_ref, use_ref_cell, kpoints, dft_control, mos, sab_orb, sab_all, qmmm, qmmm_periodic, sac_ae, sac_ppl, sac_lri, sap_ppnl, sab_vdw, sab_scp, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_almo, sab_kp, sab_kp_nosym, particle_set, energy, force, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, run_rtp, rtp, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, rho, rho_xc, pw_env, ewald_env, ewald_pw, active_space, mpools, input, para_env, blacs_env, scf_control, rel_control, kinetic, qs_charges, vppl, rho_core, rho_nlcc, rho_nlcc_g, ks_env, ks_qmmm_env, wf_history, scf_env, local_particles, local_molecules, distribution_2d, dbcsr_dist, molecule_kind_set, molecule_set, subsys, cp_subsys, oce, local_rho_set, rho_atom_set, task_list, task_list_soft, rho0_atom_set, rho0_mpole, rhoz_set, ecoul_1c, rho0_s_rs, rho0_s_gs, do_kpoints, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, nkind, natom, nelectron_total, nelectron_spin, efield, neighbor_list_id, linres_control, xas_env, virial, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, results, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, lri_env, lri_density, exstate_env, ec_env, harris_env, dispersion_env, gcp_env, vee, rho_external, external_vxc, mask, mp2_env, bs_env, kg_env, wanniercentres, atprop, ls_scf_env, do_transport, transport_env, v_hartree_rspace, s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, mscfg_env, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, eeq, rhs)
Get the QUICKSTEP environment.