get_bloq_call_graph#
View source on GitHub
|
Recursively build the bloq call graph and call totals.
qualtran.resource_counting.get_bloq_call_graph(
bloq: qualtran.Bloq,
generalizer: Optional[Union['GeneralizerT', Sequence['GeneralizerT']]] = None,
ssa: Optional[qualtran.resource_counting.SympySymbolAllocator] = None,
keep: Optional[Callable[[Bloq], bool]] = None,
max_depth: Optional[int] = None
) -> Tuple[nx.DiGraph, Dict[Bloq, Union[int, sympy.Expr]]]
See Bloq.call_graph() as a convenient way of calling this function.
Args
bloqThe bloq to count sub-bloqs.
generalizerIf provided, run this function on each (sub)bloq to replace attributes that do not affect resource estimates with generic sympy symbols. If the function returns
None, the bloq is omitted from the counts graph. If a sequence of generalizers is provided, each generalizer will be run in order.ssaa
SympySymbolAllocatorthat will be passed to theBloq.build_call_graphmethod. If yourgeneralizerfunction closes over aSympySymbolAllocator, provide it here as well. Otherwise, we will create a new allocator.keepIf this function evaluates to True for the current bloq, keep the bloq as a leaf node in the call graph instead of recursing into it.
max_depthIf provided, build a call graph with at most this many layers.
Returns
gA directed graph where nodes are (generalized) bloqs and edge attribute ‘n’ reports the number of times successor bloq is called via its predecessor.
sigmaCall totals for “leaf” bloqs. We keep a bloq as a leaf in the call graph according to
keepandmax_depth(if provided) or if a bloq cannot be decomposed.
View source on GitHub