Docs
Utility Functions

Utility Functions

Graph Visualization

visualize_graph

Visualizes the computation graph of the given arrays using Graphviz. In order to use this function, you need to have Graphviz installed on your system. If a computation does not track the dependencies via requires_grad=True, the graph will not be visualized.

def visualize_graph(arg: Array, filename: String = "computation_graph") -> None
Parameters
  • arg: The array of which to visualize the computation graph
  • filename: Output filename (without extension)

Generates a PNG image of the computation graph.

Example:
import endia as nd
 
x = nd.array('[1.0, 2.0, 3.0]', requires_grad=True)
y = nd.array('[4.0, 5.0, 6.0]', requires_grad=True)
z = nd.sum(nd.relu(x * y) * 2)
 
nd.utils.visualize_graph(z, "my_graph")
Hello

JSON Conversion

write_graph_to_json

Writes the computation graph of the given arrays to a JSON file.

def write_graph_to_json(arg: Array, filename: str = "computation_graph.json") -> None
Parameters
  • arg: The array of which to write the computation graph to JSON
  • filename: Output JSON filename
Example:
import endia as nd
 
x = nd.array('[1.0, 2.0, 3.0]', requires_grad=True)
y = nd.array('[4.0, 5.0, 6.0]', requires_grad=True)
z = nd.sum(nd.relu(x * y) * 2)
 
nd.write_graph_to_json(z, "my_graph.json")

Output:

{
   "nodes": [
       {
           "type": "arg",
           "id": 0,
           "is_view": 0,
           "shape": [3],
           "args": [],
           "grad": null
       },
       {
           "type": "arg",
           "id": 1,
           "is_view": 0,
           "shape": [3],
           "args": [],
           "grad": null
       },
        {
           "type": "mul",
           "id": 2,
           "is_view": 0,
           "shape": [3],
           "args": [0, 1],
           "grad": null
       },
       ...
   ]
}