Ejemplo n.º 1
0
 def render_back(self):
     old_plot_front = self.plot_front
     self.plot_front = lambda: None
     try:
         Bloch.render(self)
     finally:
         self.plot_front = old_plot_front
Ejemplo n.º 2
0
def bloch(ex_values, tlist, ops):
    """Plots expectation values of sx, sy and sz on the Bloch sphere.
    If one of these operators is not calculated, zeros are passed for that operator.
    
    Parameters:
    -----------
    ex_values : qutip.Result.expect or list
                expectation values per operator
    tlist : list, or numpy array
            times at which expectation values are evaluated
    ops : list
          operators of which the expectation values are found in ex_values
    
    Remark:
    -------
    Does not plot a color bar yet. The lines from the QuTiP tutorial (https://nbviewer.jupyter.org/github/qutip/qutip-notebooks/blob/master/examples/bloch_sphere_with_colorbar.ipynb), commented out down here, give an error which I have not been able to solve yet.
    """
    
    if 'sx' in ops:
        sx_exp = ex_values[ops.index('sx')]
    elif 'sx' not in ops:
        sx_exp = np.zeros(len(list(tlist)))
    if 'sy' in ops:
        sy_exp = ex_values[ops.index('sy')]
    elif 'sy' not in ops:
        sy_exp = np.zeros(len(list(tlist)))
    if 'sz' in ops:
        sz_exp = ex_values[ops.index('sz')]
    elif 'sz' not in ops:
        sz_exp = np.zeros(len(list(tlist)))
    
    b = Bloch()
    b.add_points([sx_exp, sy_exp, sz_exp], 'm')
    
    nrm = Normalize(-2,10)
    colors = cm.hot(nrm(tlist))
    b.point_color = list(colors)
    b.point_marker = ['o']
    # TODO: Plot color bar
#     left, bottom, width, height = [0.98, 0.05, 0.05, 0.9]
#     ax2 = b.fig.add_axes([left, bottom, width, height])
#     ColorbarBase(ax2, cmap=cm.hot, norm=nrm, orientation='vertical')
    b.show()
Ejemplo n.º 3
0
 def plot_arc_test(self, fig, *args, **kw):
     b = Bloch(fig=fig)
     b.add_arc(*args, **kw)
     b.render()
Ejemplo n.º 4
0
 def plot_vector_test(self, fig, vector_kws):
     b = Bloch(fig=fig)
     for kw in vector_kws:
         vectors = kw.pop("vectors")
         b.add_vectors(vectors, **kw)
     b.render()
Ejemplo n.º 5
0
 def plot_point_test(self, fig, point_kws):
     b = Bloch(fig=fig)
     for kw in point_kws:
         points = kw.pop("points")
         b.add_points(points, **kw)
     b.render()
Ejemplo n.º 6
0
 def plot_line_test(self, fig, *args, **kw):
     b = Bloch(fig=fig)
     b.add_line(*args, **kw)
     b.render()
Ejemplo n.º 7
0
 def test_arc_errors(self, start, end, err_msg):
     b = Bloch()
     with pytest.raises(ValueError) as err:
         b.add_arc(start, end)
     assert str(err.value) == err_msg
Ejemplo n.º 8
0
from qutip.bloch import Bloch
"""
Import the Bloch Sphere from the Bloch Module of the QuTiP.
"""

from matplotlib import pyplot as plt

from mpl_toolkits.mplot3d import Axes3D

figure, axes = plt.subplots(figsize=(5, 5), subplot_kw=dict(projection='3d'))

#axes.axis("square")

bloch_sphere_3d = Bloch(fig=figure, axes=axes)

bloch_sphere_3d.xlabel[0] = "$\\left|+\\right>$"
bloch_sphere_3d.xlabel[1] = "$\\left|-\\right>$"

bloch_sphere_3d.ylabel[0] = "$\\left|+i\\right>$"
bloch_sphere_3d.ylabel[1] = "$\\left|-i\\right>$"

bloch_sphere_3d.zlabel[0] = "$\\left|0\\right>$"
bloch_sphere_3d.zlabel[1] = "$\\left|1\\right>$"

bloch_sphere_3d.render(fig=figure, axes=axes)  # render to the correct subplot

# set title for the axis
axes.set_title('TITLE goes here', y=1.1, fontsize=20)

# You can anything else you want to the axis as well!
#ax.annotate('TEXT', xy=(0.1, 0.9), xytext=(0.1, 0.7), xycoords='axes fraction',