gt_frontend package

Submodules

gt_frontend.ast_node_matcher module

class gt_frontend.ast_node_matcher.Capture(name, default=None)[source]

Bases: object

Capture node used to identify and capture nodes in a python ast by match().

Example

default: Any
name: str
gt_frontend.ast_node_matcher._check_optional(pattern_node, captures=None) → bool[source]

Check if the given pattern node is optional and populate the captures dict with the default values stored in the Capture nodes.

gt_frontend.ast_node_matcher._is_placeholder_for(node, pattern_node) → bool[source]

Is the given node a valid placeholder for the pattern node.

gt_frontend.ast_node_matcher.match(concrete_node, pattern_node, captures=None) → bool[source]

Determine if concrete_node matches the pattern_node and capture values as specified in the pattern node into captures.

Example

gt_frontend.built_in_types module

class gt_frontend.built_in_types.BuiltInType[source]

Bases: object

args: List[Any] = None
class_name: str = 'BuiltInType'
namespace: str = {'__module__': 'gt_frontend.built_in_types', '__qualname__': 'BuiltInType'}
class gt_frontend.built_in_types.BuiltInTypeMeta(class_name, bases, namespace, args=None)[source]

Bases: type

Metaclass representing types used inside GTScript code.

For now only a bare minimum of operations on these types is supported, i.e. (pseudo) subclass checks and extraction of type arguments.

args: List[Any]
class_name: str
namespace: str
class gt_frontend.built_in_types.Field[source]

Bases: gt_frontend.built_in_types.BuiltInType

args: List[Any] = None
class_name: str = 'Field'
namespace: str = {'__module__': 'gt_frontend.built_in_types', '__qualname__': 'Field'}
class gt_frontend.built_in_types.Local[source]

Bases: gt_frontend.built_in_types.BuiltInType

Used as a type argument to Field representing a Local dimension.

args: List[Any] = None
class_name: str = 'Local'
namespace: str = {'__doc__': '\n Used as a type argument to :class:`.Field` representing a Local dimension.\n ', '__module__': 'gt_frontend.built_in_types', '__qualname__': 'Local'}
class gt_frontend.built_in_types.Location[source]

Bases: gt_frontend.built_in_types.BuiltInType

args: List[Any] = None
class_name: str = 'Location'
namespace: str = {'__module__': 'gt_frontend.built_in_types', '__qualname__': 'Location'}
class gt_frontend.built_in_types.Mesh[source]

Bases: gt_frontend.built_in_types.BuiltInType

args: List[Any] = None
class_name: str = 'Mesh'
namespace: str = {'__module__': 'gt_frontend.built_in_types', '__qualname__': 'Mesh'}
class gt_frontend.built_in_types.TemporaryField[source]

Bases: gt_frontend.built_in_types.BuiltInType

args: List[Any] = None
class_name: str = 'TemporaryField'
namespace: str = {'__module__': 'gt_frontend.built_in_types', '__qualname__': 'TemporaryField'}

gt_frontend.frontend module

class gt_frontend.frontend.GTScriptCompilationTask(definition)[source]

Bases: object

_annotate_args()[source]

Populate symbol table by extracting the argument types from scope the function is embedded in.

generate(*, debug=False, code_generator=<class 'gtc.unstructured.usid_codegen.UsidGpuCodeGenerator'>)[source]

Generate c++ code of the stencil.

gt_frontend.gtscript module

class gt_frontend.gtscript.Field[source]

Bases: gt_frontend.built_in_types.BuiltInType

args: List[Any] = None
class_name: str = 'Field'
namespace: str = {'__module__': 'gt_frontend.built_in_types', '__qualname__': 'Field'}
class gt_frontend.gtscript.Local[source]

Bases: gt_frontend.built_in_types.BuiltInType

Used as a type argument to Field representing a Local dimension.

args: List[Any] = None
class_name: str = 'Local'
namespace: str = {'__doc__': '\n Used as a type argument to :class:`.Field` representing a Local dimension.\n ', '__module__': 'gt_frontend.built_in_types', '__qualname__': 'Local'}
class gt_frontend.gtscript.Location[source]

Bases: gt_frontend.built_in_types.BuiltInType

args: List[Any] = None
class_name: str = 'Location'
namespace: str = {'__module__': 'gt_frontend.built_in_types', '__qualname__': 'Location'}
class gt_frontend.gtscript.Mesh[source]

Bases: gt_frontend.built_in_types.BuiltInType

args: List[Any] = None
class_name: str = 'Mesh'
namespace: str = {'__module__': 'gt_frontend.built_in_types', '__qualname__': 'Mesh'}
class gt_frontend.gtscript.TemporaryField[source]

Bases: gt_frontend.built_in_types.BuiltInType

args: List[Any] = None
class_name: str = 'TemporaryField'
namespace: str = {'__module__': 'gt_frontend.built_in_types', '__qualname__': 'TemporaryField'}
gt_frontend.gtscript.cells(*_)
gt_frontend.gtscript.computation(*_)
gt_frontend.gtscript.edges(*_)
gt_frontend.gtscript.interval(*_)
gt_frontend.gtscript.location(*_)
gt_frontend.gtscript.neighbors(*_)
gt_frontend.gtscript.vertices(*_)

gt_frontend.gtscript_ast module

class gt_frontend.gtscript_ast.Argument(*, id_: pydantic.types.StrictStr = None, name: str, type_: Union[gt_frontend.gtscript_ast.Symbol, gt_frontend.gtscript_ast.SubscriptMultiple, gt_frontend.gtscript_ast.SubscriptSingle])[source]

Bases: gt_frontend.gtscript_ast.GTScriptASTNode

name: str
type_: Union[gt_frontend.gtscript_ast.Symbol, gt_frontend.gtscript_ast.SubscriptMultiple, gt_frontend.gtscript_ast.SubscriptSingle]
class gt_frontend.gtscript_ast.Assign(*, id_: pydantic.types.StrictStr = None, target: Union[gt_frontend.gtscript_ast.Symbol, gt_frontend.gtscript_ast.SubscriptSingle, gt_frontend.gtscript_ast.SubscriptMultiple], value: gt_frontend.gtscript_ast.Expr)[source]

Bases: gt_frontend.gtscript_ast.Statement

target: Union[gt_frontend.gtscript_ast.Symbol, gt_frontend.gtscript_ast.SubscriptSingle, gt_frontend.gtscript_ast.SubscriptMultiple]
value: gt_frontend.gtscript_ast.Expr
class gt_frontend.gtscript_ast.BinaryOp(*, id_: pydantic.types.StrictStr = None, op: gtc.common.BinaryOperator, left: gt_frontend.gtscript_ast.Expr, right: gt_frontend.gtscript_ast.Expr)[source]

Bases: gt_frontend.gtscript_ast.Expr

left: gt_frontend.gtscript_ast.Expr
op: gtc.common.BinaryOperator
right: gt_frontend.gtscript_ast.Expr
class gt_frontend.gtscript_ast.Call(*, id_: pydantic.types.StrictStr = None, args: List[gt_frontend.gtscript_ast.Expr], func: str)[source]

Bases: gt_frontend.gtscript_ast.Expr

args: List[gt_frontend.gtscript_ast.Expr]
func: str
class gt_frontend.gtscript_ast.Computation(*, id_: pydantic.types.StrictStr = None, name: str, arguments: List[gt_frontend.gtscript_ast.Argument], stencils: List[gt_frontend.gtscript_ast.Stencil])[source]

Bases: gt_frontend.gtscript_ast.GTScriptASTNode

arguments: List[gt_frontend.gtscript_ast.Argument]
name: str
stencils: List[gt_frontend.gtscript_ast.Stencil]
class gt_frontend.gtscript_ast.Constant(*, id_: pydantic.types.StrictStr = None, value: Union[float, int, None, str] = None)[source]

Bases: gt_frontend.gtscript_ast.Expr

value: Union[float, int, None, str]
class gt_frontend.gtscript_ast.Expr(*, id_: pydantic.types.StrictStr = None)[source]

Bases: gt_frontend.gtscript_ast.GTScriptASTNode

id_: Optional[Str]

Unique node-id (implementation field)

class gt_frontend.gtscript_ast.GTScriptASTNode(*, id_: pydantic.types.StrictStr = None)[source]

Bases: eve.concepts.Node

id_: Optional[Str]

Unique node-id (implementation field)

class gt_frontend.gtscript_ast.Generator(*, id_: pydantic.types.StrictStr = None, generators: List[gt_frontend.gtscript_ast.LocationComprehension], elt: gt_frontend.gtscript_ast.Expr)[source]

Bases: gt_frontend.gtscript_ast.Expr

elt: gt_frontend.gtscript_ast.Expr
generators: List[gt_frontend.gtscript_ast.LocationComprehension]
class gt_frontend.gtscript_ast.Interval(*, id_: pydantic.types.StrictStr = None, start: gt_frontend.gtscript_ast.Constant, stop: gt_frontend.gtscript_ast.Constant)[source]

Bases: gt_frontend.gtscript_ast.GTScriptASTNode

Interval [start, stop[

start: gt_frontend.gtscript_ast.Constant
stop: gt_frontend.gtscript_ast.Constant
class gt_frontend.gtscript_ast.IterationOrder(*, id_: pydantic.types.StrictStr = None, order: str)[source]

Bases: gt_frontend.gtscript_ast.GTScriptASTNode

order: str
class gt_frontend.gtscript_ast.LocationComprehension(*, id_: pydantic.types.StrictStr = None, target: gt_frontend.gtscript_ast.Symbol, iterator: gt_frontend.gtscript_ast.Call)[source]

Bases: gt_frontend.gtscript_ast.GTScriptASTNode

iterator: gt_frontend.gtscript_ast.Call
target: gt_frontend.gtscript_ast.Symbol
class gt_frontend.gtscript_ast.LocationSpecification(*, id_: pydantic.types.StrictStr = None, name: gt_frontend.gtscript_ast.Symbol, location_type: str)[source]

Bases: gt_frontend.gtscript_ast.GTScriptASTNode

location_type: str
name: gt_frontend.gtscript_ast.Symbol
class gt_frontend.gtscript_ast.Pass(*, id_: pydantic.types.StrictStr = None)[source]

Bases: gt_frontend.gtscript_ast.Statement

id_: Optional[Str]

Unique node-id (implementation field)

class gt_frontend.gtscript_ast.Statement(*, id_: pydantic.types.StrictStr = None)[source]

Bases: gt_frontend.gtscript_ast.GTScriptASTNode

id_: Optional[Str]

Unique node-id (implementation field)

class gt_frontend.gtscript_ast.Stencil(*, id_: pydantic.types.StrictStr = None, iteration_spec: List[Union[gt_frontend.gtscript_ast.IterationOrder, gt_frontend.gtscript_ast.LocationSpecification, gt_frontend.gtscript_ast.Interval]], body: List[Union[gt_frontend.gtscript_ast.Statement, Stencil]])[source]

Bases: gt_frontend.gtscript_ast.GTScriptASTNode

body: List[Union[gt_frontend.gtscript_ast.Statement, Stencil]]
iteration_spec: List[Union[gt_frontend.gtscript_ast.IterationOrder, gt_frontend.gtscript_ast.LocationSpecification, gt_frontend.gtscript_ast.Interval]]
class gt_frontend.gtscript_ast.SubscriptMultiple(*, id_: pydantic.types.StrictStr = None, value: gt_frontend.gtscript_ast.Symbol, indices: List[Union[gt_frontend.gtscript_ast.Symbol, gt_frontend.gtscript_ast.SubscriptSingle, SubscriptMultiple]])[source]

Bases: gt_frontend.gtscript_ast.Expr

indices: List[Union[gt_frontend.gtscript_ast.Symbol, gt_frontend.gtscript_ast.SubscriptSingle, SubscriptMultiple]]
value: gt_frontend.gtscript_ast.Symbol
class gt_frontend.gtscript_ast.SubscriptSingle(*, id_: pydantic.types.StrictStr = None, value: gt_frontend.gtscript_ast.Symbol, index: str)[source]

Bases: gt_frontend.gtscript_ast.Expr

index: str
value: gt_frontend.gtscript_ast.Symbol
class gt_frontend.gtscript_ast.Symbol(*, id_: pydantic.types.StrictStr = None, name: str)[source]

Bases: gt_frontend.gtscript_ast.Expr

name: str

gt_frontend.gtscript_to_gtir module

class gt_frontend.gtscript_to_gtir.GTScriptToGTIR(symbol_table, *args, **kwargs)[source]

Bases: eve.visitors.NodeTranslator

classmethod apply(symbol_table, gt4py_ast: gt_frontend.gtscript_ast.Computation)[source]
visit_Assign(node: gt_frontend.gtscript_ast.Assign, *, location_stack, **kwargs) → gtc.unstructured.gtir.AssignStmt[source]
visit_BinaryOp(node: gt_frontend.gtscript_ast.BinaryOp, location_stack, **kwargs)[source]
visit_Call(node: gt_frontend.gtscript_ast.Call, *, location_stack, **kwargs)[source]
visit_Computation(node: gt_frontend.gtscript_ast.Computation) → gtc.unstructured.gtir.Computation[source]
visit_Constant(node: gt_frontend.gtscript_ast.Constant, *, location_stack, **kwargs)[source]
visit_Interval(node: gt_frontend.gtscript_ast.Interval)[source]
visit_IterationOrder(node: gt_frontend.gtscript_ast.IterationOrder)gtc.common.LoopOrder[source]
visit_LocationComprehension(node: gt_frontend.gtscript_ast.LocationComprehension, *, location_stack, **kwargs) → gtc.unstructured.gtir.LocationComprehension[source]
visit_LocationSpecification(node: gt_frontend.gtscript_ast.LocationSpecification, **kwargs) → gtc.unstructured.gtir.LocationComprehension[source]
visit_Pass(node: gt_frontend.gtscript_ast.Pass)[source]
visit_Stencil(node: gt_frontend.gtscript_ast.Stencil, **kwargs) → gtc.unstructured.gtir.Stencil[source]
visit_SubscriptMultiple(node: gt_frontend.gtscript_ast.SubscriptMultiple, *, location_stack)[source]
visit_Symbol(node: gt_frontend.gtscript_ast.Symbol, *, location_stack)[source]
class gt_frontend.gtscript_to_gtir.NodeCanonicalizer[source]

Bases: eve.visitors.NodeTranslator

classmethod apply(gt4py_ast: gt_frontend.gtscript_ast.Computation)[source]
visit_Call(node: gt_frontend.gtscript_ast.Call)[source]
visit_Computation(node: gt_frontend.gtscript_ast.Computation)[source]
visit_SubscriptSingle(node: gt_frontend.gtscript_ast.SubscriptSingle)[source]
class gt_frontend.gtscript_to_gtir.SymbolResolutionValidation(symbol_table)[source]

Bases: eve.visitors.NodeVisitor

Ensure all occurring symbols are in the symbol table.

classmethod apply(symbol_table, gt4py_ast: gt_frontend.gtscript_ast.Computation)[source]
visit_Argument(node: gt_frontend.gtscript_ast.Argument)[source]
visit_Symbol(node: gt_frontend.gtscript_ast.Symbol)[source]
class gt_frontend.gtscript_to_gtir.SymbolTable(types: Dict[str, Any], constants: Dict[str, Any])[source]

Bases: object

A simple symbol table containing all the types of all symbols and potentially their values if known at compile time

materialize_constant(symbol: str, expected_type=None)[source]

Materialize constant symbol, i.e. return the value of that symbol.

Currently the only constants are types, but this is currently the place where constant folding would happen, hence the name.

Example: .. code-block:: python

self._materialize_constant(“Vertex”) == LocationType.Vertex

class gt_frontend.gtscript_to_gtir.TemporaryFieldDeclExtractor(symbol_table)[source]

Bases: eve.visitors.NodeVisitor

classmethod apply(symbol_table, gt4py_ast: gt_frontend.gtscript_ast.Computation)[source]
primary_location: Union[None, gt_frontend.built_in_types.BuiltInTypeMeta]
symbol_table: gt_frontend.gtscript_to_gtir.SymbolTable
visit_Assign(node: gt_frontend.gtscript_ast.Assign)[source]
visit_LocationSpecification(node: gt_frontend.gtscript_ast.LocationSpecification)[source]
visit_Stencil(node: gt_frontend.gtscript_ast.Stencil)[source]
class gt_frontend.gtscript_to_gtir.VarDeclExtractor(symbol_table: gt_frontend.gtscript_to_gtir.SymbolTable, *args, **kwargs)[source]

Bases: eve.visitors.NodeVisitor

Extract all variable declarations and deduce their type.

  • Location - in location comprehensions and stencil iteration specifications
    ... for v in vertices(e)
    with Location(Vertex) as e: ...
    
  • Field - in the stencils arguments
    field_1: Field[Edge, dtype]
    field_2: Field[Edge, dtype]
    field_3: Field[Edge, dtype]
    
  • TemporaryField: - implicitly by assigning to a previously unknown variable
    field_3 = field_1+field_2
    
classmethod apply(symbol_table: gt_frontend.gtscript_to_gtir.SymbolTable, gt4py_ast: gt_frontend.gtscript_ast.Computation)[source]
visit_Argument(node: gt_frontend.gtscript_ast.Argument)[source]
visit_LocationComprehension(node: gt_frontend.gtscript_ast.LocationComprehension)[source]
visit_LocationSpecification(node: gt_frontend.gtscript_ast.LocationSpecification)[source]

gt_frontend.py_to_gtscript module

class gt_frontend.py_to_gtscript.PyToGTScript[source]

Bases: object

class Patterns[source]

Bases: object

Stores the pattern nodes / templates to be used extracting information from the Python ast.

Patterns are a 1-to-1 mapping from context and Python ast node to GTScript ast node. Context is encoded in the field types and all understood sementic is encoded in the structure.

Argument = <_ast.arg object>
Assign = <_ast.Assign object>
BinaryOp = <_ast.BinOp object>
Call = <_ast.Call object>
Computation = <_ast.FunctionDef object>
Constant = <_ast.Constant object>
Generator = <_ast.GeneratorExp object>
Interval = <_ast.withitem object>
IterationOrder = <_ast.withitem object>
LocationComprehension = <_ast.comprehension object>
LocationSpecification = <_ast.withitem object>
Pass = <_ast.Pass object>
Stencil = <_ast.With object>
SubscriptMultiple = <_ast.Subscript object>
SubscriptSingle = <_ast.Subscript object>
Symbol = <_ast.Name object>
static _all_subclasses(typ, *, module=None)[source]

Return all subclasses of a given type.

The type must be one of

  • GTScriptAstNode (returns all subclasses of the given class)

  • Union (return the subclasses of the united)

  • ForwardRef (resolve the reference given the specified module and return its subclasses)

  • built-in python type: str, int, type(None) (return as is)

leaf_map = {<class '_ast.Mult'>: <BinaryOperator.MUL: '*'>, <class '_ast.Add'>: <BinaryOperator.ADD: '+'>, <class '_ast.Div'>: <BinaryOperator.DIV: '/'>, <class '_ast.Pass'>: <class 'gt_frontend.gtscript_ast.Pass'>}
transform(node, eligible_node_types=None)[source]

Transform python ast into GTScript ast recursively.

Module contents

GTScript Frontend