-
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
fix hinton visualization bug #8447
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:
|
|
Thanks for submitting the PR for fixing the issue you found. As this is your first time contributing to Qiskit Terra, please have a look at the general Qiskit contributing guideline (especially the "Pull Request Checklist" section) and the CONTRIBUTING.md in Terra. If you are unsure about anything, please feel free to ping me. Thanks! |
Can you please write a release note and sign the Contributor License Agreement? |
Pull Request Test Coverage Report for Build 3277537504
💛 - Coveralls |
I think I have signed the Contributor License earlier today, but I am not sure about where to write a release note. Could you guide me through that? Thank you! edits: Ok I see, I am trying to add the release note with reno now. |
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 adding the release note. I left some comments for that.
Reading your original message on top, I realize the y-axis now is reverted to the normal direction (lower at the bottom, higher at the top). I am not sure about the original intention, but I believe there is a reason for the inverted direction. I will investigate that a bit.
issues: | ||
- | | ||
Fix known bug in plot_state_hinton where axes are rendered improperly. |
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.
issues: | |
- | | |
Fix known bug in plot_state_hinton where axes are rendered improperly. |
This part is not needed. For PR that fixes an issue, you only need to write fixes
section, as far as I know we don't use issues
section that much in Qiskit. Thanks for reading through the description of different sections of the release note though.
I know writing release notes are not easy. I struggle with it all the time :D For the future, if you are unsure about this, you can read other examples in the release notes folder: https://github.com/Qiskit/qiskit-terra/tree/main/releasenotes/notes
Fix known bug in plot_state_hinton where axes are rendered improperly. | ||
fixes: | ||
- | | ||
Fix known bug in plot_state_hinton. Refer to `#8446 <https://github.com/Qiskit/qiskit-terra/issues/8446>` for more details. |
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.
Can you please describe the bug in a bit more details here? You can link to the issue but it's good to have a quick summary here. If you write :func: ~Qiskit.tools.visualization.plot_state_hinton
, when the release notes are rendered to the webpage, it would automatically link to the function documentation.
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 the help. I removed the "issues" section and added more details to "fixes".
I corrected the ylim part which was a mistake introduced same PR that caused the issue this PR (8447) is trying to fix by #4811. 4811 mistakenly did When @wyqian1027 corrected |
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 a lot for the fix. Congrats for getting your first PR merged! Hope you can continue making contributions to Qiskit. If you need any help in the future, feel free to reach out to me on GitHub or Qiskit Slack.
Thank you! I will do my best. |
Looks like CI failed due to server errors. Can we trigger the CI to run again? @mtreinish |
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'm concerned about the change in ordering the outputs here. It's not simply a style choice (and even if it were, we already picked a convention, and it's not good for us to change that without a very good reason). The original form makes the Hinton plot resemble the standard matrix order, which makes it easier to read.
@jakelishman I reverted the y-axis direction in 4b43d59. It should be the same as the original direction. |
Related to that, currently the hinton plot seems to plot the matrix transversely. Is that the expected behaviour? |
I reverted the y-axis direction in 4b43d59. It should be the same as the original direction. Do you think the PR is good for merging? |
The state labels in `plot_state_hinton` did not align with the correct matrix entries. This also updates the plot to display entries in the natural "matrix" ordering, i.e. the same way that Numpy would display the matrix if directly printed. Previously, it was effectively a transpose of what it should have been, with incorrect labels.
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.
Sorry for the major delay here!
I fixed up the bit labels to match up with Qiskit's conventions, and so that DensityMatrix.from_label(...)
will now look "the same" whether you print out its data
matrix, or plot it on the Hinton plot. For example:
In [1]: from qiskit.visualization import plot_state_hinton
...:
...: arr = np.array([[1, 0, 0, 0], [0, 0, np.exp(1j * np.pi/4), 0], [0, np.exp(1j * 5*np.pi/4), 0, 0], [0, 0, 0, 1]])
...: plot_state_hinton(arr)
...: arr
Out[1]:
array([[ 1. +0.j , 0. +0.j , 0. +0.j , 0. +0.j ],
[ 0. +0.j , 0. +0.j , 0.70710678+0.70710678j, 0. +0.j ],
[ 0. +0.j , -0.70710678-0.70710678j, 0. +0.j , 0. +0.j ],
[ 0. +0.j , 0. +0.j , 0. +0.j , 1. +0.j ]])
now gives
Previously, the squares in the middle would be transposed relative to how the matrix prints, which is confusing (but what Matplotlib's documentation does, at least at the time of writing, which is where this function originally came from).
@Mergifyio requeue |
❌ This pull request head commit has not been previously disembarked from queue. |
@Mergifyio refresh |
✅ Pull request refreshed |
* fix hinton visualization bug * added release note for fix-hinton-bug * remove issues and add more details * correct set ylim * Fix display and labelling of Hinton plot The state labels in `plot_state_hinton` did not align with the correct matrix entries. This also updates the plot to display entries in the natural "matrix" ordering, i.e. the same way that Numpy would display the matrix if directly printed. Previously, it was effectively a transpose of what it should have been, with incorrect labels. * Fixup release note Co-authored-by: Junye Huang <h.jun.ye@gmail.com> Co-authored-by: Jake Lishman <jake.lishman@ibm.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> (cherry picked from commit a53fc9a)
* fix hinton visualization bug * added release note for fix-hinton-bug * remove issues and add more details * correct set ylim * Fix display and labelling of Hinton plot The state labels in `plot_state_hinton` did not align with the correct matrix entries. This also updates the plot to display entries in the natural "matrix" ordering, i.e. the same way that Numpy would display the matrix if directly printed. Previously, it was effectively a transpose of what it should have been, with incorrect labels. * Fixup release note Co-authored-by: Junye Huang <h.jun.ye@gmail.com> Co-authored-by: Jake Lishman <jake.lishman@ibm.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> (cherry picked from commit a53fc9a) Co-authored-by: WQ <42972544+wyqian1027@users.noreply.github.com>
@jakelishman Thanks for following up and checking it thoroughly! |
Summary
Fixes #8446, fixes #8324
Details and comments
I corrected
ax2.set_xlim([0, lx]) ax2.set_ylim([ly, 0])
and added
fig.tight_layout()
Tests are done on my computer to cover the change so it looks aligned:
And the spacing is fixed for a larger density matrix:
One thing is that now the diagonal of the density matrix runs from lower left to upper right, which is changed from the previous function, but it is just a style thing.