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

Make plot_gate_map generic for any backend #7814

Merged
merged 18 commits into from
Mar 31, 2022

Conversation

mtreinish
Copy link
Member

Summary

Previously the plot_gate_map() family of visualization functions only
worked with a fixed hard coded list of number of qubits. The function
made the assumption if the backend had a matching number of qubits it
was an IBM backend that had the same number of qubits (and fell into a
fixed connectivity topology) and would use the manually set graph layout
to visualize the function. This was problematic because it didn't
actually work for any backend, and if a backend had the same number of
qubits as an IBM backend but a different connectivity it would use a potentially
nonoptimal layout. This also required us to update the hard
coded list whenever a new IBM backend was released to support
visualizing them. Additionally the functions only worked with BackendV1
and BaseBackend based backends and would fail if a BackendV2 object were
passed to the function. This commit address these issues by making 4 key
changes to the function, first it adds a new qubit_coordinates kwarg to
all the methods which if specifed can be used to manually specify a
graph layout to use for the visualization. The second is that the
hardcoded list for layouts are only used if it's an IBM backend (or a
fake backend) so that we're using them where appropriate (the 127q
layout for ibm_washington is also added). The third change is that if a
graph layout isn't provided and it's not an ibm backend with a hardcoded
entry, retworkx's spring_layout() function is used to create a layout.
In the future we can use a more appropriate planar_layout() function
after its available in retworkx (see
Qiskit/rustworkx#438 ). Finally the last change
is that BackendV2 support is added to the function to make sure we're
able to use the visualization function regardless of what type of
backend is passed in.

Details and comments

Previously the plot_gate_map() family of visualization functions only
worked with a fixed hard coded list of number of qubits. The function
made the assumption if the backend had a matching number of qubits it
was an IBM backend that had the same number of qubits (and fell into a
fixed connectivity topology) and would use the manually set graph layout
to visualize the function. This was problematic because it didn't
actually work for any backend, and if a backend had the same number of
qubits as an IBM backend but a different connectivity it would use a potentially nonoptimal layout. This also required us to update the hard
coded list whenever a new IBM backend was released to support
visualizing them. Additionally the functions only worked with BackendV1
and BaseBackend based backends and would fail if a BackendV2 object were
passed to the function. This commit address these issues by making 4 key
changes to the function, first it adds a new qubit_coordinates kwarg to
all the methods which if specifed can be used to manually specify a
graph layout to use for the visualization. The second is that the
hardcoded list for layouts are only used if it's an IBM backend (or a
fake backend) so that we're using them where appropriate (the 127q
layout for ibm_washington is also added). The third change is that if a
graph layout isn't provided and it's not an ibm backend with a hardcoded
entry, retworkx's spring_layout() function is used to create a layout.
In the future we can use a more appropriate planar_layout() function
after its available in retworkx (see
Qiskit/rustworkx#438 ). Finally the last change
is that BackendV2 support is added to the function to make sure we're
able to use the visualization function regardless of what type of
backend is passed in.
@mtreinish mtreinish added the Changelog: New Feature Include in the "Added" section of the changelog label Mar 24, 2022
@mtreinish mtreinish added this to the 0.20 milestone Mar 24, 2022
@mtreinish mtreinish requested review from a team and nonhermitian as code owners March 24, 2022 17:31
@coveralls
Copy link

coveralls commented Mar 24, 2022

Pull Request Test Coverage Report for Build 2068750718

  • 32 of 102 (31.37%) changed or added relevant lines in 2 files are covered.
  • 9 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.05%) to 83.77%

Changes Missing Coverage Covered Lines Changed/Added Lines %
qiskit/transpiler/passmanager.py 0 1 0.0%
qiskit/visualization/gate_map.py 32 101 31.68%
Files with Coverage Reduction New Missed Lines %
qiskit/transpiler/passmanager.py 1 95.33%
qiskit/visualization/gate_map.py 8 41.93%
Totals Coverage Status
Change from base Build 2068749253: -0.05%
Covered Lines: 53721
Relevant Lines: 64129

💛 - Coveralls

This commit updates the logic around when we use the default hard coded
graph layouts for ibm backends. Previously there was a bug in the if
condition which would cause the hard coded layout to be unconditionally
used for an ibm backend, even if the user specified their own layout.
This fixes this by only using the hard coded layouts when
qubit_coordinates is not set.
qiskit/visualization/gate_map.py Outdated Show resolved Hide resolved
qiskit/visualization/gate_map.py Outdated Show resolved Hide resolved
qiskit/visualization/gate_map.py Outdated Show resolved Hide resolved
qiskit/visualization/gate_map.py Outdated Show resolved Hide resolved
mtreinish and others added 5 commits March 30, 2022 18:00
Previously the offset detection was looking for values < 0 which was
needlessly triggering an offset loop for values >=0 and < 1. We only
need to correct for negative values if there are any negative values in
the 2d coordinates being used for the graph layout.
@mtreinish mtreinish requested a review from kevinhartman March 30, 2022 22:07
@mergify mergify bot merged commit 009150f into Qiskit:main Mar 31, 2022
@mtreinish mtreinish deleted the update-gate-map branch March 31, 2022 09:51
@mtreinish mtreinish mentioned this pull request Apr 4, 2022
mtreinish added a commit to mtreinish/qiskit-core that referenced this pull request Apr 4, 2022
In Qiskit#7814 we updated the plot_error_map() error to be more general and
also work with BackendV2 instead of assuming it's a BaseBackend or
BackendV1 backend. However, as part of that refactor 2 errors were
accidently introduced preventing the function from being used. First in
the BackendV2 path we were incorrectly handling the backend name to use
for the plot title. Secondly, in the BaseBackend/BackendV1 path the
readout error array loop was incorrectly constructed resulting in the
array being larger than expected causing an error. This commit fixes
both conditions so that we can correctly plot the result.

Fixes Qiskit#7879
mergify bot pushed a commit that referenced this pull request Apr 4, 2022
* Fix plot_error_map

In #7814 we updated the plot_error_map() error to be more general and
also work with BackendV2 instead of assuming it's a BaseBackend or
BackendV1 backend. However, as part of that refactor 2 errors were
accidently introduced preventing the function from being used. First in
the BackendV2 path we were incorrectly handling the backend name to use
for the plot title. Secondly, in the BaseBackend/BackendV1 path the
readout error array loop was incorrectly constructed resulting in the
array being larger than expected causing an error. This commit fixes
both conditions so that we can correctly plot the result.

Fixes #7879

* Add tests for plot_error_map

This commit adds test coverage for plot_error_map. The reason the issues
around this function slipped in was a complete lack of test coverage.
This adds some basic tests with both the BackendV1 and BackendV2 test
paths to ensure we have some coverage for the function.

* Add release note
mergify bot pushed a commit that referenced this pull request Apr 4, 2022
* Fix plot_error_map

In #7814 we updated the plot_error_map() error to be more general and
also work with BackendV2 instead of assuming it's a BaseBackend or
BackendV1 backend. However, as part of that refactor 2 errors were
accidently introduced preventing the function from being used. First in
the BackendV2 path we were incorrectly handling the backend name to use
for the plot title. Secondly, in the BaseBackend/BackendV1 path the
readout error array loop was incorrectly constructed resulting in the
array being larger than expected causing an error. This commit fixes
both conditions so that we can correctly plot the result.

Fixes #7879

* Add tests for plot_error_map

This commit adds test coverage for plot_error_map. The reason the issues
around this function slipped in was a complete lack of test coverage.
This adds some basic tests with both the BackendV1 and BackendV2 test
paths to ensure we have some coverage for the function.

* Add release note

(cherry picked from commit d430e4d)
mergify bot added a commit that referenced this pull request Apr 4, 2022
…7887)

* Fix plot_error_map

In #7814 we updated the plot_error_map() error to be more general and
also work with BackendV2 instead of assuming it's a BaseBackend or
BackendV1 backend. However, as part of that refactor 2 errors were
accidently introduced preventing the function from being used. First in
the BackendV2 path we were incorrectly handling the backend name to use
for the plot title. Secondly, in the BaseBackend/BackendV1 path the
readout error array loop was incorrectly constructed resulting in the
array being larger than expected causing an error. This commit fixes
both conditions so that we can correctly plot the result.

Fixes #7879

* Add tests for plot_error_map

This commit adds test coverage for plot_error_map. The reason the issues
around this function slipped in was a complete lack of test coverage.
This adds some basic tests with both the BackendV1 and BackendV2 test
paths to ensure we have some coverage for the function.

* Add release note

(cherry picked from commit d430e4d)

Co-authored-by: Matthew Treinish <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: New Feature Include in the "Added" section of the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants