graph.node

class dolfinx_graph_ad.graph.node.AbstractNode(object: Any, version=0, **kwargs)

Bases: object

The base class for nodes in the graph.

AbstractNodes provide the functionality to represent the object and operations in the graph.

To create a new node, the user can inherit from this class or use it directly.

The AbstractNode class is used to represent objects without any numerical value.

Variables:
  • id (int) – The python id of the object

  • version (int, optional) – The version of the object, indicates if an object is an updated version of an already existing object. Defaults to 0.

  • object (Any) – The object that the node represents

  • grad_fns (list) – A list of the edges into the node, whose adjoint values it receives

  • _name (str) – The name of the node

property name

Returns the name of the node.

Returns:

The name of the node

Return type:

str

release()

Releases the values saved in the node.

property snapshot: None

None, since a node without a numerical value saves nothing, see Node.

class dolfinx_graph_ad.graph.node.Node(object: Any, **kwargs)

Bases: AbstractNode

The Node class is used to represent objects with a numerical value.

The Node class inherits from the AbstractNode class and provides the functionality to represent the object and operations in the graph.

Variables:
  • grad (float or PETSc.Vec) – The gradient of the object

  • snapshot (Any or None) – The saved copy of this version’s value, or None when no copy is held. Subclasses implement save to create it.

accumulate_grad(value: float | Vec)

Accumulate a gradient contribution in the node.

Note

Contributions relying on shared data types (e.g. PETSc.Vec) should be accumulated without modifying the contribution. This is ensured for PETSc.Vec by using the copy method. Contributions relying on non-shared data types (e.g. float) can be accumulated directly.

Parameters:

value (float or PETSc.Vec) – The gradient contribution to accumulate

release()

Releases the object, the snapshot and the gradient of the node.

reset_grad()
property snapshot: Any | None

The snapshot owned by this version, or None; only the node replaces it.