quantumlib / Qualtran

Qᴜᴀʟᴛʀᴀɴ is a Python library for expressing and analyzing Fault Tolerant Quantum algorithms.
https://qualtran.readthedocs.io/en/latest/
Apache License 2.0
166 stars 40 forks source link

Qubit costs not getting displayed for intermedediate bloqs in `show_call_graph(_modexp_small.make())` #1401

Open tanujkhattar opened 1 week ago

tanujkhattar commented 1 week ago

Running show_call_graph(_modexp_small.make()) gives the following diagram:

image

For some reason, Qubits property is not displayed for a bunch of bloqs like CModMulK, CtrlScaleModAdd etc. I'm not sure what's going on here.

mpharrigan commented 1 week ago

This is a related issue to #1397

The helper function for drawing does two things: it makes a call graph and it computes the cost of the root bloq. There's no guarantee that each node in the call graph will have its costs cached during the computation of costs on the root bloq. This can be because of

I sortof figured it could be better to only show the costs that actually fed into the cost of the root bloq; and avoid any potential discrepancies where the cost of the callee doesn't "add up" when looking at the caller costs. This can be changed by explicitly computing the costs of all nodes in the call graph; e.g. modify GraphvizCallGraph.from_bloq to call get_cost_cache for each bloq in g.nodes. You can keep feeding the overall cost cache back in, so this should be efficient. Or modify query_costs to take a sequence of bloqs (and then do that same thing)