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

Update plots to work with quantum state classes #4324

Merged
merged 16 commits into from
Jul 17, 2020

Conversation

chriseclectic
Copy link
Member

@chriseclectic chriseclectic commented Apr 28, 2020

Summary

  • Updates state plotting functions to work directly with Statevector and DensityMatrix objects (along with anything that can be converted to a density matrix like arrays and lists).

  • Simplified some of the plotting code that works with Pauli basis by using the new PauliTable and SparsePauliOp classes.

Details and comments

jaygambetta
jaygambetta previously approved these changes Apr 28, 2020
ajavadia
ajavadia previously approved these changes Apr 29, 2020
@kdk kdk added this to the 0.14 milestone Apr 29, 2020
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.

Lint failure:

************* Module qiskit.visualization.state_visualization
qiskit/visualization/state_visualization.py:61:0: W9006: "VisualizationError" not documented as being raised (missing-raises-doc)
qiskit/visualization/state_visualization.py:279:0: W9006: "VisualizationError" not documented as being raised (missing-raises-doc)
qiskit/visualization/state_visualization.py:628:0: W9006: "VisualizationError" not documented as being raised (missing-raises-doc)
************* Module qiskit.visualization.utils
qiskit/visualization/utils.py:293:0: W9006: "VisualizationError" not documented as being raised (missing-raises-doc)
qiskit/visualization/utils.py:316:0: W9006: "VisualizationError" not documented as being raised (missing-raises-doc)
************* Module qiskit.visualization.interactive.iplot_paulivec
qiskit/visualization/interactive/iplot_paulivec.py:84:0: R1721: Unnecessary use of a comprehension (unnecessary-comprehension)
************* Module qiskit.visualization.interactive.iplot_cities
qiskit/visualization/interactive/iplot_cities.py:33:0: W9006: "VisualizationError" not documented as being raised (missing-raises-doc)
************* Module qiskit.visualization.interactive.iplot_qsphere
qiskit/visualization/interactive/iplot_qsphere.py:37:0: W9006: "VisualizationError" not documented as being raised (missing-raises-doc)
************* Module qiskit.visualization.interactive.iplot_hinton
qiskit/visualization/interactive/iplot_hinton.py:33:0: W9006: "VisualizationError" not documented as being raised (missing-raises-doc)

************* Module qiskit.visualization.state_visualization
qiskit/visualization/state_visualization.py:61:0: W9006: "VisualizationError" not documented as being raised (missing-raises-doc)
qiskit/visualization/state_visualization.py:279:0: W9006: "VisualizationError" not documented as being raised (missing-raises-doc)
qiskit/visualization/state_visualization.py:628:0: W9006: "VisualizationError" not documented as being raised (missing-raises-doc)
************* Module qiskit.visualization.utils
qiskit/visualization/utils.py:293:0: W9006: "VisualizationError" not documented as being raised (missing-raises-doc)
qiskit/visualization/utils.py:316:0: W9006: "VisualizationError" not documented as being raised (missing-raises-doc)
************* Module qiskit.visualization.interactive.iplot_paulivec
qiskit/visualization/interactive/iplot_paulivec.py:84:0: R1721: Unnecessary use of a comprehension (unnecessary-comprehension)
************* Module qiskit.visualization.interactive.iplot_cities
qiskit/visualization/interactive/iplot_cities.py:33:0: W9006: "VisualizationError" not documented as being raised (missing-raises-doc)
************* Module qiskit.visualization.interactive.iplot_qsphere
qiskit/visualization/interactive/iplot_qsphere.py:37:0: W9006: "VisualizationError" not documented as being raised (missing-raises-doc)
************* Module qiskit.visualization.interactive.iplot_hinton
qiskit/visualization/interactive/iplot_hinton.py:33:0: W9006: "VisualizationError" not documented as being raised (missing-raises-doc)

https://dev.azure.com/qiskit-ci/qiskit-terra/_build/results?buildId=12705&view=logs&j=7684b0c9-af38-5400-184f-6880bd8a4dd7&t=9d95188b-4e59-58d8-f7c4-3f1fbd4209ad&l=12

and doc failure

QiskitError: 'Cannot apply instruction with classical registers: measure'

https://dev.azure.com/qiskit-ci/qiskit-terra/_build/results?buildId=12705&view=logs&j=23e88340-9b01-571b-4128-239215012d30&t=fd5b7ae3-9f70-5b67-b24e-b010b8098eb2&l=8107

@kdk kdk removed the automerge label Apr 29, 2020
@kdk kdk removed this from the 0.14 milestone Apr 29, 2020
@chriseclectic chriseclectic dismissed stale reviews from ajavadia and jaygambetta via 5594902 April 30, 2020 15:13
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, tested it locally with some scripts I wrote in late 2018 to fix some bugs and everything still works as expected. My only concern with this is the renaming of rho to state as the first param. I agree state is a better name, but we've considered the interface stable for some time now and a user could (however unlikely) be calling the positional param by name, something like :plot_state_hinton(title='My hinton', rho=my_state) which would be broken by this change. @kdk wrote a handy decorator for these cases: https://github.com/Qiskit/qiskit-terra/blob/master/qiskit/util.py#L102 which can be used like: https://github.com/Qiskit/qiskit-terra/blob/86294337a9255ec7ef04ff666a5df02a18b8c218/qiskit/circuit/quantumcircuit.py#L1600-L1601 once you deprecate rho this should be good to go

@mtreinish mtreinish added this to the 0.15 milestone May 28, 2020
@chriseclectic chriseclectic requested a review from a team as a code owner July 7, 2020 16:00
In environments without matplotlib installed the deprecation decorator
would not be imported leading to an import error on qiskit because the
decorator needs to exist at module import time. This commit corrects
this by moving the decorator import outside the HAS_MPL condition so
it's always present.
The deprecate arguments decorator is used to enable people to pass a
positional parameter by name using a depcrecated old name while we
transition to a new one. It works by allowing the old name as a keyword
only argument and having the decorator pass that value to the new
positional arg. However, for this to work the old name of the positional
argument must be set as a kwarg on the function. This commit adjust the
function signature to enable this.
@mtreinish
Copy link
Member

I've updated this PR to fix the issues and correct the usage of the @deprecate_arguments decorator, I also added a release note. I've touched this PR enough that someone else should probably review it, but I think it's ready to go now.

@kdk kdk added automerge Changelog: API Change Include in the "Changed" section of the changelog labels Jul 17, 2020
@mergify mergify bot merged commit 705f971 into Qiskit:master Jul 17, 2020
@mtreinish mtreinish added Changelog: Deprecation Include in "Deprecated" section of changelog Changelog: New Feature Include in the "Added" section of the changelog Changelog: API Change Include in the "Changed" section of the changelog and removed Changelog: API Change Include in the "Changed" section of the changelog Changelog: New Feature Include in the "Added" section of the changelog labels Aug 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: API Change Include in the "Changed" section of the changelog Changelog: Deprecation Include in "Deprecated" section of changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants