psyclone.domain.lfric

Module for the LFRic domain.

Submodules

Classes

  • ArgOrdering: Base class capturing the arguments, type and ordering of data in

  • FunctionSpace: Manages the name of a function space. If it is an any_space or

  • KernCallAccArgList: Kernel call arguments that need to be declared by OpenACC

  • KernCallArgList: Creates the argument list required to call kernel “kern” from the

  • KernelInterface: Create the kernel arguments for the supplied kernel as specified by

  • KernStubArgList: Creates the argument list required to create and declare the

  • LFRicArgDescriptor: This class captures the information specified in one of LFRic API argument

  • LFRicCollection: Base class for managing the declaration and initialisation of a

  • LFRicConstants: This class stores all LFRic constants. Note that some constants

  • LFRicDofmaps: Holds all information on the dofmaps (including column-banded and

  • LFRicExtractDriverCreator: This class provides the functionality to create a driver that

  • LFRicFields: Manages the declarations for all field arguments required by an Invoke

  • LFRicInvoke: The LFRic-specific Invoke class. This passes the LFRic-specific

  • LFRicInvokes: The LFRic-specific invokes class. This passes the LFRic-specific

  • LFRicKern: Stores information about LFRic Kernels as specified by the

  • LFRicKernCallFactory: Create the necessary framework for an LFRic kernel call.

  • LFRicKernMetadata: Captures the Kernel subroutine code and metadata describing

  • LFRicLoop: The LFRic-specific PSyLoop class. This passes the LFRic-specific

  • LFRicLoopBounds: Handles all variables required for specifying loop limits within

  • LFRicRunTimeChecks: Handle declarations and code generation for run-time checks. This

  • LFRicScalarArgs: Handles the declarations of scalar kernel arguments appearing in either

  • LFRicStencils: Stencil information and code generation associated with a PSy-layer

  • LFRicSymbolTable: Sub-classes SymbolTable to provide a LFRic-specific implementation.

class psyclone.domain.lfric.ArgOrdering(kern)

Base class capturing the arguments, type and ordering of data in a Kernel call. This base class implements some functionality of a list (extend and append functions), but not using list as a base class. Reason is that many typical functions of a list make only sense to be used after generate is called, which would then require a large number of functions to be re-implemented. So instead the property arglist checks that generate has been called and then provides a list.

Parameters:

kern (psyclone.domain.lfric.LFRicKern) – the kernel call object to use.

Inheritance

Inheritance diagram of ArgOrdering
append(var_name, var_accesses=None, var_access_name=None, mode=AccessType.READ, metadata_posn=None)

Appends the specified variable name to the list of all arguments and stores the mapping between the position of this actual argument and the corresponding metadata entry. If var_accesses is given, it will also record the access to the variable. The name of the variable accessed can be overwritten by specifying var_access_name. By default it is assumed that access mode is READ (which can be set with mode).

Parameters:
  • var_name (str) – the name of the variable.

  • var_accesses (psyclone.core.VariablesAccessInfo) – optional class to store variable access information.

  • var_access_name (str) – optional name of the variable for which access information is stored (used e.g. when the actual argument is field_proxy, but the access is to be recorded for field).

  • mode (psyclone.core.access_type.AccessType) – optional access mode (defaults to READ).

  • metadata_posn (int) – the location of the corresponding entry in the list of arguments in the kernel metadata (if any).

append_array_reference(array_name, indices, intrinsic_type, tag=None, symbol=None)

This function adds an array reference. If there is no symbol with the given tag, a new array symbol will be defined using the given intrinsic_type. If a symbol already exists but has no type, it will be replaced. The created reference is added to the list of PSyIR expressions, and the symbol is returned to the user.

Parameters:
  • array_name (str) – the name and tag of the array.

  • indices (List[Union[str, py:class:psyclone.psyir.nodes.Node]]) – the indices to be used in the PSyIR reference. It must either be “:”, or a PSyIR node.

  • intrinsic_type (psyclone.psyir.symbols.datatypes.ScalarType.Intrinsic) – the intrinsic type of the array.

  • tag (Optional[str]) – optional tag for the symbol.

  • symbol (Optional[psyclone.psyir.symbols.Symbol]) – optional the symbol to use.

Returns:

the symbol used in the added reference.

Return type:

psyclone.psyir.symbols.Symbol

append_integer_reference(name, tag=None)

This function adds a reference to an integer variable to the list of PSyIR nodes. If the symbol does not exist, it will be added to the symbol table. If no tag is specified, is uses the name as tag. It also returns the symbol.

Parameters:
  • name (str) – name of the integer variable to declare.

  • tag (Optional[str]) – optional tag of the integer variable to declare.

Returns:

the symbol to which a reference was added.

Return type:

psyclone.psyir.symbols.Symbol

property arglist
Returns:

the kernel argument list. The generate method must be called first.

Return type:

List[str]

Raises:

InternalError – if the generate() method has not been called.

banded_dofmap(function_space, var_accesses=None)

Add banded dofmap (required for CMA operator assembly).

Parameters:
abstract basis(function_space, var_accesses=None)

Add basis function information for this function space to the argument list and optionally to the variable access information.

Parameters:
cell_map(var_accesses=None)

Add cell-map and related cell counts (for inter-grid kernels) to the argument list. If supplied it also stores these accesses to the var_access object.

Parameters:

var_accesses (psyclone.core.VariablesAccessInfo) – optional VariablesAccessInfo instance to store the information about variable accesses.

cell_position(var_accesses=None)

Add cell position information.

Parameters:

var_accesses (psyclone.core.VariablesAccessInfo) – optional VariablesAccessInfo instance to store the information about variable accesses.

abstract cma_operator(arg, var_accesses=None)

Add the CMA operator and associated scalars to the argument list and optionally add them to the variable access information.

Parameters:
abstract diff_basis(function_space, var_accesses=None)

Add differential basis information for the function space to the argument list. If supplied it also stores this access in var_accesses.

Parameters:
extend(list_var_name, var_accesses=None, mode=AccessType.READ, list_metadata_posn=None)

Appends all variable names in the argument list to the list of all arguments. If var_accesses is given, it will also record the access to the variables. By default any access will be recorded as a read-only access, but this can be changed (for all variables included) using mode.

Parameters:
  • list_var_name (list of str.) – the list with name of the variables to append.

  • var_accesses (psyclone.core.VariablesAccessInfo) – optional class to store variable access information.

  • mode (Optional[psyclone.core.access_type.AccessType]) – optional access mode (defaults to READ).

  • list_metadata_posn (Optional[List[int]]) – list of metadata argument positions.

abstract field(arg, var_accesses=None)

Add the field array associated with the argument ‘arg’ to the argument list. If supplied it also stores this access in var_accesses.

Parameters:
abstract field_bcs_kernel(function_space, var_accesses=None)

Implement the boundary_dofs array fix for a field. If supplied it also stores this access in var_accesses.

Parameters:
  • function_space – the function space for which boundary dofs are required.

  • var_accesses (psyclone.core.VariablesAccessInfo) – optional VariablesAccessInfo instance to store the information about variable accesses.

abstract field_vector(argvect, var_accesses=None)

Add the field vector associated with the argument ‘argvect’ to the argument list. If supplied it also stores these accesses to the var_access object.

Parameters:
fs_common(function_space, var_accesses=None)

Add function-space related arguments common to LMA operators and fields. If supplied it also stores this access in var_accesses.

Parameters:
fs_compulsory_field(function_space, var_accesses=None)

Add compulsory arguments associated with this function space to the list. If supplied it also stores this access in var_accesses.

Parameters:
abstract fs_intergrid(function_space, var_accesses=None)

Add function-space related arguments for an intergrid kernel. If supplied it also stores this access in var_accesses.

Parameters:
generate(var_accesses=None)

Specifies which arguments appear in an argument list, their type and their ordering. Calls methods for each type of argument that can be specialised by a child class for its particular need. If the optional argument var_accesses is supplied, this function will also add variable access information for each implicit argument (i.e. that is not explicitly listed in kernel metadata) that is added. These accesses will be marked as read.

Parameters:

var_accesses (psyclone.core.VariablesAccessInfo) – optional VariablesAccessInfo instance that stores the information about variable accesses.

Raises:

GenerationError – if the kernel arguments break the rules for the LFRic API.

get_array_reference(array_name, indices, intrinsic_type, tag=None, symbol=None)

This function creates an array reference. If there is no symbol with the given tag, a new array symbol will be defined using the given intrinsic_type. If a symbol already exists but has no type, it will be replaced.

Parameters:
  • array_name (str) – the name and tag of the array.

  • indices (List[Union[str, py:class:psyclone.psyir.nodes.Node]]) – the indices to be used in the PSyIR reference. It must either be “:”, or a PSyIR node.

  • intrinsic_type (psyclone.psyir.symbols.datatypes.ScalarType.Intrinsic) – the intrinsic type of the array.

  • tag (Optional[str]) – optional tag for the symbol.

  • symbol – optional the symbol to use.

Type:

Optional[psyclone.psyir.symbols.Symbol]

Returns:

a reference to the symbol used.

Return type:

psyclone.psyir.nodes.Reference

indirection_dofmap(function_space, operator=None, var_accesses=None)

Add indirection dofmap required when applying a CMA operator. If supplied it also stores this access in var_accesses.

Parameters:
mesh_height(var_accesses=None)

Add mesh height (nlayers) to the argument list and if supplied stores this access in var_accesses.

Parameters:

var_accesses (psyclone.core.VariablesAccessInfo) – optional VariablesAccessInfo instance to store the information about variable accesses.

abstract mesh_properties(var_accesses=None)

Provide the kernel arguments required for the mesh properties specified in the kernel metadata. If supplied it also stores this access in var_accesses.

Parameters:

var_accesses (psyclone.core.VariablesAccessInfo) – optional VariablesAccessInfo instance to store the information about variable accesses.

metadata_index_from_actual_index(idx)

Returns the index of the entry in the meta_args list from which the actual subroutine argument at idx originated.

Parameters:

idx (int) – the index of an actual argument to the kernel subroutine.

Returns:

the 0-indexed position of the corresponding metadata entry or None if there isn’t one.

Return type:

Optional[int]

property num_args
Returns:

the current number of arguments stored in _arglist.

Return type:

int

abstract operator(arg, var_accesses=None)

Add the operator arguments to the argument list. If supplied it also stores this access in var_accesses.

Parameters:
abstract operator_bcs_kernel(function_space, var_accesses=None)

Supply necessary additional arguments for the kernel that applies boundary conditions to a LMA operator. If supplied it also stores this access in var_accesses.

Parameters:
psyir_append(node)

Appends a PSyIR node to the PSyIR argument list.

Parameters:

node (psyclone.psyir.nodes.Node) – the node to append.

property psyir_arglist
Returns:

the kernel argument list as PSyIR expressions. The generate method must be called first.

Return type:

List[psyclone.psyir.nodes.Reference]

Raises:

InternalError – if the generate() method has not been called.

abstract quad_rule(var_accesses=None)

Add quadrature-related information to the kernel argument list. Adds the necessary arguments to the argument list, and optionally adds variable access information to the var_accesses object.

Parameters:

var_accesses (psyclone.core.VariablesAccessInfo) – optional VariablesAccessInfo instance to store the information about variable accesses.

ref_element_properties(var_accesses=None)

Add kernel arguments relating to properties of the reference element. If supplied it also stores this access in var_accesses.

Parameters:

var_accesses (psyclone.core.VariablesAccessInfo) – optional VariablesAccessInfo instance to store the information about variable accesses.

scalar(scalar_arg, var_accesses=None)

Add the name associated with the scalar argument to the argument list and optionally add this scalar to the variable access information.

Parameters:
Raises:

InternalError – if the argument is not a recognised scalar type.

abstract stencil(arg, var_accesses=None)

Add general stencil information associated with the argument ‘arg’ to the argument list. If supplied it also stores this access in var_accesses.

Parameters:
abstract stencil_2d(arg, var_accesses=None)

Add 2D stencil information associated with the argument ‘arg’ to the argument list. If supplied it also stores this access in var_accesses.

Parameters:
abstract stencil_2d_max_extent(arg, var_accesses=None)

Add 2D stencil information to the argument list associated with the argument ‘arg’ if the stencil extent (from which it is calculated) is passed from the Algorithm layer rather than being specified in kernel metadata. If supplied it also stores this access in var_accesses.

Parameters:
abstract stencil_2d_unknown_extent(arg, var_accesses=None)

Add 2D stencil information to the argument list associated with the argument ‘arg’ if the extent is unknown. If supplied it also stores this access in var_accesses.

Parameters:
abstract stencil_unknown_direction(arg, var_accesses=None)

Add stencil information to the argument list associated with the argument ‘arg’ if the direction is unknown (i.e. it’s being supplied in a variable). If supplied it also stores this access in var_accesses.

Parameters:
abstract stencil_unknown_extent(arg, var_accesses=None)

Add stencil information to the argument list associated with the argument ‘arg’ if the extent is unknown. If supplied it also stores this access in var_accesses.

Parameters:
class psyclone.domain.lfric.FunctionSpace(name, kernel_args)

Manages the name of a function space. If it is an any_space or any_discontinuous_space then its name is mangled such that it is unique within the scope of an Invoke.

Parameters:
  • name (str) – original name of function space to create a mangled name for.

  • kernel_args (psyclone.dynamo0p3.DynKernelArguments) – object encapsulating all arguments to the kernel, one or more of which are on this function space.

Raises:

InternalError – if an unrecognised function space is encountered.

Inheritance

Inheritance diagram of FunctionSpace
property cbanded_map_name
Returns:

the name of a column-banded dofmap for this FunctionSpace.

Return type:

str

property cma_indirection_map_name
Returns:

the name of a CMA indirection dofmap for the supplied FunctionSpace.

Return type:

str

cma_on_space(arguments)

Returns the corresponding argument if the supplied list of arguments contains a cma operator that maps to/from this FunctionSpace. Otherwise this function returns None.

Parameters:

arguments (psyclone.dynamo0p3.DynKernelArguments) – list of arguments to be tested.

Returns:

the argument from the supplied list of arguments that contains a field that exists on this space or None.

Return type:

psyclone.dynamo0p3.DynKernelArgument or None

field_on_space(arguments)

Returns the corresponding argument if the supplied list of arguments contains a field that exists on this space. Otherwise this function returns None.

Parameters:

arguments (psyclone.dynamo0p3.DynKernelArguments) – list of arguments to be tested.

Returns:

the argument from the supplied list of arguments that contains a field that exists on this space or None.

Return type:

psyclone.dynamo0p3.DynKernelArgument or None

get_basis_name(qr_var=None, on_space=None)

Returns a name for the basis function on this FunctionSpace. If the name of an associated quadrature object is supplied then this is appended to the returned name. Similarly, if the function space at which the basis is to be evaluated is supplied then this is also appended to the name.

Parameters:
  • qr_var (string) – the name of the Quadrature Object for which the basis functions are required

  • on_space (psyclone.domain.lfric.FunctionSpace) – the function space at which the basis functions will be evaluated

Returns:

name for the Fortran array holding the basis function

Return type:

str

get_diff_basis_name(qr_var=None, on_space=None)

Returns a name for the differential basis function on this FunctionSpace. If the name of an associated quadrature object is supplied then this is appended to the returned name. Similarly, if the function space at which the basis is to be evaluated is supplied then this is also appended to the name.

Parameters:
  • qr_var (str) – the name of the Quadrature Object for which the differential basis functions are required.

  • on_space (psyclone.dynamo0p3.domain.lfric.                        FunctionSpace) – the function space at which the differential basis functions will be evaluated

Returns:

name for the Fortran array holding the differential basis function

Return type:

str

get_operator_name(operator_name, qr_var=None, on_space=None)

Returns the name of the specified operator (basis or differential basis) for this FunctionSpace.

Parameters:
  • operator_name (str) – name (type) of the operator.

  • qr_var (str) – the name of the Quadrature Object for which the operator is required.

  • on_space (psyclone.domain.lfric.FunctionSpace) – the function space at which the operator is required.

Returns:

name for the Fortran arry holding the named operator for the specified function space.

Return type:

str

property has_scalar_basis
Returns:

True if this function space has scalar basis functions.

Return type:

bool

property has_scalar_diff_basis
Returns:

True if this function space has scalar differential basis functions.

Return type:

bool

property has_vector_basis
Returns:

True if this function space has vector basis functions.

Return type:

bool

property has_vector_diff_basis
Returns:

True if this function space has vector differential basis functions.

Return type:

bool

property mangled_name

Returns the mangled name of this function space such that it is unique within the scope of an invoke. If the mangled name has not been generated then we do that the first time we are called.

Returns:

mangled name of this function space.

Return type:

str

property map_name
Returns:

a dofmap name for the supplied FunctionSpace.

Return type:

str

property ndf_name
Returns:

a ndf name for this FunctionSpace object.

Return type:

str

property orig_name

Returns the name of this function space as declared in the kernel meta-data.

Returns:

original name of this function space.

Return type:

str

property short_name

Returns the short name of this function space (original name for a valid LFRic function space and condensed name for any_*_spaces).

Returns:

short name of this function space.

Return type:

str

property undf_name
Returns:

a undf name for this FunctionSpace object.

Return type:

str

class psyclone.domain.lfric.KernCallAccArgList(kern)

Kernel call arguments that need to be declared by OpenACC directives. KernCallArgList only needs to be specialised where modified, or additional, arguments are required. Scalars are apparently not required but it is valid in OpenACC to include them and requires less specialisation to keep them in.

Inheritance

Inheritance diagram of KernCallAccArgList
cell_map(var_accesses=None)

Add cell-map to the list of required arrays.

Parameters:

var_accesses (Optional[ psyclone.core.VariablesAccessInfo]) – optional VariablesAccessInfo instance to store the information about variable accesses.

cell_position(var_accesses=None)

Adds a cell argument to the argument list and if supplied stores this access in var_accesses. Although normally just a scalar, the cell argument may actually require a lookup from a colour map array. Either way, this method adds the name of the variable to the argument list.

Parameters:

var_accesses (Optional[ psyclone.core.VariablesAccessInfo]) – optional VariablesAccessInfo instance to store the information about variable accesses.

fs_compulsory_field(function_space, var_accesses=None)

Add compulsory arguments associated with this function space to the list. OpenACC requires the full function-space map to be specified. If supplied it also stores this access in var_accesses.

Parameters:
fs_intergrid(function_space, var_accesses=None)

Add arrays that need to be uploaded for inter-grid kernels. These arrays contain the mapping between fine and coarse meshes.

Parameters:
operator(arg, var_accesses=None)

Add the operator arguments if they have not already been added. OpenACC requires the derived type and the dereferenced data to be specified. If supplied it also stores this access in var_accesses.

Parameters:
scalar(scalar_arg, var_accesses=None)

Override the default implementation as there’s no need to specify scalars for an OpenACC data region.

Parameters:
stencil(arg, var_accesses=None)

Add general stencil information associated with the argument ‘arg’ to the argument list. OpenACC requires the full dofmap to be specified. If supplied it also stores this access in var_accesses.

Parameters:
stencil_2d(arg, var_accesses=None)

Add general 2D stencil information associated with the argument ‘arg’ to the argument list. OpenACC requires the full dofmap to be specified. If supplied it also stores this access in var_accesses.This method passes through to the stencil method.

Parameters:
stencil_2d_unknown_extent(arg, var_accesses=None)

Add 2D stencil information to the argument list associated with the argument ‘arg’ if the extent is unknown. If supplied it also stores this access in var_accesses. This method passes through to the stencil_unknown_extent method.

Parameters:
stencil_unknown_extent(arg, var_accesses=None)

Add stencil information to the argument list associated with the argument ‘arg’ if the extent is unknown. If supplied it also stores this access in var_accesses.

Parameters:
class psyclone.domain.lfric.KernCallArgList(kern)

Creates the argument list required to call kernel “kern” from the PSy-layer and captures the positions of the following arguments in the argument list: nlayers, number of quadrature points and number of degrees of freedom. The ordering and type of arguments is captured by the base class.

Parameters:

kern (psyclone.domain.lfric.LFRicKern) – The kernel that is being called.

Inheritance

Inheritance diagram of KernCallArgList
class NdfInfo(position, function_space)
function_space

Alias for field number 1

position

Alias for field number 0

append_structure_reference(module_name, user_type, member_list, name, tag=None, overwrite_datatype=None)

Creates a reference to a variable of a user-defined type. If required, the required import statements will all be generated.

Parameters:
  • module_name (str) – the name of the module from which the user-defined type must be imported.

  • user_type (str) – the name of the user-defined type.

  • member_list (List[str]) – the members used hierarchically.

  • name (str) – the name of the variable to be used in the Reference.

  • tag (Optional[str]) – tag to use for the variable, defaults to the name

  • overwrite_datatype (Optional[psyclone.psyir.symbols.DataType]) – the datatype for the reference, which will overwrite the value determined by analysing the corresponding user defined type. This is useful when e.g. the module that declares the structure cannot be accessed.

Returns:

the symbol that is used in the reference

Return type:

psyclone.psyir.symbols.Symbol

basis(function_space, var_accesses=None)

Add basis function information for this function space to the argument list and optionally to the variable access information.

Parameters:
cell_map(var_accesses=None)

Add cell-map and related cell counts (for inter-grid kernels) to the argument list. If supplied it also stores these accesses to the var_access object.

Parameters:

var_accesses (psyclone.core.VariablesAccessInfo) – optional VariablesAccessInfo instance to store the information about variable accesses.

cell_position(var_accesses=None)

Adds a cell argument to the argument list and if supplied stores this access in var_accesses.

Parameters:

var_accesses (psyclone.core.VariablesAccessInfo) – optional VariablesAccessInfo instance to store the information about variable accesses.

cell_ref_name(var_accesses=None)

Utility routine which determines whether to return the cell value or the colourmap lookup value. If supplied it also stores this access in var_accesses.

Parameters:

var_accesses (psyclone.core.VariablesAccessInfo) – optional VariablesAccessInfo instance to store the information about variable accesses.

Returns:

the Fortran code needed to access the current cell index.

Return type:

Tuple[str, py:class:psyclone.psyir.nodes.Reference]

cma_operator(arg, var_accesses=None)

Add the CMA operator and associated scalars to the argument list and optionally add them to the variable access information.

Parameters:
diff_basis(function_space, var_accesses=None)

Add differential basis information for the function space to the argument list. If supplied it also stores this access in var_accesses.

Parameters:
field(arg, var_accesses=None)

Add the field array associated with the argument ‘arg’ to the argument list. If supplied it also stores this access in var_accesses.

Parameters:
field_bcs_kernel(function_space, var_accesses=None)

Implement the boundary_dofs array fix for a field. If supplied it also stores this access in var_accesses.

Parameters:
Raises:

GenerationError – if the bcs kernel does not contain a field as argument (but e.g. an operator).

field_vector(argvect, var_accesses=None)

Add the field vector associated with the argument ‘argvect’ to the argument list. If supplied it also stores these accesses to the var_access object.

Parameters:
fs_common(function_space, var_accesses=None)

Add function-space related arguments common to LMA operators and fields. If supplied it also stores this access in var_accesses.

Parameters:
fs_compulsory_field(function_space, var_accesses=None)

Add compulsory arguments associated with this function space to the list. If supplied it also stores this access in var_accesses.

Parameters:
fs_intergrid(function_space, var_accesses=None)

Add function-space related arguments for an intergrid kernel. If supplied it also stores this access in var_accesses.

Parameters:
get_user_type(module_name, user_type, name, tag=None)

Returns the symbol for a user-defined type. If required, the required import statements will all be generated.

Parameters:
  • module_name (str) – the name of the module from which the user-defined type must be imported.

  • user_type (str) – the name of the user-defined type.

  • name (str) – the name of the variable to be used in the Reference.

  • tag (Optional[str]) – tag to use for the variable, defaults to the name

Returns:

the symbol that is used in the reference

Return type:

psyclone.psyir.symbols.Symbol

mesh_height(var_accesses=None)

Add mesh height (nlayers) to the argument list and if supplied stores this access in var_accesses.

Parameters:

var_accesses (psyclone.core.VariablesAccessInfo) – optional VariablesAccessInfo instance to store the information about variable accesses.

mesh_properties(var_accesses=None)

Provide the kernel arguments required for the mesh properties specified in the kernel metadata. If supplied it also stores this access in var_accesses.

Parameters:

var_accesses (psyclone.core.VariablesAccessInfo) – optional VariablesAccessInfo instance to store the information about variable accesses.

property ndf_positions
Returns:

the position(s) in the argument list and the function space(s) associated with the variable(s) that pass(es) the number of degrees of freedom for the function space. The generate method must be called first.

Return type:

list of namedtuple (position=int, function_space=str).

Raises:

InternalError – if the generate() method has not been called.

property nlayers_positions
Returns:

the position(s) in the argument list of the variable(s) that passes the number of layers. The generate method must be called first.

Return type:

list of int.

Raises:

InternalError – if the generate() method has not been called.

property nqp_positions
Returns:

the positions in the argument list of the variables that pass the number of quadrature points. The number and type of these will change depending on the type of quadrature. A list of dictionaries is returned with the quadrature types being the keys to the dictionaries and their position in the argument list being the values. At the moment only XYoZ is supported (which has horizontal and vertical quadrature points). The generate method must be called first.

Return type:

[{str: int, …}]

Raises:

InternalError – if the generate() method has not been called.

operator(arg, var_accesses=None)

Add the operator arguments to the argument list. If supplied it also stores this access in var_accesses.

Parameters:
operator_bcs_kernel(function_space, var_accesses=None)

Supply necessary additional arguments for the kernel that applies boundary conditions to a LMA operator. If supplied it also stores this access in var_accesses.

Parameters:
  • function_space (psyclone.dynamo3.FunctionSpace) – unused, only for consistency with base class.

  • var_accesses (psyclone.core.VariablesAccessInfo) – optional VariablesAccessInfo instance to store the information about variable accesses.

quad_rule(var_accesses=None)

Add quadrature-related information to the kernel argument list. Adds the necessary arguments to the argument list, and optionally adds variable access information to the var_accesses object.

Parameters:

var_accesses (psyclone.core.VariablesAccessInfo) – optional VariablesAccessInfo instance to store the information about variable accesses.

scalar(scalar_arg, var_accesses=None)

Add the necessary argument for a scalar quantity as well as an appropriate Symbol to the SymbolTable.

Parameters:
stencil(arg, var_accesses=None)

Add general stencil information associated with the argument ‘arg’ to the argument list. If supplied it also stores this access in var_accesses.

Parameters:
stencil_2d(arg, var_accesses=None)

Add general 2D stencil information associated with the argument ‘arg’ to the argument list. If supplied it also stores this access in var_accesses.

Parameters:
stencil_2d_max_extent(arg, var_accesses=None)

Add the maximum branch extent for a 2D stencil associated with the argument ‘arg’ to the argument list. If supplied it also stores this in var_accesses.

Parameters:
  • arg (pclone.dynamo0p3.DynKernelArgument) – the kernel argument with which the stencil is associated.

  • var_accesses (psyclone.core.SingleVariableAccessInfo) – optional SingleVariableAccessInfo instance to store the information about variable accesses.

stencil_2d_unknown_extent(arg, var_accesses=None)

Add 2D stencil information to the argument list associated with the argument ‘arg’ if the extent is unknown. If supplied it also stores this access in var_accesses.

Parameters:
stencil_unknown_direction(arg, var_accesses=None)

Add stencil information to the argument list associated with the argument ‘arg’ if the direction is unknown (i.e. it’s being supplied in a variable). If supplied it also stores this access in var_accesses.

Parameters:
stencil_unknown_extent(arg, var_accesses=None)

Add stencil information to the argument list associated with the argument ‘arg’ if the extent is unknown. If supplied it also stores this access in var_accesses.

Parameters:
class psyclone.domain.lfric.KernelInterface(kern)

Create the kernel arguments for the supplied kernel as specified by the associated kernel metadata and the kernel ordering rules encoded in the ArgOrdering base class as method callbacks.

A PSyIR symbol table is created containing appropriate LFRic PSyIR symbols to specify the arguments. If an argument is an array with one or more dimension sizes specified by another argument, then the associated array symbol is created so that it references the appropriate symbol.

Related arguments - e.g. a field has an associated dofmap - are not directly connected, they must be inferred from the function space names. It is not yet clear whether this would be useful or not.

TODO #928: This class should replace the current kernel stub generation code when all of its methods are implemented.

Parameters:

kern (psyclone.domain.lfric.LFRicKern) – the kernel for which to create arguments.

Inheritance

Inheritance diagram of KernelInterface
banded_dofmap(function_space, var_accesses=None)

Not implemented.

Parameters:
  • function_space (psyclone.domain.lfric.FunctionSpace) – the function space for this dofmap.

  • var_accesses (: py:class:psyclone.core.VariablesAccessInfo) – an unused optional argument that stores information about variable accesses.

Raises:

NotImplementedError – as this method is not implemented.

basis(function_space, var_accesses=None)

Create an LFRic basis function argument and add it to the symbol table and argument list.

Parameters:
  • function_space (psyclone.domain.lfric.FunctionSpace) – the function space for this basis function.

  • var_accesses (: py:class:psyclone.core.VariablesAccessInfo) – an unused optional argument that stores information about variable accesses.

basis_mapping = {'gh_quadrature_edge': 'BasisFunctionQrEdgeDataSymbol', 'gh_quadrature_face': 'BasisFunctionQrFaceDataSymbol', 'gh_quadrature_xyoz': 'BasisFunctionQrXyozDataSymbol'}

Mapping from the LFRic metadata description of quadrature to the associated LFRic-specific basis function datasymbol.

cell_map(var_accesses=None)

Not implemented.

Parameters:

var_accesses (: py:class:psyclone.core.VariablesAccessInfo) – an unused optional argument that stores information about variable accesses.

Raises:

NotImplementedError – as this method is not implemented.

cell_position(var_accesses=None)

Create an LFRic cell-position object and add it to the symbol table and argument list.

Parameters:

var_accesses (: py:class:psyclone.core.VariablesAccessInfo) – an unused optional argument that stores information about variable accesses.

cma_operator(arg, var_accesses=None)

Not implemented.

Parameters:
  • arg (psyclone.dynamo0p3.DynKernelArgument) – the CMA operator argument.

  • var_accesses (: py:class:psyclone.core.VariablesAccessInfo) – an unused optional argument that stores information about variable accesses.

Raises:

NotImplementedError – as this method is not implemented.

diff_basis(function_space, var_accesses=None)

Create an LFRic differential basis function argument and add it to the symbol table and argument list.

Parameters:
  • function_space (psyclone.domain.lfric.FunctionSpace) – the function space for this differential basis function.

  • var_accesses (: py:class:psyclone.core.VariablesAccessInfo) – an unused optional argument that stores information about variable accesses.

diff_basis_mapping = {'gh_quadrature_edge': 'DiffBasisFunctionQrEdgeDataSymbol', 'gh_quadrature_face': 'DiffBasisFunctionQrFaceDataSymbol', 'gh_quadrature_xyoz': 'DiffBasisFunctionQrXyozDataSymbol'}

Mapping from the LFRic metadata description of quadrature to the associated LFRic-specific differential basis function datasymbol.

field(arg, var_accesses=None)

Create an LFRic field argument and add it to the symbol table and argument list. Also declare the associated “undf” symbol if it has not already been declared so that it can be used to dimension the field argument.

Parameters:
  • arg (psyclone.dynamo0p3.DynKernelArgument) – the field to add.

  • var_accesses (: py:class:psyclone.core.VariablesAccessInfo) – an unused optional argument that stores information about variable accesses.

Raises:

NotImplementedError – if the datatype of the field is not supported.

field_bcs_kernel(function_space, var_accesses=None)

Create the boundary-dofs mask argument required for the enforce_bc_code kernel. Adds it to the symbol table and the argument list.

Parameters:
Raises:
  • InternalError – if the kernel does not have a single field as argument.

  • InternalError – if the field argument is not on the ‘ANY_SPACE_1’ function space.

field_mapping = {'integer': 'IntegerFieldDataSymbol', 'logical': 'LogicalFieldDataSymbol', 'real': 'RealFieldDataSymbol'}

Mapping from a generic PSyIR datatype to the equivalent LFRic-specific field datasymbol.

field_vector(argvect, var_accesses=None)

Create LFRic field vector arguments and add them to the symbol table and argument list. Also declare the associated “undf” symbol if it has not already been declared so that it can be used to dimension the field vector arguments.

Parameters:
  • argvect (psyclone.dynamo0p3.DynKernelArgument) – the field vector to add.

  • var_accesses (: py:class:psyclone.core.VariablesAccessInfo) – an unused optional argument that stores information about variable accesses.

Raises:

NotImplementedError – if the datatype of the vector field is not supported.

fs_common(function_space, var_accesses=None)

Create any arguments that are common to a particular function space. At this time the only common argument is the number of degrees of freedom. Create the associated LFRic symbol, and add it to the symbol table and argument list.

Parameters:
  • function_space (psyclone.domain.lfric.FunctionSpace) – the function space for any common arguments.

  • var_accesses (: py:class:psyclone.core.VariablesAccessInfo) – an unused optional argument that stores information about variable accesses.

fs_compulsory_field(function_space, var_accesses=None)

Create any arguments that are compulsory for a field on a particular function space. At this time the compulsory arguments are the unique number of degrees of freedom and the dofmap. Create the associated LFRic symbol, and add it to the symbol table and argument list. Also declare the number of degrees of freedom and add to the symbol table if one has not yet been added.

Parameters:
  • function_space (psyclone.domain.lfric.FunctionSpace) – the function space for any compulsory arguments.

  • var_accesses (: py:class:psyclone.core.VariablesAccessInfo) – an unused optional argument that stores information about variable accesses.

fs_intergrid(function_space, var_accesses=None)

Not implemented.

Parameters:
  • arg (psyclone.dynamo0p3.DynKernelArgument) – the CMA operator argument.

  • var_accesses (: py:class:psyclone.core.VariablesAccessInfo) – an unused optional argument that stores information about variable accesses.

Raises:

NotImplementedError – as this method is not implemented.

generate(var_accesses=None)

Call the generate base class then add the argument list as it can’t be appended as we go along.

Parameters:

var_accesses (: py:class:psyclone.core.VariablesAccessInfo) – an unused optional argument that stores information about variable accesses.

indirection_dofmap(function_space, operator=None, var_accesses=None)

Not implemented.

Parameters:
Raises:

NotImplementedError – as this method is not implemented.

mesh_height(var_accesses=None)

Create an LFRic mesh height object and add it to the symbol table and argument list.

Parameters:

var_accesses (: py:class:psyclone.core.VariablesAccessInfo) – an unused optional argument that stores information about variable accesses.

mesh_properties(var_accesses=None)

Properties associated with the mesh

Parameters:

var_accesses (: py:class:psyclone.core.VariablesAccessInfo) – an unused optional argument that stores information about variable accesses.

operator(arg, var_accesses=None)

Create an LFRic operator argument and an ncells argument and add them to the symbol table and argument list. Also declare the associated ‘fs_from’, ‘fs_to’ symbols if they have not already been declared so that they can be used to dimension the operator symbol (as well as ncells).

Parameters:
Raises:

NotImplementedError – if the datatype of the field is not supported.

operator_bcs_kernel(function_space, var_accesses=None)

Not implemented.

Parameters:
  • function_space (psyclone.domain.lfric.FunctionSpace) – the function space for this bcs kernel

  • var_accesses (: py:class:psyclone.core.VariablesAccessInfo) – an unused optional argument that stores information about variable accesses.

Raises:

NotImplementedError – as this method is not implemented.

quad_rule(var_accesses=None)

Create LFRic arguments associated with the required quadrature, if they do not already exist, and add them to the symbol table and argument list. The arguments depend on the type of quadrature requested.

Parameters:

var_accesses (: py:class:psyclone.core.VariablesAccessInfo) – an unused optional argument that stores information about variable accesses.

Raises:

InternalError – if an unsupported quadrature shape is found.

ref_element_properties(var_accesses=None)

Properties associated with the reference element

Parameters:

var_accesses (: py:class:psyclone.core.VariablesAccessInfo) – an unused optional argument that stores information about variable accesses.

scalar(scalar_arg, var_accesses=None)

Create an LFRic scalar argument and add it to the symbol table and argument list.

Parameters:
  • scalar_arg (psyclone.dynamo0p3.DynKernelArgument) – the scalar to add.

  • var_accesses (: py:class:psyclone.core.VariablesAccessInfo) – an unused optional argument that stores information about variable accesses.

Raises:

NotImplementedError – if the datatype of the scalar is not supported.

stencil(arg, var_accesses=None)

Not implemented.

Parameters:
  • arg (psyclone.dynamo0p3.DynKernelArgument) – the kernel argument with which the stencil is associated.

  • var_accesses (: py:class:psyclone.core.VariablesAccessInfo) – an unused optional argument that stores information about variable accesses.

Raises:

NotImplementedError – as this method is not implemented.

stencil_unknown_direction(arg, var_accesses=None)

Not implemented.

Parameters:
  • arg (psyclone.dynamo0p3.DynKernelArgument) – the kernel argument with which the stencil is associated.

  • var_accesses (: py:class:psyclone.core.VariablesAccessInfo) – an unused optional argument that stores information about variable accesses.

Raises:

NotImplementedError – as this method is not implemented.

stencil_unknown_extent(arg, var_accesses=None)

Not implemented.

Parameters:
  • arg (psyclone.dynamo0p3.DynKernelArgument) – the kernel argument with which the stencil is associated.

  • var_accesses (: py:class:psyclone.core.VariablesAccessInfo) – an unused optional argument that stores information about variable accesses.

Raises:

NotImplementedError – as this method is not implemented.

vector_field_mapping = {'integer': 'IntegerVectorFieldDataSymbol', 'logical': 'LogicalVectorFieldDataSymbol', 'real': 'RealVectorFieldDataSymbol'}

Mapping from a generic PSyIR datatype to the equivalent LFRic-specific vector field datasymbol.

class psyclone.domain.lfric.KernStubArgList(kern)

Creates the argument list required to create and declare the required arguments for a kernel subroutine. The ordering and type of the arguments is captured by the base class.

Parameters:

kern (psyclone.domain.lfric.LFRicKern) – Kernel for which to create argument list.

Raises:
  • NotImplementedError – if the kernel is inter-grid.

  • NotImplementedError – if the kernel requires properties of the reference element.

Inheritance

Inheritance diagram of KernStubArgList
basis(function_space, var_accesses=None)

Add basis function information for this function space to the argument list and optionally to the variable access information. There can be more than one if this is an evaluator and/or multiple ‘gh_shape’s have been requested in the kernel metadata. If supplied it also stores these accesses in var_accesses.

Parameters:
Raises:

InternalError – if the evaluator shape is not recognised.

cell_position(var_accesses=None)

Adds a cell argument to the argument list and if supplied stores this access in var_accesses.

Parameters:

var_accesses (psyclone.core.VariablesAccessInfo) – optional VariablesAccessInfo instance to store the information about variable accesses.

cma_operator(arg, var_accesses=None)

Add the CMA operator and associated scalars to the argument list and optionally add them to the variable access information.

Parameters:
diff_basis(function_space, var_accesses=None)

Add differential basis information for the function space to the argument list. If supplied it also stores this access in var_accesses.

Parameters:
Raises:

InternalError – if the evaluator shape is not recognised.

field(arg, var_accesses=None)

Add the field array associated with the argument ‘arg’ to the argument list. If supplied it also stores this access in var_accesses.

Parameters:
field_bcs_kernel(function_space, var_accesses=None)

Implement the boundary_dofs array fix for a field. If supplied it also stores this access in var_accesses.

Parameters:
field_vector(argvect, var_accesses=None)

Add the field vector associated with the argument ‘argvect’ to the argument list. If supplied it also stores these accesses to the var_access object.

Parameters:
fs_compulsory_field(function_space, var_accesses=None)

Provide compulsory arguments if there is a field on this function space. If supplied it also stores this access in var_accesses.

Parameters:
indirection_dofmap(function_space, operator=None, var_accesses=None)

Add indirection dofmap required when applying a CMA operator. If supplied it also stores this access in var_accesses.

Parameters:
Raises:
mesh_height(var_accesses=None)

Add mesh height (nlayers) to the argument list and if supplied stores this access in var_accesses.

Parameters:

var_accesses (psyclone.core.VariablesAccessInfo) – optional VariablesAccessInfo instance to store the information about variable accesses.

mesh_properties(var_accesses=None)

Provide the kernel arguments required for the mesh properties specified in the kernel metadata. If supplied it also stores this access in var_accesses.

Parameters:

var_accesses (psyclone.core.VariablesAccessInfo) – optional VariablesAccessInfo instance to store the information about variable accesses.

operator(arg, var_accesses=None)

Add the operator arguments to the argument list. If supplied it also stores this access in var_accesses.

Parameters:
operator_bcs_kernel(function_space, var_accesses=None)

Supply necessary additional arguments for the kernel that applies boundary conditions to a LMA operator. If supplied it also stores this access in var_accesses.

Parameters:
  • function_space (psyclone.dynamo3.FunctionSpace) – the ‘to’ function space of the operator.

  • var_accesses (psyclone.core.VariablesAccessInfo) – optional VariablesAccessInfo instance to store the information about variable accesses.

quad_rule(var_accesses=None)

Add quadrature-related information to the kernel argument list. Adds the necessary arguments to the argument list, and optionally adds variable access information to the var_accesses object.

Parameters:

var_accesses (psyclone.core.VariablesAccessInfo) – optional VariablesAccessInfo instance to store the information about variable accesses.

stencil(arg, var_accesses=None)

Add general stencil information associated with the argument ‘arg’ to the argument list. If supplied it also stores this access in var_accesses.

Parameters:
stencil_2d(arg, var_accesses=None)

Add general 2D stencil information associated with the argument ‘arg’ to the argument list. If supplied it also stores this access in var_accesses.

Parameters:
stencil_2d_max_extent(arg, var_accesses=None)

Add the maximum branch extent for a 2D stencil associated with the argument ‘arg’ to the argument list. If supplied it also stores this in var_accesses.

Parameters:
stencil_2d_unknown_extent(arg, var_accesses=None)

Add 2D stencil information to the argument list associated with the argument ‘arg’ if the extent is unknown. If supplied it also stores this access in var_accesses.

Parameters:
stencil_unknown_direction(arg, var_accesses=None)

Add stencil information to the argument list associated with the argument ‘arg’ if the direction is unknown. If supplied it also stores this access in var_accesses.

Parameters:
stencil_unknown_extent(arg, var_accesses=None)

Add stencil information to the argument list associated with the argument ‘arg’ if the extent is unknown. If supplied it also stores this access in var_accesses.

Parameters:
class psyclone.domain.lfric.LFRicArgDescriptor(arg_type, operates_on, metadata_index)

This class captures the information specified in one of LFRic API argument descriptors (scalars, fields and operators).

Parameters:
  • arg_type (psyclone.expression.FunctionVar or psyclone.expression.BinaryOperator) – LFRic API valid argument type (scalar, field or operator).

  • operates_on (str) – value of operates_on from the parsed kernel metadata (used for validation).

  • metadata_index (int) – position of this argument in the list of arguments specified in the metadata.

Raises:
  • ParseError – if a ‘meta_arg’ entry is not of ‘arg_type’ type.

  • ParseError – if the first argument of a ‘meta_arg’ entry is not one of LFRic API valid argument types.

  • ParseError – if the second argument of a ‘meta_arg’ entry is not one of LFRic API valid data types.

  • ParseError – if a ‘meta_arg’ entry has fewer than 3 args.

  • ParseError – if the third ‘meta_arg’ entry is not a valid access descriptor.

  • InternalError – if the operates_on from the parsed kernel metadata is not ‘cell_column’ or ‘dof’.

  • InternalError – if all the metadata checks fail to catch an invalid argument type.

Inheritance

Inheritance diagram of LFRicArgDescriptor
property data_type
Returns:

intrinsic Fortran (primitive) type of the argument data.

Return type:

str

property function_space

Returns the function space name related to this kernel argument depending on the argument type: a single function space for a field, function_space_from for an operator and nothing for a scalar.

Returns:

function space relating to this kernel argument or None (for a scalar).

Return type:

str or NoneType

Raises:

InternalError – if an invalid argument type is passed in.

property function_space_from

Returns the “from” function space for an operator. This is the second function space specified in the metadata.

Returns:

“from” function space for an operator.

Return type:

str

Raises:

InternalError – if this is not an operator.

property function_space_to

Returns the “to” function space for an operator. This is the first function space specified in the metadata.

Returns:

“to” function space for an operator.

Return type:

str

Raises:

InternalError – if this is not an operator.

property function_spaces

Returns the function space names related to this kernel argument as a list depending on the argument type: one function space for a field, both function spaces (“to”- and then “from”-) for an operator and an empty list for a scalar.

Returns:

function space names related to this kernel argument.

Return type:

list of str

Raises:

InternalError – if an invalid argument type is passed in.

property vector_size

Returns the vector size of the argument. This will be 1 if *n has not been specified for all argument types except scalars (their vector size is set to 0).

Returns:

vector size of the argument.

Return type:

int

class psyclone.domain.lfric.LFRicCollection(node)

Base class for managing the declaration and initialisation of a group of related entities within an Invoke or Kernel stub

Parameters:

node (psyclone.domain.lfric.LFRicInvoke or psyclone.domain.lfric.LFRicKern) – the Kernel or Invoke for which to manage variable declarations and initialisation.

Raises:

InternalError – if the supplied node is not an LFRicInvoke or an LFRicKern.

Inheritance

Inheritance diagram of LFRicCollection
declarations(parent)

Insert declarations for all necessary variables into the AST of the generated code. Simply calls either ‘_invoke_declarations()’ or ‘_stub_declarations()’ depending on whether we’re handling an Invoke or a Kernel stub.

Parameters:

parent (psyclone.f2pygen.SubroutineGen) – the node in the f2pygen AST representing the routine in which to insert the declarations.

Raises:

InternalError – if neither ‘self._invoke’ nor ‘self._kernel’ are set.

initialise(parent)

Add code to initialise the entities being managed by this class. We do nothing by default - it is up to the sub-class to override this method if initialisation is required.

Parameters:

parent (psyclone.f2pygen.SubroutineGen) – the node in the f2pygen AST to which to add initialisation code.

class psyclone.domain.lfric.LFRicConstants

This class stores all LFRic constants. Note that some constants depend on values in the config file, so this class can only be used after the config file has been read. It stores all values in class variables (to avoid re-evaluating them).

Inheritance

Inheritance diagram of LFRicConstants
precision_for_type(data_type)

This function returns the precision required for the various LFRic types.

Parameters:

data_type (str) – the name of the data type.

Returns:

the precision as defined in domain.lfric.lfric_types (one of R_SOLVER, R_TRAN, R_DEF).

Return type:

psyclone.psyir.symbols.DataSymbol

Raises:

InternalError – if an unknown data_type is specified.

static specific_function_space(name)

Maps from a valid kernel metadata function-space name to one that exists within the LFRic infrastructure. This is necessary because meta-data can contain ‘generic’ names such as ‘any_w2’ but, when generating code, we need the name of a specific function space that is recognised by the LFRic infrastructure.

Parameters:

name (str) – the name of the function space in metadata.

Returns:

the name of a specific function space.

Return type:

str

Raises:
  • ValueError – if the supplied name is not a valid LFRic function-space name.

  • InternalError – if an unrecognised wildcard function-space name is supplied.

class psyclone.domain.lfric.LFRicDofmaps(node)

Holds all information on the dofmaps (including column-banded and indirection) required by an invoke.

Parameters:

node (psyclone.domain.lfric.LFRicKern or psyclone.dynamo0p3.LFRicInvoke) – Kernel or Invoke for which to manage dofmaps.

Inheritance

Inheritance diagram of LFRicDofmaps
initialise(parent)

Generates the calls to the LFRic infrastructure that look-up the necessary dofmaps. Adds these calls as children of the supplied parent node. This must be an appropriate f2pygen object.

class psyclone.domain.lfric.LFRicExtractDriverCreator

This class provides the functionality to create a driver that reads in extracted data produced by using the PSyData kernel-extraction functionality.

The driver is created as follows:

  1. The corresponding psyclone.psyGen.Invoke statement that contains the kernel(s) is copied. This way we avoid affecting the tree of the caller. We need the invoke since it contains the symbol table.

  2. We remove all halo exchange nodes. For now, the extract transformation will not work when distributed memory is enabled, but since this restriction is expected to be lifted, the code to handle this is already added.

  3. We lower each kernel (child of the invoke) that was requested to be extracted, all others are removed. This is required since the kernel extraction will not contain the required data for the other kernels to be called. The lowering is important to fix the variable names for the loop boundaries of the psyclone.domain.lfric.LFRicLoop: the loop start/stop expressions (loop0_start etc.) depend on the position of the loop in the tree. For example, if there are two kernels, they will be using loop0_start and loop1_start. If only the second is extracted, the former second (and now only) loop would be using loop0_start without lowering, but the kernel extraction would have written the values for loop1_start.

  4. We create a program for the driver with a new symbol table and start adding symbols for the program unit, precision symbols, PSyData read module etc to it.

  5. We add all required symbols to the new symbol table. The copied tree will still rely on the symbol table in the original PSyIR, so the symbols must be declared in the symbol table of the driver program. This is done by replacing all references in the extracted region with new references, which use new symbols which are declared in the driver symbol table.

    1. We first handle all non user-defined type. We can be certain that these symbols are already unique (since it’s the original kernel code).

    2. Then we handle user-defined types. Since we only use basic Fortran types, accesses to these types need to be ‘flattened’: an access like a%b%c will be flattened to a_b_c to create a valid symbol name without needing the user-defined type. We use the original access string (a%b%c) as tag, since we know this tag is unique, and create a new, unique symbol based on a_b_c. This takes care if the user should be using this newly generated name (e.g. if the user uses a%b%c and a_b_c, a_b_c as non user defined symbol will be added to the symbol table first. When then a%b%c is flattened, the symbol table will detect that the symbol a_b_c already exists and create a_b_c_1 for the tag a%b%c). For known LFRic types, the actual name used in a reference will be changed to the name the user expects. For example, if field f is used, the access will be f_proxy%data. The kernel extraction does the same and stores the values under the name f, so the driver similarly simplifies the name back to the original f. The psyclone.domain.lfric.KernCallArgList class will have enforced the appropriate basic Fortran type declaration for each reference to a user defined variable. For example, if a field f is used, the reference to f_proxy%data will have a data type attribute of a 1D real array (with the correct precision).

  6. We create the code for reading in all of the variables in the input- and output-lists. Mostly, no special handling of argument type is required (since the generic interface will make sure to call the appropriate function). But in case of user-defined types, we need to use the original names with ‘%’ when calling the functions for reading in data, since this is the name that was used when creating the data file. For example, the name of a parameter like f_proxy%local_stencil will be stored in the data file with the ‘%’ notation (which is also the tag used for the symbol). So when reading the values in the driver, we need to use the original name (or tag) with ‘%’, but the values will be stored in a flattened variable. For example, the code created might be: call extract_psy_data%ReadVariable(‘f_proxy%local_stencil’, fproxy_local_stencil)

    1. Input variables are read in using functions from the PSyData ReadKernelData module. These function will allocate all array variables to the right size based on the data from the input file.

    2. For parameters that are read and written, two variables will be declared: the input will be stored in the unmodified variable name, and the output values in a variable with _post appended. For example, a field f as input will be read into f using the name f, and output values will be read into f_post using the name f_post. The symbol table will make sure that the _post name is unique.

    3. Similar to b., output only parameters will be read into a variable named with ‘_post’ attached, e.g. output field f will be stored in a variable f_post. Then the array f is allocated based on the shape of f_post and initialised to 0 (since it’s an output-only parameter the value doesn’t really matter).

  7. The extracted kernels are added to the program. Since in step 5 all references have been replaced, the created code will use the correct new variable names (which just have been read in). The output variables with _post attached will not be used at all so far.

  8. After the kernel calls are executed, each output variable is compared with the value stored in the corresponding _post variable. For example, a variable f which was modified in the kernel call(s), will then be compared with f_post.

Parameters:

precision (Optional[Dict[str, str]]) – a mapping of the various precisions used in LFRic to the actual Fortran data type to be used in a stand-alone driver.

Raises:

InternalError – if the precision argument is specified but is not a dictionary.

Inheritance

Inheritance diagram of LFRicExtractDriverCreator
static collect_all_required_modules(file_container)

Collects recursively all modules used in the file container. It returns a dictionary, with the keys being all the (directly or indirectly) used modules.

Parameters:

file_container (psyclone.psyir.psyir.nodes.FileContainer) – the FileContainer for which to collect all used modules.

Returns:

a dictionary, with the required module names as key, and as value a set of all modules required by the key module.

Return type:

Dict[str, Set[str]]

create(nodes, read_write_info, prefix, postfix, region_name)

This function uses the PSyIR to create a stand-alone driver that reads in a previously created file with kernel input and output information, and calls the kernels specified in the ‘nodes’ PSyIR tree with the parameters from the file. The nodes are consecutive nodes from the PSyIR tree. It returns the file container which contains the driver.

Parameters:
  • nodes (List[psyclone.psyir.nodes.Node]) – a list of nodes.

  • read_write_info (psyclone.psyir.tools.ReadWriteInfo) – information about all input and output parameters.

  • prefix (str) – the prefix to use for each PSyData symbol, e.g. ‘extract’ as prefix will create symbols extract_psydata.

  • postfix (str) – a postfix that is appended to an output variable to create the corresponding variable that stores the output value from the kernel data file. The caller must guarantee that no name clashes are created when adding the postfix to a variable and that the postfix is consistent between extract code and driver code (see ‘ExtractTrans.determine_postfix()’).

  • region_name (Tuple[str,str]) – an optional name to use for this PSyData area, provided as a 2-tuple containing a location name followed by a local name. The pair of strings should uniquely identify a region.

Returns:

the program PSyIR for a stand-alone driver.

Return type:

psyclone.psyir.psyir.nodes.FileContainer

get_driver_as_string(nodes, read_write_info, prefix, postfix, region_name, writer=<psyclone.psyir.backend.fortran.FortranWriter object>)

This function uses the create() function to get the PSyIR of a stand-alone driver, and then uses the provided language writer to create a string representation in the selected language (defaults to Fortran). All required modules will be inlined in the correct order, i.e. each module will only depend on modules inlined earlier, which will allow compilation of the driver. No other dependencies (except system dependencies like NetCDF) are required for compilation.

Parameters:
  • nodes (List[psyclone.psyir.nodes.Node]) – a list of nodes.

  • read_write_info (psyclone.psyir.tools.ReadWriteInfo) – information about all input and output parameters.

  • prefix (str) – the prefix to use for each PSyData symbol, e.g. ‘extract’ as prefix will create symbols extract_psydata.

  • postfix (str) – a postfix that is appended to an output variable to create the corresponding variable that stores the output value from the kernel data file. The caller must guarantee that no name clashes are created when adding the postfix to a variable and that the postfix is consistent between extract code and driver code (see ‘ExtractTrans.determine_postfix()’).

  • region_name (Tuple[str,str]) – an optional name to use for this PSyData area, provided as a 2-tuple containing a location name followed by a local name. The pair of strings should uniquely identify a region.

  • language_writer (psyclone.psyir.backend.language_writer.LanguageWriter) – a backend visitor to convert PSyIR representation to the selected language. It defaults to the FortranWriter.

Returns:

the driver in the selected language.

Return type:

str

Raises:

NotImplementedError – if the driver creation fails.

write_driver(nodes, read_write_info, prefix, postfix, region_name, writer=<psyclone.psyir.backend.fortran.FortranWriter object>)

This function uses the get_driver_as_string() function to get a a stand-alone driver, and then writes this source code to a file. The file name is derived from the region name: “driver-“+module_name+”_”+region_name+”.F90”

Parameters:
  • nodes (List[psyclone.psyir.nodes.Node]) – a list of nodes containing the body of the driver routine.

  • read_write_info (psyclone.psyir.tools.ReadWriteInfo) – information about all input and output parameters.

  • prefix (str) – the prefix to use for each PSyData symbol, e.g. ‘extract’ as prefix will create symbols extract_psydata.

  • postfix (str) – a postfix that is appended to an output variable to create the corresponding variable that stores the output value from the kernel data file. The caller must guarantee that no name clashes are created when adding the postfix to a variable and that the postfix is consistent between extract code and driver code (see ‘ExtractTrans.determine_postfix()’).

  • region_name (Tuple[str,str]) – an optional name to use for this PSyData area, provided as a 2-tuple containing a location name followed by a local name. The pair of strings should uniquely identify a region.

  • writer (psyclone.psyir.backend.language_writer.LanguageWriter) – a backend visitor to convert PSyIR representation to the selected language. It defaults to the FortranWriter.

class psyclone.domain.lfric.LFRicFields(node)

Manages the declarations for all field arguments required by an Invoke or Kernel stub.

Inheritance

Inheritance diagram of LFRicFields
class psyclone.domain.lfric.LFRicInvoke(alg_invocation, idx, invokes)

The LFRic-specific Invoke class. This passes the LFRic-specific InvokeSchedule class to the base class so it creates the one we require. Also overrides the ‘gen_code’ method so that we generate dynamo specific invocation code.

Parameters:
Raises:

GenerationError – if integer reductions are required in the PSy-layer.

Inheritance

Inheritance diagram of LFRicInvoke
arg_for_funcspace(fspace)

Returns an argument object which is on the requested function space. Searches through all Kernel calls in this Invoke. Currently the first argument object that is found is used. Throws an exception if no argument exists.

Parameters:

fspace (psyclone.domain.lfric.FunctionSpace) – function space of the argument.

Returns:

an argument object which is on the requested function space.

Return type:

psyclone.dynamo0p3.DynKernelArgument

Raises:

GenerationError – if the argument object does not exist.

field_on_space(func_space)

If a field exists on this space for any kernel in this Invoke then return that field. Otherwise return ‘None’.

Parameters:

func_space (psyclone.domain.lfric.FunctionSpace) – the function space for which to find an argument.

gen_code(parent)

Generates LFRic-specific invocation code (the subroutine called by the associated Invoke call in the algorithm layer). This consists of the PSy invocation subroutine and the declaration of its arguments.

Parameters:

parent (psyclone.f2pygen.ModuleGen) – the parent node in the AST (of the code to be generated) to which the node describing the PSy subroutine will be added.

property operates_on_dofs_only
Returns:

whether or not this Invoke consists only of kernels that operate on DoFs.

Return type:

bool

unique_fss()
Returns:

the unique function space objects over all kernel calls in this Invoke.

Return type:

list of psyclone.domain.lfric.FunctionSpace

class psyclone.domain.lfric.LFRicInvokes(alg_calls, psy)

The LFRic-specific invokes class. This passes the LFRic-specific LFRicInvoke class to the base class so it creates the one we require.

Parameters:

Inheritance

Inheritance diagram of LFRicInvokes
class psyclone.domain.lfric.LFRicKern

Stores information about LFRic Kernels as specified by the Kernel metadata and associated algorithm call. Uses this information to generate appropriate PSy layer code for the Kernel instance or to generate a Kernel stub.

Inheritance

Inheritance diagram of LFRicKern
class QRRule(alg_name, psy_name, kernel_args)
alg_name

Alias for field number 0

kernel_args

Alias for field number 2

psy_name

Alias for field number 1

property all_updates_are_writes
Returns:

True if all of the arguments updated by this kernel have ‘GH_WRITE’ access, False otherwise.

Return type:

bool

property argument_kinds
Returns:

kinds (precisions) for all arguments in a kernel.

Return type:

set of str

property base_name
Returns:

a base name for this kernel.

Return type:

str

property cma_operation
Returns:

the type of CMA operation performed by this kernel (one of ‘assembly’, ‘apply’ or ‘matrix-matrix’) or None if the kernel does not involve CMA operators.

Return type:

str

property colourmap

Getter for the name of the colourmap associated with this kernel call.

Returns:

name of the colourmap (Fortran array).

Return type:

str

Raises:

InternalError – if this kernel is not coloured.

property eval_shapes
Returns:

the value(s) of GH_SHAPE for this kernel or an empty list if none are specified.

Return type:

list

property eval_targets
Returns:

the function spaces upon which basis/diff-basis functions are to be evaluated for this kernel.

Return type:

dict of (psyclone.domain.lfric.FunctionSpace, :py:class`psyclone.dynamo0p3.DynKernelArgument`), indexed by the names of the target function spaces.

property fs_descriptors
Returns:

a list of function space descriptor objects of type FSDescriptors which contain information about the function spaces.

Return type:

List[psyclone.FSDescriptors].

property gen_stub

Create the fparser1 AST for a kernel stub.

Returns:

root of fparser1 AST for the stub routine.

Return type:

fparser.one.block_statements.Module

Raises:

GenerationError – if the supplied kernel stub does not operate on a supported subset of the domain (currently only “cell_column”).

get_kernel_schedule()

Returns a PSyIR Schedule representing the kernel code. The base class creates the PSyIR schedule on first invocation which is then checked for consistency with the kernel metadata here. The Schedule is just generated on first invocation, this allows us to retain transformations that may subsequently be applied to the Schedule.

Once issue #935 is implemented, this routine will return the PSyIR Schedule using LFRic-specific PSyIR where possible.

Returns:

Schedule representing the kernel code.

Return type:

psyclone.psyGen.KernelSchedule

Raises:

GenerationError – if no subroutine matching this kernel can be found in the parse tree of the associated source code.

property is_intergrid
Returns:

True if it is an inter-grid kernel, False otherwise

Return type:

bool

property last_cell_all_colours_symbol

Getter for the symbol of the array holding the index of the last cell of each colour.

Returns:

name of the array.

Return type:

str

Raises:

InternalError – if this kernel is not coloured.

load(call, parent=None)

Sets up kernel information with the call object which is created by the parser. This object includes information about the invoke call and the associated kernel.

Parameters:
load_meta(ktype)

Sets up kernel information with the kernel type object which is created by the parser. The object includes the metadata describing the kernel code.

Parameters:

ktype (psyclone.domain.lfric.LFRicKernMetadata) – the kernel metadata object produced by the parser

Raises:
property mesh
Returns:

the mesh properties required by this kernel.

Return type:

:py:class`psyclone.dynamo0p3.MeshPropertiesMetaData`

property ncolours_var

Getter for the name of the variable holding the number of colours associated with this kernel call.

Returns:

name of the variable holding the number of colours

Return type:

Optional[str]

Raises:

InternalError – if this kernel is not coloured.

property qr_required
Returns:

True if this kernel requires quadrature, else returns False.

Return type:

bool

property qr_rules
Returns:

details of each of the quadrature rules required by this kernel.

Return type:

OrderedDict containing psyclone.domain.lfric.LFRicKern.QRRule indexed by quadrature shape.

reference_accesses(var_accesses)

Get all variable access information. All accesses are marked according to the kernel metadata

Parameters:

var_accesses (psyclone.core.VariablesAccessInfo) – VariablesAccessInfo instance that stores the information about variable accesses.

property reference_element
Returns:

the reference-element properties required by this kernel.

Return type:

psyclone.dynamo0p3.RefElementMetaData

validate_global_constraints()

Perform validation checks for any global constraints (that require the tree to be complete).

Raises:
  • GenerationError – if this kernel does not have a supported operates-on (currently only “cell_column”).

  • GenerationError – if the loop goes beyond the level 1 halo and an operator is accessed.

  • GenerationError – if a kernel in the loop has an inc access and the loop is not coloured but is within an OpenMP parallel region.

validate_kernel_code_args(table)

Check that the arguments in the kernel code match the expected arguments as defined by the kernel metadata and the LFRic API.

Parameters:

table (psyclone.psyir.symbols.SymbolTable) – the symbol table to validate against the metadata.

Raises:

GenerationError – if the number of arguments indicated by the kernel metadata doesn’t match the actual number of arguments in the symbol table.

class psyclone.domain.lfric.LFRicKernCallFactory

Create the necessary framework for an LFRic kernel call. This consists of a Loop over cells containing a call to the user-supplied kernel routine.

Inheritance

Inheritance diagram of LFRicKernCallFactory
static create(call, parent=None)

Create the objects needed for a call to the kernel described in the call object.

Parameters:
class psyclone.domain.lfric.LFRicKernMetadata(ast, name=None)

Captures the Kernel subroutine code and metadata describing the subroutine for the LFRic API.

Parameters:
  • ast (fparser.block_statements.BeginSource) – fparser1 AST for the kernel.

  • name (str) – the name of this kernel.

Raises:

ParseError – if the metadata does not conform to the rules for the LFRic API.

Inheritance

Inheritance diagram of LFRicKernMetadata
property cma_operation

Returns the type of CMA operation identified from the kernel metadata (one of ‘assembly’, ‘apply’ or ‘matrix-matrix’) or None if the kernel does not involve CMA operators

property eval_shapes

Returns the shape(s) of evaluator required by this kernel or an empty string if none.

Returns:

the shape(s) of the evaluator (one of VALID_EVALUATOR_SHAPES) or an empty list if the kernel does not require one.

Return type:

list

property eval_targets

Returns the list of function spaces upon which any evaluator must be provided. This list is obtained from the GH_EVALUATOR_TARGETS metadata entry (if present). If this is not specified in the metadata then we default to providing evaluators on all of the function spaces associated with the arguments which this kernel updates.

Returns:

list of the names of the function spaces (as they appear in kernel metadata) upon which any evaluator must be provided.

Return type:

list of str

property func_descriptors

Returns metadata about the function spaces within a Kernel. This metadata is provided within Kernel code via the meta_funcs variable. Information is returned as a list of DynFuncDescriptor03 objects, one for each function space.

property is_intergrid

Returns whether or not this is an inter-grid kernel.

Returns:

True if kernel is an inter-grid kernel, False otherwise

Return type:

bool

class psyclone.domain.lfric.LFRicLoop(loop_type='', **kwargs)

The LFRic-specific PSyLoop class. This passes the LFRic-specific loop information to the base class so it creates the one we require. Creates LFRic-specific loop bounds when the code is being generated.

Parameters:
  • loop_type (str) – the type (iteration space) of this loop.

  • kwargs (unwrapped dict.) – additional keyword arguments provided to the PSyIR node.

Raises:

InternalError – if an unrecognised loop_type is specified.

Inheritance

Inheritance diagram of LFRicLoop
create_halo_exchanges()

Add halo exchanges before this loop as required by fields within this loop. To keep the logic simple we assume that any field that accesses the halo will require a halo exchange and then remove the halo exchange if this is not the case (when previous writers perform sufficient redundant computation). It is implemented this way as the halo exchange class determines whether it is required or not so a halo exchange needs to exist in order to find out. The appropriate logic is coded in the _add_halo_exchange helper method. In some cases a new halo exchange will replace an existing one. In this situation that routine also removes the old one.

gen_code(parent)

Call the base class to generate the code and then add any required halo exchanges.

Parameters:

parent (psyclone.f2pygen.BaseGen) – an f2pygen object that will be the parent of f2pygen objects created in this method.

gen_mark_halos_clean_dirty(parent)

Generates the necessary code to mark halo regions for all modified fields as clean or dirty following execution of this loop.

Parameters:

parent (psyclone.f2pygen.BaseGen) – the node in the f2pygen AST to which to add content.

independent_iterations(test_all_variables=False, signatures_to_ignore=None, dep_tools=None)

This function is an LFRic-specific override of the default method in the Loop class. It allows domain-specific rules to be applied when determining whether or not loop iterations are independent.

Parameters:
  • test_all_variables (bool) – if True, it will test if all variable accesses are independent, otherwise it will stop after the first variable access is found that isn’t.

  • signatures_to_ignore (Optional[ List[psyclone.core.Signature]]) – list of signatures for which to skip the access checks.

  • dep_tools (Optional[ psyclone.psyir.tools.DependencyTools]) – an optional instance of DependencyTools so that the caller can access any diagnostic messages detailing why the loop iterations are not independent.

Returns:

True if the loop iterations are independent, False otherwise.

Return type:

bool

load(kern)

Load the state of this Loop using the supplied Kernel object. This method is provided so that we can individually construct Loop objects for a given kernel call.

Parameters:

kern (psyclone.domain.lfric.LFRicKern) – Kernel object to use to populate state of Loop

Raises:

GenerationError – if the field updated by the kernel has an unexpected function space or if the kernel’s ‘operates-on’ is not consistent with the loop type.

lower_to_language_level()

In-place replacement of DSL or high-level concepts into generic PSyIR constructs. This function replaces a LFRicLoop with a PSyLoop and inserts the loop boundaries into the new PSyLoop, or removes the loop node in case of a domain kernel. Once TODO #1731 is done (which should fix the loop boundaries, which atm rely on index of the loop in the schedule, i.e. can change when transformations are applied), this function can likely be removed.

Returns:

the lowered version of this node.

Return type:

psyclone.psyir.node.Node

node_str(colour=True)

Creates a text summary of this loop node. We override this method from the Loop class because, in Dynamo0.3, the function space is now an object and we need to call orig_name on it. We also include the upper loop bound as this can now be modified.

Parameters:

colour (bool) – whether or not to include control codes for colour.

Returns:

text summary of this node, optionally with control codes for colour highlighting.

Return type:

str

set_lower_bound(name, index=None)

Set the lower bounds of this loop

set_upper_bound(name, index=None)

Set the upper bound of this loop

Parameters:
  • name (String) – A loop upper bound name. This should be a supported name.

  • index (int) – An optional argument indicating the depth of halo

property start_expr
Returns:

the PSyIR for the lower bound of this loop.

Return type:

psyclone.psyir.Node

property stop_expr
Returns:

the PSyIR for the upper bound of this loop.

Return type:

psyclone.psyir.Node

update_halo_exchanges()

add and/or remove halo exchanges due to changes in the loops bounds

property upper_bound_halo_depth

Returns the index of the upper loop bound. This is None if the upper bound name is not in HALO_ACCESS_LOOP_BOUNDS.

Returns:

the depth of the halo for a loops upper bound. If it is None then a depth has not been provided. The depth value is only valid when the upper-bound name is associated with a halo e.g. ‘cell_halo’.

Return type:

int

property upper_bound_name

Returns the name of the upper loop bound

class psyclone.domain.lfric.LFRicLoopBounds(node)

Handles all variables required for specifying loop limits within an LFRic PSy-layer routine.

Inheritance

Inheritance diagram of LFRicLoopBounds
initialise(parent)

Updates the f2pygen AST so that all of the variables holding the lower and upper bounds of all loops in an Invoke are initialised.

Parameters:

parent (psyclone.f2pygen.SubroutineGen) – the f2pygen node representing the PSy-layer routine.

class psyclone.domain.lfric.LFRicRunTimeChecks(node)

Handle declarations and code generation for run-time checks. This is not used in the stub generator.

Inheritance

Inheritance diagram of LFRicRunTimeChecks
initialise(parent)

Add runtime checks to make sure that the arguments being passed from the algorithm layer are consistent with the metadata specified in the associated kernels. Currently checks are limited to ensuring that field function spaces are consistent with the associated kernel function-space metadata.

Parameters:

parent (psyclone.f2pygen.SubroutineGen) – the node in the f2pygen AST representing the PSy- layer routine.

class psyclone.domain.lfric.LFRicScalarArgs(node)

Handles the declarations of scalar kernel arguments appearing in either an Invoke or a Kernel stub.

Parameters:

node (psyclone.domain.lfric.LFRicKern or psyclone.domain.lfric.LFRicInvoke) – the Invoke or Kernel stub for which to manage the scalar arguments.

Inheritance

Inheritance diagram of LFRicScalarArgs
class psyclone.domain.lfric.LFRicStencils(node)

Stencil information and code generation associated with a PSy-layer routine or Kernel stub.

Parameters:

node (psyclone.dynamo0p3.LFRicInvoke or psyclone.domain.lfric.LFRicKern) – the Invoke or Kernel stub for which to provide stencil info.

Raises:

GenerationError – if a literal has been supplied for a stencil direction.

Inheritance

Inheritance diagram of LFRicStencils
static direction_name(symtab, arg)

Creates a Fortran variable name to hold the direction of the stencil associated with the supplied kernel argument.

Parameters:
Returns:

a Fortran variable name for the stencil direction.

Return type:

str

static dofmap_size_symbol(symtab, arg)

Create a valid symbol for the size (in cells) of a stencil dofmap in the PSy layer.

Parameters:
Returns:

a symbol for the stencil size.

Return type:

psyclone.psyir.symbols.Symbol

static dofmap_symbol(symtab, arg)

Creates and registers a symbol for the stencil dofmap associated with the supplied kernel argument.

Parameters:
Returns:

a dofmap symbol for a stencil in the PSy layer.

Return type:

psyclone.psyir.symbols.Symbol

static extent_value(arg)

Returns the content of the stencil extent which may be a literal value (a number) or a variable name. This function simplifies this problem by returning a string in either case.

Parameters:

arg (psyclone.dynamo0p3.DynKernelArgument) – the argument with which the stencil is associated.

Returns:

the content of the stencil extent.

Return type:

str

initialise(parent)

Adds in the code to initialise stencil dofmaps to the PSy layer.

Parameters:

parent (psyclone.f2pygen.SubroutineGen) – the node in the f2pygen AST to which to add the initialisations.

Raises:

GenerationError – if an unsupported stencil type is encountered.

map_name(arg)

Creates and registers a name for the stencil map associated with the supplied kernel argument.

Parameters:

arg (psyclone.dynamo0p3.DynKernelArgument) – kernel argument with which the stencil is associated.

Returns:

a valid unique map name for a stencil in the PSy layer.

Return type:

str

static max_branch_length_name(symtab, arg)

Create a valid unique name for the maximum length of a stencil branch (in cells) of a 2D stencil dofmap in the PSy layer. This is required in the kernels for defining the maximum possible length of one of the dofmap array dimensions.

Parameters:
Returns:

a Fortran variable name for the max stencil branch length.

Return type:

str

static stencil_unique_str(arg, context)

Creates a unique identifier for a stencil. As a stencil differs due to the function space it operates on, type of stencil and extent of stencil, we concatenate these things together to create a unique string.

Parameters:
  • arg (psyclone.dynamo0p3.DynKernelArgument) – kernel argument with which stencil is associated.

  • context (str) – a context for this stencil (e.g. “size” or “direction”).

Returns:

unique string identifying the stencil for this argument.

Return type:

str

Raises:

GenerationError – if an explicit stencil extent is found in the metadata for the kernel argument.

property unique_alg_vars
Returns:

list of the names of the extent and direction arguments supplied to the PSy routine from the Algorithm layer.

Return type:

list of str

class psyclone.domain.lfric.LFRicSymbolTable(node=None, default_visibility=Visibility.PUBLIC)

Sub-classes SymbolTable to provide a LFRic-specific implementation.

Parameters:

Inheritance

Inheritance diagram of LFRicSymbolTable
add_lfric_precision_symbol(name)

If the named LFRic precision symbol is not already in the table then add it. Also ensure that the Container symbol from which it is imported is in the table.

Parameters:

name (str) – name of the LFRic precision symbol to add to table.

Returns:

the specified LFRic precision symbol.

Return type:

psyclone.psyir.symbols.DataSymbol

Raises:
  • ValueError – if the supplied name is not a recognised LFRic precision variable.

  • ValueError – if a symbol with the same name is already in the table but is not imported from the correct container.

find_or_create_array(array_name, num_dimensions, intrinsic_type, tag=None)

This function returns a symbol for an ArrayReference. If the symbol does not exist, it is created. If a new array symbol is created, it gets the DEFERRED attribute, which in Fortran means it will be declared as an allocatable array.

Parameters:
  • array_name (str) – the name and tag of the array.

  • num_dimensions (int) – the number of dimensions of this array.

  • intrinsic_type (psyclone.psyir.symbols.datatypes.ScalarType.Intrinsic) – the intrinsic type of the array.

  • tag (Optional[str]) – optional tag to be used in searching and defining.

Returns:

the requested symbol

Return type:

psyclone.psyir.symbols.Symbol

Raises:

TypeError – if the symbol exists, but is not a DataSymbol, or not an Array, or has different number of dimensions.

find_or_create_integer_symbol(name, tag=None)

This function returns a symbol for an integer reference. If a tag is specified, it will be used to search for an existing symbol, otherwise the name will be used. If the symbol should not already exist in the symbol table, it will be returned, otherwise a new symbol will be created.

Parameters:
  • name (str) – name of the integer variable to declare.

  • tag (Optional[str]) – optional tag of the integer variable to declare.

Returns:

the symbol for the variable.

Return type:

psyclone.psyir.symbols.Symbol

Raises:
  • TypeError – TypeError if the symbol exists but is not a DataSymbol.

  • TypeError – TypeError if the symbol exists and is a DataSymbol, but not an Integer.