class chainer.computational_graph.ComputationalGraph(nodes, edges, variable_style='default', function_style='default', rankdir='TB', remove_variable=False, show_name=True)[source]

Class that represents computational graph.


We assume that the computational graph is directed and acyclic.

  • nodes (list) – List of nodes. Each node is either VariableNode object or FunctionNode object.

  • edges (list) – List of edges. Each edge consists of pair of nodes.

  • variable_style (dict or ‘default’) – Dot node style for variable. If the special value 'default' is specified, the default configuration will be used.

  • function_style (dict or default) – Dot node style for function. If the special value 'default' is specified, the default configuration will be used.

  • rankdir (str) – Direction of the graph that must be TB (top to bottom), BT (bottom to top), LR (left to right) or RL (right to left).

  • remove_variable (bool) – If True, VariableNodes are removed from the resulting computational graph. Only FunctionNodes are shown in the output.

  • show_name (bool) – If True, the name attribute of each node is added to the label of the node. Default is True.


The default configuration for variable_style is {'shape': 'octagon', 'fillcolor': '#E0E0E0', 'style': 'filled'} and the default configuration for function_style is {'shape': 'record', 'fillcolor': '#6495ED', 'style': 'filled'}.


The default behavior of ComputationalGraph has been changed from v1.23.0, so that it ouputs the richest representation of a graph as default, namely, styles are set and names of functions and variables are shown. To reproduce the same result as previous versions (<= v1.22.0), please specify variable_style=None, function_style=None, and show_name=False explicitly.



Dumps graph as a text.

  • format (str) – The graph language name of the output.

  • Currently

  • must be 'dot'. (it) –


The graph in specified format.

Return type


__eq__(value, /)

Return self==value.

__ne__(value, /)

Return self!=value.

__lt__(value, /)

Return self<value.

__le__(value, /)

Return self<=value.

__gt__(value, /)

Return self>value.

__ge__(value, /)

Return self>=value.