pf.compute_graph
Submodules
pf.compute_graph.compute_graph —
procfunc.compute_graph.compute_graphpf.compute_graph.node —
procfunc.compute_graph.nodepf.compute_graph.operators_info —
procfunc.compute_graph.operators_infopf.compute_graph.proxy —
procfunc.compute_graph.proxypf.compute_graph.util —
procfunc.compute_graph.util
Members
- class procfunc.compute_graph.ComputeGraph[source]
Bases:
objectComputeGraph(inputs: procfunc.util.pytree.PyTree[typing.Any, procfunc.compute_graph.node.Node], outputs: procfunc.util.pytree.PyTree[typing.Any, procfunc.compute_graph.node.Node], name: str, metadata: dict[str, typing.Any])
- __init__(inputs, outputs, name, metadata)
Supported special methods:
__call__
- class procfunc.compute_graph.GetAttributeNode[source]
Bases:
NodeGetAttributeNode(source: procfunc.compute_graph.node.Node, attribute_name: str, metadata: dict[str, typing.Any] = None)
- class procfunc.compute_graph.MethodCallNode[source]
Bases:
Noderepresents an {args[0]}.{method_name}(*args[1:], **kwargs) call
the node to be used as self is the first arg, since it is a dynamic value
the method name is assumed to be const
- class procfunc.compute_graph.MutatedArgumentNode[source]
Bases:
Node- __init__(original_node, mutator_call_node, metadata=None)[source]
- Parameters:
original_node (Node)
mutator_call_node (FunctionCallNode | MethodCallNode)
- class procfunc.compute_graph.Node[source]
Bases:
object
- class procfunc.compute_graph.ProceduralNode[source]
Bases:
NodeProceduralNode(node_type: str, attrs: dict[str, typing.Any], kwargs: dict, metadata: dict[str, typing.Any] = None)
- procfunc.compute_graph.normalize_args_to_kwargs(func, args, kwargs)[source]
Try to fully populate kwargs, by moving over positional args & filling in defaults
Some args may not be able to be converted to kwargs, e.g. *args have no names that work
- Parameters:
- Returns:
A tuple of (args, kwargs) where args is a tuple of positional arguments and kwargs is a dictionary of keyword arguments.
- Return type:
GUARANTEE: func(*returned_args, **returned_kwargs) == func(*args, **kwargs) and does not crash
- class procfunc.compute_graph.OperatorType[source]
Bases:
Enum- ADD = 'add'
- SUB = 'sub'
- MUL = 'mul'
- DIV = 'div'
- TRUEDIV = 'truediv'
- POW = 'pow'
- MOD = 'mod'
- LESS_THAN = 'lt'
- LESS_THAN_EQUAL = 'le'
- GREATER_THAN = 'gt'
- GREATER_THAN_EQUAL = 'ge'
- EQUAL = 'eq'
- NOT_EQUAL = 'ne'
- AND = 'and'
- OR = 'or'
- NOT = 'invert'
- LSHIFT = 'lshift'
- RSHIFT = 'rshift'
- BIT_AND = 'and'
- BIT_OR = 'or'
- BIT_XOR = 'xor'
- GETITEM = 'getitem'
- VECTOR_PACK = 'VECTOR_PACK'
- NOOP = 'NOOP'
Supported special methods:
__contains__,__getitem__,__iter__,__len__
- class procfunc.compute_graph.AttributeProxy[source]
Bases:
ProxySpecial proxy for attribute access that supports peekthrough optimization
Supported special methods:
__abs__,__add__,__and__,__bool__,__call__,__floordiv__,__getattr__,__getitem__,__invert__,__iter__,__len__,__lshift__,__mod__,__mul__,__neg__,__or__,__pos__,__pow__,__radd__,__rand___,__rfloordiv__,__rlshift__,__rmod__,__rmul__,__ror___,__rpow__,__rrshift__,__rshift__,__rsub__,__rtruediv__,__rxor__,__sub__,__truediv__,__xor__
- class procfunc.compute_graph.Proxy[source]
Bases:
Generic[T]General-purpose wrapper for Node that provides all dunder methods.
Supported special methods:
__abs__,__add__,__and__,__bool__,__call__,__floordiv__,__getattr__,__getitem__,__invert__,__iter__,__len__,__lshift__,__mod__,__mul__,__neg__,__or__,__pos__,__pow__,__radd__,__rand___,__rfloordiv__,__rlshift__,__rmod__,__rmul__,__ror___,__rpow__,__rrshift__,__rshift__,__rsub__,__rtruediv__,__rxor__,__sub__,__truediv__,__xor__
- procfunc.compute_graph.graph_nodes_equal(graph1, graph2)[source]
- Parameters:
graph1 (ComputeGraph)
graph2 (ComputeGraph)
- Return type:
- procfunc.compute_graph.transform_compute_graph(compute_graph, transform_fn, graph_name=None)[source]
- Parameters:
compute_graph (ComputeGraph)
graph_name (str | None)
- procfunc.compute_graph.traverse_breadth_first(graph, yield_parent=False, yield_name=False, yield_consts=False)[source]
Traverse all nodes in the compute graph.
- Parameters:
graph (ComputeGraph) – The compute graph to traverse
yield_parent (bool) – If True, yield (parent, child), with output nodes having parent=None
yield_name (bool) – If True, yield (name, child) or (name, parent, child) if yield_parent is also True
yield_consts (bool) – If True, yield child arguments of nodes even if they are not Nodes
- Return type:
- procfunc.compute_graph.traverse_depth_first(graph, yield_parent=False, yield_name=False, yield_consts=False, order='postorder')[source]
- procfunc.compute_graph.traverse_depth_first_node(node, yield_consts=False, order='postorder')[source]
- procfunc.compute_graph.traverse_nested_graphs(graph, yield_call_nodes=False)[source]
- Parameters:
graph (ComputeGraph)
yield_call_nodes (bool)
- Return type:
Generator[tuple[Node | None, ComputeGraph], None, None]
pf.compute_graph.compute_graph
- class procfunc.compute_graph.compute_graph.ComputeGraph[source]
Bases:
objectComputeGraph(inputs: procfunc.util.pytree.PyTree[typing.Any, procfunc.compute_graph.node.Node], outputs: procfunc.util.pytree.PyTree[typing.Any, procfunc.compute_graph.node.Node], name: str, metadata: dict[str, typing.Any])
- __init__(inputs, outputs, name, metadata)
Supported special methods:
__call__
pf.compute_graph.node
- class procfunc.compute_graph.node.Node[source]
Bases:
object
- class procfunc.compute_graph.node.MethodCallNode[source]
Bases:
Noderepresents an {args[0]}.{method_name}(*args[1:], **kwargs) call
the node to be used as self is the first arg, since it is a dynamic value
the method name is assumed to be const
- class procfunc.compute_graph.node.GetAttributeNode[source]
Bases:
NodeGetAttributeNode(source: procfunc.compute_graph.node.Node, attribute_name: str, metadata: dict[str, typing.Any] = None)
- class procfunc.compute_graph.node.ProceduralNode[source]
Bases:
NodeProceduralNode(node_type: str, attrs: dict[str, typing.Any], kwargs: dict, metadata: dict[str, typing.Any] = None)
- class procfunc.compute_graph.node.MutatedArgumentNode[source]
Bases:
Node- __init__(original_node, mutator_call_node, metadata=None)[source]
- Parameters:
original_node (Node)
mutator_call_node (FunctionCallNode | MethodCallNode)
- procfunc.compute_graph.node.normalize_args_to_kwargs(func, args, kwargs)[source]
Try to fully populate kwargs, by moving over positional args & filling in defaults
Some args may not be able to be converted to kwargs, e.g. *args have no names that work
- Parameters:
- Returns:
A tuple of (args, kwargs) where args is a tuple of positional arguments and kwargs is a dictionary of keyword arguments.
- Return type:
GUARANTEE: func(*returned_args, **returned_kwargs) == func(*args, **kwargs) and does not crash
pf.compute_graph.operators_info
- class procfunc.compute_graph.operators_info.OperatorType[source]
Bases:
Enum- ADD = 'add'
- SUB = 'sub'
- MUL = 'mul'
- DIV = 'div'
- TRUEDIV = 'truediv'
- POW = 'pow'
- MOD = 'mod'
- LESS_THAN = 'lt'
- LESS_THAN_EQUAL = 'le'
- GREATER_THAN = 'gt'
- GREATER_THAN_EQUAL = 'ge'
- EQUAL = 'eq'
- NOT_EQUAL = 'ne'
- AND = 'and'
- OR = 'or'
- NOT = 'invert'
- LSHIFT = 'lshift'
- RSHIFT = 'rshift'
- BIT_AND = 'and'
- BIT_OR = 'or'
- BIT_XOR = 'xor'
- GETITEM = 'getitem'
- VECTOR_PACK = 'VECTOR_PACK'
- NOOP = 'NOOP'
Supported special methods:
__contains__,__getitem__,__iter__,__len__
pf.compute_graph.proxy
General-purpose Proxy wrapper for Node with all dunders.
- class procfunc.compute_graph.proxy.Proxy[source]
Bases:
Generic[T]General-purpose wrapper for Node that provides all dunder methods.
Supported special methods:
__abs__,__add__,__and__,__bool__,__call__,__floordiv__,__getattr__,__getitem__,__invert__,__iter__,__len__,__lshift__,__mod__,__mul__,__neg__,__or__,__pos__,__pow__,__radd__,__rand___,__rfloordiv__,__rlshift__,__rmod__,__rmul__,__ror___,__rpow__,__rrshift__,__rshift__,__rsub__,__rtruediv__,__rxor__,__sub__,__truediv__,__xor__
- class procfunc.compute_graph.proxy.AttributeProxy[source]
Bases:
ProxySpecial proxy for attribute access that supports peekthrough optimization
Supported special methods:
__abs__,__add__,__and__,__bool__,__call__,__floordiv__,__getattr__,__getitem__,__invert__,__iter__,__len__,__lshift__,__mod__,__mul__,__neg__,__or__,__pos__,__pow__,__radd__,__rand___,__rfloordiv__,__rlshift__,__rmod__,__rmul__,__ror___,__rpow__,__rrshift__,__rshift__,__rsub__,__rtruediv__,__rxor__,__sub__,__truediv__,__xor__
pf.compute_graph.util
- procfunc.compute_graph.util.traverse_breadth_first(graph, yield_parent=False, yield_name=False, yield_consts=False)[source]
Traverse all nodes in the compute graph.
- Parameters:
graph (ComputeGraph) – The compute graph to traverse
yield_parent (bool) – If True, yield (parent, child), with output nodes having parent=None
yield_name (bool) – If True, yield (name, child) or (name, parent, child) if yield_parent is also True
yield_consts (bool) – If True, yield child arguments of nodes even if they are not Nodes
- Return type:
- procfunc.compute_graph.util.traverse_depth_first_node(node, yield_consts=False, order='postorder')[source]
- procfunc.compute_graph.util.traverse_depth_first(graph, yield_parent=False, yield_name=False, yield_consts=False, order='postorder')[source]
- procfunc.compute_graph.util.traverse_nested_graphs(graph, yield_call_nodes=False)[source]
- Parameters:
graph (ComputeGraph)
yield_call_nodes (bool)
- Return type:
Generator[tuple[Node | None, ComputeGraph], None, None]
- procfunc.compute_graph.util.usages_per_node(graph)[source]
- Parameters:
graph (ComputeGraph)
- Return type:
- procfunc.compute_graph.util.graph_nodes_equal(graph1, graph2)[source]
- Parameters:
graph1 (ComputeGraph)
graph2 (ComputeGraph)
- Return type: