psyclone.psyad.domain.common.adjoint_utils
Provides various utilities in support of the PSyAD adjoint functionality.
Functions
create_adjoint_name()
: Create an adjoint name from the supplied tangent linear name. Thiscreate_real_comparison()
: Creates PSyIR that checks the values held by Symbols var1 and var2_common_write()
: Creates PSyIR that writes whether the precision test passed orfind_container()
: Finds the first Container in the supplied PSyIR that is not a
- psyclone.psyad.domain.common.adjoint_utils.create_adjoint_name(tl_name, table=None)
Create an adjoint name from the supplied tangent linear name. This is done by stripping the TL_NAME_PREFIX from the name if it exists and then adding the ADJOINT_NAME_PREFIX. The adjoint name is also lower-cased. If a symbol table is supplied, then this routine also ensures that the new name is not present in that table.
- Parameters:
str – the tangent-linear name.
table (Optional[
psyclone.psyir.symbols.SymbolTable
]) – an optional symbol table in which the new adjoint name must be unique.
- Returns:
the adjoint name.
- Return type:
str
- psyclone.psyad.domain.common.adjoint_utils.create_real_comparison(sym_table, kernel, var1, var2)
Creates PSyIR that checks the values held by Symbols var1 and var2 for equality, allowing for machine precision and writes the success or failure of the checks to stdout.
- Parameters:
sym_table (
psyclone.psyir.symbols.SymbolTable
) – the SymbolTable in which to put new Symbols.kernel (
psyclone.psyir.nodes.Routine
) – the routine for which this adjoint test is being performed.var1 (
psyclone.psyir.symbols.DataSymbol
) – the symbol holding the first value for the comparison.var2 (
psyclone.psyir.symbols.DataSymbol
) – the symbol holding the second value for the comparison.
- Returns:
the PSyIR nodes that perform the check and write its success or failure to stdout.
- Return type:
- psyclone.psyad.domain.common.adjoint_utils._common_write(sym_table, kernel, var1, var2)
Creates PSyIR that writes whether the precision test passed or failed to stdout.
- Parameters:
sym_table (
psyclone.psyir.symbols.SymbolTable
) – the SymbolTable in which to read existing Symbols.kernel (
psyclone.psyir.nodes.Routine
) – the routine for which this adjoint test is being performed.var1 (
psyclone.psyir.symbols.DataSymbol
) – the symbol holding the first value for the comparison.var2 (
psyclone.psyir.symbols.DataSymbol
) – the symbol holding the second value for the comparison.
- Returns:
PSyIR nodes that write out test success or failure to stdout.
- Return type:
- psyclone.psyad.domain.common.adjoint_utils.find_container(psyir)
Finds the first Container in the supplied PSyIR that is not a FileContainer. Also validates that the PSyIR contains at most one FileContainer which, if present, contains a Container.
- Parameters:
psyir (
psyclone.psyir.nodes.Node
) – the PSyIR to search for a Container.- Returns:
the first Container that is not a FileContainer or None if there is none.
- Return type:
psyclone.psyir.nodes.Container
or NoneType- Raises:
InternalError – if there are two Containers and the second is a FileContainer.
NotImplementedError – if there are two Containers and the first is not a FileContainer.
NotImplementedError – if there are more than two Containers.