(git:6344619)
Loading...
Searching...
No Matches
qs_ot_minimizer_unittest.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2026 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
9 USE kinds, ONLY: dp
17
18 IMPLICIT NONE
19
20 REAL(kind=dp), PARAMETER :: tolerance = 1.0e-14_dp
21
22 INTEGER :: i
23 LOGICAL :: accepted
24 REAL(kind=dp) :: damping, measured, predicted, quality, ratio, &
25 scale, sy, weight, yy
26
27 ! Histories must restart when they cease to describe a usable descent step.
28 IF (.NOT. broyden_history_restart_required(.true., .false., .true.)) THEN
29 error stop "Broyden retained a non-descent history"
30 END IF
31 IF (broyden_history_restart_required(.false., .true., .true.)) THEN
32 error stop "Broyden discarded a descent history"
33 END IF
34 IF (.NOT. cg_history_restart_required(.true., 0.5_dp + 32.0_dp*epsilon(1.0_dp), 0.5_dp)) THEN
35 error stop "CG retained unresolved free-energy history"
36 END IF
37 IF (cg_history_restart_required(.true., 0.5_dp + 256.0_dp*epsilon(1.0_dp), 0.5_dp)) THEN
38 error stop "CG discarded resolved free-energy history"
39 END IF
40 IF (lbfgs_history_restart_required(100.0_dp, 1.0_dp)) THEN
41 error stop "L-BFGS restarted at the gradient-growth threshold"
42 END IF
43 IF (.NOT. lbfgs_history_restart_required(100.0001_dp, 1.0_dp)) THEN
44 error stop "L-BFGS missed excessive gradient growth"
45 END IF
46 IF (lbfgs_step_restart_required(1.0e-6_dp*0.1_dp, 0.1_dp)) THEN
47 error stop "L-BFGS restarted at the step-collapse threshold"
48 END IF
49 IF (.NOT. lbfgs_step_restart_required(0.999e-6_dp*0.1_dp, 0.1_dp)) THEN
50 error stop "L-BFGS retained a collapsed step"
51 END IF
52
53 ! Damping must satisfy the curvature bound for weak and negative curvature.
54 IF (lbfgs_curvature_damping_shift(0.6_dp, 1.0_dp, 1.0_dp, 0.5_dp) /= 0.0_dp) THEN
55 error stop "Well-conditioned L-BFGS curvature was damped"
56 END IF
57 DO i = -1, 1, 2
58 sy = real(i, kind=dp)*0.1_dp
59 damping = lbfgs_curvature_damping_shift(sy, 1.0_dp, 1.0_dp, 0.5_dp)
60 yy = 1.0_dp + 2.0_dp*damping*sy + damping**2
61 IF (.NOT. (damping > 0.0_dp .AND. sy + damping > 0.5_dp*sqrt(yy))) THEN
62 error stop "L-BFGS damping failed the relative-curvature bound"
63 END IF
64 END DO
65
66 ! Keep the norm matching, Powell bound, and rejected-secant behavior together.
67 CALL lbfgs_response_secant_parameters(1.0_dp, 4.0_dp, 2.0_dp, 9.0_dp, scale, weight, accepted)
68 IF (.NOT. (accepted .AND. abs(scale - 1.5_dp) <= tolerance .AND. weight == 1.0_dp)) THEN
69 error stop "L-BFGS response secant changed the H0 direction norm"
70 END IF
71 CALL lbfgs_response_secant_parameters(0.01_dp, 4.0_dp, 2.0_dp, 9.0_dp, scale, weight, accepted)
72 sy = weight*scale*0.01_dp + (1.0_dp - weight)*2.0_dp
73 IF (.NOT. (accepted .AND. abs(sy - 0.4_dp) <= tolerance .AND. weight > 0.0_dp .AND. weight < 1.0_dp)) THEN
74 error stop "L-BFGS response secant failed the Powell curvature bound"
75 END IF
76 CALL lbfgs_response_secant_parameters(-1.0_dp, 4.0_dp, 2.0_dp, 9.0_dp, scale, weight, accepted)
77 IF (accepted .OR. weight /= 0.0_dp) error stop "Rejected response secant changed H0"
78
79 ! A useful Mermin response must lower free energy without growing the residual.
81 10.0_dp, 9.6_dp, 1.0_dp, 0.8_dp, 1.0_dp, 1.0_dp, 0.5_dp, 0.1_dp, &
82 predicted, measured, quality, ratio, accepted)
83 IF (.NOT. (accepted .AND. abs(predicted - 0.375_dp) <= tolerance .AND. &
84 abs(measured - 0.4_dp) <= tolerance .AND. abs(quality - 0.4_dp/0.375_dp) <= tolerance .AND. &
85 abs(ratio - 0.8_dp) <= tolerance)) error stop "Useful Mermin response was rejected"
87 10.0_dp, 9.6_dp, 1.0_dp, 1.5_dp, 1.0_dp, 1.0_dp, 0.5_dp, 0.1_dp, &
88 predicted, measured, quality, ratio, accepted)
89 IF (accepted) error stop "Residual-growing Mermin response was accepted"
90
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
orbital transformations
pure subroutine, public lbfgs_response_secant_parameters(g_dot_response, response_norm_sq, g_dot_h0_g, h0_g_norm_sq, response_scale, response_weight, valid)
Normalize and damp an occupation-response secant against the conventional H0 direction.
pure subroutine, public ot_mermin_response_assess(reference_energy, current_energy, reference_residual, current_residual, predicted_slope, predicted_curvature, position, default_step, predicted_drop, measured_drop, quality, residual_ratio, good)
Assess a finite-response candidate at its accepted Mermin endpoint.
pure elemental logical function, public broyden_history_restart_required(non_descent, forget_history, do_ener)
Decide whether a non-descent Broyden step invalidates its secant history.
pure real(kind=dp) function, public lbfgs_curvature_damping_shift(sy, ss, yy, curvature_tol)
Returns the smallest shift y <- y + shift*s that meets relative L-BFGS curvature.
pure logical function, public lbfgs_history_restart_required(current_gradient_norm_sq, previous_gradient_norm_sq)
Decides whether an L-BFGS history must be discarded after excessive gradient growth.
pure elemental logical function, public cg_history_restart_required(occupation_preconditioned, current_energy, reference_energy)
Decide whether an unresolved accepted energy change invalidates CG conjugacy.
pure logical function, public lbfgs_step_restart_required(accepted_step, reference_step)
Decides whether L-BFGS must recover from a collapsed accepted line-search step.
program qs_ot_minimizer_unittest