GraphvizCallGraph#
qualtran.drawing.GraphvizCallGraph
View source on GitHub
|
Draw a bloq call graph using Graphviz with additional data.
qualtran.drawing.GraphvizCallGraph(
g: nx.DiGraph, bloq_data: Optional[Dict['Bloq', Dict[Any, Any]]] = None
)
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.
Args
gThe call graph, from e.g.
Bloq.call_graph().bloq_dataA 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
@classmethodformat_qubit_count( val:qualtran.symbolics.SymbolicInt) -> Dict[str, str]
Format QubitCount cost values as a string.
Args
valThe qubit count value, which should be an integer
Returns
format_qec_gates_cost
@classmethodformat_qec_gates_cost( val: 'GateCounts', agg: Optional[str] = None ) -> Dict[str, str]
Format QECGatesCost cost values as a string.
Args
valThe qec gate costs value, which should be a
GateCountsdataclass.aggOne 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
GateCountsfor more information.
Returns
format_cost_data
@classmethodformat_cost_data( cost_data: Dict['Bloq', Dict['CostKey', 'CostValT']], agg_gate_counts: Optional[str] = None ) -> Dict['Bloq', Dict[str, str]]
Format cost_data as human-readable strings.
Args
cost_dataThe cost data, likely returned from a call to
query_costs(). This class method will delegate toformat_qubit_countandformat_qec_gates_costforQubitCountandQECGatesCostcost keys, respectively.agg_gate_countsOne 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
GateCountsfor more information.
Returns
from_bloq
@classmethodfrom_bloq( bloq:qualtran.Bloq, *, max_depth: Optional[int] = None, agg_gate_counts: Optional[str] = None ) -> 'GraphvizCallGraph'
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
bloqThe bloq from which we construct the call graph and query the costs.
max_depthThe 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_countsOne 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
GateCountsfor more information.
Returns
get_node_title
get_node_title(
b: qualtran.Bloq
)
Return text to use as a title of a node.
Override this method for complete control over the titles of nodes.
get_node_properties
get_node_properties(
b: 'Bloq'
)
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.
View source on GitHub