Skip to content
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

Avoid routing 2q barriers in SabreSwap #11295

Merged
merged 6 commits into from
Nov 23, 2023

Conversation

mtreinish
Copy link
Member

Summary

This commit fixes an oversight in the sabre swap pass where a 2 qubit barrier would have been treated like a 2 qubit gate and swaps could potentially be inserted if the sabre algorithm thought it didn't have connectivity for the qargs to the barrier. However as barrier is just a compiler directive it is valid on all qubit pairs so this swap insertion was unnecessary, it was still valid but just not an optimal output. This commit fixes it by adding context to the sabre dag around whether a given node is a directive (and valid on all qubits) or not.

Details and comments

This commit fixes an oversight in the sabre swap pass where a 2 qubit
barrier would have been treated like a 2 qubit gate and swaps could
potentially be inserted if the sabre algorithm thought it didn't have
connectivity for the qargs to the barrier. However as barrier is just
a compiler directive it is valid on all qubit pairs so this swap
insertion was unnecessary, it was still valid but just not an optimal
output. This commit fixes it by adding context to the sabre dag around
whether a given node is a directive (and valid on all qubits) or not.
@mtreinish mtreinish added the Changelog: None Do not include in changelog label Nov 22, 2023
@mtreinish mtreinish requested a review from a team as a code owner November 22, 2023 15:10
@qiskit-bot
Copy link
Collaborator

One or more of the the following people are requested to review this:

@mtreinish mtreinish added the Rust This PR or issue is related to Rust code in the repository label Nov 22, 2023
@coveralls
Copy link

coveralls commented Nov 22, 2023

Pull Request Test Coverage Report for Build 6962479250

  • 36 of 36 (100.0%) changed or added relevant lines in 2 files are covered.
  • 11 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.01%) to 86.425%

Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/lex.rs 5 90.91%
crates/qasm2/src/parse.rs 6 96.2%
Totals Coverage Status
Change from base Build 6961554254: -0.01%
Covered Lines: 66273
Relevant Lines: 76683

💛 - Coveralls

Copy link
Contributor

@kevinhartman kevinhartman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you also need to update extended set population to ignore directives:

if required_predecessors[successor_index] == 0 {
    if !dag.dag[node].directive && !dag.node_blocks.contains_key(&successor_index) {
        if let [a, b] = dag.dag[successor_node].qubits[..] {
            extended_set.push([a.to_phys(layout), b.to_phys(layout)]);
        }
    }
    to_visit.push(successor_node);
}

Otherwise, this looks good!

@mtreinish
Copy link
Member Author

I believe you also need to update extended set population to ignore directives:

Done in: 89da56e

@mtreinish mtreinish added Changelog: Bugfix Include in the "Fixed" section of the changelog and removed Changelog: None Do not include in changelog labels Nov 22, 2023
This commit updates a layout in the:
`TestSabreLayout.test_layout_many_search_trials` test case which was
recently changed in Qiskit#10323. The change in test ouput caused by Qiskit#10323
is what triggered the investigation into this bugfix and now that
barriers are being treated correctly by sabre the layout doesn't change
in the test case anymore and this is reverting the test assertion to use
the original layout before Qiskit#10323 was merged.
Copy link
Contributor

@kevinhartman kevinhartman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for the updates!

@kevinhartman kevinhartman added this pull request to the merge queue Nov 23, 2023
Merged via the queue into Qiskit:main with commit 920fa57 Nov 23, 2023
14 checks passed
@mtreinish mtreinish deleted the sabre-no-barrier branch November 23, 2023 10:47
gluonhiggs pushed a commit to gluonhiggs/qiskit that referenced this pull request Nov 23, 2023
* Avoid routing 2q barriers in SabreSwap

This commit fixes an oversight in the sabre swap pass where a 2 qubit
barrier would have been treated like a 2 qubit gate and swaps could
potentially be inserted if the sabre algorithm thought it didn't have
connectivity for the qargs to the barrier. However as barrier is just
a compiler directive it is valid on all qubit pairs so this swap
insertion was unnecessary, it was still valid but just not an optimal
output. This commit fixes it by adding context to the sabre dag around
whether a given node is a directive (and valid on all qubits) or not.

* Update rust tests too

* Skip directives in extended set generation too

Co-authored-by: Kevin Hartman <kevin@hart.mn>

* Add release note

* Update test layout in test_layout_many_search_trials

This commit updates a layout in the:
`TestSabreLayout.test_layout_many_search_trials` test case which was
recently changed in Qiskit#10323. The change in test ouput caused by Qiskit#10323
is what triggered the investigation into this bugfix and now that
barriers are being treated correctly by sabre the layout doesn't change
in the test case anymore and this is reverting the test assertion to use
the original layout before Qiskit#10323 was merged.

---------

Co-authored-by: Kevin Hartman <kevin@hart.mn>
FabianBrings pushed a commit to FabianBrings/qiskit that referenced this pull request Nov 27, 2023
* Avoid routing 2q barriers in SabreSwap

This commit fixes an oversight in the sabre swap pass where a 2 qubit
barrier would have been treated like a 2 qubit gate and swaps could
potentially be inserted if the sabre algorithm thought it didn't have
connectivity for the qargs to the barrier. However as barrier is just
a compiler directive it is valid on all qubit pairs so this swap
insertion was unnecessary, it was still valid but just not an optimal
output. This commit fixes it by adding context to the sabre dag around
whether a given node is a directive (and valid on all qubits) or not.

* Update rust tests too

* Skip directives in extended set generation too

Co-authored-by: Kevin Hartman <kevin@hart.mn>

* Add release note

* Update test layout in test_layout_many_search_trials

This commit updates a layout in the:
`TestSabreLayout.test_layout_many_search_trials` test case which was
recently changed in Qiskit#10323. The change in test ouput caused by Qiskit#10323
is what triggered the investigation into this bugfix and now that
barriers are being treated correctly by sabre the layout doesn't change
in the test case anymore and this is reverting the test assertion to use
the original layout before Qiskit#10323 was merged.

---------

Co-authored-by: Kevin Hartman <kevin@hart.mn>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: Bugfix Include in the "Fixed" section of the changelog Rust This PR or issue is related to Rust code in the repository
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants