chainer.computational_graph.build_computational_graph

chainer.computational_graph.build_computational_graph(outputs, remove_split=True, variable_style='default', function_style='default', rankdir='TB', remove_variable=False, show_name=True)[source]

Builds a graph of functions and variables backward-reachable from outputs.

Parameters
  • outputs (Variable, VariableNode, FunctionNode, or list) – node(s) from which the graph is constructed. Each element of outputs must be either Variable object, VariableNode object, or FunctionNode object.

  • remove_split (bool) – It must be True. This argument is left for backward compatibility.

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

  • function_style (dict or 'default') – Dot node style for function. Possible keys are ‘shape’, ‘color’, ‘fillcolor’, ‘style’ etc. 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.

Returns

A graph consisting of nodes and edges that are backward-reachable from at least one of outputs.

If unchain_backward was called in some variable in the computational graph before this function, backward step is stopped at this variable.

For example, suppose that computational graph is as follows:

    |--> f ---> y
x --+
    |--> g ---> z

Let outputs = [y, z]. Then the full graph is emitted.

Next, let outputs = [y]. Note that z and g are not backward-reachable from y. The resulting graph would be following:

x ---> f ---> y

See TestGraphBuilder for details.

Return type

ComputationalGraph

Note

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'}.

Note

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.