pf.compute_graph

Submodules

Members

class procfunc.compute_graph.ComputeGraph[source]

Bases: object

ComputeGraph(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])

inputs: PyTree[Any, Node]
outputs: PyTree[Any, Node]
name: str
metadata: dict[str, Any]
clear_values()[source]
__init__(inputs, outputs, name, metadata)
Parameters:
Return type:

None

Supported special methods: __call__

class procfunc.compute_graph.ConstantNode[source]

Bases: Node

__init__(value, metadata=None)[source]
Parameters:
class procfunc.compute_graph.FunctionCallNode[source]

Bases: Node

__init__(func, args, kwargs, metadata=None)[source]
Parameters:
class procfunc.compute_graph.GetAttributeNode[source]

Bases: Node

GetAttributeNode(source: procfunc.compute_graph.node.Node, attribute_name: str, metadata: dict[str, typing.Any] = None)

__init__(source, attribute_name, metadata=None)[source]
Parameters:
class procfunc.compute_graph.InputPlaceholderNode[source]

Bases: Node

__init__(name, default_value, metadata=None)[source]
Parameters:
class procfunc.compute_graph.MethodCallNode[source]

Bases: Node

represents 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

__init__(callee, method_name, args, kwargs, metadata=None)[source]
Parameters:
class procfunc.compute_graph.MutatedArgumentNode[source]

Bases: Node

__init__(original_node, mutator_call_node, metadata=None)[source]
Parameters:
class procfunc.compute_graph.Node[source]

Bases: object

__init__(args, kwargs, metadata=None)[source]
Parameters:
inputs_pytree()[source]
Return type:

PyTree

class procfunc.compute_graph.ProceduralNode[source]

Bases: Node

ProceduralNode(node_type: str, attrs: dict[str, typing.Any], kwargs: dict, metadata: dict[str, typing.Any] = None)

__init__(node_type, attrs, kwargs, metadata=None)[source]
Parameters:
class procfunc.compute_graph.SubgraphCallNode[source]

Bases: Node

__init__(subgraph, args, kwargs, metadata=None)[source]
Parameters:
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:
  • func (Callable) – The function whose signature we should respect

  • args (tuple) – The original positional arguments to the function

  • kwargs (dict) – The keyword arguments to the function

Returns:

A tuple of (args, kwargs) where args is a tuple of positional arguments and kwargs is a dictionary of keyword arguments.

Return type:

tuple[tuple, dict]

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: Proxy

Special proxy for attribute access that supports peekthrough optimization

__init__(node)[source]
Parameters:

node (Node)

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.

node: Node
__init__(node)
Parameters:

node (Node)

Return type:

None

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.LiteralConstant[source]

Bases: object

__init__(value)[source]
Parameters:

value (Any)

procfunc.compute_graph.graph_nodes_equal(graph1, graph2)[source]
Parameters:
Return type:

bool

procfunc.compute_graph.transform_compute_graph(compute_graph, transform_fn, graph_name=None)[source]
Parameters:
procfunc.compute_graph.transform_nodetree(root, transform_fn, memo={})[source]
Parameters:
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:

Generator[Any, None, None]

procfunc.compute_graph.traverse_depth_first(graph, yield_parent=False, yield_name=False, yield_consts=False, order='postorder')[source]
Parameters:
Return type:

Generator[Any, None, None]

procfunc.compute_graph.traverse_depth_first_node(node, yield_consts=False, order='postorder')[source]
Parameters:
Return type:

Generator[Any, None, None]

procfunc.compute_graph.traverse_nested_graphs(graph, yield_call_nodes=False)[source]
Parameters:
Return type:

Generator[tuple[Node | None, ComputeGraph], None, None]

procfunc.compute_graph.usages_per_node(graph)[source]
Parameters:

graph (ComputeGraph)

Return type:

dict[int, list[Node]]

pf.compute_graph.compute_graph

class procfunc.compute_graph.compute_graph.ComputeGraph[source]

Bases: object

ComputeGraph(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])

inputs: PyTree[Any, Node]
outputs: PyTree[Any, Node]
name: str
metadata: dict[str, Any]
clear_values()[source]
__init__(inputs, outputs, name, metadata)
Parameters:
Return type:

None

Supported special methods: __call__

pf.compute_graph.node

class procfunc.compute_graph.node.Node[source]

Bases: object

__init__(args, kwargs, metadata=None)[source]
Parameters:
inputs_pytree()[source]
Return type:

PyTree

class procfunc.compute_graph.node.SubgraphCallNode[source]

Bases: Node

__init__(subgraph, args, kwargs, metadata=None)[source]
Parameters:
class procfunc.compute_graph.node.FunctionCallNode[source]

Bases: Node

__init__(func, args, kwargs, metadata=None)[source]
Parameters:
class procfunc.compute_graph.node.MethodCallNode[source]

Bases: Node

represents 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

__init__(callee, method_name, args, kwargs, metadata=None)[source]
Parameters:
class procfunc.compute_graph.node.GetAttributeNode[source]

Bases: Node

GetAttributeNode(source: procfunc.compute_graph.node.Node, attribute_name: str, metadata: dict[str, typing.Any] = None)

__init__(source, attribute_name, metadata=None)[source]
Parameters:
class procfunc.compute_graph.node.ProceduralNode[source]

Bases: Node

ProceduralNode(node_type: str, attrs: dict[str, typing.Any], kwargs: dict, metadata: dict[str, typing.Any] = None)

__init__(node_type, attrs, kwargs, metadata=None)[source]
Parameters:
class procfunc.compute_graph.node.MutatedArgumentNode[source]

Bases: Node

__init__(original_node, mutator_call_node, metadata=None)[source]
Parameters:
class procfunc.compute_graph.node.ConstantNode[source]

Bases: Node

__init__(value, metadata=None)[source]
Parameters:
class procfunc.compute_graph.node.InputPlaceholderNode[source]

Bases: Node

__init__(name, default_value, metadata=None)[source]
Parameters:
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:
  • func (Callable) – The function whose signature we should respect

  • args (tuple) – The original positional arguments to the function

  • kwargs (dict) – The keyword arguments to the function

Returns:

A tuple of (args, kwargs) where args is a tuple of positional arguments and kwargs is a dictionary of keyword arguments.

Return type:

tuple[tuple, dict]

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.

node: Node
__init__(node)
Parameters:

node (Node)

Return type:

None

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: Proxy

Special proxy for attribute access that supports peekthrough optimization

__init__(node)[source]
Parameters:

node (Node)

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

class procfunc.compute_graph.util.LiteralConstant[source]

Bases: object

__init__(value)[source]
Parameters:

value (Any)

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:

Generator[Any, None, None]

procfunc.compute_graph.util.traverse_depth_first_node(node, yield_consts=False, order='postorder')[source]
Parameters:
Return type:

Generator[Any, None, None]

procfunc.compute_graph.util.traverse_depth_first(graph, yield_parent=False, yield_name=False, yield_consts=False, order='postorder')[source]
Parameters:
Return type:

Generator[Any, None, None]

procfunc.compute_graph.util.traverse_nested_graphs(graph, yield_call_nodes=False)[source]
Parameters:
Return type:

Generator[tuple[Node | None, ComputeGraph], None, None]

procfunc.compute_graph.util.usages_per_node(graph)[source]
Parameters:

graph (ComputeGraph)

Return type:

dict[int, list[Node]]

procfunc.compute_graph.util.graph_nodes_equal(graph1, graph2)[source]
Parameters:
Return type:

bool

procfunc.compute_graph.util.transform_nodetree(root, transform_fn, memo={})[source]
Parameters:
procfunc.compute_graph.util.transform_compute_graph(compute_graph, transform_fn, graph_name=None)[source]
Parameters: