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

Assert properties not specifics of DenseLayout results #10901

Merged
merged 1 commit into from
Sep 27, 2023

Conversation

jakelishman
Copy link
Member

Summary

DenseLayout is a deterministic pass, so there's no risk of RNG manipulations changing the output. Internally, however, the use of the sparse-matrix bandwidth-reduction algorithm in Scipy's reverse_cuthill_mckee uses numpy.argsort internally with the unstable default sorting algorithm, which means the output can be dependent on the way that sort is implemented. The arrays that are sorted are directly related to the input coupling map, and are likely to include degeneracies, which pose problems when the implementation of the unstable sort changes. This was the case moving from Numpy 1.24 to Numpy 1.25.

This commit instead changes the tests from asserting that a precise layout was returned to asserting that the returned layout contains only a connected subgraph of qubits. The "most" connected component that DenseLayout finds must be at least connected, though this assertion is not quite as strong as finding the densest. The extra test accounts for this weakening.

Details and comments

This is another case where our tests were incompatible with Numpy 1.25+ (see #10305), and a simpler one to fix than the others noted in that issue; it's not an unsoundness of the library, just a sort-method instability that we can make the tests more resilient against.

`DenseLayout` is a deterministic pass, so there's no risk of RNG
manipulations changing the output.  Internally, however, the use of the
sparse-matrix bandwidth-reduction algorithm in Scipy's
`reverse_cuthill_mckee` uses `numpy.argsort` internally with the
unstable default sorting algorithm, which means the output _can_ be
dependent on the way that sort is implemented.  The arrays that are
sorted are directly related to the input coupling map, and are likely to
include degeneracies, which pose problems when the implementation of the
unstable sort changes.  This was the case moving from Numpy 1.24 to
Numpy 1.25.

This commit instead changes the tests from asserting that a precise
layout was returned to asserting that the returned layout contains only
a connected subgraph of qubits.  The "most" connected component that
`DenseLayout` finds must be _at least_ connected, though this assertion
is not quite as strong as finding the _densest_.  The extra test
accounts for this weakening.
@jakelishman jakelishman added type: qa Issues and PRs that relate to testing and code quality stable backport potential The bug might be minimal and/or import enough to be port to stable Changelog: None Do not include in changelog labels Sep 26, 2023
@jakelishman jakelishman added this to the 0.25.2 milestone Sep 26, 2023
@jakelishman jakelishman requested a review from a team as a code owner September 26, 2023 17:11
@qiskit-bot
Copy link
Collaborator

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

  • @Qiskit/terra-core

Copy link
Member

@kdk kdk left a comment

Choose a reason for hiding this comment

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

This approach LGTM.

@jakelishman jakelishman added this pull request to the merge queue Sep 27, 2023
Merged via the queue into Qiskit:main with commit 0f66cdf Sep 27, 2023
13 checks passed
mergify bot pushed a commit that referenced this pull request Sep 27, 2023
`DenseLayout` is a deterministic pass, so there's no risk of RNG
manipulations changing the output.  Internally, however, the use of the
sparse-matrix bandwidth-reduction algorithm in Scipy's
`reverse_cuthill_mckee` uses `numpy.argsort` internally with the
unstable default sorting algorithm, which means the output _can_ be
dependent on the way that sort is implemented.  The arrays that are
sorted are directly related to the input coupling map, and are likely to
include degeneracies, which pose problems when the implementation of the
unstable sort changes.  This was the case moving from Numpy 1.24 to
Numpy 1.25.

This commit instead changes the tests from asserting that a precise
layout was returned to asserting that the returned layout contains only
a connected subgraph of qubits.  The "most" connected component that
`DenseLayout` finds must be _at least_ connected, though this assertion
is not quite as strong as finding the _densest_.  The extra test
accounts for this weakening.

(cherry picked from commit 0f66cdf)
@jakelishman jakelishman deleted the dense-layout-stable-tests branch September 27, 2023 18:30
github-merge-queue bot pushed a commit that referenced this pull request Sep 29, 2023
…0901) (#10907)

* Assert properties not specifics of `DenseLayout` results (#10901)

`DenseLayout` is a deterministic pass, so there's no risk of RNG
manipulations changing the output.  Internally, however, the use of the
sparse-matrix bandwidth-reduction algorithm in Scipy's
`reverse_cuthill_mckee` uses `numpy.argsort` internally with the
unstable default sorting algorithm, which means the output _can_ be
dependent on the way that sort is implemented.  The arrays that are
sorted are directly related to the input coupling map, and are likely to
include degeneracies, which pose problems when the implementation of the
unstable sort changes.  This was the case moving from Numpy 1.24 to
Numpy 1.25.

This commit instead changes the tests from asserting that a precise
layout was returned to asserting that the returned layout contains only
a connected subgraph of qubits.  The "most" connected component that
`DenseLayout` finds must be _at least_ connected, though this assertion
is not quite as strong as finding the _densest_.  The extra test
accounts for this weakening.

(cherry picked from commit 0f66cdf)

* Avoid use of un-backported kwarg

* Update test/python/transpiler/test_dense_layout.py

---------

Co-authored-by: Jake Lishman <[email protected]>
rupeshknn pushed a commit to rupeshknn/qiskit that referenced this pull request Oct 9, 2023
`DenseLayout` is a deterministic pass, so there's no risk of RNG
manipulations changing the output.  Internally, however, the use of the
sparse-matrix bandwidth-reduction algorithm in Scipy's
`reverse_cuthill_mckee` uses `numpy.argsort` internally with the
unstable default sorting algorithm, which means the output _can_ be
dependent on the way that sort is implemented.  The arrays that are
sorted are directly related to the input coupling map, and are likely to
include degeneracies, which pose problems when the implementation of the
unstable sort changes.  This was the case moving from Numpy 1.24 to
Numpy 1.25.

This commit instead changes the tests from asserting that a precise
layout was returned to asserting that the returned layout contains only
a connected subgraph of qubits.  The "most" connected component that
`DenseLayout` finds must be _at least_ connected, though this assertion
is not quite as strong as finding the _densest_.  The extra test
accounts for this weakening.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: None Do not include in changelog stable backport potential The bug might be minimal and/or import enough to be port to stable type: qa Issues and PRs that relate to testing and code quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants