Exemplo n.º 1
0
def _rand_cqobjevo(N=5):
    tlist = np.linspace(0, 10, 10001)
    tlistlog = np.logspace(-3, 1, 10001)
    O0, O1, O2 = rand_herm(N), rand_herm(N), rand_herm(N)
    cte = [QobjEvo([O0])]
    wargs = [
        QobjEvo([O0, [O1, _f1], [O2, _f2]], args={
            "w1": 1,
            "w2": 2
        }),
        QobjEvo([O0, [O1, "sin(w1*t)"], [O2, "cos(w2*t)"]],
                args={
                    "w1": 1,
                    "w2": 2
                })
    ]
    nargs = [
        QobjEvo([O0, [O1, np.sin(tlist)], [O2, np.cos(2 * tlist)]],
                tlist=tlist),
        QobjEvo([O0, [O1, np.sin(tlistlog)], [O2, np.cos(2 * tlistlog)]],
                tlist=tlistlog),
        QobjEvo([
            O0, [O1, Cubic_Spline(0, 10, np.sin(tlist))],
            [O2, Cubic_Spline(0, 10, np.cos(2 * tlist))]
        ])
    ]
    cqobjevos = cte + wargs + nargs
    base_qobjs = [O0, O1, O2]
    return cqobjevos, base_qobjs
Exemplo n.º 2
0
def _random_QobjEvo(shape=(1, 1), ops=[0, 0, 0], cte=True, tlist=None):
    """Create a list to make a QobjEvo with up to 3 coefficients"""
    if tlist is None:
        tlist = np.linspace(0, 1, 301)
    Qobj_list = []
    if cte:
        Qobj_list.append(Qobj(np.random.random(shape) + \
                              1j*np.random.random(shape)))
    coeff = [[
        _f1, "sin(w1*t)",
        np.sin(tlist),
        Cubic_Spline(0, 1, np.sin(tlist))
    ], [_f2, "cos(w2*t)",
        np.cos(tlist),
        Cubic_Spline(0, 1, np.cos(tlist))],
             [
                 _f3, "exp(w3*t*1j)",
                 np.exp(tlist * 1j),
                 Cubic_Spline(0, 1, np.exp(tlist * 1j))
             ]]
    for i, form in enumerate(ops):
        if form:
            Qobj_list.append(
                [Qobj(np.random.random(shape)), coeff[i][form - 1]])
    return Qobj_list
Exemplo n.º 3
0
def combine_pulses(*pulses):
    """
    Combines multiple pulses into a single pulse.

    Args:
        pulse (object): The pulse shape. 

    Returns:
        obj: combined pulse.

    """

    pulse_all = copy.deepcopy(pulses[0])

    pulse_base_I = np.zeros(shape = len(pulse_all.t_ls)) 
    pulse_base_Q = np.zeros(shape = len(pulse_all.t_ls)) 

    for pulse in pulses:

        pulse_base_I += pulse.I(pulse_all.t_ls)
        pulse_base_Q += pulse.Q(pulse_all.t_ls)

    pulse_all.I = Cubic_Spline(pulse_all.t_ls[0], pulse_all.t_ls[-1], pulse_base_I)
    pulse_all.Q = Cubic_Spline(pulse_all.t_ls[0], pulse_all.t_ls[-1], pulse_base_Q)

    return pulse_all
Exemplo n.º 4
0
    def update_base(self):
        '''Updates the shape of the pulse in I-Q plane.'''

        t_cutoff = self.t_cutoff * self.sigma

        offset = np.exp(-(t_cutoff / 2)**2 / (2 * self.sigma**2))
        norm = 1 - offset

        gaussian_shape = 2 * np.pi * 1e9 * self.amp * np.exp(
            1j * self.phase) * (np.exp(-(self.t_ls - self.t_0)**2 /
                                       (2 * self.sigma**2)) - offset) / norm
        drag_shape = -1j * self.amp * self.drag_coeff * np.exp(
            1j * self.phase) * 2 * (self.t_ls - self.t_0) / (
                2 * self.sigma**2) * np.exp(-(self.t_ls - self.t_0)**2 /
                                            (2 * self.sigma**2)) / norm

        gaussian_pulse = gaussian_shape * (
            (self.t_ls > self.t_0 - t_cutoff / 2) &
            (self.t_ls < self.t_0 + t_cutoff / 2))
        gaussian_pulse += drag_shape * ((self.t_ls > self.t_0 - t_cutoff / 2) &
                                        (self.t_ls < self.t_0 + t_cutoff / 2))

        self.I = Cubic_Spline(self.t_ls[0], self.t_ls[-1],
                              np.real(gaussian_pulse))
        self.Q = Cubic_Spline(self.t_ls[0], self.t_ls[-1],
                              np.imag(gaussian_pulse))

        return
Exemplo n.º 5
0
    def update_base(self):
        '''Updates the shape of the pulse in I-Q plane.'''

        square_shape = 2 * np.pi * 1e9 * self.amp * np.exp(1j * self.phase)
        square_pulse = square_shape * ((self.t_ls > self.t_0 - self.T / 2) &
                                       (self.t_ls < self.t_0 + self.T / 2))

        self.I = Cubic_Spline(self.t_ls[0], self.t_ls[-1],
                              np.real(square_pulse))
        self.Q = Cubic_Spline(self.t_ls[0], self.t_ls[-1],
                              np.imag(square_pulse))

        return
Exemplo n.º 6
0
    def test_05_1_state_with_interp_H(self):
        "sesolve: state with td interp H"
        delta = 1.0 * 2*np.pi   # atom frequency
        psi0 = basis(2, 0)        # initial state
        H1 = 0.5*delta*sigmax()      # Hamiltonian operator
        tlist = np.linspace(0, 20, 200)

        alpha = 0.1
        td_args = {'alpha':alpha}
        tcub = np.linspace(0, 20, 50)
        S = Cubic_Spline(0, 20, np.exp(-alpha*tcub))
        H = [[H1, S]]
        analytic_func = lambda t, args: ((1 - np.exp(-args['alpha']*t))
                                        /args['alpha'])

        self.check_evolution(H, delta, psi0, tlist, analytic_func,
                             td_args=td_args)
Exemplo n.º 7
0
    def setup_Hamiltonian(self, tin, tfn, **kwargs):
        """
        Setup the Hamiltonian and required arguments for call-back functions
        in case of pulse durations e.g. (pi)x and (pi/2)x/y pulses as well as 
        free evolution time. If the pulse is (pi/2)x then sign is always +1
        else if the pulse is (pi)x then sign is either +1 or -1.
        
        The Hamiltonian:
        $\mathcal{H}(t) = \frac{\Lambda_\perp}{2}\left\{\cos\varphi\sigma_x
        - \sin\varphi\sigma_y\right\} + \frac{\Lambda_\perp}{2}\cos\left(2\omega_{ge}t
        + \varphi\right)\sigma_x + \frac{\Lambda_\perp}{2}\sin\left(2\omega_{ge}t 
        + \varphi\right)\sigma_y - \Lambda_z\cos\left(\omega_{ge}t 
        + \varphi\right)\sigma_z - \lambda_\perp\left\{a f_x^*(t) 
        + a^\dagger f_x(t)\right\}\sigma_x - \lambda_\perp\left\{a f_y^*(t) 
        + a^\dagger f_y(t)\right\}\sigma_y + \lambda_z    \left\{a f_z^*(t)
        + a^\dagger f_z(t)\right\}\sigma_z$ where $f_z(t)= e^{i\omega_r t}$, 
        $f_x(t) = f_z(t)\cos(\omega_{ge}t)$, and $f_y(t)= f_z(t) \sin(\omega_{ge}t)$.
        The pulse amplitudes are $\Lambda_\perp=A \frac{\Delta}{\omega_{ge}}$ 
        and $\Lambda_z=A \frac{\varepsilon}{\omega_{ge}}$.
        #-------------------------------------------
        # Ht = -lt * (a * conj(fx) + a.dag * fx) * sx
        #      -lt * (a * conj(fy) + a.dag * fy) * sy
        #      +lz * (a * conj(fz) + a.dag * fz) * sz
        #      +LT/2 * (cos(phi) * sx - sin(phi) * sy)
        #      +LT/2 * fcx * sx 
        #      +LT/2 * fcy * sy 
        #      -LZ   * fcz * sz
        # lt:lambda_t, lz:lambda_z, LT:Lambda_T, LZ:Lambda_Z
        # See http://qutip.org/docs/4.1/guide/dynamics/dynamics-time.html
        #print ("Setup Hamiltonian", end=" ")
        """
        if not (kwargs):
            raise KeyError("**kwargs=None")

        #-------------------------------------------
        # Input Parameters
        #-------------------------------------------

        # check its existance
        if 'evolType' in kwargs:
            evolType = kwargs.get('evolType')
        else:
            raise KeyError('evolType is not present')

        # modulate sign if the evolution is (pi)x pulse
        if evolType == '(pi)x':
            try:
                sign = kwargs.get('sign')
                LT = sign * pars['LambdaT']
                LZ = sign * pars['LambdaZ']
                #print ("sign=",sign, ' in ', evolType);
            except:
                raise KeyError("sign is not present for (pi)x pulse")
        else:
            #Default values
            LT = pars['LambdaT']
            LZ = pars['LambdaZ']

        #Default value
        varphi = 0.0
        #Pulse phase in control pulse sinusoid

        # phase setting if the evolution is (pi/2)y
        if evolType == '(pi/2)y':
            varphi = -np.pi / 2
        #if evolType == '(pi/2)x' or evolType == '(pi)x' or evolType == '(pi/2)y':
        #   print ("varphi=",varphi, ' in ', evolType);

        lt = pars['lambdat']
        lz = pars['lambdaz']

        dt = pars['deltat']
        dz = pars['deltaz']

        #-----------------------------------------------------
        # Initialize dictionary for Hamiltonian functions
        Hargs = {}
        Hargs['varphi'] = varphi
        Hargs['omegaR'] = pars['omegaR']
        Hargs['omegaGE'] = pars['omegaGE']
        Hargs['2omegaGE'] = 2 * pars['omegaGE']
        Hargs['Wmin'] = pars['Wmin']
        Hargs['Nf'] = pars['Nf']

        sx = self.sx
        sy = self.sy
        sz = self.sz
        a = self.a

        #Set the default value for theSys label for interaction part of the Hamiltonian
        theSys = 'qubit-HO'

        if 'theSys' in kwargs:
            theSys = kwargs.get('theSys')
            #print ('theSys=', theSys, ' in ', evolType);

        if evolType == 'free' and theSys == 'qubit':
            raise ValueError("Invalid Hamiltonian for qubit system")

        if theSys == 'qubit':
            Hop = []
            # setting qubit operators
            sx = sigmax()
            sy = sigmay()
            sz = sigmaz()
        elif theSys == 'qubit-HO':
            Hop = [[-lt * sx * a.dag(), fx], [-lt * sy * a.dag(), fy],
                   [+lz * sz * a.dag(), fz], [-lt * sx * a, fx_conj],
                   [-lt * sy * a, fy_conj], [+lz * sz * a, fz_conj]]
        else:
            raise KeyError(
                "theSys must be set to either 'qubit' or 'qubit-HO'")

        #Flux noise part of the Hamiltonian for free evolution
        if kwargs.get('evolType') == 'free' and self.collapse != []:
            ##CONSIDER REVISING ('m' in kwargs or 'n' in kwargs) FOR m & n BELOW
            if ('m' in kwargs or 'n' in kwargs):
                m = kwargs.get('m')
                n = kwargs.get('n')
            else:
                raise KeyError("Invalid m & n for flux noise data file")

            if ('dirname' in kwargs) and (kwargs.get('dirname') != []):
                dirname = kwargs.get('dirname')
            else:
                raise KeyError("Invalid dirname for flux noise data")
            data_xyz = np.loadtxt("../" + dirname + "/cpmg%02dn%02d.out" %
                                  (m + 1, n))
            #print ('m=',m, ', n=',n)#(data_xyz)

            # To turn these data points into a function we call the QuTiP qutip.interpolate.Cubic_Spline class
            # using the first and last domain time points, t[0] and t[-1], respectively,
            # as well as the entire array of data points:
            from qutip.interpolate import Cubic_Spline
            cSx = Cubic_Spline(data_xyz[0][0], data_xyz[0][-1], data_xyz[1])
            cSy = Cubic_Spline(data_xyz[0][0], data_xyz[0][-1], data_xyz[2])
            cSz = Cubic_Spline(data_xyz[0][0], data_xyz[0][-1], data_xyz[3])
            Hop.append([+dt * sx, cSx])
            Hop.append([+dt * sy, cSy])
            Hop.append([-dz * sz, cSz])

        # Control part of the Hamiltonian for pulse sequence
        if (evolType == '(pi/2)x' or evolType == '(pi)x'
                or evolType == '(pi/2)y'):
            if (pars['betarf'] == 0.0):
                Hop.append(+LT / 2 *
                           (np.cos(varphi) * sx - np.sin(varphi) * sy))
                Hop.append([+LT / 2 * sx, fcx])
                Hop.append([+LT / 2 * sy, fcy])
                Hop.append([-LZ * sz, fcz])
            else:
                # Parameters for shaped (pi)x and (pi/2)x pulses
                Hargs['tb'] = tin
                #tbegin (MUST BE SET FOR EACH HAMILTONIAN SETUP)
                Hargs['te'] = tfn
                #tend
                Hargs['tr'] = (Hargs['te'] -
                               Hargs['tb']) * pars['betarf'] / 4.0
                #rising endge
                Hargs['tf'] = Hargs['tr']
                #falling edge
                Hargs['tp'] = (Hargs['te'] -
                               Hargs['tb']) * (1 - pars['betarf'] / 2.0)
                #Peak
                Hargs['pi2tf'] = np.pi / Hargs['tf']
                #pi/tfall
                Hargs['pi2tr'] = np.pi / Hargs['tr']
                #pi/trise
                #print ("(ti,tf)=","(",tin,Hargs['te'],") trise=",Hargs['tr'], ", pi/tr=", Hargs['pi2tr'])

                LT_prime = LT / (1 - pars['betarf'] / 4.0)
                LZ_prime = LZ / (1 - pars['betarf'] / 4.0)
                #print ("for shaped (pi/2)x or (pi)x pulse")
                Hop.append([
                    +LT_prime / 2 *
                    (np.cos(varphi) * sx - np.sin(varphi) * sy), fA
                ])
                Hop.append([+LT_prime / 2 * sx, fcAx])
                Hop.append([+LT_prime / 2 * sy, fcAy])
                Hop.append([-LZ_prime * sz, fcAz])
        return (Hop, Hargs)