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 1q matrix bug in Quantum Shannon Decomposer #10126

Merged
merged 17 commits into from
Jul 18, 2023

Conversation

ewinston
Copy link
Contributor

@ewinston ewinston commented May 17, 2023

Summary

Fixes #10036

Details and comments

@qiskit-bot
Copy link
Collaborator

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

  • @Qiskit/terra-core
  • @ikkoham

@coveralls
Copy link

coveralls commented May 17, 2023

Pull Request Test Coverage Report for Build 5202288191

  • 3 of 4 (75.0%) changed or added relevant lines in 1 file are covered.
  • 67 unchanged lines in 10 files lost coverage.
  • Overall coverage increased (+0.06%) to 85.907%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit/quantum_info/synthesis/qsd.py 3 4 75.0%
Files with Coverage Reduction New Missed Lines %
crates/accelerate/src/sabre_swap/mod.rs 1 99.77%
crates/qasm2/src/expr.rs 1 93.76%
qiskit/circuit/tools/pi_check.py 1 91.23%
crates/qasm2/src/lex.rs 3 90.89%
qiskit/pulse/library/waveform.py 3 93.75%
qiskit/pulse/macros.py 3 94.67%
qiskit/pulse/filters.py 6 94.12%
crates/qasm2/src/parse.rs 12 97.11%
qiskit/visualization/circuit/circuit_visualization.py 13 69.91%
qiskit/pulse/schedule.py 24 88.27%
Totals Coverage Status
Change from base Build 5177933484: 0.06%
Covered Lines: 71257
Relevant Lines: 82947

💛 - Coveralls

@mtreinish mtreinish added the Changelog: Bugfix Include in the "Fixed" section of the changelog label May 17, 2023
@mtreinish mtreinish added this to the 0.24.1 milestone May 17, 2023
@mtreinish mtreinish added the stable backport potential The bug might be minimal and/or import enough to be port to stable label May 17, 2023
@jlapeyre
Copy link
Contributor

jlapeyre commented May 17, 2023

I think this example from the bug report #10036 still fails with this commit

qs_decomposition(qiskit.quantum_info.random_unitary(4).to_matrix())

Not only the 1q example fails, but some two qubit unitaries also result in an error.

I think the fix given in the bug report looks like a correct fix: for some 2q input matrices ind2q is empty so that mat2 is not bound.

@jlapeyre
Copy link
Contributor

jlapeyre commented May 18, 2023

I added a short fix and a test for a matrix that still failed with this PR, and made a PR to this PR branch ewinston#4

The matrix I used in the test is CXGate().to_matrix(). Note that the qsd decomposition is more complicated than the input, but at least it does not throw an error.

@ewinston
Copy link
Contributor Author

@jlapeyre Since the fix you and @jsmallz333 proposed works regardless of my approach maybe you should just submit that pr separately and I'll close this one.

@jlapeyre
Copy link
Contributor

@ewinston , as we discussed out-of-band I think that it makes sense to include the commits you made in this PR as well. This will avoid calling the synthesis method in some cases where it can't do any good.

Unless I misunderstand, I think you can just commit ewinston#4 in order to include the commits that fix the bug proper. If you prefer separating the PRs, I'm fine with making a separate PR as you suggest above.

@jlapeyre jlapeyre mentioned this pull request May 31, 2023
4 tasks
jlapeyre and others added 2 commits June 1, 2023 13:02
@jlapeyre jlapeyre modified the milestones: 0.24.1, 0.24.2 Jun 1, 2023
ewinston and others added 2 commits June 2, 2023 12:17
Add check that decomposition includes qsd2q gates before optimizing them
@jlapeyre
Copy link
Contributor

jlapeyre commented Jun 5, 2023

This looks good to go. But I think someone other than me should merge, since I added a commit to this PR.

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.

This LGTM, I just have a small nit inline about the comments. I'm going to apply the suggestion and enqueue for merging. (I forgot about the missing release note).

test/python/quantum_info/test_synthesis.py Outdated Show resolved Hide resolved
test/python/quantum_info/test_synthesis.py Outdated Show resolved Hide resolved
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.

Oh, I also forgot about a release note. Would you mine adding one so we can document we fixed this in the next bugfix release.

jlapeyre and others added 2 commits June 5, 2023 18:26
Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
@jlapeyre
Copy link
Contributor

jlapeyre commented Jun 5, 2023

I also forgot about a release note.

Yes, of course. I forgot too. This is done in a PR to this PR branch ewinston#5

@ewinston
Copy link
Contributor Author

ewinston commented Jun 6, 2023

Thanks @jlapeyre

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.

This LGTM, but I think it's still missing a release note to cover the bug fix

@jlapeyre
Copy link
Contributor

jlapeyre commented Jul 10, 2023

I pushed a new commit to
Add release note for fix to issue 10036 #5
to make a requested change in the release note.

jlapeyre and others added 3 commits July 10, 2023 12:51
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.

LGTM, thanks for adding the release note.

@mtreinish mtreinish added this pull request to the merge queue Jul 18, 2023
Merged via the queue into Qiskit:main with commit b831bcf Jul 18, 2023
mergify bot pushed a commit that referenced this pull request Jul 18, 2023
* fix 1q bug

* formatting

* restrict 2q gates from apply_a2

* Add check that decomposition includes qsd2q gates before optimizing them

Co-authored-by: jsmallz333 <90203920+jsmallz333@users.noreply.github.com>

* Apply suggestions from code review

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

* Add release note for fix to issue 10036

* avoid creating unitary gate if initial gate is 2q

* remove debug code

* Change "certain" to "trivial"

This was requested in a review comment.

---------

Co-authored-by: John Lapeyre <jlapeyre@users.noreply.github.com>
Co-authored-by: jsmallz333 <90203920+jsmallz333@users.noreply.github.com>
Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
(cherry picked from commit b831bcf)
github-merge-queue bot pushed a commit that referenced this pull request Jul 19, 2023
* fix 1q bug

* formatting

* restrict 2q gates from apply_a2

* Add check that decomposition includes qsd2q gates before optimizing them

Co-authored-by: jsmallz333 <90203920+jsmallz333@users.noreply.github.com>

* Apply suggestions from code review

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

* Add release note for fix to issue 10036

* avoid creating unitary gate if initial gate is 2q

* remove debug code

* Change "certain" to "trivial"

This was requested in a review comment.

---------

Co-authored-by: John Lapeyre <jlapeyre@users.noreply.github.com>
Co-authored-by: jsmallz333 <90203920+jsmallz333@users.noreply.github.com>
Co-authored-by: Matthew Treinish <mtreinish@kortar.org>
(cherry picked from commit b831bcf)

Co-authored-by: ewinston <ewinston@us.ibm.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.

Quantum shannon decomposition failing for some inputs
5 participants