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 classical-bit handling in control-flow StochasticSwap #8906

Merged
merged 4 commits into from
Oct 19, 2022

Conversation

jakelishman
Copy link
Member

Summary

Previously we were expanding control-flow blocks to be full-width over all wires, and only contracting the qubits back again, without changing the clbits given as node arguments. This modifies the

The changes in most of the tests are necessary because the tests were testing behaviour that should be considered incorrect. The principal new test of all this behaviour is the additional assertions added in _visit_block in the random tests; these uniformly fail without this patch, and succeed with it.

Details and comments

Fix #8903.

Previously we were expanding control-flow blocks to be full-width over
_all_ wires, and only contracting the qubits back again, without
changing the clbits given as node arguments.  This modifies the

The changes in most of the tests are necessary because the tests were
testing behaviour that should be considered incorrect.  The principal
new test of all this behaviour is the additional assertions added in
`_visit_block` in the random tests; these uniformly fail without this
patch, and succeed with it.
@jakelishman jakelishman added stable backport potential The bug might be minimal and/or import enough to be port to stable Changelog: Bugfix Include in the "Fixed" section of the changelog labels Oct 14, 2022
@jakelishman jakelishman added this to the 0.22.1 milestone Oct 14, 2022
@jakelishman jakelishman requested a review from a team as a code owner October 14, 2022 14:20
@qiskit-bot
Copy link
Collaborator

Thank you for opening a new pull request.

Before your PR can be merged it will first need to pass continuous integration tests and be reviewed. Sometimes the review process can be slow, so please be patient.

While you're waiting, please feel free to review other open PRs. While only a subset of people are authorized to approve pull requests for merging, everyone is encouraged to review open pull requests. Doing reviews helps reduce the burden on the core team and helps make the project's code better for everyone.

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

  • @Qiskit/terra-core

@coveralls
Copy link

coveralls commented Oct 14, 2022

Pull Request Test Coverage Report for Build 3282607050

  • 12 of 12 (100.0%) changed or added relevant lines in 1 file are covered.
  • 2 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.0003%) to 84.761%

Files with Coverage Reduction New Missed Lines %
qiskit/extensions/quantum_initializer/squ.py 2 79.78%
Totals Coverage Status
Change from base Build 3282605851: 0.0003%
Covered Lines: 61946
Relevant Lines: 73083

💛 - 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.

The code change looks good to me, but the one thing I think would be good is a dedicated test for this, or specifically with the follow-on effects to ensure we can serialize with qpy and qasm3 transpiled control flow circuits. Just to verify we don't regress this in the future, especially once we get sabre control flow aware.

@jakelishman
Copy link
Member Author

This idea of writing post-transpile integration tests turned out to be an excellent idea - in trying to write them, I've already turned up more bugs in unrelated code than I was expected, such as #8923.

These are general integration tests for QPY and OpenQASM 3 dumping, with
a particular emphasis on making sure control-flow constructs don't
invalidate these two operations.
@jakelishman
Copy link
Member Author

jakelishman commented Oct 17, 2022

Added more tests in fb30ff8. They need all of:

to merge first before they'll pass, because of other bugs I found while writing the integration tests.

@jakelishman
Copy link
Member Author

This PR should be ready to review and merge, now that its dependents are in.

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 extensive testing and fixing the long tail of issues it uncovered.

@mergify mergify bot merged commit 514e383 into Qiskit:main Oct 19, 2022
mergify bot pushed a commit that referenced this pull request Oct 19, 2022
* Fix classical-bit handling in control-flow StochasticSwap

Previously we were expanding control-flow blocks to be full-width over
_all_ wires, and only contracting the qubits back again, without
changing the clbits given as node arguments.  This modifies the

The changes in most of the tests are necessary because the tests were
testing behaviour that should be considered incorrect.  The principal
new test of all this behaviour is the additional assertions added in
`_visit_block` in the random tests; these uniformly fail without this
patch, and succeed with it.

* Add integration tests of some post-transpile work

These are general integration tests for QPY and OpenQASM 3 dumping, with
a particular emphasis on making sure control-flow constructs don't
invalidate these two operations.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
(cherry picked from commit 514e383)
@jakelishman jakelishman deleted the fix-extra-clbit-wires branch October 19, 2022 17:21
mergify bot added a commit that referenced this pull request Oct 19, 2022
)

* Fix classical-bit handling in control-flow StochasticSwap

Previously we were expanding control-flow blocks to be full-width over
_all_ wires, and only contracting the qubits back again, without
changing the clbits given as node arguments.  This modifies the

The changes in most of the tests are necessary because the tests were
testing behaviour that should be considered incorrect.  The principal
new test of all this behaviour is the additional assertions added in
`_visit_block` in the random tests; these uniformly fail without this
patch, and succeed with it.

* Add integration tests of some post-transpile work

These are general integration tests for QPY and OpenQASM 3 dumping, with
a particular emphasis on making sure control-flow constructs don't
invalidate these two operations.

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
(cherry picked from commit 514e383)

Co-authored-by: Jake Lishman <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@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.

Qasm3 exporter failing when if branch does not contain all clbits
4 participants