Octopus
opt_control_global.F90
Go to the documentation of this file.
1!! Copyright (C) 2002-2006 M. Marques, A. Castro, A. Rubio, G. Bertsch
2!!
3!! This program is free software; you can redistribute it and/or modify
4!! it under the terms of the GNU General Public License as published by
5!! the Free Software Foundation; either version 2, or (at your option)
6!! any later version.
7!!
8!! This program is distributed in the hope that it will be useful,
9!! but WITHOUT ANY WARRANTY; without even the implied warranty of
10!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11!! GNU General Public License for more details.
12!!
13!! You should have received a copy of the GNU General Public License
14!! along with this program; if not, write to the Free Software
15!! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16!! 02110-1301, USA.
17!!
18
19#include "global.h"
20
29 use debug_oct_m
30 use global_oct_m
31 use, intrinsic :: iso_fortran_env
34 use parser_oct_m
36
37 implicit none
38
39 private
40 public :: &
41 oct_t, &
44
49 type oct_t
50 ! Components are public by default
51 integer :: algorithm
53 logical :: mode_fixed_fluence
55 real(real64) :: eta, delta
56 real(real64) :: direct_step
58 logical :: oct_double_check
60 real(real64) :: check_gradient
63 integer :: number_checkpoints
66 logical :: random_initial_guess
68 end type oct_t
69
70contains
71
78 subroutine oct_read_inp(oct, namespace)
79 type(oct_t), intent(inout) :: oct
80 type(namespace_t), intent(in) :: namespace
81
82 push_sub(oct_read_inp)
83
84 call messages_print_with_emphasis(msg="OCT run mode", namespace=namespace)
85 call messages_obsolete_variable(namespace, 'OCTControlRepresentation')
86
87 !%Variable OCTScheme
88 !%Type integer
89 !%Section Calculation Modes::Optimal Control
90 !%Default oct_zbr98
91 !%Description
92 !% Optimal Control Theory can be performed with <tt>Octopus</tt> with a variety of different
93 !% algorithms. Not all of them can be used with any choice of target or control function
94 !% representation. For example, some algorithms cannot be used if
95 !% <tt>OCTControlRepresentation = control_function_real_time</tt>
96 !% (<tt>OCTScheme</tt> > <tt>oct_straight_iteration</tt>), and others cannot be used
97 !% if <tt>OCTControlRepresentation = control_function_parametrized</tt>
98 !% (<tt>OCTScheme</tt> < <tt>oct_straight_iteration</tt>).
99 !%Option oct_zbr98 1
100 !% Backward-Forward-Backward scheme described in <i>JCP</i> <b>108</b>, 1953 (1998).
101 !% Only possible if target operator is a projection operator.
102 !% Provides fast, stable and monotonic convergence.
103 !%Option oct_zr98 2
104 !% Forward-Backward-Forward scheme described in <i>JCP</i> <b>109</b>, 385 (1998).
105 !% Works for projection and more general target operators also. The convergence is
106 !% stable but slower than ZBR98.
107 !% Note that local operators show an extremely slow convergence. It ensures monotonic
108 !% convergence.
109 !%Option oct_wg05 3
110 !% Forward-Backward scheme described in <i>J. Opt. B.</i> <b>7</b>, 300 (2005).
111 !% Works for all kinds of target operators, can be used with all kinds of filters, and
112 !% allows a fixed fluence.
113 !% The price is a rather unstable convergence.
114 !% If the restrictions set by the filter and fluence are reasonable, a good overlap can be
115 !% expected within 20 iterations.
116 !% No monotonic convergence.
117 !%Option oct_mt03 4
118 !% Basically an improved and generalized scheme.
119 !% Comparable to ZBR98/ZR98. See [Y. Maday and G. Turinici, <i>J. Chem. Phys.</i> <b>118</b>, 8191 (2003)].
120 !%Option oct_krotov 5
121 !% The procedure reported in [D. Tannor, V. Kazakov and V.
122 !% Orlov, in <i>Time-Dependent Quantum Molecular Dynamics</i>, edited by J. Broeckhove
123 !% and L. Lathouweres (Plenum, New York, 1992), pp. 347-360].
124 !%Option oct_straight_iteration 6
125 !% Straight iteration: one forward and one backward propagation is performed at each
126 !% iteration, both with the same control field. An output field is calculated with the
127 !% resulting wavefunctions.
128 !%Option oct_cg 7
129 !% Conjugate-gradients, as implemented in the GNU GSL library. In particular, the
130 !% Fletcher-Reeves version.
131 !% The seed for the random number generator can be modified by setting
132 !% <tt>GSL_RNG_SEED</tt> environment variable.
133 !%Option oct_bfgs 8
134 !% The methods use the vector Broyden-Fletcher-Goldfarb-Shanno (BFGS) algorithm.
135 !% Also, it calls the GNU GSL library version of the algorithm. It is a quasi-Newton
136 !% method which builds up an approximation to the second derivatives of the function using
137 !% the difference between successive gradient vectors. By combining the first and second
138 !% derivatives the algorithm is able to take Newton-type steps towards the function minimum,
139 !% assuming quadratic behavior in that region. We have chosen to implement the "bfgs2" version,
140 !% as GSL calls it, which is supposed to be the most efficient version available, and a faithful
141 !% implementation of the line minimization scheme described in "Practical Methods of Optimization",
142 !% (Fletcher), Algorithms 2.6.2 and 2.6.4.
143 !%Option oct_direct 9
144 !% This is a "direct" optimization scheme. This means that we do not make use of the
145 !% "usual" QOCT equations (backward-forward propagations, etc), but we use some gradient-free
146 !% maximization algorithm for the function that we want to optimize. In this case, the
147 !% maximization algorithm is the Nelder-Mead algorithm as implemented in the GSL. The function
148 !% values are obtained by successive forward propagations.
149 !% The seed for the random number generator can be modified by setting
150 !% <tt>GSL_RNG_SEED</tt> environment variable.
151 !%Option oct_nlopt_bobyqa 11
152 !% The BOBYQA algorithm, as implemented in the NLOPT library -- therefore, octopus has to
153 !% be compiled with it in order to be able to use this option.
154 !% The seed for the random number generator can be modified by setting
155 !% <tt>GSL_RNG_SEED</tt> environment variable.
156 !%Option oct_nlopt_lbfgs 12
157 !% The local BFGS, as implemented in the NLOPT library -- therefore, octopus has to
158 !% be compiled with it in order to be able to use this option.
159 !% The seed for the random number generator can be modified by setting
160 !% <tt>GSL_RNG_SEED</tt> environment variable.
161 !%End
162 call parse_variable(namespace, 'OCTScheme', option__octscheme__oct_zr98, oct%algorithm)
163 if (.not. varinfo_valid_option('OCTScheme', oct%algorithm)) call messages_input_error(namespace, 'OCTScheme')
164 ! We must check that the algorithm is consistent with OCTControlRepresentation, i.e.
165 ! some algorithms only make sense if the control functions are handled directly in real
166 ! time, some others make only sense if the control functions are parameterized.
167 ! This check cannot be here any more, and it should be placed somewhere else.
168 call messages_print_var_option("OCTScheme", oct%algorithm, namespace=namespace)
169 select case (oct%algorithm)
170 case (option__octscheme__oct_mt03)
171 oct%delta = m_two
172 oct%eta = m_zero
173 !%Variable OCTEta
174 !%Type float
175 !%Section Calculation Modes::Optimal Control
176 !%Default 1.0
177 !%Description
178 !% If <tt>OCTScheme = oct_mt03</tt>, then you can supply the "eta" and "delta" parameters
179 !% described in [Y. Maday and G. Turinici, <i>J. Chem. Phys.</i> <b>118</b>, 8191 (2003)], using the
180 !% <tt>OCTEta</tt> and <tt>OCTDelta</tt> variables.
181 !%End
182 call parse_variable(namespace, 'OCTEta', m_one, oct%eta)
183 !%Variable OCTDelta
184 !%Type float
185 !%Section Calculation Modes::Optimal Control
186 !%Default 0.0
187 !%Description
188 !% If <tt>OCTScheme = oct_mt03</tt>, then you can supply the "eta" and "delta" parameters
189 !% described in [Y. Maday and G. Turinici, <i>J. Chem. Phys.</i> <b>118</b>, 8191 (2003)], using the
190 !% <tt>OCTEta</tt> and <tt>OCTDelta</tt> variables.
191 !%End
192 call parse_variable(namespace, 'OCTDelta', m_zero, oct%delta)
193
194 case (option__octscheme__oct_zr98)
195 oct%delta = m_one
196 oct%eta = m_one
197 case (option__octscheme__oct_krotov)
198 oct%delta = m_one
199 oct%eta = m_zero
200 case (option__octscheme__oct_straight_iteration)
201 oct%delta = m_zero
202 oct%eta = m_one
203 case (option__octscheme__oct_cg)
204 oct%delta = m_zero
205 oct%eta = m_one
206 case (option__octscheme__oct_bfgs)
207 oct%delta = m_zero
208 oct%eta = m_one
209 case (option__octscheme__oct_direct)
210 ! The use of these variables for the direct and bobyqa schemes remain undocumented for the moment.
211 call parse_variable(namespace, 'OCTEta', m_one, oct%eta)
212 call parse_variable(namespace, 'OCTDelta', m_zero, oct%delta)
213 case (option__octscheme__oct_nlopt_bobyqa, option__octscheme__oct_nlopt_lbfgs)
214#if defined(HAVE_NLOPT)
215 !WARNING: not clear if this is needed, probably not.
216 call parse_variable(namespace, 'OCTEta', m_one, oct%eta)
217 call parse_variable(namespace, 'OCTDelta', m_zero, oct%delta)
218#else
219 write(message(1), '(a)') '"OCTScheme = oct_nlopt_bobyqa" or "OCTScheme = oct_nlopt_lbfgs" are'
220 write(message(2), '(a)') ' only possible if the nlopt library has been compiled.'
221 call messages_fatal(2, namespace=namespace)
222#endif
223 case default
224 oct%delta = m_one
225 oct%eta = m_one
226 end select
227
228 !%Variable OCTDoubleCheck
229 !%Type logical
230 !%Section Calculation Modes::Optimal Control
231 !%Default true
232 !%Description
233 !% In order to make sure that the optimized field indeed does its job, the code
234 !% may run a normal propagation after the optimization using the optimized field.
235 !%End
236 call parse_variable(namespace, 'OCTDoubleCheck', .true., oct%oct_double_check)
237 call messages_print_var_value("OCTDoubleCheck", oct%oct_double_check, namespace=namespace)
238
239
240 !%Variable OCTCheckGradient
241 !%Type float
242 !%Section Calculation Modes::Optimal Control
243 !%Default 0.0
244 !%Description
245 !% When doing QOCT with the conjugate-gradient optimization scheme, the gradient is
246 !% computed thanks to a forward-backwards propagation. For debugging purposes, this
247 !% gradient can be compared with the value obtained "numerically" (<i>i.e.</i> by doing
248 !% successive forward propagations with control fields separated by small finite
249 !% differences).
250 !%
251 !% In order to activate this feature, set <tt>OCTCheckGradient</tt> to some non-zero value,
252 !% which will be the finite difference used to numerically compute the gradient.
253 !%End
254 call parse_variable(namespace, 'OCTCheckGradient', 0.0_real64, oct%check_gradient)
255 call messages_print_var_value("OCTCheckGradient", oct%check_gradient, namespace=namespace)
256
257
258 !%Variable OCTDirectStep
259 !%Type float
260 !%Section Calculation Modes::Optimal Control
261 !%Default 0.25
262 !%Description
263 !% If you choose <tt>OCTScheme = oct_direct</tt> or <tt>OCTScheme = oct_nlopt_bobyqa</tt>,
264 !% the algorithms necessitate an initial "step" to perform the direct search for the
265 !% optimal value. The precise meaning of this "step" differs.
266 !%End
267 call parse_variable(namespace, 'OCTDirectStep', 0.25_real64, oct%direct_step)
268 call messages_print_var_value("OCTDirectStep", oct%direct_step, namespace=namespace)
269
270 !%Variable OCTNumberCheckPoints
271 !%Type integer
272 !%Section Calculation Modes::Optimal Control
273 !%Default 0
274 !%Description
275 !% During an OCT propagation, the code may write the wavefunctions at some time steps (the
276 !% "check points"). When the inverse backward or forward propagation
277 !% is performed in a following step, the wavefunction should reverse its path
278 !% (almost) exactly. This can be checked to make sure that it is the case -- otherwise
279 !% one should try reducing the time-step, or altering in some other way the
280 !% variables that control the propagation.
281 !%
282 !% If the backward (or forward) propagation is not retracing the steps of the previous
283 !% forward (or backward) propagation, the code will write a warning.
284 !%End
285 call parse_variable(namespace, 'OCTNumberCheckPoints', 0, oct%number_checkpoints)
286 call messages_print_var_value("OCTNumberCheckPoints", oct%number_checkpoints, namespace=namespace)
287
288 !%Variable OCTRandomInitialGuess
289 !%Type logical
290 !%Section Calculation Modes::Optimal Control
291 !%Default false
292 !%Description
293 !% The initial field to start the optimization search is usually given in the <tt>inp</tt> file,
294 !% through a <tt>TDExternalFields</tt> block. However, you can start from a random guess if you
295 !% set this variable to true.
296 !%
297 !% Note, however, that this is only valid for the "direct" optimization schemes; moreover
298 !% you still need to provide a <tt>TDExternalFields</tt> block.
299 !%End
300 call parse_variable(namespace, 'OCTRandomInitialGuess', .false., oct%random_initial_guess)
301 call messages_print_var_value("OCTRandomInitialGuess", oct%random_initial_guess, namespace=namespace)
302
303 call messages_print_with_emphasis(namespace=namespace)
304
305 pop_sub(oct_read_inp)
306 end subroutine oct_read_inp
307 ! ---------------------------------------------------------
308
309
310
313 logical pure function oct_algorithm_is_direct(oct)
314 type(oct_t), intent(in) :: oct
315 oct_algorithm_is_direct = (oct%algorithm == option__octscheme__oct_direct) .or. &
316 (oct%algorithm == option__octscheme__oct_nlopt_bobyqa)
317 end function oct_algorithm_is_direct
318 ! ---------------------------------------------------------
319
320
322
323!! Local Variables:
324!! mode: f90
325!! coding: utf-8
326!! End:
Prints out to iunit a message in the form: ["InputVariable" = value] where "InputVariable" is given b...
Definition: messages.F90:180
real(real64), parameter, public m_two
Definition: global.F90:189
real(real64), parameter, public m_zero
Definition: global.F90:187
real(real64), parameter, public m_one
Definition: global.F90:188
subroutine, public messages_print_with_emphasis(msg, iunit, namespace)
Definition: messages.F90:930
character(len=512), private msg
Definition: messages.F90:165
subroutine, public messages_obsolete_variable(namespace, name, rep)
Definition: messages.F90:1057
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:160
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
Definition: messages.F90:420
subroutine, public messages_input_error(namespace, var, details, row, column)
Definition: messages.F90:723
This module contains the definition of the oct_t data type, which contains some of the basic informat...
subroutine, public oct_read_inp(oct, namespace)
Reads, from the inp file, some global information about how the QOCT run should be.
logical pure function, public oct_algorithm_is_direct(oct)
Returns .true. if the algorithm to be used is one of the "direct" or "gradient-less" algorithms – the...
!brief The oct_t datatype stores the basic information about how the OCT run is done.
int true(void)