Pattern
A graph of operator constraints that ModelGraph.find_pattern locates: add_node declares what a node must be (one OpCode, one of several, or a predicate over Node), add_edge declares which pattern node feeds which; the first node added is the root. Pattern([OpCode.MatMul, OpCode.Relu]) is the straight chain. Occurrences never overlap; a matched node may have inputs and consumers the pattern does not name; an optional node absent from an occurrence reads as None and its neighbors are read as connected (spell the edges of the full line only).
__init__
__init____init__(self, codes: object | None = None) -> None
init(self, codes: object | None = None) -> None
Pattern(codes=None)
An empty pattern to build with add_node / add_edge, or, given a sequence of OpCodes, the straight chain codes[0] -> codes[1] -> ... (each feeding the next on any port, none optional).
add_edge
add_edgeadd_edge(self, from_node: int, to_node: int, from_port: int | None = None, to_port: int | None = None) -> None
add_edge(self, from_node: int, to_node: int, from_port: int | None = None, to_port: int | None = None) -> None
add_edge(from_node, to_node, from_port=None, to_port=None) -> None
The output of pattern node from_node feeds an input of pattern node to_node: on exactly the ports given, on any port when they are None. Spell the edges of the full line only; an edge around an optional node is the search's own when that node is absent. An id that names no node is reported by find_pattern.
add_node
add_nodeadd_node(self, what: object, optional: bool = False) -> int
add_node(self, what: object, optional: bool = False) -> int
add_node(what, optional=False) -> int
A pattern node: what is one OpCode the graph node must run, a sequence of OpCodes it may run any of, or a callable taking a Node and returning True to accept it (the callable runs inside the search; an exception it raises ends the search and find_pattern raises with its message). The first node added is the root and is always required; optional on a later node lets an occurrence lack it (its Match entry is then None). Returns the node's id: its position in add_node order, the index of its Match entry.
chain
chain(*args, **kwargs)
chain(codes: object) -> clika_runtime._core.graph.Pattern
chain(codes) -> Pattern
The straight line codes[0] -> codes[1] -> ..., each node feeding the next on any port, none optional.
size
sizesize(self) -> int
size(self) -> int
size() -> int
How many pattern nodes were added.