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

Bug fix in ElidePermutations #13186

Merged
merged 2 commits into from
Sep 19, 2024

Conversation

alexanderivrii
Copy link
Contributor

Summary

A bug fix for the ElidePermutations pass where the internal qubit mapping was not updated correctly after a PermutationGate. This fix was already present in #13094, however we have decided to separate it to an independent PR as to allow backport.

@alexanderivrii alexanderivrii added the Changelog: Bugfix Include in the "Fixed" section of the changelog label Sep 19, 2024
@alexanderivrii alexanderivrii added this to the 1.2.2 milestone Sep 19, 2024
@alexanderivrii alexanderivrii requested a review from a team as a code owner September 19, 2024 10:42
@qiskit-bot
Copy link
Collaborator

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

  • @Qiskit/terra-core

@coveralls
Copy link

coveralls commented Sep 19, 2024

Pull Request Test Coverage Report for Build 10941526894

Details

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

Files with Coverage Reduction New Missed Lines %
qiskit/transpiler/passes/synthesis/unitary_synthesis.py 2 88.26%
crates/qasm2/src/lex.rs 3 92.73%
qiskit/synthesis/two_qubit/xx_decompose/decomposer.py 6 90.91%
Totals Coverage Status
Change from base Build 10931978471: -0.01%
Covered Lines: 73481
Relevant Lines: 82722

💛 - Coveralls

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, it was clearly a mistake like this because we ended up using the elision permutation tracking instead of the actual circuit index. I just had one small inline question about the test assertions, otherwise I think this is good to merge.

expected.cx(4, 3)

res = self.swap_pass(qc)
self.assertEqual(res, expected)
Copy link
Member

Choose a reason for hiding this comment

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

Should we add some assertions on the permutation tracking too to make sure it's correct and reverses to the original circuit?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a good idea. I have extended the test in 6791002. Do you think it's a good idea to add more "random circuits" tests, with swaps and permutations?

Copy link
Member

Choose a reason for hiding this comment

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

Adding more tests wouldn't hurt. I think the one you added here provides sufficient coverage to prevent a regression here. But if you wanted to add more that would give us more coverage against potential future issues.

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 updating the tests. If you want to add more test coverage in the future I think you can do that in a standalone PR. It'll be an easy PR to review/merge if all it does is expand the test coverage.

Comment on lines +237 to +239
perm = pass_.property_set["virtual_permutation_layout"].to_permutation(qc.qubits)
res.append(PermutationGate(perm), [0, 1, 2, 3, 4])
self.assertEqual(Operator(res), Operator(qc))
Copy link
Member

Choose a reason for hiding this comment

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

TBH, I'm surprised you didn't just use Operator.from_circuit here, but adding a permutation gate like this works fine too.

@mtreinish mtreinish added this pull request to the merge queue Sep 19, 2024
@mtreinish mtreinish added the stable backport potential The bug might be minimal and/or import enough to be port to stable label Sep 19, 2024
Merged via the queue into Qiskit:main with commit adf55e1 Sep 19, 2024
15 checks passed
mergify bot pushed a commit that referenced this pull request Sep 19, 2024
* elide permutations fix

* extending the test to check the final permutation

(cherry picked from commit adf55e1)
github-merge-queue bot pushed a commit that referenced this pull request Sep 19, 2024
* elide permutations fix

* extending the test to check the final permutation

(cherry picked from commit adf55e1)

Co-authored-by: Alexander Ivrii <alexi@il.ibm.com>
github-merge-queue bot pushed a commit that referenced this pull request Sep 19, 2024
* elide permutations fix

* extending the test to check the final permutation

(cherry picked from commit adf55e1)

Co-authored-by: Alexander Ivrii <alexi@il.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
Status: done
Development

Successfully merging this pull request may close these issues.

4 participants