def draw_sphere_zenith(zenith_points, hv_points, root):
    b = Bloch()
    b.point_color = ['m', 'k', 'g', 'b', 'w', 'c', 'y', 'r']
    b.zlabel = ['$z$', '']
    b.point_marker = ['o']
    b.point_size = [30]
    b.frame_width = 1.2
    fig = plt.figure(figsize=(20, 20))
    b.fig = fig

    x = (basis(2, 0) + (1 + 0j) * basis(2, 1)).unit()
    y = (basis(2, 0) + (0 + 1j) * basis(2, 1)).unit()
    z = (basis(2, 0) + (0 + 0j) * basis(2, 1)).unit()
    b.add_states([x, y, z])

    for i in range(len(zenith_points)):
        # Transform xyz to zxy coordinates
        tmp1 = np.array(
            [zenith_points[i][2], zenith_points[i][0], zenith_points[i][1]])
        tmp2 = np.vstack(
            [hv_points[i][:, 2], hv_points[i][:, 0], hv_points[i][:, 1]]).T
        tmp = np.vstack([tmp1, -tmp1, tmp2]).T
        b.add_points(tmp)

    # tmp1 = np.array([zenith_points[-1][2], zenith_points[-1][0], zenith_points[-1][1]])
    # tmp = np.array([tmp1, -tmp1]).T
    # b.add_points(tmp)
    name = os.path.join(root, 'zenith_on_sphere.jpg')
    b.save(name=name)
示例#2
0
def create_gif(qstates, qstart, qtarget, name):
    '''
    Inputs:
    # qstates: list of states as np.arrays
    # qstart, qtarget: respectively the target ans start state
    # name: name of the output gif
    '''

    b = Bloch()
    duration = 5  #framerate
    images = []

    for (qstate, i) in zip(qstates, range(0, len(qstates))):

        b.clear()

        b.point_color = "r"  # options: 'r', 'g', 'b' etc.
        b.point_marker = ['o']
        b.point_size = [40]

        b.add_states(qutip_qstate(qstart))
        b.add_states(qutip_qstate(qtarget))
        for previous in range(i):
            b.add_states(qutip_qstate(qstates[previous]),
                         "point")  #plots previous visited states as points
        b.add_states(qutip_qstate(qstate))
        filename = 't.png'
        b.save(filename)
        images.append(imageio.imread(filename))

    imageio.mimsave(name, images, 'GIF', fps=duration)
def draw_consensus_rectified_sphere(hv_points, root):
    b = Bloch()
    b.point_color = ['m', 'k', 'g', 'b', 'w', 'c', 'y', 'r']
    b.zlabel = ['$z$', '']
    b.point_marker = ['o']
    b.point_size = [80]
    b.frame_width = 1.2
    fig = plt.figure(figsize=(20, 20))
    b.fig = fig

    x = (basis(2, 0) + (1 + 0j) * basis(2, 1)).unit()
    y = (basis(2, 0) + (0 + 1j) * basis(2, 1)).unit()
    z = (basis(2, 0) + (0 + 0j) * basis(2, 1)).unit()
    b.add_states([x, y, z])
    for i in range(len(hv_points)):
        # Transform xyz to zxy coordinates
        tmp2 = np.vstack(
            [hv_points[i][:, 2], hv_points[i][:, 0], hv_points[i][:, 1]]).T
        tmp = tmp2.T
        b.add_points(tmp)

    # b.add_points([ 0.99619469809174555, 0.087155742747658166, 0])
    # b.add_points([0.99619469809174555, -0.087155742747658166, 0])
    # b.add_points(tmp)
    name = os.path.join(root, 'consensus_zenith_on_rectified_sphere.jpg')
    b.save(name=name)
示例#4
0
    def bloch_plot(self, points=None, F=None):
        """
        Plot the current state on the Bloch sphere using
        qutip. 
        """
        # create instance of 3d plot
        bloch = Bloch(figsize=[9, 9])
        bloch.add_vectors([0, 0, 1])
        bloch.xlabel = ['$<F_x>$', '']
        bloch.ylabel = ['$<F_y>$', '']
        bloch.zlabel = ['$<F_z>$', '']
        if self.spin == 'half':
            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
            bloch = Bloch(figsize=[9, 9])
        elif self.spin == 'one':
            #points is list of items in format [[x1,x2],[y1,y2],[z1,z2]]
            if points is None:
                points = [getStars(self.state)]
            bloch.point_color = ['g', 'r',
                                 'b']  #ensures point and line are same colour
            bloch.point_marker = ['o', 'd', 'o']
            #bloch.point_color  = ['g','r'] #ensures point and line are same colour
            #bloch.point_marker = ['o','d']
            for p in points:
                bloch.add_points([p[0][0], p[1][0], p[2][0]])
                bloch.add_points([p[0][1], p[1][1], p[2][1]])
                bloch.add_points(p, meth='l')
            '''

            bloch.point_color = ['b','b'] #ensures point and line are same colour
            bloch.point_marker = ['o','o']
            for p in points:
                bloch.add_points(p)
                bloch.add_points(p, meth='l')
            '''
        # add state
        #bloch.render(bloch.fig, bloch.axes)
        #bloch.fig.savefig("bloch.png",dpi=600, transparent=True)
        bloch.show()
def draw_center_hvps_rectified_sphere(hv_points, root):
    b = Bloch()
    b.point_color = ['m', 'k', 'g', 'b', 'w', 'c', 'y', 'r']
    b.zlabel = ['$z$', '']
    b.point_marker = ['o']
    b.point_size = [80]
    b.frame_width = 1.2
    fig = plt.figure(figsize=(20, 20))
    b.fig = fig

    x = (basis(2, 0) + (1 + 0j) * basis(2, 1)).unit()
    y = (basis(2, 0) + (0 + 1j) * basis(2, 1)).unit()
    z = (basis(2, 0) + (0 + 0j) * basis(2, 1)).unit()
    b.add_states([x, y, z])
    for i in range(len(hv_points)):
        # Transform xyz to zxy coordinates
        tmp1 = np.array([hv_points[i][2], hv_points[i][0], hv_points[i][1]])
        tmp2 = np.vstack([tmp1, -tmp1]).T
        tmp = tmp2
        b.add_points(tmp)

    name = os.path.join(root, 'consensus_hvps_center_on_rectified_sphere.jpg')
    b.save(name=name)
示例#6
0
 def maj_vid(self, points):
     #takes screenshots of majorana stars over time to produce vid
     if points is None:
         points = [getStars(self.state)]
     i = 0
     for p in points:
         bloch = Bloch(figsize=[9, 9])
         bloch.xlabel = ['$<F_x>$', '']
         bloch.ylabel = ['$<F_y>$', '']
         bloch.zlabel = ['$<F_z>$', '']
         bloch.point_color = ['g', 'r',
                              'b']  #ensures point and line are same colour
         bloch.point_marker = ['o', 'd', 'o']
         bloch.add_points([p[0][0], p[1][0], p[2][0]])
         bloch.add_points([p[0][1], p[1][1], p[2][1]])
         bloch.add_points(p, meth='l')
         bloch.render(bloch.fig, bloch.axes)
         bloch.fig.savefig(
             "bloch" + str(i).zfill(int(np.ceil(np.log10(len(points))))) +
             ".png",
             dpi=600,
             transparent=False)
         i += 1
    # point2 = np.array([0., 0., 1.])
    #
    #
    # # pitch = np.arctan(point1[2] / point1[1])
    # # roll = - np.arctan(point1[0] / np.sign(point1[1]) * np.hypot(point1[1], point1[2]))
    #
    #
    # ## print(R_pitch(pitch).dot(R_roll(roll).dot(np.array([0, 1, 0]))))
    #
    #
    # hl = np.array([[0., 774.0801861], [1600., 825.23757385], [np.nan, np.nan]])
    # hl_homo = np.array([np.hstack([hl[0] - 800, 800]), np.hstack([hl[1] - 800, 800])])
    #
    #
    # hvps = np.array([[830.73055179,800.6414392],[1158.09074533, 811.10824692]])
    # img = Image.open('/home/zhup/Desktop/Pano/Pano_hl_z_vp/3_im_hl.jpg')
    # draw = ImageDraw.Draw(img)
    # draw.line([tuple(hvps[0]), tuple(hvps[1])], width=6, fill='yellow')
    # img.save(os.path.join(root, 'render_part3.jpg'))

    b = Bloch()
    b.point_color = ['m', 'k', 'g', 'b', 'w', 'c', 'y', 'r']
    b.zlabel = ['$z$', '']
    b.point_marker = ['o']
    b.point_size = [3]
    b.frame_width = 0.5
    fig = plt.figure(figsize=(20, 20))
    b.fig = fig
    name = os.path.join('zenith_on_sphere.jpg')
    b.save(name=name)