mygrad.computational_graph.build_graph#

mygrad.computational_graph.build_graph(fin, names=None, *, render=True, save=False, dims=False, dtypes=False, sum_stats=False)[source]#

Builds and renders a computational graph.

Parameters:
finmygrad.Tensor

The tensor object that will be the final node in the computational graph.

namesOptional[Dict[str, Union[mygrad.Tensor, numpy.ndarray]]]

A dictionary that maps names of Tensors to Tensor objects. If an argument is passed to names, the key name that maps to a Tensor included in the computational graph will be used as a label for the Tensor’s node. If no argument is passed, the nodes on the computational graph will display the full Tensor.

To use the names assigned in the local environment, pass names=locals() to the build_graph function.

If different names are used from the local environment, the key must map to the exact Tensor object. A new Tensor or copy of the original Tensor should not be created as the value in the dictionary.

Only instances of mygrad.Tensor or numpy.ndarray can have labels assigned to Nodes. If a list or tuple is used in an operation with a Tensor, and names is not None, the Node label will be set to Constant. If a list or tuple is used in multiple operations, a unique Node will be created for each time it is used.

A scalar will always be used as the label for a 0-dimensional Tensor’s Node.

renderbool, optional (default=True)

If True, build_graph will return a graphviz Digraph object that, when called, will render the computational graph in a Jupyter notebook or the Jupyter Qt console. If False, nothing is returned.

savebool, optional (default=False)

If True, build_graph will save a rendered computational graph to the current working directory as computational_graph.pdf.

dimsbool, optional (default=False)

If True, Tensor dimensions are added to Node labels. Dimensions will not be displayed for scalar values.

dtypesbool, optional (default=False)

If True, Tensor data types are added to Node labels.

sum_statsbool, optional (default=False)

If True, Tensor minimums, maximums, medians, and means are added to Node labels. These will not be displayed for scalar values.

Returns:
Union[graphviz.Digraph, None]

Notes

build_graph requires that Graphviz is installed.