elasticai.creator.ir.rewriting.rewriter#
Module Contents#
Classes#
Use a given mapping to make the data dictionary accessible via node names from graph. |
|
Specifies how |
API#
- class elasticai.creator.ir.rewriting.rewriter.Node[source]#
Bases:
typing.Protocol- abstract property data: dict[str, Any]#
- abstract property name: str#
- class elasticai.creator.ir.rewriting.rewriter.Edge[source]#
Bases:
typing.Protocol- abstract property data: dict[str, Any]#
- abstract property src: str#
- abstract property dst: str#
- class elasticai.creator.ir.rewriting.rewriter.ReadOnlyDataGraph[source]#
Bases:
typing.Protocol- property graph: elasticai.creator.graph.Graph[str]#
- abstract property nodes: collections.abc.Mapping[str, N]#
- abstract property edges: collections.abc.Mapping[tuple[str, str], E]#
- abstract property data: dict[str, Any]#
- class elasticai.creator.ir.rewriting.rewriter.DataGraph[source]#
Bases:
elasticai.creator.ir.rewriting.rewriter.ReadOnlyDataGraph[elasticai.creator.ir.rewriting.rewriter.DataGraph.N,elasticai.creator.ir.rewriting.rewriter.DataGraph.E],typing.Protocol- abstract property data: dict[str, Any]#
- class elasticai.creator.ir.rewriting.rewriter.RemappedSubImplementation(mapping: dict[str, str], graph: elasticai.creator.graph.Graph[str], data: dict[str, Any], node_fn: collections.abc.Callable[[str, dict[str, Any]], N], edge_fn: collections.abc.Callable[[str, str, dict[str, Any]], E])[source]#
Bases:
elasticai.creator.ir.rewriting.rewriter.ReadOnlyDataGraph[elasticai.creator.ir.rewriting.rewriter.RemappedSubImplementation.N,elasticai.creator.ir.rewriting.rewriter.RemappedSubImplementation.E]Use a given mapping to make the data dictionary accessible via node names from graph.
This allows to access the data dictionary using the names from the graph. The provided mapping is used to map the node names of the graph to the node names in the data dictionary. This is used e.g., to initialize new nodes, that were replaced during rewriting. The mapping is assumed to be one-to-one, i.e. each node name in the graph maps to exactly one node name in the data dictionary.
Initialization
- property graph: elasticai.creator.graph.Graph[str]#
- property data: dict[str, Any]#
- property nodes: collections.abc.Mapping[str, N]#
- property edges: collections.abc.Mapping[tuple[str, str], E]#
- class elasticai.creator.ir.rewriting.rewriter.CompositeRule(rules: collections.abc.Iterable[elasticai.creator.ir.rewriting.rewriter.Rule])[source]#
Initialization
- class elasticai.creator.ir.rewriting.rewriter.Pattern[source]#
Bases:
typing.Protocol- abstract property graph: elasticai.creator.ir.rewriting.rewriter.DataGraph#
- property interface: collections.abc.Collection[str]#
- abstractmethod match(g: elasticai.creator.ir.rewriting.rewriter.ReadOnlyDataGraph) list[dict[str, str]][source]#
- class elasticai.creator.ir.rewriting.rewriter.StdPattern(graph: elasticai.creator.ir.rewriting.rewriter.DataGraph, node_constraint: collections.abc.Callable[[elasticai.creator.ir.rewriting.rewriter.Node, elasticai.creator.ir.rewriting.rewriter.Node], bool], interface: collections.abc.Collection[str])[source]#
Bases:
elasticai.creator.ir.rewriting.rewriter.Pattern- property graph: elasticai.creator.ir.rewriting.rewriter.DataGraph#
- property interface: collections.abc.Collection[str]#
- match(g: elasticai.creator.ir.rewriting.rewriter.ReadOnlyDataGraph) list[dict[str, str]][source]#
- class elasticai.creator.ir.rewriting.rewriter.PatternRule(spec: elasticai.creator.ir.rewriting.rewriter.PatternRuleSpec, ir_factory: elasticai.creator.ir.rewriting.rewriter.IrFactory[N, E, G])[source]#
Initialization
- class elasticai.creator.ir.rewriting.rewriter.PatternRuleSpec(pattern: elasticai.creator.ir.rewriting.rewriter.Pattern, replacement_fn: collections.abc.Callable[[elasticai.creator.ir.rewriting.rewriter.ReadOnlyDataGraph], elasticai.creator.ir.rewriting.rewriter.ReadOnlyDataGraph])[source]#
Specifies how
PatternRuleshould create a newDataGraphfrom an existing one.It consists of
a pattern to match in the original DataGraph.
a replacement to apply when the pattern is matched. The
PatternRulewill use thereplacement_fnfunction to create a newDataGraph. The function receives the matched part of the DataGraph as an argument, so you can build the replacement based on the parameters found in your matched pattern. The node names in this matched subimplementation are remapped from the original graph to the pattern graph, so you can access the data dictionary using the names from the pattern graph. E.g., if the pattern specifies a node'conv'you can acces the data of the original DataGraph that this node corresponds to usingmatched.nodes['conv'].data.an interface that specifies which nodes are part of the pattern and of the replacement, nodes that are part of the interface are neither replaced nor initialized. Instead they are used to connect the pattern and the replacement.
Initialization
- property interface: collections.abc.Collection[str]#