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

Standardize visualization signatures and styling. #1359

Merged
merged 38 commits into from
Dec 3, 2018
Merged

Standardize visualization signatures and styling. #1359

merged 38 commits into from
Dec 3, 2018

Conversation

nonhermitian
Copy link
Contributor

Summary

An overhaul of the counts and states visualization functions (both mpl and interactive) to standardize the function signatures, styling, and allow for more functionality.

Details and comments

  • The signatures of all functions are now as close to identical as possible, and follow the standard mpl way to doing things.
  • The styling has also been updated.
  • It is now possible to change the figure size in every function, and it is possible to change the colors used in most functions (e.g. it is now possible to change a single bar color in plot_histogram)
  • The interactive and mpl functions are no longer called together. Instead the interactive ones must be explicitly called using the 'i'+plot_routine naming convention.
  • Each mpl based visualization is loaded regardless of whether mpl is installed or not, but gives an ImportError: Matploltib not installed. if trying to call the function and mpl is not installed.
  • The city plots are now in the same row rather than same column.

@nonhermitian nonhermitian added the type: enhancement It's working, but needs polishing label Nov 28, 2018
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.

I've only made it through the histogram so far, but I found a couple things to fix in there. We probably also need to update the CHANGELOG for everything here, because it will have a lot of user facing implications.

Aside from the inline comments there is also a potential issue with number_to_keep. The docstring says it will make another bar for the other values, but at least in my testing it doesn't do this. It just removes all the values except for the N most frequent. Although in my testing without this branch it looks like what we have in there today doesn't do this either. Maybe we just update the docstring to reflect how it works.

"""Plot a histogram of data.

Args:
data (list or dict): This is either a list of dictionaries or a single
dict containing the values to represent (ex {'001': 130})
number_to_keep (int): DEPRECATED the number of terms to plot and rest
Copy link
Member

Choose a reason for hiding this comment

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

Heh, well this definitely should be definitely go in the changelog. We deprecated this in 0.6 and now we're un-deprecating it and removing what we said was the alternative.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, forgot to remove.

qiskit/tools/visualization/_counts_visualization.py Outdated Show resolved Hide resolved
@nonhermitian
Copy link
Contributor Author

So I looked into the number_to_keep issue and it is basically just a bug. The 'other' values are just not being added to the labels for the dict lookup. Additionally, with out these values being added, the selected results are re-normalized, and give incorrect answers. In addition, when keeping only a few values, the labels for the basis states that are truncated are still plotted. I would think it would be better to only plot those states that are actually in the kept distribution. Of course, others may have different thoughts.

@jaygambetta
Copy link
Member

if we are going to depreciate plot_state please make sure the tutorial explains all the plotting methods clearly.

@jaygambetta jaygambetta added this to the 0.7 milestone Nov 29, 2018
@mtreinish
Copy link
Member

@jaygambetta yeah, I'm planning to push an update to the notebook after this merges

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 for the most part, I've just got a few inline comments on some small things before we merge this. The biggest things are we're deprecating the multiqubit bloch vector plot without an alternative and the title support for the functions which take a title (which was everything but qsphere) didn't really work all that well. Either too small or put the title on a subplot instead of the whole thing (which looks like an existing bug).

qiskit/tools/visualization/_state_visualization.py Outdated Show resolved Hide resolved
qiskit/tools/visualization/_state_visualization.py Outdated Show resolved Hide resolved
qiskit/tools/visualization/_state_visualization.py Outdated Show resolved Hide resolved
qiskit/tools/visualization/_state_visualization.py Outdated Show resolved Hide resolved
elif method == "wigner":
fig = plot_wigner_function(rho, filename=filename, show=show)
fig = plot_wigner_function(rho)
Copy link
Member

Choose a reason for hiding this comment

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

We don't expose this function via qiskit.tools.visualization.__init__ so we'll drop the functionality when we remove plot_state() I'm fine with doing that since this method always felt a bit out of place, and given we need to come to a resolution in #1106 and #1302 I think if we want to make wigner part of the public api we do it as a separate thing.

@nonhermitian
Copy link
Contributor Author

I believe that all known issues are resolved. If this looks good, I will go ahead and update the changelog.

@mtreinish
Copy link
Member

@nonhermitian yeah I think this looks good, so lets update the changelog and then I'll approve.

@mtreinish mtreinish self-assigned this Nov 30, 2018
mtreinish added a commit to mtreinish/qiskit-tutorial that referenced this pull request Nov 30, 2018
This commit updates the tutorial notebook for plotting data with updates
to the interface being made in Qiskit/qiskit#1359 . The changes
made in that PR will reflect the stable interface of the plotting data
functions documented here. So we'll have to update the notebook before
the release.
@jaygambetta jaygambetta merged commit 3644593 into Qiskit:master Dec 3, 2018
@mtreinish mtreinish mentioned this pull request Dec 4, 2018
5 tasks
jaygambetta pushed a commit to Qiskit/qiskit-tutorials that referenced this pull request Dec 5, 2018
* Update plotting data notebook with interface changes

This commit updates the tutorial notebook for plotting data with updates
to the interface being made in Qiskit/qiskit#1359 . The changes
made in that PR will reflect the stable interface of the plotting data
functions documented here. So we'll have to update the notebook before
the release.

* Finishing Touches

* Regenerate to get histogram legend fix
lia-approves pushed a commit to edasgupta/qiskit-terra that referenced this pull request Jul 30, 2019
* Fix parallezation in transpile.compile

* Revert "Fix parallezation in transpile.compile"

This reverts commit 98e78d0.

* remove oops files

* update plot_histogram

* updates

* updates

* do the imports correctly

* fixes

* fix style

* fix linter

* linter again

* fix font size

* just return None

* fix histogram issues

* suggested fixes and fixed number_to_keep

* update changelog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement It's working, but needs polishing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants