-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bloq.call_graph()
should preserve ordering of successors across calls / build_call_graph
should return a Dict instead of Set
#845
Comments
Are sets not ordered in Python? either a list of 2-tuples or a dict would be fine. I think the point of the "set" was to encode that order doesn't matter. Perhaps a more important property is that each bloq appears only once, which isn't captured by set. It's possible that networkx will shuffle things later anyways, so if you want determinism I suggest throwing in some |
Nope. Dicts are, but sets aren't. I vote for a dict instead of a list of 2-tuples.
That's true, and a dict would capture that as well.
I think it's less likely if we just traverse the graph and not modify it. But we can deal with any potential indeterminism due to networkx when we encounter it. AFAIK, this shouldn't be an issue. |
@mpharrigan should the bloq author ensure that each unique bloq in the counts = set()
if condition_1: counts.add((XGate(), 1))
if condition_2: counts.add((XGate(), 2))
return counts This luckily works as long as the frequencies are different, but fails if they are equal. |
^^^ I've been caught out by this before |
@anurudhp I think that's what this issue is about. If we change it to use dictionaries, you'd have to do something like counts = defaultdict(lambda: 0)
if condition_1: counts[XGate()] += 1
if condition_2: counts[XGate()] += 2
return counts |
My latest thoughts: I think this is still a good idea. IMO, the execution of this change should go through a mini deprecation cycle. Since |
- We changed build_call_graph to return a dictionary as a part quantumlib#845. - This now emits a deprecation warning now that all the built-in bloqs are converted.
* Add warning for build_call_graph returning a set - We changed build_call_graph to return a dictionary as a part #845. - This now emits a deprecation warning now that all the built-in bloqs are converted. * Add DeprecationWarning --------- Co-authored-by: Matthew Harrigan <[email protected]>
This is done thanks to @dstrain115 |
Every time you call
bloq.call_graph()
you can get a differentnx.DiGraph
where the ordering of successors of a node is different. This happens becausebuild_call_graph
returns aSet
instead of aDict
so iterating over a set to get the call graph destroys ordering.I encountered this when writing tests for #732 where the output of
get_flame_graph_data
is different across calls because the DFS ordering of nodes inbloq.call_graph
is different.@mpharrigan What's the reason to destroy ordering? Is this by design? Can we preserve ordering? I agree that most properties of the call graph analysis shouldn't depend upon the ordering but I think it's still nice to preserve the order across calls.
The text was updated successfully, but these errors were encountered: