Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix handling of conditions in SabreDAG creation (#8727)
* Fix handling of conditions in SabreDAG creation In #8388 we moved all of the SabreSwap pass's processing into rust. To facilitate that we had to create a rust DAG data structure to represent the data flow graph solely in Rust to enable analyzing the DAG structure in rust code without having to callback to python. To do this the DAGCircuit (which has a nearly identical representation in python) would export a list of nodes and the bits (both quantum and classical) that they operated on. This information is then used to create the SabreDAG used in the rust code. However, in this process an edge case was missed with classical condtions. If a condition was specified solely as a property of the operation and not in cargs list the SabreDAG would not know about the classical bit dependency between any subsequent operations involving that classical bit. This would cause incorrect output because the ndoes would not get processed as they were in the circuit. This commit fixes this issue by explicitly checking if there is a condition on the operation and there are no cargs and if so adding the carg bits to the SabreDAG directly. This fixes the incorrect representation in SabreDAG. Fixes #8675 * Fix handling of instructions with condition and cargs This commit fixes the logic for handling instructions that have both cargs and conditions set. The previous commit fixed the behavior only if cargs was mutually exclusive with having classical arguments. However, the same bug this PR is fixing would persist for instructions with clbit arguments and a condition. This fixes the behavior to correctly represent the data dependency in SabreDAG for these cases. * Improve efficiency of condition handling This commit improves the efficiency of the condition handling on SabreDAG creation that was added in the previous commit. Previously, it was potentially expensive to loop over the list of cargs and condition bits as for instructions with a large number of both the repeated duplicate searches would get quite expensive. This commit fixes that by converting the cargs data structure to be a set to prevent adding duplicates. Since the order isn't significant for the cargs in sabre as it's only used to represent data dependency between instructions we can convert it to internally use a set in python and a HashSet in rust. This also removes storing of cargs for each node in the SabreDAG as this was never used and just wasted memory by storing the list and never using it. Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
- Loading branch information