示例#1
0
    def bloch_field(self, time):
        """
        Plot magnetic field vector normalised to the bloch sphere
        """
        # seperate coordinates into axis set
        xb = self.fields[0](time)
        yb = self.fields[1](time)
        zb = self.fields[2](time)
        # add to list and normalise
        points = [list(xb), list(yb), list(zb)]
        sqsum = 0.0
        for i, point in enumerate(points[0]):
            # compute magnitude and store largest value
            sqsum_test = np.sqrt(points[0][i]**2 + points[1][i]**2 +
                                 points[2][i]**2)
            if sqsum_test > sqsum:
                sqsum = sqsum_test

        points = points / sqsum

        # create Bloch sphere instance
        bloch = Bloch()
        # add points and show
        bloch.add_points(points)
        bloch.show()
def plot_quantum_state(amplitudes):
    """
    Thin function to abstract the plotting on the Bloch sphere.
    """
    bloch_sphere = Bloch()
    vec = get_vector(amplitudes[0], amplitudes[1])
    bloch_sphere.add_vectors(vec)
    bloch_sphere.show()
    bloch_sphere.clear()
示例#3
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 PlotStateAnalyzer(InputState, hwpAngle, qwpAngle):
    QWPstate = QWP(qwpAngle) @ InputState
    OutputState = HWP(hwpAngle) @ QWP(qwpAngle) @ InputState
    pntsX = [
        StateToBloch(QWP(th) @ InputState)[0] for th in arange(0, pi, pi / 64)
    ]
    pntsY = [
        StateToBloch(QWP(th) @ InputState)[1] for th in arange(0, pi, pi / 64)
    ]
    pntsZ = [
        StateToBloch(QWP(th) @ InputState)[2] for th in arange(0, pi, pi / 64)
    ]
    pnts = [pntsX, pntsY, pntsZ]
    pntsX2 = [
        StateToBloch(HWP(th) @ QWP(qwpAngle) @ InputState)[0]
        for th in arange(0, pi, pi / 64)
    ]
    pntsY2 = [
        StateToBloch(HWP(th) @ QWP(qwpAngle) @ InputState)[1]
        for th in arange(0, pi, pi / 64)
    ]
    pntsZ2 = [
        StateToBloch(HWP(th) @ QWP(qwpAngle) @ InputState)[2]
        for th in arange(0, pi, pi / 64)
    ]
    pnts2 = [pntsX2, pntsY2, pntsZ2]
    bsph = Bloch()
    bsph.add_points(pnts)
    bsph.add_points(pnts2)
    bsph.add_vectors(StateToBloch(OutputState))
    bsph.add_vectors(StateToBloch(InputState))
    bsph.add_vectors(StateToBloch(QWPstate))
    return bsph.show()
示例#5
0
    def field_plot(self, params, bloch=[False, 1]):
        """
        Plots the signal components given simulation parameters over the specified time doman
        """

        # get time varying fields and simulation data
        time, cparams, Bfields = field_get(params=params)

        # plot magnetic field vector on Bloch sphere
        if bloch[0]:
            Bfields = Bfields[::bloch[1], :]
            # normalise each magnetic field vector
            for i in range(len(Bfields)):
                norm = np.sqrt(Bfields[i, 0]**2 + Bfields[i, 1]**2 +
                               Bfields[i, 2]**2)
                Bfields[i, 0] /= norm
                Bfields[i, 1] /= norm
                Bfields[i, 2] /= norm

            # extract x,y,z fields
            Bx = Bfields[:, 0]
            By = Bfields[:, 1]
            Bz = Bfields[:, 2]

            # define bloch object
            b = Bloch()
            b.add_points([Bx, By, Bz])
            b.show()

        else:
            # plot fields
            fig, ax = plt.subplots(nrows=3, ncols=1, sharex=True, sharey=False)
            for i, row in enumerate(ax):
                # plot each component, skipping zero time value
                row.plot(time, Bfields[:, i])
                row.set_title("Field vector along {} axis".format(
                    ['x', 'y', 'z'][i]))

            plt.ylabel('Frequency (Hz)')
            plt.xlabel("Time (s)")
            #plt.ylabel("Ampltiude ($Hz/Gauss$)")
            plt.show()
示例#6
0
    def bloch_plot(self, points=None):
        """
        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
        bloch = Bloch(figsize=[9, 9])
        # add state
        bloch.add_points(points)
        bloch.add_vectors([0, 0, 1])
        bloch.render(bloch.fig, bloch.axes)
        bloch.fig.savefig("bloch.png", dpi=600, transparent=True)
        bloch.show()
def PlotStateQWP(InputState, qwpAngle):
    OutputState = QWP(qwpAngle) @ InputState
    pntsX = [
        StateToBloch(QWP(th) @ InputState)[0] for th in arange(0, pi, pi / 64)
    ]
    pntsY = [
        StateToBloch(QWP(th) @ InputState)[1] for th in arange(0, pi, pi / 64)
    ]
    pntsZ = [
        StateToBloch(QWP(th) @ InputState)[2] for th in arange(0, pi, pi / 64)
    ]
    pnts = [pntsX, pntsY, pntsZ]
    bsph = Bloch()
    bsph.add_points(pnts)
    bsph.add_vectors(StateToBloch(OutputState))
    bsph.add_vectors(StateToBloch(InputState))
    return bsph.show()
#!/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()

示例#9
0
# um nicht immer numpy schreiben zu muessen
import numpy as np

# importieren der Python eigene Mathematik Library
import math

# Beispielseite zu qutip
# http://qutip.org/docs/3.1.0/guide/guide-bloch.html

# %% -1-
# Bloch() erzeugt eine Bloch
# mit b verweisen wir spaeter auf diese
b = Bloch()

# b.show() zeigt die aktuelle Blochkugel an
b.show()
print('-1-')
input('Press ENTER to continue.'
      )  # Ansonst wird Fenster sofort wieder geschlossen bzw. ueberschrieben.

# %% -2-
# hinzufuegen eines Vektor
#  x,y,z
v = [1, 0, 0]  # dazu geben wir einen Vektor in die x-Richtung an
b.add_vectors(
    v)  # mit b.add_vectors wird der Vektor v der Blochkugel hinzugefuegt
b.show()
print('-2-')
input('Press ENTER to continue.')

# %% -3-
示例#10
0
def PlotBlochState(state):
    bsph = Bloch()
    bsph.add_vectors(StateToBloch(state))
    return bsph.show()