lineapy.visualizer package

Submodules

lineapy.visualizer.graphviz module

Functionality to display the tracer as a visual graph.

It first convert it to a graph, using visual_graph.py, and then renders that with graphviz.

lineapy.visualizer.graphviz.add_legend(dot: Digraph, options: VisualGraphOptions)[source]

Add a legend with nodes and edge styles.

Creates one node for each node style and one edge for each edge style.

It was difficult to get it to appear in a way that didn’t disrupt the main graph. It was easiest to get it to be a vertically aligned column of nodes, on the left of the graph. To do this, I link all the nodes with invisible edges so they stay vertically aligned.

https://stackoverflow.com/a/52300532/907060.

lineapy.visualizer.graphviz.edge_labels(options: VisualGraphOptions) Dict[VisualEdgeType, str][source]

Labels for the edge types to use in the legend,

lineapy.visualizer.graphviz.extra_label_labels(options: VisualGraphOptions) Dict[ExtraLabelType, str][source]

Labels for the extra label, to use in the legend,

lineapy.visualizer.graphviz.extra_labels_to_html(extra_labels: List[ExtraLabel], highlighted: bool) str[source]

Convert extra labels into an HTML table, where each label is a row. A single node could have multiple variables and artifacts pointing at it. So we make a table with a row for each artifact. Why a table? Well we are putting it in the xlabel and a table was an easy way to have multiple rows with different colors.

lineapy.visualizer.graphviz.get_color(tp: Union[NodeType, ExtraLabelType, VisualEdgeType], highlighted: bool) str[source]

Get the color for a type. Note that graphviz colorscheme indexing is 1 based

lineapy.visualizer.optimize_svg module

Optimizes an SVG file to reduce the size in the notebook.

lineapy.visualizer.visual_graph module

An abstract graph representation that is conducive to being visualized easily.

We include in this graph:

  • From the DB about this session: * Nodes * Artifacts * Source code

  • From the tracer: * Mutation and view edges * Variables

We currently don’t include, but could:

  • Node values

class lineapy.visualizer.visual_graph.ExtraLabel(label: 'str', type: 'ExtraLabelType')[source]
class lineapy.visualizer.visual_graph.ExtraLabelType(value)[source]

An enumeration.

class lineapy.visualizer.visual_graph.SourceLineType[source]

Type used to represent a source code line

class lineapy.visualizer.visual_graph.VisualEdge(source: 'VisualEdgeID', target: 'VisualEdgeID', type: 'VisualEdgeType', highlighted: 'bool' = True)[source]
class lineapy.visualizer.visual_graph.VisualEdgeID(node_id: 'str', port: 'Optional[str]' = None)[source]
class lineapy.visualizer.visual_graph.VisualEdgeType(value)[source]

A visual edges includes all the possible edges in our DB types, as well as the edges we store temporarily to assist in tracing

class lineapy.visualizer.visual_graph.VisualGraph(_nodes: ~typing.List[~lineapy.visualizer.visual_graph.VisualNode] = <factory>, _edges: ~typing.List[~lineapy.visualizer.visual_graph.VisualEdge] = <factory>, _node_id_to_parent_edges: ~typing.Dict[str, ~typing.List[~lineapy.visualizer.visual_graph.VisualEdge]] = <factory>, _node_id_to_node: ~typing.Dict[str, ~lineapy.visualizer.visual_graph.VisualNode] = <factory>)[source]

A visual graph contains a number of nodes and directed edges

highlight_ancestors(node_id: str) None[source]

Update a graph to only highlight the ancestors of a certain node.

We could instead do this graph traversal with the original nodes, as we do when computing the program slice. However we have some graph only nodes, like the source code, so for now we are re-walking the graph to determine the slice at the visual graph level.

class lineapy.visualizer.visual_graph.VisualGraphOptions(graph: Graph, tracer: Optional[Tracer], highlight_node: Optional[str], show_implied_mutations: bool, show_views: bool, show_artifacts: bool, show_variables: bool)[source]

Class to store options for the visualizer, so that we can properly type them as we pass this down the stack.

class lineapy.visualizer.visual_graph.VisualNode(id: 'str', type: 'VisualNodeType', contents: 'str', extra_labels: 'ExtraLabels', highlighted: 'bool' = True)[source]
lineapy.visualizer.visual_graph.process_node(vg: VisualGraph, node: Union[ImportNode, CallNode, LiteralNode, LookupNode, MutateNode, GlobalNode], options: VisualGraphOptions) str[source]

Returns the contents of a node and add its edges.

lineapy.visualizer.visual_graph.to_visual_graph(options: VisualGraphOptions) VisualGraph[source]

Returns a visual graph based on the options.

Module contents

class lineapy.visualizer.Visualizer(options: InitVar[VisualGraphOptions])[source]

Stores a rendered graphviz digraph. Has helper classmethods to use for construction, as well as methods for output as different useful formats.

classmethod for_public(tracer: Tracer) Visualizer[source]

Create a graph for our public API, when showing the whole graph.

classmethod for_public_node(graph: Graph, node_id: str) Visualizer[source]

Create a graph for our public API, when showing a single node.

Note: The tracer won’t be passed in this case, since it is happening inside the executor and we don’t have access to the tracer.

classmethod for_test_cli(tracer: Tracer) Visualizer[source]

Create a graph to use when visualizing after passing in –visualize during testing.

Show as much as we can for debugging.

classmethod for_test_snapshot(tracer: Tracer) Visualizer[source]

Create a graph for saving as a snapshot, to help with visual diffs in PRs.

render_pdf_file(filename: str = 'tracer') None[source]

Renders a PDF file for the graph and tries to open it.