elasticai.creator.ir.datagraph_rewriting#

Module Contents#

Classes#

Pattern

StdPattern

Use a simple constraint over Nodes to find all matching subgraphs.

PatternRuleSpec

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

PatternRule

API#

class elasticai.creator.ir.datagraph_rewriting.Pattern[source]#

Bases: typing.Protocol

abstract property graph: elasticai.creator.ir.datagraph_rewriting.DataGraph#
property interface: collections.abc.Collection[str]#
abstractmethod match(g: elasticai.creator.ir.datagraph_rewriting.DataGraph, registry: elasticai.creator.ir.datagraph_rewriting.Registry, /) list[dict[str, str]][source]#
class elasticai.creator.ir.datagraph_rewriting.StdPattern(graph: elasticai.creator.ir.datagraph_rewriting.DataGraph, node_constraint: collections.abc.Callable[[elasticai.creator.ir.datagraph.Node, elasticai.creator.ir.datagraph.Node], bool], interface: collections.abc.Collection[str])[source]#

Bases: elasticai.creator.ir.datagraph_rewriting.Pattern

Use a simple constraint over Nodes to find all matching subgraphs.

This pattern ignores the registry, so you cannot analyse attributes of other graphs that nodes might refer to. Thus, all information your pattern matching needs, needs to be present in the graph under match already. As this is often the case, the pattern is provided as StdPattern.

If you need more control, implement your own pattern.

Initialization

property graph: elasticai.creator.ir.datagraph_rewriting.DataGraph#
property interface: collections.abc.Collection[str]#
match(g: elasticai.creator.ir.datagraph_rewriting.DataGraph, registry: elasticai.creator.ir.datagraph_rewriting.Registry, /) list[dict[str, str]][source]#
class elasticai.creator.ir.datagraph_rewriting.PatternRuleSpec(pattern: elasticai.creator.ir.datagraph_rewriting.Pattern, replacement_fn: elasticai.creator.ir.datagraph_rewriting.Rule)[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]#
match(g: elasticai.creator.ir.datagraph_rewriting.DataGraph, registry: elasticai.creator.ir.datagraph_rewriting.Registry) list[dict[str, str]][source]#
create_replacement(g: elasticai.creator.ir.datagraph_rewriting.DataGraph, registry: elasticai.creator.ir.datagraph_rewriting.Registry) tuple[elasticai.creator.ir.datagraph_rewriting.DataGraph, elasticai.creator.ir.datagraph_rewriting.Registry][source]#
class elasticai.creator.ir.datagraph_rewriting.PatternRule(spec: elasticai.creator.ir.datagraph_rewriting.PatternRuleSpec)[source]#

Initialization

__call__(graph: elasticai.creator.ir.datagraph_rewriting.DataGraph, registry: elasticai.creator.ir.datagraph_rewriting.Registry) tuple[elasticai.creator.ir.datagraph_rewriting.DataGraph, elasticai.creator.ir.datagraph_rewriting.Registry][source]#