GraphvizCallGraph#

qualtran.drawing.GraphvizCallGraph

Draw a bloq call graph using Graphviz with additional data.

Each edge is labeled with the number of times the “caller” (predecessor) bloq calls the “callee” (successor) bloq.

The constructor of this class assumes you have already generated the call graph as a networkx graph and constructed any associated data. See the factory method GraphvizCallGraph.from_bloq() to set up a call graph diagram from a bloq with sensible defaults.

This class uses a bloq’s __str__ string to title the bloq. Arbitrary additional tabular data can be provided with bloq_data.

g

The call graph, from e.g. Bloq.call_graph().

bloq_data

A mapping from a bloq to a set of key, value pairs to include in a table in each node. The keys and values must support str().

Methods#

format_qubit_count

View source

Format QubitCount cost values as a string.

Args

val

The qubit count value, which should be an integer

Returns

format_qec_gates_cost

View source

Format QECGatesCost cost values as a string.

Args

val

The qec gate costs value, which should be a GateCounts dataclass.

agg

One of ‘factored’, ‘total_t’, ‘t_and_ccz’, or ‘beverland’ to (optionally) aggregate the gate counts. If not specified, the ‘factored’ approach is used where each type of gate is counted individually. See the methods on GateCounts for more information.

Returns

format_cost_data

View source

Format cost_data as human-readable strings.

Args

cost_data

The cost data, likely returned from a call to query_costs(). This class method will delegate to format_qubit_count and format_qec_gates_cost for QubitCount and QECGatesCost cost keys, respectively.

agg_gate_counts

One of ‘factored’, ‘total_t’, ‘t_and_ccz’, or ‘beverland’ to (optionally) aggregate the gate counts. If not specified, the ‘factored’ approach is used where each type of gate is counted individually. See the methods on GateCounts for more information.

Returns

from_bloq

View source

Draw a bloq call graph.

This factory method will generate a call graph from the bloq, query the QECGatesCost and QubitCount costs, format the cost data, and merge it with the call graph to create a call graph diagram with annotated costs.

For additional customization, users can construct the call graph and bloq data themselves and use the normal constructor, or provide minor display customizations by overriding the format_xxx class methods.

Args

bloq

The bloq from which we construct the call graph and query the costs.

max_depth

The maximum depth (from the root bloq) of the call graph to draw. Note that the cost computations will walk the whole call graph, but only the nodes within this depth will be drawn.

agg_gate_counts

One of ‘factored’, ‘total_t’, ‘t_and_ccz’, or ‘beverland’ to (optionally) aggregate the gate counts. If not specified, the ‘factored’ approach is used where each type of gate is counted individually. See the methods on GateCounts for more information.

Returns

get_node_title

View source

Return text to use as a title of a node.

Override this method for complete control over the titles of nodes.

get_node_properties

View source

Get graphviz properties for a bloq node representing b.

By default, this will craft a label from get_node_title and get_node_details, and a rectangular node shape. Override this method to provide further customization.