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

Changed plot histogram code example and added another one in the API reference #8351

Merged

Conversation

Guillermo-Mijares-Vilarino
Copy link
Contributor

@Guillermo-Mijares-Vilarino Guillermo-Mijares-Vilarino commented Jul 15, 2022

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 the display function.

@qiskit-bot
Copy link
Collaborator

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:

@coveralls
Copy link

coveralls commented Jul 15, 2022

Pull Request Test Coverage Report for Build 3038655689

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 84.305%

Totals Coverage Status
Change from base Build 3032832563: 0.0%
Covered Lines: 57827
Relevant Lines: 68593

💛 - Coveralls

@HuangJunye HuangJunye self-assigned this Jul 22, 2022
@Guillermo-Mijares-Vilarino Guillermo-Mijares-Vilarino marked this pull request as ready for review July 28, 2022 07:55
@mtreinish mtreinish added documentation Something is not clear or an error documentation stable backport potential The bug might be minimal and/or import enough to be port to stable labels Jul 28, 2022
@mtreinish mtreinish added this to the 0.21.2 milestone Jul 28, 2022
@mtreinish mtreinish added the Changelog: None Do not include in changelog label Jul 28, 2022
Copy link
Collaborator

@HuangJunye HuangJunye left a 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
Copy link
Collaborator

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

qiskit/visualization/counts_visualization.py Show resolved Hide resolved
qiskit/visualization/counts_visualization.py Show resolved Hide resolved
HuangJunye
HuangJunye previously approved these changes Aug 3, 2022
Copy link
Collaborator

@HuangJunye HuangJunye left a 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.

@HuangJunye HuangJunye added the Intern PR PR submitted by IBM Quantum interns label Aug 4, 2022
HuangJunye
HuangJunye previously approved these changes Aug 4, 2022
Co-authored-by: Luciano Bello <bel@zurich.ibm.com>
Co-authored-by: Luciano Bello <bel@zurich.ibm.com>
Copy link
Member

@1ucian0 1ucian0 left a 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.

@Guillermo-Mijares-Vilarino
Copy link
Contributor Author

Guillermo-Mijares-Vilarino commented Aug 4, 2022

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.

@1ucian0
Copy link
Member

1ucian0 commented Aug 5, 2022

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)

@HuangJunye HuangJunye assigned 1ucian0 and mtreinish and unassigned 1ucian0 Aug 16, 2022
@mtreinish mtreinish removed the stable backport potential The bug might be minimal and/or import enough to be port to stable label Aug 19, 2022
@mtreinish mtreinish removed this from the 0.21.2 milestone Aug 19, 2022
@HuangJunye HuangJunye requested a review from 1ucian0 August 31, 2022 10:52
@HuangJunye
Copy link
Collaborator

@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)

@HuangJunye
Copy link
Collaborator

@Guillermo-Mijares-Vilarino You can take a look at the examples I created for the module level api page: #8569

@Guillermo-Mijares-Vilarino
Copy link
Contributor Author

@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)

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 Statevector(QuantumCircuit) to Statevector(np.array) for example?

@HuangJunye
Copy link
Collaborator

@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)

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 Statevector(QuantumCircuit) to Statevector(np.array) for example?

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.

@Guillermo-Mijares-Vilarino
Copy link
Contributor Author

Is there any other change that needs to be made @1ucian0?

Copy link
Member

@1ucian0 1ucian0 left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks!

@mergify mergify bot merged commit 055fe0f into Qiskit:main Sep 12, 2022
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 documentation Something is not clear or an error documentation Intern PR PR submitted by IBM Quantum interns
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

6 participants