-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
improving quantum_causal_cone
method in python
#12668
Conversation
One or more of the following people are relevant to this code:
|
Pull Request Test Coverage Report for Build 9678104465Details
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This LGTM, thank you for improving this function!
upgrade_circuits: | ||
- | | ||
Improved the method :meth:`.DAGCircuit.quantum_causal_cone` to avoid examining the same | ||
non-directive node multiple times when reached from different paths. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't really an upgrade note, an upgrade note is reserved for something that we want to document might require user input when upgrading from the previous release to the new one. Examples would be a breaking api change, minimum dependency version bump, etc. I would expect this to be more of a feature note (to indicate improved performance) or a bug fix release note if we want to document this in the release.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this is not the first time I am making this mistake, but I will eventually remember what "upgrade" stands for.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done in 23877fe
Pull Request Test Coverage Report for Build 9692828532Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for fixing the release note, this should be good to merge.
* improving quantum_causal_cone * fixing release note
Summary
When trying to port the method
DAGCircuit.quantum_causal_cone
(introduced in #10325) to Rust, I have noticed that the existing algorithm examines each node multiple times (when reached from different paths), making the algorithm worst-case exponential.For a specific example, consider the circuit
In this PR we hash the set of processed non-directive nodes.
Let me also explain the point about not hashing "directive" nodes such as barriers (or measures). A barrier may involve all the qubits in the circuit, however not all of these should be considered to be a part of the causal cone. So when processing a barrier node the original algorithm only adds the quantum predecessors of that barrier node that intersect the current set of qubits in the quantum cone. However, this does potentially require to examine each barrier multiple times. (Aside: I am still not fully certain that this logic is 100% correct, however I was not able to find an example where this does not do what's intended). See also #10325.
This PR does not change this logic, however for clarity the two cases (directives and not-directives) are treated separately (and there are some other minor renaming and other minor code simplifications). It also adds more Python tests that explore the corner-cases.
It would be nice to have this PR merged before adding the Rust version of this to the new DAGCircuit, as it can serve as a reference for that implementation and also adds more python tests.