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

Fix UnitarySynthesis pass bug when target contains global gates #13651

Merged
merged 5 commits into from
Jan 13, 2025

Conversation

ElePT
Copy link
Contributor

@ElePT ElePT commented Jan 10, 2025

Summary

While working on #12850 I realized that the UnitarySynthesis Rust implementation would sometimes append non-2q-gates to the basis set and panic over the dimension mismatch. I had assumed that target.operation_names_for_qargs(Some(&qubits)) would only return gates whose number of qubits matched len(qubits), but this assumption is incorrect. It will return any gate with some overlap with the provided qargs, independently of the number of qubits of the gate. This bug would come up often when the target contained global gates.

I believe that the fix is as simple as making sure the 2q basis contains only 2q gates, at least for the cases I found.

Details and comments

@ElePT ElePT requested a review from a team as a code owner January 10, 2025 14:10
@qiskit-bot
Copy link
Collaborator

One or more of the following people are relevant to this code:

  • @Qiskit/terra-core

@ElePT ElePT added the Changelog: Bugfix Include in the "Fixed" section of the changelog label Jan 10, 2025
@ElePT ElePT added the stable backport potential The bug might be minimal and/or import enough to be port to stable label Jan 10, 2025
@ElePT ElePT added this to the 1.3.2 milestone Jan 10, 2025
Copy link
Member

@mtreinish mtreinish left a comment

Choose a reason for hiding this comment

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

Looks good to me, but just one small code comment

crates/accelerate/src/unitary_synthesis.rs Outdated Show resolved Hide resolved
Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
@coveralls
Copy link

coveralls commented Jan 10, 2025

Pull Request Test Coverage Report for Build 12743897780

Details

  • 4 of 4 (100.0%) changed or added relevant lines in 1 file are covered.
  • 8 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.004%) to 88.923%

Files with Coverage Reduction New Missed Lines %
crates/qasm2/src/lex.rs 2 92.48%
crates/qasm2/src/parse.rs 6 97.62%
Totals Coverage Status
Change from base Build 12710188694: 0.004%
Covered Lines: 79433
Relevant Lines: 89328

💛 - Coveralls

Copy link
Member

@ShellyGarion ShellyGarion left a comment

Choose a reason for hiding this comment

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

Good catch! Thanks!


// Filter out non-2q-gate candidates
if op.operation.num_qubits() != 2 {
continue;
Copy link
Member

Choose a reason for hiding this comment

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

it's the same behavior both for 1-qubit and n-qubits gates (n>2)?

Copy link
Contributor Author

@ElePT ElePT Jan 13, 2025

Choose a reason for hiding this comment

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

yes, the gate matrix needs to be 4x4 in this part of the code, any n!=2 qubit gate causes the dimension mismatch panic

@mtreinish mtreinish added this pull request to the merge queue Jan 13, 2025
Merged via the queue into Qiskit:main with commit d041d5b Jan 13, 2025
17 checks passed
mergify bot pushed a commit that referenced this pull request Jan 13, 2025
…3651)

* Confirm 2q basis gate candidates are in fact 2-qubit gates. Add test using target with global gates.

* Add reno

* Apply Matt's suggestion

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>

* Add semicolon

* Apply Shelly's suggestion

---------

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
(cherry picked from commit d041d5b)
github-merge-queue bot pushed a commit that referenced this pull request Jan 14, 2025
…3651) (#13656)

* Confirm 2q basis gate candidates are in fact 2-qubit gates. Add test using target with global gates.

* Add reno

* Apply Matt's suggestion

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>

* Add semicolon

* Apply Shelly's suggestion

---------

Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
(cherry picked from commit d041d5b)

Co-authored-by: Elena Peña Tapia <57907331+ElePT@users.noreply.github.com>
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 stable backport potential The bug might be minimal and/or import enough to be port to stable
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants