GraphDrawer#

qualtran.drawing.GraphDrawer

A class to encapsulate methods for displaying a CompositeBloq as a graph using graphviz.

Graphviz has nodes, edges, and ports. Nodes are HTML tables representing bloq instances. Each cell in the table has a graphviz port and represents a soquet. Edges connect node:port tuples representing connections between soquets.

Each node and port has a string identifier. We use the _IDBuilder helper class to assign unique, readable IDs to each object.

Users should call GraphDrawer.get_graph() as the primary entry point. Other methods can be overridden to customize the look of the resulting graph.

To display a graph in a jupyter notebook consider using the SVG utilities:

>>> dr = GraphDrawer(cbloq)
>>> dr.get_svg()
bloq

The bloq or composite bloq to draw.

Methods#

get_dangle_node

View source

Overridable method to create a Node representing dangling Soquets.

add_dangles

View source

Add nodes representing dangling indices to the graph.

We wrap this in a subgraph to align (rank=same) the ‘nodes’

soq_label

View source

Overridable method for getting label text for a Soquet.

get_thru_register

View source

Overridable method for generating a representing a THRU soquet.

This should have a colspan="2" to make sure there aren’t separate left and right cells / soquets.

get_binst_table_attributes

View source

Overridable method to configure the desired table attributes for the bloq.

get_binst_header_text

View source

Overridable method returning the text used for the header cell of a bloq.

add_binst

View source

Process and add a bloq instance to the Graph.

cxn_label

View source

Overridable method to return labels for connections.

cxn_edge

View source

Overridable method to style a pydot.Edge for connecionts.

add_cxn

View source

Process and add a connection to the Graph.

Connections are specified using a : delimited set of ids. The first element is the node (bloq instance). For most bloq instances, the second element is the port (soquet). The final element is the compass direction of where exactly the connecting line should be anchored.

For DangleT nodes, there aren’t any Soquets so the second element is omitted.

get_graph

View source

Get the graphviz graph representing the Bloq.

This is the main entry-point to this class.

get_svg_bytes

View source

Get the SVG code (as bytes) for drawing the graph.

get_svg

View source

Get an IPython SVG object displaying the graph.