-
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
Include new interactive visualizations #765
Include new interactive visualizations #765
Conversation
|
||
|
||
def iplot_histogram(executions_results, options=None): | ||
""" Create a hinton representation """ |
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 make the docstring more descriptive for all of the new interactive visualization functions? This includes a general description of the function, and more importantly what the args are. For example you have options
which can take slider
, showLegend
, etc. Also what is executions_results
? It should be a density matrix.
Thanks @filemaster. These look really cool. |
The axis font on the city map is really small and hard to read. from qiskit import *
from qiskit.tools.visualization.interactive import *
q = QuantumRegister(1)
c = ClassicalRegister(1)
circ = QuantumCircuit(q, c)
circ.x(q[0])
circ.h(q[0])
result = execute(circ, 'local_statevector_simulator').result()
import numpy as np
v = result.get_statevector()
iplot_cities(np.outer(v, v)) |
The histogram does not display for me, it just shows an empty axis. The same code works for non-interactive from qiskit import *
from qiskit.tools.visualization.interactive import *
q = QuantumRegister(1)
c = ClassicalRegister(1)
circ = QuantumCircuit(q, c)
circ.x(q[0])
circ.h(q[0])
circ.measure(q, c)
result = execute(circ, 'local_qasm_simulator').result()
counts = result.get_counts()
iplot_histogram(counts) |
The
|
On the Qsphere, it seems like the There are several things going on in the picture below. Also, the colors seem to be wrong here. On the Qsphere, the color is supposed to signify the phase. In my example, every basis state has the same zero phase, so they should all be green. from qiskit import *
from qiskit.tools.visualization import *
from qiskit.tools.visualization.interactive import *
q = QuantumRegister(4)
c = ClassicalRegister(4)
circ = QuantumCircuit(q, c)
circ.h(q)
result = execute(circ, 'local_statevector_simulator').result()
import numpy as np
v = result.get_statevector()
iplot_qsphere(np.outer(v,v)) |
Finally, it would be nice to have a similar structure to the functions as the non-interactive visualizations. There, you will see a function This way, we have two simple user-facing functions: If we get the interfaces of the interactive and non-interactive the same, it will be easy to switch between them. |
Thanks @filemaster for the PR and @ajavadia for the review! Looking forward to having the neat interactive visualizations in place. Please note as well that for this particular PR, some decisions (most of them visual, but also some of them arquitectural) involve not only |
import numpy as np | ||
from qiskit.tools.qi.pauli import pauli_singles | ||
try: | ||
from IPython.core.display import display, HTML |
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.
All of these import statements work in a normal IPython terminal env, and thus do not actually check for a notebook env. Instead, try this:
import sys
if ('ipykernel' in sys.modules) and ('spyder' not in sys.modules):
from IPython.core.display import display, HTML
This covers everything except for the edge case of someone using the Qtconsole. But I have yet to run into someone actually using that now that notebooks exist.
@ajavadia, we already added the necessary docstring to understand how to use the functions. About the histogram, the new function can show different execution results in the same graph, so an input array of data is required. Following your example, it must look like:
We know it is a bit more complex than the older version, but the real advantage is the possibility of compare results from different executions:
|
before we merge we should make sure it is the same as the static plots and the static plots are also the same as these. I would also request that the plot defaults to interactive and then the non-interactive is made if the user does not have the extensions. |
@ajavadia. About the iplot_paulivec, the input is not the density matrix. The input for paulivec is similar to the histogram, an array of data objects. Is it possible you were trying to plot a Hinton? Hinton is like the cities but using 2D instead 3D, both of them use the density matrix as an input. |
the puali_vec needs to take in the state matrix. |
i will say the plots look awesome. Great job |
@filemaster the paulivec should have the same input as the other state visualization methods (density matrix). This is the case in non-interactive visualizations as well. from qiskit import *
from qiskit.tools.visualization import *
q = QuantumRegister(2)
c = ClassicalRegister(2)
circ = QuantumCircuit(q, c)
circ.h(q)
result = execute(circ, 'local_statevector_simulator').result()
import numpy as np
v = result.get_statevector()
plot_state(np.outer(v,v), 'paulivec') That's also why i suggested a wrapper method |
@ajavadia , @jaygambetta we are making the required changes to use the density matrix with paulivec visualization and the other issues. Thanks for your comments. |
All issues were fixed. We added a new function called
|
@filemaster thank you. I made some tiny changes mostly in the comments. One comment about the histogram: what does the If you look at the static plotter, there is an option from qiskit import *
from qiskit.tools.visualization import *
from qiskit.tools.visualization.interactive import *
q = QuantumRegister(5)
c = ClassicalRegister(5)
circ = QuantumCircuit(q, c)
circ.h(q)
circ.measure(q,c)
result = execute(circ, 'local_qasm_simulator').result()
c = result.get_counts()
plot_histogram(c, number_to_keep=3) I thought the |
The |
# Conflicts: # CHANGELOG.rst
Thanks you @Tansito and @filemaster. These look great. I'll follow up with another issue to think about how to make these the default when qiskit is run in Jupyter, and to see if we can make the |
* Include new interactive visualizations * Update changelog * Removing Travis warnings... * Adding required extra lines * Improved docstring * Import modified according @nonhermitian comments * Fixed qsphere phase values * Added support in paulivec for density matrix * Changed execution_results by rho for coherence * Modified IPython import. * Added iplot_state function. * Style update * Updated docstring and lint fixes * Update CHANGELOG.rst * Update _iplot_qsphere.py * Update _iplot_hinton.py * Changed showLegend by show_legend to be consistent * Modified rest behaviour by number_to_keep option * Added new imports for histogram * Fixed lint issues * Added required blank line * Updated docstring for histogram process_data function
Summary
Add new interactive visualizations for Jupyter, including:
Details and comments
Closes #718