Esempio n. 1
0
 def sort(self, sort_by=None):
     """
         Sorts the filled parts of the coupling and energy buffers in place. Both are sorted as specified by the
         sort_by argument (see utils.sorting.sort_star_coefficients)
     """
     if not self.is_symmetric:
         self.gamma_buf[:self._next_n], self.xi_buf[:self._next_n] = \
             sort_star_coefficients(self.gamma_buf[:self._next_n], self.xi_buf[:self._next_n], sort_by=sort_by)
     else:
         self.gamma_buf[:2*self._next_n], self.xi_buf[:2*self._next_n] = \
             sort_star_coefficients(self.gamma_buf[:2*self._next_n], self.xi_buf[:2*self._next_n], sort_by=sort_by)
Esempio n. 2
0
def get_from_chain_stepwise_convergence(J,
                                        domain,
                                        nof_coefficients,
                                        disc_type='sp_quad',
                                        interval_type='log',
                                        mapping_type='sp_hes',
                                        permute=None,
                                        residual=True,
                                        low_memory=True,
                                        stable=False,
                                        min_ncap=10,
                                        max_ncap=2000,
                                        step_ncap=1,
                                        stop_rel=1e-10,
                                        stop_abs=1e-10,
                                        get_trafo=False,
                                        force_sp=False,
                                        mp_dps=30,
                                        sort_by=None,
                                        **kwargs):
    """
        Returns star coefficients, constructed from chain coefficients via diagonalization
        see chain.get_from_stepwise_convergence and convert_chain_to_star for an explanation of the arguments.
        Sort_by sorts the couplings and energies (if passed and not None), see utils.sorting.sort_star_coefficients
        for details on the parameters.
        Defaults to logarithmic intervals for the direct discretization
    :returns: gamma (couplings), xi (energies), info dict from both the conversion and the chain mapping
              if get_trafo is set True, the dict only contains the latest transformation (from chain to star here)
    """
    c0, omega, t, info = get_from_stepwise_convergence(
        J,
        domain,
        nof_coefficients,
        disc_type=disc_type,
        interval_type=interval_type,
        mapping_type=mapping_type,
        permute=permute,
        residual=residual,
        low_memory=low_memory,
        stable=stable,
        min_ncap=min_ncap,
        max_ncap=max_ncap,
        step_ncap=step_ncap,
        stop_rel=stop_rel,
        stop_abs=stop_abs,
        get_trafo=False,
        **kwargs)
    gamma, xi, trafo_info = convert_chain_to_star(c0,
                                                  omega,
                                                  t,
                                                  force_sp=force_sp,
                                                  mp_dps=mp_dps,
                                                  get_trafo=get_trafo)
    gamma, xi = sort_star_coefficients(gamma, xi, sort_by)
    return gamma, xi, info.update(trafo_info)
Esempio n. 3
0
def convert_chain_to_star(c0,
                          omega,
                          t,
                          get_trafo=False,
                          force_sp=False,
                          mp_dps=30,
                          sort_by=None):
    """
        Converts chain coefficients in the form c0, omega, t (system to bath coupling, bath energies,
        bath-bath couplings) into the equivalent star geometry coefficients gamma, xi (star system to bath coupling,
        star bath energies) by using diagonalization with either arbitrary precision mpmath if the library is installed
        or scipy eigh_tridiagonal in float precision
    :param c0: System to bath coupling float
    :param omega: Bath energies (numpy array)
    :param t: Bath-bath couplings (numpy array)
    :param get_trafo: If the transformation between the chain and the star should be returned or not
                      This matrix is only for the omega/t coefficients
    :param force_sp: Force the use of the scipy method eigh_tridiagonal, even if mpmath is installed
    :param mp_dps: Decimals, which mpmath uses for the computation
    :return: gamma (star system to bath coupling), xi (star bath energies),
             info dict with the keys: 'trafo': Contains the transformation Matrix between the geometries
    """
    assert len(omega) - 1 == len(t)
    info = dict()
    info['trafo'] = None
    if mp is None or force_sp:
        w, v = eigh_tridiagonal(omega, t)
        gamma = c0 * np.abs(v[0, :])
        xi = w
        if get_trafo:
            info['trafo'] = v
    else:
        mp.set_dps = mp_dps
        nof_coefficients = len(omega)
        A = np.zeros((nof_coefficients, nof_coefficients))
        drows, dcols = np.diag_indices_from(A)
        A[drows[:nof_coefficients], dcols[:nof_coefficients]] = omega
        rng = np.arange(nof_coefficients - 1)
        A[rng + 1, rng] = t
        A[rng, rng + 1] = t
        E, Q = mp.eigsy(mp.matrix(A.tolist()))
        xi = np.empty(nof_coefficients)
        gamma = np.empty(nof_coefficients)
        for i in range(A.shape[1]):
            xi[i] = float(E[i])
            gamma[i] = c0 * np.abs(float(Q[0, i]))
        if get_trafo:
            Q = np.array(Q.tolist(), dtype=np.float64)
            info['trafo'] = Q
    gamma, xi = sort_star_coefficients(gamma, xi, sort_by)
    return gamma, xi, info
Esempio n. 4
0
def get_from_hr_star_stepwise_convergence(discretized_bath,
                                          nof_coefficients,
                                          mapping_type='sp_hes',
                                          permute=None,
                                          residual=True,
                                          low_memory=True,
                                          stable=False,
                                          min_ncap=10,
                                          max_ncap=2000,
                                          step_ncap=1,
                                          stop_rel=1e-10,
                                          stop_abs=1e-10,
                                          get_trafo=False,
                                          force_sp=False,
                                          mp_dps=30,
                                          sort_by=None):
    """
        Returns star coefficients, constructed from chain coefficients via diagonalization using a pre-
        constructed discretized bath as 'high-resolution' star, which is mapped to chain, truncated and
        then mapped back,
        see chain.from_bath_from_stepwise_convergence and convert_chain_to_star for an explanation of the arguments.
        Sort_by sorts the couplings and energies (if passed and not None), see utils.sorting.sort_star_coefficients
        for details on the parameters.
    :returns: gamma (couplings), xi (energies), info dict from both the conversion and the chain mapping
              if get_trafo is set True, the dict only contains the latest transformation (from chain to star here)
    """
    c0, omega, t, info = from_bath_from_stepwise_convergence(
        discretized_bath,
        nof_coefficients,
        mapping_type=mapping_type,
        permute=permute,
        residual=residual,
        low_memory=low_memory,
        stable=stable,
        min_ncap=min_ncap,
        max_ncap=max_ncap,
        step_ncap=step_ncap,
        stop_rel=stop_rel,
        stop_abs=stop_abs,
        get_trafo=get_trafo)
    gamma, xi, trafo_info = convert_chain_to_star(c0,
                                                  omega,
                                                  t,
                                                  force_sp=force_sp,
                                                  mp_dps=mp_dps,
                                                  get_trafo=get_trafo)
    gamma, xi = sort_star_coefficients(gamma, xi, sort_by)
    return gamma, xi, info.update(trafo_info)
Esempio n. 5
0
 def get_sorted(self, sort_by=None):
     """
     :return: Copy of the couplings (gamma), Copy of the energies (xi). Both sorted as specified by the
              sort_by argument (see utils.sorting.sort_star_coefficients)
     """
     return sort_star_coefficients(self.gamma, self.xi, sort_by=sort_by)