elasticai.creator.ir.rewriting.rewriter#

Module Contents#

Classes#

Node

Edge

ReadOnlyDataGraph

DataGraph

RemappedSubImplementation

Use a given mapping to make the data dictionary accessible via node names from graph.

CompositeRule

Pattern

StdPattern

IrFactory

PatternRule

PatternRuleSpec

Specifies how PatternRule should create a new DataGraph from an existing one.

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]#
abstractmethod successors(node: str) collections.abc.Mapping[str, N][source]#
abstractmethod predecessors(node: str) collections.abc.Mapping[str, N][source]#
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

abstractmethod add_node(node: N) Self[source]#
abstractmethod add_edge(edge: E) Self[source]#
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]#
successors(node: str) collections.abc.Mapping[str, N][source]#
predecessors(node: str) collections.abc.Mapping[str, N][source]#
class elasticai.creator.ir.rewriting.rewriter.CompositeRule(rules: collections.abc.Iterable[elasticai.creator.ir.rewriting.rewriter.Rule])[source]#

Initialization

__call__(impl: elasticai.creator.ir.rewriting.rewriter.DataGraph) elasticai.creator.ir.rewriting.rewriter.DataGraph[source]#
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.IrFactory[source]#

Bases: typing.Protocol

abstractmethod node(name: str, data: collections.abc.Mapping[str, Any]) N[source]#
abstractmethod edge(src: str, dst: str, data: collections.abc.Mapping[str, Any]) E[source]#
abstractmethod data_graph() G[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

__call__(graph: elasticai.creator.ir.rewriting.rewriter.DataGraph) elasticai.creator.ir.rewriting.rewriter.DataGraph[source]#
apply(graph: elasticai.creator.ir.rewriting.rewriter.ReadOnlyDataGraph) elasticai.creator.ir.rewriting.rewriter.DataGraph[source]#
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 PatternRule should create a new DataGraph from an existing one.

It consists of

  • a pattern to match in the original DataGraph.

  • a replacement to apply when the pattern is matched. The PatternRule will use the replacement_fn function to create a new DataGraph. 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 using matched.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]#