opto.trace.nodes.Node.backward#
- Node.backward(feedback: Any = '', propagator=None, retain_graph=False, visualize=False, simple_visualization=True, reverse_plot=False, print_limit=100)[source]#
Performs a backward pass in a computational graph.
This function propagates feedback from the current node to its parents, updates the graph visualization if required, and returns the resulting graph.
- Parameters:
feedback – The feedback given to the current node.
propagator – A function that takes in a node and a feedback, and returns a dict of {parent: parent_feedback}. If not provided, a default GraphPropagator object is used.
retain_graph – If True, the graph will be retained after backward pass.
visualize – If True, the graph will be visualized using graphviz.
simple_visualization – If True, identity operators will be skipped in the visualization.
reverse_plot – If True, plot the graph in reverse order (from child to parent).
print_limit – The maximum number of characters to print for node descriptions and content.
- Returns:
The visualization graph object if visualize=True, None otherwise.
- Return type:
digraph
- Raises:
AttributeError – If the node has already been backwarded.
Notes
The function checks if the current node has already been backwarded. If it has, an AttributeError is raised. For root nodes (no parents), only visualization is performed if enabled. For non-root nodes, feedback is propagated through the graph using a priority queue to ensure correct ordering. The propagator computes feedback for parent nodes based on the current node’s description, data and feedback. Visualization is handled using graphviz if enabled, with options to simplify the graph by skipping identity operators.