GraphDrawer#
qualtran.drawing.GraphDrawer
View source on GitHub
|
A class to encapsulate methods for displaying a CompositeBloq as a graph using graphviz.
qualtran.drawing.GraphDrawer(
bloq: qualtran.Bloq
)
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()
Args
Methods#
get_dangle_node
get_dangle_node(
soq: qualtran.Soquet
) -> pydot.Node
Overridable method to create a Node representing dangling Soquets.
add_dangles
add_dangles(
graph: pydot.Graph,
signature: qualtran.Signature,
dangle: qualtran.DanglingT
) -> pydot.Graph
Add nodes representing dangling indices to the graph.
We wrap this in a subgraph to align (rank=same) the ‘nodes’
soq_label
soq_label(
soq: qualtran.Soquet
) -> str
Overridable method for getting label text for a Soquet.
get_thru_register
get_thru_register(
thru: qualtran.Soquet
) -> str
Overridable method for generating a
This should have a colspan="2" to make sure there aren’t separate left and right
cells / soquets.
get_binst_table_attributes
get_binst_table_attributes() -> str
Overridable method to configure the desired table attributes for the bloq.
get_binst_header_text
get_binst_header_text(
binst: qualtran.BloqInstance
) -> str
Overridable method returning the text used for the header cell of a bloq.
add_binst
add_binst(
graph: pydot.Graph,
binst: qualtran.BloqInstance
) -> pydot.Graph
Process and add a bloq instance to the Graph.
cxn_label
cxn_label(
cxn: qualtran.Connection
) -> str
Overridable method to return labels for connections.
cxn_edge
cxn_edge(
left_id: str,
right_id: str,
cxn: qualtran.Connection
) -> pydot.Edge
Overridable method to style a pydot.Edge for connecionts.
add_cxn
add_cxn(
graph: pydot.Graph,
cxn: qualtran.Connection
) -> pydot.Graph
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
get_graph() -> pydot.Graph
Get the graphviz graph representing the Bloq.
This is the main entry-point to this class.
get_svg_bytes
get_svg_bytes() -> bytes
Get the SVG code (as bytes) for drawing the graph.
get_svg
get_svg() -> IPython.display.SVG
Get an IPython SVG object displaying the graph.
View source on GitHub