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

Update qsphere plots to show state labels and phases #4384

Merged
merged 12 commits into from
May 13, 2020
Merged

Update qsphere plots to show state labels and phases #4384

merged 12 commits into from
May 13, 2020

Conversation

aasfaw
Copy link

@aasfaw aasfaw commented May 4, 2020

Summary

Theplot_state_qsphere visualization currently shows quantum states without state labels and phase angles. This makes things difficult to interpret when many basis states are being visualized, especially in the case of multiple qubits. This PR does three things:

-- Adds basis state labels to each blob by default. Can be disabled using argument show_state_labels
-- Adds a show_state_phases argument to enable showing phases next to each basis state
-- Adds a use_degrees argument which allows switching to degrees when desired

Details and comments

Previous:
image

This PR:
image

show_state_phases = True
image

show_state_phases = True, use_degrees = True
image

Copy link
Contributor

@maddy-tod maddy-tod left a comment

Choose a reason for hiding this comment

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

This definitely makes the q sphere easier to understand - thanks! There are a couple of things I think need adjusting but looks good.

qiskit/visualization/state_visualization.py Outdated Show resolved Hide resolved
qiskit/visualization/state_visualization.py Outdated Show resolved Hide resolved
@aasfaw aasfaw requested a review from maddy-tod May 4, 2020 09:55
jaygambetta
jaygambetta previously approved these changes May 4, 2020
@nonhermitian
Copy link
Contributor

Radians should be default. This is what is used everywhere else in qiskit.

@aasfaw
Copy link
Author

aasfaw commented May 4, 2020

Default is now radians

@aasfaw aasfaw requested a review from jaygambetta May 4, 2020 12:46
qiskit/visualization/state_visualization.py Outdated Show resolved Hide resolved
qiskit/visualization/state_visualization.py Show resolved Hide resolved
@aasfaw aasfaw requested a review from taalexander as a code owner May 12, 2020 05:41
@aasfaw aasfaw changed the title Update qsphere plots to show state labels and phases, switch phase to degrees Update qsphere plots to show state labels and phases May 12, 2020
jaygambetta
jaygambetta previously approved these changes May 12, 2020
@mtreinish
Copy link
Member

CI passed here: https://github.com/Qiskit/qiskit-terra/runs/668101667 the checks api looks like it just got stuck. Going to merge this

@mtreinish mtreinish merged commit 8032b32 into Qiskit:master May 13, 2020
@TanveshT
Copy link
Contributor

I wasn't able to use these 2 parameters on the Qiskit version that is loaded on the IBM Q Experience: show_state_labels parameter and show_state_phases.
Qiskit Version in IBM Q Experience = '0.14.1'

@HuangJunye
Copy link
Collaborator

Is this feature included in the latest 0.19.6 version? I am not able to use it.

@mtreinish
Copy link
Member

@HuangJunye This change has not been included in a terra release yet. Qiskit 0.19.6 has terra 0.14.2 which does not have this PR. This will be included in the next release 0.15.0

@HuangJunye
Copy link
Collaborator

@mtrrinish Thanks for the reply! Can’t wait to get this feature. It’s so handy for my presentations! I’ll use the unstable version for now :)

faisaldebouni pushed a commit to faisaldebouni/qiskit-terra that referenced this pull request Aug 5, 2020
Theplot_state_qsphere visualization currently shows quantum states without state labels and phase angles. This makes things difficult to interpret when many basis states are being visualized, especially in the case of multiple qubits. This PR does three things:

-- Adds basis state labels to each blob by default. Can be disabled using argument show_state_labels
-- Adds a show_state_phases argument to enable showing phases next to each basis state
-- Adds a use_degrees argument which allows switching to degrees when desired

* update qsphere plots to show state labels and phases, switch to degrees

* remove whitespace for style and lint tests, add docstrings

* add use_degrees and fix 180 degrees overlap with phase circle

* changed default to radians

* remove stray print, clean up code, default radians

* add release note

* remove prelude section from release notes

Co-authored-by: Jay Gambetta <jay.gambetta@us.ibm.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
@mtreinish mtreinish added the Changelog: New Feature Include in the "Added" section of the changelog label Aug 6, 2020
@pifparfait
Copy link

Hi @mtreinish,

I just read that the mentioned changes are already included. Please could you confirm it?

Many thanks

@aasfaw
Copy link
Author

aasfaw commented Aug 8, 2020

Hi @pifparfait -- the meta package isn't done yet, but the subpackages are. So you probably want to do pip install --upgrade qiskit-terra if you're looking for this change specifically.

@pifparfait
Copy link

@aasfaw got it!!! many thanks!!

@pragyakatyayan
Copy link

pragyakatyayan commented Oct 1, 2020

image
I just updated my qiskit package to 0.21.0. I was trying to plot a q-sphere with all the additions from this PR, but the state |00> and its degree value don't show up in the plot. What am I doing wrong?

@aasfaw
Copy link
Author

aasfaw commented Oct 1, 2020

Hi @pragyakatyayan -- I wrote the PR thinking that the state labels are only shown for states that have non-zero weight. Otherwise, if you show them all the time, then you might end up in situations where the image gets very crowded for many qubits. One option to do what you want is to open a new PR with a new argument to plot_state_qsphere that shows all state labels when set to True

@pragyakatyayan
Copy link

Hi @pragyakatyayan -- I wrote the PR thinking that the state labels are only shown for states that have non-zero weight. Otherwise, if you show them all the time, then you might end up in situations where the image gets very crowded for many qubits. One option to do what you want is to open a new PR with a new argument to plot_state_qsphere that shows all state labels when set to True

Thanks @aasfaw, I am on it. The only doubt left is that in the snapshot I submitted shows the label and phase for state |11>, which had zero weight. The experiment I was doing was aimed at getting |01> and |10> with 50% probabilities each, so both |00> and |11> had zero weights. Hence, I got confused when label/phase representation was visible for |11> but not for |00>. I'll dive into it a little deeper, may be I find what led to this particular case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Changelog: New Feature Include in the "Added" section of the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants