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

Remove autoscale view call from plot_state_hinton #4811

Merged
merged 5 commits into from
Dec 3, 2020

Conversation

mtreinish
Copy link
Member

@mtreinish mtreinish commented Jul 27, 2020

Summary

This commit removes the use of matplotlib's autoscale_view() [1] from
the plot state hinton visualization. This function is truncating the
plot if there are axis that are empty. This is not really necessary for
the hinton function anyway since we have fixed limits on the plots as we
add the ticks based on the shape of the input matrix. However it was
being used to handle boxes on edges of the graph (ie when the top row or
right most edge had a box) that wouldn't be properly centered. This
commit worksaround that by padding both sides of the tick list to ensure
the data is always centered.

Details and comments

[1] https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.autoscale_view.html

Co-authored-by: Christopher J. Wood cjwood@us.ibm.com

Fixes #4249

This commit removes the use of matplotlib's autoscale_view() [1] from
the plot state hinton visualization. This function is truncating the
plot if there are axis that are empty. This is not really necessary for
the hinton function anyway since we have fixed limits on the plots as we
add the ticks based on the shape of the input matrix. However it was
being used to handle boxes on edges of the graph (ie when the top row or
right most edge had a box) that wouldn't be properly centered. This
commit worksaround that by padding both sides of the tick list to ensure
the data is always centered.

Fixes Qiskit#4249

[1] https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.autoscale_view.html
@mtreinish mtreinish added this to the 0.15 milestone Jul 27, 2020
@mtreinish mtreinish requested review from maddy-tod, nonhermitian and a team as code owners July 27, 2020 13:45
@mtreinish mtreinish requested a review from chriseclectic July 27, 2020 14:28
@kdk kdk self-assigned this Jul 28, 2020
1ucian0
1ucian0 previously requested changes Aug 1, 2020
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.

I might be missing something. Here is the output on the branch mtreinish:fix-hinton:

from qiskit import QuantumCircuit, BasicAer, execute, visualization
qc = QuantumCircuit(2)
qc.h(0)
qc.cx(0,1)
qc.z(1)
backend = BasicAer.get_backend('statevector_simulator')
job = execute(qc, backend=backend)
sv = job.result().get_statevector(qc)
visualization.plot_state_hinton(sv)

image

In master, it looks fine:
image

@mtreinish
Copy link
Member Author

Ugh, yeah it looks like everything is off by one now, in that case. I only tested the bug case and it worked fine for that, but clearly this needs more adjustment

@mtreinish mtreinish removed this from the 0.15 milestone Aug 3, 2020
@mtreinish
Copy link
Member Author

With @chriseclectic fix on top of my branch this works fine with the example before:

hinton

so this should be good to go now.

@mtreinish mtreinish requested a review from 1ucian0 November 24, 2020 18:03
@mtreinish mtreinish dismissed 1ucian0’s stale review November 24, 2020 18:03

This has been fixed

@mergify mergify bot merged commit 4cab222 into Qiskit:master Dec 3, 2020
@mtreinish mtreinish deleted the fix-hinton branch December 4, 2020 01:56
@kdk kdk added the Changelog: None Do not include in changelog label Mar 31, 2021
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

plot_state_hinton doesn't plot all real matrix components
4 participants