Exemplo n.º 1
0
def expm_multiply_parallel(A, B, t=1.0, balance=False):

    if not B.flags["C_CONTIGUOUS"]:
        B = np.copy(B, order='C')

    if len(A.shape) != 2 or A.shape[0] != A.shape[1]:
        raise ValueError('expected A to be like a square matrix')
    if A.shape[1] != B.shape[0]:
        raise ValueError('the matrices A and B have incompatible shapes')

    ident = _ident_like(A)
    n = A.shape[0]
    if len(B.shape) == 1:
        n0 = 1
    elif len(B.shape) == 2:
        n0 = B.shape[1]
    else:
        raise ValueError('expected B to be like a matrix or a vector')
    u_d = 2**-53
    tol = u_d
    mu = _trace(A) / float(n)
    A_2 = A - mu * ident
    A_1_norm = _exact_1_norm(A_2)

    if t * A_1_norm == 0:
        m_star, s = 0, 1
    else:
        ell = 2
        norm_info = LazyOperatorNormInfo(t * A, A_1_norm=t * A_1_norm, ell=ell)
        m_star, s = _fragment_3_1(norm_info, n0, tol, ell=ell)

    return _my_expm_multiply_simple_core(A, B, t, mu, m_star, s, tol, balance)
Exemplo n.º 2
0
 def _calculate_partition(self):
     if _np.abs(self._a) * self._A_1_norm == 0:
         self._m_star, self._s = 0, 1
     else:
         ell = 2
         norm_info = LazyOperatorNormInfo(self._A,
                                          self._A_1_norm,
                                          self._a,
                                          self._mu,
                                          self._dtype,
                                          ell=ell)
         self._m_star, self._s = _fragment_3_1(norm_info,
                                               1,
                                               self._tol,
                                               ell=ell)
Exemplo n.º 3
0
def expL_multiply(rho_list, c_H_sum, c_stack, t_c=1.0):

    if not isinstance(rho_list, list):
        rho_list = [rho_list]

    if not rho_list[0].flags["C_CONTIGUOUS"]:
        rho_list = [np.copy(rho, order='C') for rho in rho_list]


#     if len(H.shape) != 2 or H.shape[0] != H.shape[1]:
#         raise ValueError('expected H to be like a square matrix')
#     if H.shape[1] != rho.shape[0]:
#         raise ValueError('the matrices H and rho have incompatible shapes')

#     if c_dag_list is None:
#         c_dag_list = [c.conj().T for c in c_list]
    H = c_H_sum
    ident = _ident_like(H)
    n = H.shape[0]
    rho = rho_list[0]
    if len(rho.shape) == 1:
        n0 = 1
    elif len(rho.shape) == 2:
        n0 = rho.shape[1]
    else:
        raise ValueError('expected rho to be like a matrix or a vector')
    u_d = 2**-53
    tol = u_d
    mu_H = _trace(H) / float(n)
    H_2 = H - mu_H * ident
    op_list = [H_2]

    #     if c_dag_c_sum is not 0:
    #         mu_cdc = _trace(c_dag_c_sum) / float(n)
    #         c_dag_c_sum_2 = c_dag_c_sum - mu_cdc * ident
    #         op_list += [c_dag_c_sum_2]

    norm_list = [_exact_1_norm(c) for c in op_list]
    t_list = [1, t_c]

    m_star_max, s_max = 0, 1
    for i, h in enumerate(norm_list):
        t = t_list[i]
        if t * h == 0:
            m_star, s = 0, 1
        else:
            ell = 2
            norm_info = LazyOperatorNormInfo(t * op_list[i],
                                             A_1_norm=t * h,
                                             ell=ell)
            m_star, s = _fragment_3_1(norm_info, n0, tol, ell=ell)

        m_star_max, s_max = max(m_star_max, m_star), max(s_max, s)
    m_star_max, s_max = m_star_g, s_g
    rho_out_list = [
        _expL_multiply_simple_core(rho, c_H_sum, c_stack, t_c, m_star_max,
                                   s_max, tol) for rho in rho_list
    ]

    if len(rho_out_list) > 1:
        return rho_out_list
    else:
        return rho_out_list[0]