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 animate_bloch(vectors, duration=0.1, save_all=False):
    numberOfLoops = 1  #Enter '1' to apply only ONE mode [Excitation or Relaxation] or '2' to to apply only BOTH modes [Excitation and Relaxation] starting with the selected mode
    if numberOfLoops == 1:
        maxAngle = 2 * np.pi
    elif numberOfLoops == 2:
        maxAngle = 4 * np.pi
    mode = 1  #Enter '0' to activate Excitation Mode or '1' to activate Relaxation Mode
    omega = np.pi / 6  #Enter the angular frequency
    z = 0
    sqAngle = np.pi / 2
    a = 5
    vectorM = Bloch()
    # vectorM.view = [90,90] #Activate this line to view magnetization’s trajectory on x-y plane
    images = []
    for t in np.arange(omega, maxAngle, 0.1):
        if mode == 0:
            z = np.pi / 2 * np.sin(t / (4))
            if t == 2 * np.pi:
                mode = 1
        elif mode == 1:
            z = np.pi / 2 * np.cos(t / (4))
            if t == 2 * np.pi:
                mode = 0
        else:
            pass
        vectorM.clear()
        vectorM.add_vectors([
            np.sin(omega) * np.cos(t),
            np.sin(omega) * np.sin(t),
            np.cos(omega)
        ])
        vectorM.add_vectors(
            [np.sin(z) * np.cos(a * t),
             np.sin(z) * np.sin(a * t),
             np.cos(z)])
        vectorM.add_vectors([
            np.sin(sqAngle) * np.cos(t),
            np.sin(sqAngle) * np.sin(t),
            np.cos(sqAngle)
        ])
        filename = 'temp_file.png'
        vectorM.save(filename)
        images.append(imageio.imread(filename))
    imageio.mimsave('bloch_anim.gif', images, duration=duration)
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
b.add_states([x, y])
b.add_states(z)
b.show()
print('-7-')
input('Press ENTER to continue.')

# %% -8-
b.clear()
# genauso kann die Exponentialfunktion und Sinus, Cosinus verwendet werden
# BSP 5 vom 5. Nov
psi = (np.cos(np.pi / 4) * up +
       np.sin(np.pi / 4) * np.exp(-1j * np.pi / 4) * down).unit()
b.add_states(psi)
b.show()
b.save('bloch.png')  # erzeug ein Bild des aktuellen Zustandes
print('-8-')
input('Press ENTER to continue.')

# Um das Beipsiel 5 vom 5 Nov als Bild zu erhalten, wuerden folgende 7 Zeile ausreichen:
# from qutip import Bloch, basis
# import numpy as np
# b = Bloch()
# psi = (np.cos(np.pi/4)*up + np.sin(np.pi/4)*np.exp(-1j*np.pi/4)*down).unit()
# b.add_states(psi)
# b.show()
# b.save('bloch_5a.png')

# %%
print(b)  # zeigt die Einstellungsmoeglichkeiten an
# siehe: http://qutip.org/docs/4.1/guide/guide-bloch.html#bloch-class-options
    # 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)