Skip to content

visualizer

visualizer #

A procedure DAG as a Graphviz flowchart.

One box per node (its label, kind and settings), one edge per data-flow input (labeled with the input name) and per substep (labeled with its step number), so the picture shows the same structure the wire form carries.

procedure_to_graphviz(procedure, group_by_depth=False) #

Render a Procedure DAG as a Graphviz diagram.

Parameters:

Name Type Description Default
procedure Procedure

The root procedure to visualize (any procedure in the DAG).

required
group_by_depth bool

Rank nodes by their depth in the hierarchy, so each level lays out on one row.

False

Returns:

Type Description
Digraph

A Graphviz Digraph, renderable to PNG / SVG / PDF.

Example
graph = cg.procedure_to_graphviz(my_procedure, group_by_depth=True)
graph.render("my_procedure", format="png", cleanup=True)
Source code in capturegraph-lib/capturegraph/procedures/procedure/exporting/visualizer.py
def procedure_to_graphviz(
    procedure: Procedure,
    group_by_depth: bool = False,
) -> Digraph:
    """Render a Procedure DAG as a Graphviz diagram.

    Args:
        procedure: The root procedure to visualize (any procedure in the DAG).
        group_by_depth: Rank nodes by their depth in the hierarchy, so each level
            lays out on one row.

    Returns:
        A Graphviz ``Digraph``, renderable to PNG / SVG / PDF.

    Example:
        ```python
        graph = cg.procedure_to_graphviz(my_procedure, group_by_depth=True)
        graph.render("my_procedure", format="png", cleanup=True)
        ```
    """
    dot = Digraph(node_attr=_NODE_STYLE, graph_attr=_GRAPH_STYLE)
    depths: dict[str, int] = {}
    _add_procedure(dot, procedure, 0, depths)
    if group_by_depth:
        _rank_by_depth(dot, depths)
    return dot