-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Changed plot histogram code example and added another one in the API reference #8351
Changed plot histogram code example and added another one in the API reference #8351
Conversation
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:
|
Pull Request Test Coverage Report for Build 3038655689
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this. I will modify your PR directly based on our discussions offline.
.. jupyter-execute:: | ||
|
||
from qiskit import QuantumCircuit, BasicAer, execute | ||
from qiskit import QuantumCircuit, Aer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should use BasicAer whenever possible so that the documentation only relies on Terra
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks for making this contribution.
Co-authored-by: Luciano Bello <bel@zurich.ibm.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No sure.. this is getting into how-to land. The original example was much simpler.
Even more, in the same spirit as #8350, this could be as simple as
plot_histogram({'00': 525, '11': 499})
I gave you this is a bit of the opposite extreme. I'm trying to make a point. An example is a stand-alone situation. With less other unrelated things.
If you are talking about the second example @1ucian0, this was done so there were enough bars with varied height to show different ways to sort them. With 2 or 3 bars it's hard to observe the difference. |
from qiskit.visualization import plot_histogram
counts = {'001': 596, '011': 211, '010': 50, '000': 117, '101': 33, '111': 8, '100': 6, '110': 3}
hist1 = plot_histogram(counts, sort='value_desc')
hist2 = plot_histogram(counts, sort='hamming', target_string='001')
display(hist1, hist2) |
@Guillermo-Mijares-Vilarino Can you please simplify all the examples to use counts dictionary instead of result.get_counts similar to the second example based on Luciano's comment? #8351 (comment) |
@Guillermo-Mijares-Vilarino You can take a look at the examples I created for the module level api page: #8569 |
If I do that at least to the first example from this PR it would become practically identical to one of the examples you added in #8569 @HuangJunye. We should then decide which one to keep. This is the only of my code examples PRs that uses any counts as the rest use states so there would be nothing else to change. Or you mean changing any |
It's ok to have identical examples because the entry point of users could be from search engine not from the module api page. Yeah I think changing this one is enough. YOu can keep the statevector examples. |
Is there any other change that needs to be made @1ucian0? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks!
Summary
Changed the current
plot_histogram
code example in the API reference and added another one.Details and comments
For the original code example I removed any references to the deprecated
execute
function and plotted two different executions in different colors instead of only one.The new example shows two different ways to order the bars using the
sort
argument: by descending probability order (value_desc
) and by Hamming distance (hamming
). It also shows how one can easily represent two different histograms in the same code cell with thedisplay
function.