Interactive viewer#
Interactive Plotly Bloch spheres: rotate and zoom with the mouse, play animations with a slider,
export to a standalone HTML file, and update live in Jupyter (LiveBloch).
Examples
>>> from qiskit import QuantumCircuit
>>> from quantum_mind.viz import circuit_trajectory, animate_bloch, save_html, LiveBloch
>>> qc = QuantumCircuit(2); qc.h(0); qc.cx(0, 1)
>>> save_html(animate_bloch(circuit_trajectory(qc)), 'bell.html')
>>> live = LiveBloch(2).show()
>>> live.play(circuit_trajectory(qc), fps=30)
Classes
Real-time Bloch spheres. |
Functions
Interactive figure with one sphere per qubit. |
|
Animated interactive figure with play and pause buttons and a slider labelled with the frame labels. |
|
Write a standalone HTML file (Plotly JavaScript loaded from its CDN). |
- class LiveBloch(n_qubits=1, names=None, theme='dark', backend='auto', trail=True, title=None)[source]#
Bases:
objectReal-time Bloch spheres.
In Jupyter (with ipywidgets and anywidget) the figure is a Plotly
FigureWidgetupdated in place; elsewhere a Matplotlib window is redrawn. Feed it states, Bloch vectors or whole trajectories.- Parameters:
Examples
>>> live = LiveBloch(2).show() >>> for state in states: ... live.update(state) >>> live.play(circuit_trajectory(qc), fps=30)
- show()[source]#
Display the spheres (a widget in Jupyter, a window elsewhere).
- Returns:
LiveBloch–self.
- bloch_figure(vectors, names=None, theme='dark', title=None, height=460)[source]#
Interactive figure with one sphere per qubit.
- animate_bloch(traj, theme='dark', fps=30, trail=True, title=None, height=500, max_frames=400)[source]#
Animated interactive figure with play and pause buttons and a slider labelled with the frame labels.
- Parameters:
- Returns:
plotly.graph_objects.Figure