示例#1
0
def bloch_from_dataframe(df, fig, axes):
    """
    Plot Bloch sphere
    :param df: pd.DataFrame
    :param axes:
    :return:
    """
    bloch = Bloch(fig=fig, axes=axes)

    bloch.vector_color = plt.get_cmap('viridis')(np.linspace(0, 1, len(df)))

    bloch.add_states([
        Qobj([[row.Jxx, row.beta + 1j * row.gamma],
              [row.beta - 1j * row.gamma, row.Jyy]])
        for _, row in df.iterrows()
    ])

    bloch.make_sphere()
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Jul 30 12:26:48 2019

@author: banano
"""
#
from qutip import Bloch, Bloch3d
b1 = Bloch()
vec = [0,1,0]
b1.add_vectors(vec)
b1.vector_color = ['k']
b2 = Bloch()
vec = [0,0,1]
b2.add_vectors(vec)
b2.vector_color = ['r']
b2.show()
b1.show()

示例#3
0
    def bloch_plot2(self,
                    filename,
                    save=False,
                    vecList=[],
                    vecColour=[],
                    view=[190, 10],
                    points=None,
                    folder=False,
                    fig=False,
                    ax=False):
        """
        Plot the current state on the Bloch sphere using
        qutip. 
        """
        if points is None:
            # convert current state into density operator
            rho = np.outer(self.state.H, self.state)
            # get Bloch vector representation
            points = self.get_bloch_vec(rho)
            # Can only plot systems of dimension 2 at this time
            assert len(
                points
            ) == 3, "System dimension must be spin 1/2 for Bloch sphere plot"

        # create instance of 3d plot
        if not fig or not ax:
            bloch = Bloch(figsize=[9, 9], view=view)
        else:
            bloch = Bloch(fig=fig, axes=ax, view=view)
        # add state
        bloch.add_points(points)
        # bloch.zlabel = [r'$\left|+z\right>$',r'$\left|-z\right>$']
        bloch.zlabel = [r'$\ket{+_z}$', r'$\ket{-_z}$']
        # bloch.ylabel = [r'$\ket{+_y}$',r'$\ket{-_y}$']
        # bloch.ylabel = [r'$\ket{+_y}$',r'$\ket{-_y}$']
        # print(vecList.shape)

        # add vectors
        if vecList.shape[1] == 3:
            if len(vecColour) >= vecList.shape[0] and len(vecColour) > 0:
                bloch.vector_color = vecColour
            else:
                bloch.vector_color = ['#CC6600', 'royalblue', 'r', 'm', 'g']
            bloch.add_vectors(vecList)
        # add field vector
        # bloch.add_vectors([1,0,0.15])
        # bloch.add_vectors([0,0,1])
        # bloch.add_vectors([1,0,0])

        # render bloch sphere
        if not fig or not ax:
            bloch.render()
        else:
            # bloch.render(fig = fig, axes = ax)
            bloch.render(fig=fig)

        # save output
        if save is True:
            if not folder:
                folder = 'C:/Users/Boundsy/Desktop/Uni Work/PHS2360/Sim Results/'
            print('Bloch plot saved to ' + str(folder))
            path1 = folder + str(filename) + '.png'
            path2 = folder + str(filename) + '.pdf'
            bloch.fig.savefig(path1, dpi=800, transparent=True)
            bloch.fig.savefig(path2, dpi=800, transparent=True)

        # return axes for annotations
        return bloch.fig, bloch.axes