graph.edge

class dolfinx_graph_ad.graph.edge.Edge(predecessor: Node, successor: Node, ctx=None)

Bases: object

The 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.

Variables:
  • predecessor (Node) – The predecessor node of the edge

  • ctx (Any) – The context variable of the edge

calculate_adjoint(value: Any) → Any

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 predecessor node is generally calculated as follows:

adjoint(predecessor) = adjoint(successor) * d(successor)/d(predecessor)

The computed value only corresponds to the contribution of the current edge to the predecessor node. The total adjoint value of the predecessor node is the sum of all contributions from all edges into it.

Parameters:

value (Any) – The adjoint value of the successor node, or shared operation data prepared by a downstream edge.

Returns:

The adjoint contribution to the predecessor node. Edges between operations may return shared adjoint data; edges into numerical nodes return a scalar or PETSc.Vec gradient, of which only the entries owned by the calling rank have to be valid. None if it vanishes.

Return type:

Any

property next_functions: list

The edges into the predecessor node, which the propagation continues with.

release()

Releases the values saved in the edge.

property successor

The successor node of the edge, referenced weakly, or None for an edge that ends nowhere.