opto.trace.bundle
#
Module Contents#
Classes#
This is a context manager for keeping track which nodes are read/used in an operator. |
|
This is a decorator to trace a function. The wrapped function returns a MessageNode. |
Functions#
Wrap a function as a FunModule, which returns node objects. The input signature to the wrapped function stays the same. bundle can be used with other decorators so long as they are not named ‘bundle’. |
|
Extract the data from a node or a container of nodes. |
|
Wrap a node on top of the original object |
|
Detach a node or a container of nodes. |
|
Update the value of a local variable in a frame. |
API#
- bundle(description=None, traceable_code=False, _process_inputs=True, trainable=False, catch_execution_error=True, allow_external_dependencies=False, overwrite_python_recursion=False)[source]#
Wrap a function as a FunModule, which returns node objects. The input signature to the wrapped function stays the same. bundle can be used with other decorators so long as they are not named ‘bundle’.
- class trace_nodes[source]#
This is a context manager for keeping track which nodes are read/used in an operator.
- class FunModule(fun: Callable, description: str = None, traceable_code: bool = False, _process_inputs: bool = True, trainable=False, catch_execution_error=True, allow_external_dependencies=False, overwrite_python_recursion=False, _ldict=None)[source]#
Bases:
opto.trace.modules.Module
This is a decorator to trace a function. The wrapped function returns a MessageNode.
- Args:
fun (callable): the operator to be traced. description (str): a description of the operator; see the MessageNode for syntax. _process_inputs (bool): if True, the input is extracted from the container of nodes; if False, the inputs are passed directly to the underlying function. trainable (bool): if True, the block of code is treated as a variable in the optimization catch_execution_error (bool): if True, the operator catches the exception raised during the execution of the operator and return ExecutionError. allow_external_dependencies (bool): if True, the operator allows external dependencies to be used in the operator. Namely, not all nodes used to create the output are in the inputs. In this case, the extra dependencies are stored in the info dictionary with key ‘extra_dependencies’. overwrite_python_recursion (bool): if True, the operator allows the python recursion behavior of calling the decorated function to be overwritten. When true, applying bundle on a recursive function, would be the same as calling the function directly. When False, the Python’s oriignal recursion behavior of decorated functions is preserved. _ldict (dict): the local dictionary to execute the code block.
Initialization
- property trainable#
- property fun#
- property name#
- forward(*args, **kwargs)[source]#
All nodes used in the operator fun are added to used_nodes during the execution. If the output is not a Node, we wrap it as a MessageNode, whose inputs are nodes in used_nodes.
- wrap(output: Any, inputs: Union[List[opto.trace.nodes.Node], Dict[str, opto.trace.nodes.Node]], external_dependencies: List[opto.trace.nodes.Node])[source]#
Wrap the output as a MessageNode of inputs as the parents.