-
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
Adding a new argument to plot_state_qsphere to visualize all the possible states on qsphere when set to True #5607
Conversation
…ible states on qsphere when set to True
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 pushing a PR, I took a quick look and personally I tend to agree with @aasfaw that I feel this ends up making a more cluttered visualization. But, it's fine to add a flag to make this an opt-in view for people who find it useful. But, before this is ready I think we need to provide some more detail in the docs about the potential limitations with the flag, especially with more than a couple qubits. I also think there is a bug in showing the state phase for a label.
show_all_state_labels (bool): An optional boolean indicating whether to | ||
show labels for all basis states. |
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 probably need to provide more guidance on this option to the documentation here. This flag really isn't desirable with more than a few qubits. For example I just passed in a 5 qubit random state to the drawer and set this flag and it returned:
which is too cluttered. We probably should mention that this defaults false, and that with larger qubit counts (maybe >3 or something like that) the number of state labels can clutter the output.
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 @mtreinish for reviewing this PR. Yes, you are absolutely right, this argument would clutter the image for more than 3 qubits. That is why I marked it 'False' by default. Only motive of introducing this new argument is to let the interested user know visually where on the qsphere are all the states located and which ones out of all possible states have magnitude. 2D view is a bit messy but may be a 3D view would carry this argument well without clutter.
I will make the changes in documentation as per your suggestion, so that the user is well aware of what he might encounter.
if show_state_phases: | ||
element_angle = (np.angle(state[i]) + (np.pi * 4)) % (np.pi * 2) | ||
if use_degrees: | ||
element_text += '\n$%.1f^\\circ$' % (element_angle * 180/np.pi) | ||
else: | ||
element_angle = pi_check(element_angle, ndigits=3).replace('pi', '\\pi') | ||
element_text += '\n$%s$' % (element_angle) |
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.
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 wasn't able to replicate this bug, could you please help me understand when you got this? I tried a random 5-qubit circuit with both arguments set to true, and got the following:
This is cluttered for sure but does not look over written like yours. If I could understand what gave you that bug, I will try to resolve it too within this PR. Thanks.
…skit-terra into addnewargument Updated documentation for new argument
Superseded by #6596. |
Closing as superseded. |
*** This PR is being carried forward to #6596 with resolved conflicts, no test failures and updated code of state_visualization.py ***
UPDATE #1:
I tried to do a PR (#5177) on 3 October 2020, but it was failing some tests. Also visualization code has changed with new releases. So, this time I am trying afresh after performing all local tests. Hope it proves helpful to the community.
Motivation
I ran into this situation where only some states were visible while visualizing the qsphere few months back and asked help here. It was then that @aasfaw motivated me to do something like this. Many thanks to him. See the conversation here.
Summary
The previous
show_state_labels
argument is meant to show labels for only weighted states. When used withshow_state_phases=True
the weighted states displayed their phase values. The states with 0 weights were not given the labels.The new 'optional' argument
show_all_state_labels
which is added with this PR shows all possible state labels when set to True. This Boolean variable which is false by default, aims at letting the end-user distinguish visually on the q-sphere between the states having zero weights and those having non-zero weights. The argument is kept optional to ensure that it is set to true only if the user wants to display all possible state labels for any particular circuit, the default view would show labels (and phases) for non-zero states only.The new argument works well with
show_state_phases=True
and shows phase values for all possible state labels.The test cases given below are performed for two circuits-one with 2 qubits and other with 3 qubits. Both the circuits were deliberately made to produce weights for half of the possible states, to notice the working of new argument for states with zero-weights. Snapshots show the default view and the new argument's output.
Details and comments
Case 1: Tested for two-qubit circuit (clutter possibility is low)
Default:
New Argument:
show_all_state_labels=True
with
show_state_phases=True
Default:
New Argument:
show_all_state_labels=True, show_state_phases=True
Case 2: Tested for three-qubit circuit (clutter possibility is medium-high)
Default:
New Argument:
with
show_state_phases=True
Default:
New Argument:
CAUTION: Users must note that this new argument might give you a cluttered output in case of qubits>3. That is why the argument's default setting is
False
. This argument must be set toTrue
if and only if user wants to see the positioning of all possible states on the qsphere.