4 |
Author: Patrick Heimbach |
Author: Patrick Heimbach |
5 |
|
|
6 |
{\sf Automatic differentiation} (AD), also referred to as algorithmic |
{\sf Automatic differentiation} (AD), also referred to as algorithmic |
7 |
(or, more loosely, computational) differentiation, involves |
(or, more loosely, computational) differentiation, involves |
8 |
automatically deriving code to calculate |
automatically deriving code to calculate partial derivatives from an |
9 |
partial derivatives from an existing fully non-linear prognostic code. |
existing fully non-linear prognostic code. (see \cite{gri:00}). A |
10 |
(see \cite{gri:00}). |
software tool is used that parses and transforms source files |
11 |
A software tool is used that parses and transforms source files |
according to a set of linguistic and mathematical rules. AD tools are |
12 |
according to a set of linguistic and mathematical rules. |
like source-to-source translators in that they parse a program code as |
13 |
AD tools are like source-to-source translators in that |
input and produce a new program code as output. However, unlike a |
14 |
they parse a program code as input and produce a new program code |
pure source-to-source translation, the output program represents a new |
15 |
as output. |
algorithm, such as the evaluation of the Jacobian, the Hessian, or |
16 |
However, unlike a pure source-to-source translation, the output program |
higher derivative operators. In principle, a variety of derived |
17 |
represents a new algorithm, such as the evaluation of the |
algorithms can be generated automatically in this way. |
18 |
Jacobian, the Hessian, or higher derivative operators. |
|
19 |
In principle, a variety of derived algorithms |
MITgcm has been adapted for use with the Tangent linear and Adjoint |
20 |
can be generated automatically in this way. |
Model Compiler (TAMC) and its successor TAF (Transformation of |
21 |
|
Algorithms in Fortran), developed by Ralf Giering (\cite{gie-kam:98}, |
22 |
The MITGCM has been adapted for use with the |
\cite{gie:99,gie:00}). The first application of the adjoint of MITgcm |
23 |
Tangent linear and Adjoint Model Compiler (TAMC) and its successor TAF |
for sensitivity studies has been published by \cite{maro-eta:99}. |
24 |
(Transformation of Algorithms in Fortran), developed |
\cite{sta-eta:97,sta-eta:01} use MITgcm and its adjoint for ocean |
25 |
by Ralf Giering (\cite{gie-kam:98}, \cite{gie:99,gie:00}). |
state estimation studies. In the following we shall refer to TAMC and |
26 |
The first application of the adjoint of the MITGCM for sensitivity |
TAF synonymously, except were explicitly stated otherwise. |
27 |
studies has been published by \cite{maro-eta:99}. |
|
28 |
\cite{sta-eta:97,sta-eta:01} use the MITGCM and its adjoint |
TAMC exploits the chain rule for computing the first derivative of a |
29 |
for ocean state estimation studies. |
function with respect to a set of input variables. Treating a given |
30 |
In the following we shall refer to TAMC and TAF synonymously, |
forward code as a composition of operations -- each line representing |
31 |
except were explicitly stated otherwise. |
a compositional element, the chain rule is rigorously applied to the |
32 |
|
code, line by line. The resulting tangent linear or adjoint code, |
33 |
TAMC exploits the chain rule for computing the first |
then, may be thought of as the composition in forward or reverse |
34 |
derivative of a function with |
order, respectively, of the Jacobian matrices of the forward code's |
35 |
respect to a set of input variables. |
compositional elements. |
|
Treating a given forward code as a composition of operations -- |
|
|
each line representing a compositional element, the chain rule is |
|
|
rigorously applied to the code, line by line. The resulting |
|
|
tangent linear or adjoint code, |
|
|
then, may be thought of as the composition in |
|
|
forward or reverse order, respectively, of the |
|
|
Jacobian matrices of the forward code's compositional elements. |
|
36 |
|
|
37 |
%********************************************************************** |
%********************************************************************** |
38 |
\section{Some basic algebra} |
\section{Some basic algebra} |
686 |
\input{part5/doc_ad_the_model} |
\input{part5/doc_ad_the_model} |
687 |
|
|
688 |
The basic flow is depicted in \ref{fig:adthemodel}. |
The basic flow is depicted in \ref{fig:adthemodel}. |
689 |
If CPP option {\tt ALLOW\_AUTODIFF\_TAMC} is defined, the driver routine |
If CPP option \texttt{ALLOW\_AUTODIFF\_TAMC} is defined, |
690 |
|
the driver routine |
691 |
{\it the\_model\_main}, instead of calling {\it the\_main\_loop}, |
{\it the\_model\_main}, instead of calling {\it the\_main\_loop}, |
692 |
invokes the adjoint of this routine, {\it adthe\_main\_loop}, |
invokes the adjoint of this routine, {\it adthe\_main\_loop} |
693 |
which is the toplevel routine in terms of automatic differentiation. |
(case \texttt{\#define ALLOW\_ADJOINT\_RUN}), or |
694 |
The routine {\it adthe\_main\_loop} has been generated by TAF. |
the tangent linear of this routine {\it g\_the\_main\_loop} |
695 |
|
(case \texttt{\#define ALLOW\_TANGENTLINEAR\_RUN}), |
696 |
|
which are the toplevel routines in terms of automatic differentiation. |
697 |
|
The routines {\it adthe\_main\_loop} or {\it g\_the\_main\_loop} |
698 |
|
are generated by TAF. |
699 |
It contains both the forward integration of the full model, the |
It contains both the forward integration of the full model, the |
700 |
cost function calculation, |
cost function calculation, |
701 |
any additional storing that is required for efficient checkpointing, |
any additional storing that is required for efficient checkpointing, |
948 |
{\tt eesupp/src/} and {\tt model/src/} |
{\tt eesupp/src/} and {\tt model/src/} |
949 |
reside in {\tt pkg/autodiff/}. |
reside in {\tt pkg/autodiff/}. |
950 |
This directory also contains hand-written adjoint code |
This directory also contains hand-written adjoint code |
951 |
for the MITgcm WRAPPER (see Section ???). |
for the MITgcm WRAPPER (section \ref{chap:sarch}). |
952 |
|
|
953 |
Flow directives for package-specific routines are contained in |
Flow directives for package-specific routines are contained in |
954 |
the corresponding package directories in the file |
the corresponding package directories in the file |
1202 |
\\ |
\\ |
1203 |
% |
% |
1204 |
Two important issues related to the handling of the control |
Two important issues related to the handling of the control |
1205 |
variables in the MITGCM need to be addressed. |
variables in MITgcm need to be addressed. |
1206 |
First, in order to save memory, the control variable arrays |
First, in order to save memory, the control variable arrays |
1207 |
are not kept in memory, but rather read from file and added |
are not kept in memory, but rather read from file and added |
1208 |
to the initial fields during the model initialization phase. |
to the initial fields during the model initialization phase. |
1277 |
tamc -input 'xx_tr1 ...' ... |
tamc -input 'xx_tr1 ...' ... |
1278 |
\end{verbatim} |
\end{verbatim} |
1279 |
% |
% |
1280 |
Now, as mentioned above, the MITGCM avoids maintaining |
Now, as mentioned above, MITgcm avoids maintaining |
1281 |
an array for each control variable by reading the |
an array for each control variable by reading the |
1282 |
perturbation to a temporary array from file. |
perturbation to a temporary array from file. |
1283 |
To ensure the symbolic link to be recognized by TAMC, a scalar |
To ensure the symbolic link to be recognized by TAMC, a scalar |