Goal: Introduction to forward mode AD with CoDiPack.
Prerequisite: AD forward mode. See Forward AD Equation
Function: Simple real valued function
Full code:
The derivative computation with the forward mode of CoDiPack is quite simple and needs only three steps:
The simplicity comes from the implementation. The tangent data is stored in the active types and no tape is recorded. All tangent evaluations are directly done in the statement evaluation. This is what ADOL-C calls the ''tapeless'' mode.
If you need to record a tape and evaluate it in a forward manner, please have a look at example Example 6 - Forward mode tape evaluation.
In the forward AD equation, the variable
In this step, CoDiPack is only indirectly involved. The function using Real = codi::RealForward
is used and all doubles in the program are changed to this typedef. The calculation type can then be changed during compile time and different executables can be generated.
In the forward AD equation, the variable
The forward mode is very simple to use and multiple tangents evaluations do not require any additional effort. The only think to keep in mind is that tangent values are only reset by CoDiPack if the value is overwritten. Tangent seedings, that are set on the input values, are not reset and need to be reset by the user.
Left over tangent seedings can also happen if the computational path changes and values from an old evaluation are used. See Example 1 - Old tangent leftovers in forward mode AD for an example.