dolfinx_adjoint.edge module
- class dolfinx_adjoint.edge.Edge(predecessor: Node, successor: Node, ctx=None, input_value=None)
Bases:
objectThe edge class provides the functionality to represent the edges in the graph.
Edges are used to keep track of the dependencies betweeen the nodes in the graph and are important for the backpropagation of the gradients. To this end, the edges store the adjoint equations to calculate the derivative of the successor node with respect to the predecessor node.
Calling an edge will perform the backpropagation of the graph, by calculating the adjoint value and passing it to the edges connected to the predecessor node.
- next_functions
The list of the gradient functions that are connected to the edge
- Type:
list
- ctx
The context variable of the edge
- Type:
Any
- input_value
The input value of the edge
- Type:
float or PETSc.Vec
- calculate_adjoint()
This method calculates the default adjoint equation for the edge, which corresponds to the derivative:
d(successor)/d(predecessor) = 1.0
This operator is stored in the edge and applied to the input. The adjoint value of the predeccessor node is generally calculated as follows:
adjoint(predecessor) += adjoint(successor) * d(successor)/d(predecessor)
- Returns:
The adjoint value of the predecessor node
- Return type:
float or PETSc.Vec
- set_next_functions(funcList: list)
This method sets the next functions in the path of the edge.
Typically the next functions are the edges that are connected to the predecessor node.
- Parameters:
funcList (list) – A list of the gradient functions that are connected to the edge