Beispiel #1
0
    def propagate(self, rho_0, t_init, t_final, dt,
                  input_has_bath=False, output_has_bath=False,
                  is_verbose=True):

        if is_verbose:
            print "--- Propagating RDM ...",

        times = np.arange(t_init, t_final, dt)
        self.write_bath_corr_fn(times)
        if input_has_bath:
            rho_hierarchy = rho_0.copy()
        else:
            rho_hierarchy = self.initialize_rho_hierarchy(rho_0)

        integrator = Integrator('ODE', dt, deriv_fn=self.heom_deriv)
        integrator.set_initial_value(rho_hierarchy, t_init)

        rhos_site = []
        rhos_eig = []
        while integrator.t < t_final+1e-8:
            #print " - Propagating at time t =", integrator.t

            # Retrieve data from integrator
            if output_has_bath:
                rho_site = integrator.y
                rho_eig = []
                for ado_site in rho_site:
                    rho_eig.append(self.ham.site2eig(ado_site))
                rho_eig = np.array(rho_eig)
                    
            else:
                rho_site = integrator.y[0]
                rho_eig = self.ham.site2eig(rho_site)

            # Collect results
            rhos_site.append(rho_site.copy())
            rhos_eig.append(rho_eig.copy())

            # Propagate one timestep
            integrator.integrate()

            # TODO(TCB): If filtering, check if we can remove any ADMs

        if is_verbose:
            print "done."
        
        return times, rhos_site, rhos_eig
Beispiel #2
0
    def propagate_full(self, rho_hierarchy, t_init, t_final, dt):
        integrator = Integrator('ODE', dt, deriv_fn=self.heom_deriv)
        integrator.set_initial_value(rho_hierarchy, t_init)

        rhos_site = list()
        times = np.arange(t_init, t_final, dt)
        for time in times:
            rhos_site.append(integrator.y.copy())
            integrator.integrate()
            # TODO(TCB): If filtering, check if we can remove any ADMs

        return times, np.array(rhos_site)
Beispiel #3
0
    def propagate_full(self,
                       rho_0,
                       t_init,
                       t_final,
                       dt,
                       markov_tol=1e-3,
                       markov_time=np.inf,
                       is_verbose=False):
        self.markov_tol = markov_tol
        self.markov_time = markov_time

        times = np.arange(t_init, t_final, dt)
        rho_eig = self.ham.site2eig(rho_0)

        integrator = Integrator(self.diffeq_type,
                                dt,
                                Omega=self.Omega,
                                R=self.R,
                                K=self.K)
        if self.method == 'TCL2':
            if not hasattr(self, 'redfield_tensor_n'):
                self.precompute_redfield_tensor(t_init, t_final, dt)
            elif len(self.redfield_tensor_n) < int((t_final - t_init) / dt):
                self.precompute_redfield_tensor(t_init, t_final, dt)
        if self.method == 'TC2':
            self.precompute_redfield_tensor(t_init, t_final, dt)
        #self.precompute_redfield_tensor_finegrid(t_init, t_final, dt,
        #                                         integrator)

        integrator.set_initial_value(utils.to_liouville(rho_eig), t_init)

        rhos_site = []
        for time in times:
            # Retrieve data from integrator
            rho_eig = utils.from_liouville(integrator.y)

            # Collect results
            rho_site = self.ham.eig2site(rho_eig)
            rhos_site.append(rho_site)

            # Propagate one timestep
            integrator.integrate()

        if is_verbose:
            print("\n--- Finished performing RDM dynamics")

        return times, rhos_site
Beispiel #4
0
    def propagate_full(self, rho_bath, t_init, t_final, dt):
        times = np.arange(t_init, t_final, dt)

        def deriv_fn(t, y):
            return self.deriv(t, y)

        rho_0, q, p = self.unpack(rho_bath)
        rho_int_0 = self.ham.to_interaction(self.ham.site2eig(rho_0), t_init)
        integrator = Integrator('ODE', dt, deriv_fn=deriv_fn)
        integrator.set_initial_value(self.pack(rho_int_0, q, p), t_init)

        rho_bath_traj = list()
        for time in times:
            rho_int_t, qt, pt = self.unpack(np.array(integrator.y))
            rho_t = self.ham.eig2site(
                self.ham.from_interaction(rho_int_t, time))
            rho_bath_traj.append(self.pack(rho_t, qt, pt))
            integrator.integrate()

        return times, np.array(rho_bath_traj)
Beispiel #5
0
    def propagate(self, rho_0, t_init, t_final, dt, is_verbose=True):
        """Propagate the RDM according to Ehrenfest dynamics.

        Parameters
        ----------
        rho_0 : np.array
            The initial RDM.
        t_init : float
            The initial time.
        t_final : float
            The final time.
        dt : float
            The timestep.
        is_verbose : bool
            Flag to indicate verbose printing.

        Returns
        -------
        times : list of floats
            The times at which the RDM has been calculated.
        rhos_site : list of np.arrays
            The RDM at each time in the site basis.
        rhos_eig : list of np.arrays
            The RDM at each time in the system eigen-basis.

        """
        times = np.arange(t_init, t_final, dt)
        modes = self.modes = self.ham.init_classical_modes(self.nmode)
        self._hamsb = np.array(self.ham.sysbath)
        self._omegasq = np.zeros((self.ham.nbath,self.nmode))
        self._c = np.zeros((self.ham.nbath,self.nmode))
        for n,modes_n in enumerate(self.modes):
            self._omegasq[n,:] = np.array([mode.omega**2 for mode in modes_n])
            self._c[n:] = np.array([mode.c for mode in modes_n])

        def deriv_fn(t,y):
            return self.deriv(t,y)

        rhos_site_avg = np.zeros((len(times),self.ham.nsite,self.ham.nsite), dtype=np.complex) 
        rhos_eig_avg = np.zeros((len(times),self.ham.nsite,self.ham.nsite), dtype=np.complex) 
        for trajectory in range(self.ntraj):
            self.ham.sample_classical_modes(modes)
            q = np.zeros((self.ham.nbath, self.nmode))
            p = np.zeros((self.ham.nbath, self.nmode))
            for n in range(self.ham.nbath):
                for k in range(self.nmode):
                    q[n,k] = modes[n][k].Q
                    p[n,k] = modes[n][k].P

            integrator = Integrator('ODE', dt, deriv_fn=deriv_fn)
            integrator.set_initial_value(self.pack(rho_0,q,p), t_init)

            rhos_site = []
            rhos_eig = []
            for time in times:
                # Retrieve data from integrator
                rho_site, q, p = self.unpack(integrator.y)

                # Collect results
                rhos_site.append(rho_site)
                rhos_eig.append(self.ham.site2eig(rho_site))

                # Propagate one timestep
                integrator.integrate()

            # Remember: rhos_site is a Python list, not a numpy array
            rhos_site_avg += np.array(rhos_site)/self.ntraj
            rhos_eig_avg += np.array(rhos_eig)/self.ntraj

        if is_verbose:
            print "\n--- Finished performing RDM dynamics"
        
        # Return as a list of 2D ndarrays
        return times, [x for x in rhos_site_avg], [x for x in rhos_eig_avg]
Beispiel #6
0
    def propagate(self, rho_0, t_init, t_final, dt, 
                  markov_tol = 1e-3, markov_time = np.inf,
                  is_verbose=True):
        """Propagate the RDM according to Redfield-like dynamics.

        Parameters
        ----------
        rho_0 : np.array
            The initial RDM.
        t_init : float
            The initial time.
        t_final : float
            The final time.
        dt : float
            The timestep.
        markov_tol : float
            The relative tolerance at which to decide that the memory tensor
            has stopped changing (and henceforth Markovian).
        markov_time : float
            The hard-coded time to stop re-calculating the memory tensor.
        is_verbose : bool
            Flag to indicate verbose printing.

        Returns
        -------
        times : list of floats
            The times at which the RDM has been calculated.
        rhos_site : list of np.arrays
            The RDM at each time in the site basis.
        rhos_eig : list of np.arrays
            The RDM at each time in the system eigen-basis.

        """
        self.markov_tol = markov_tol
        self.markov_time = markov_time

        times = np.arange(t_init, t_final, dt)
        rho_site = rho_0.copy()
        rho_eig = self.ham.site2eig(rho_site)

        integrator = Integrator(self.diffeq_type, dt, 
                                Omega=self.Omega, R=self.R, K=self.K)
        if self.method in ['TCL2', 'TC2']:
            self.precompute_redfield_tensor(t_init, t_final, dt)
            #self.precompute_redfield_tensor_finegrid(t_init, t_final, dt, 
            #                                         integrator)

        integrator.set_initial_value(utils.to_liouville(rho_eig), t_init)

        rhos_site = []
        rhos_eig = []
        for time in times:
            # Retrieve data from integrator
            rho_eig = utils.from_liouville(integrator.y)

            # Collect results
            rho_site = self.ham.eig2site(rho_eig)
            rhos_site.append(rho_site)
            rhos_eig.append(rho_eig)

            # Propagate one timestep
            integrator.integrate()

        if is_verbose:
            print "\n--- Finished performing RDM dynamics"
        
        return times, rhos_site, rhos_eig