Beispiel #1
0
def coarse_graining(matrix, in2):

    T = matrix
    TI = in2
    d = D**2

    #print ("Iteration", int(count+1), "of" , numlevels)
    Za = ncon((T, T), ([-1, 1, 2, -2], [-3, 1, 2, -4]))  # *
    Zb = ncon((T, T), ([-1, 1, -2, 2], [-3, 1, -4, 2]))  # *
    MMdag_prime = ncon((Za, Zb), ([-1, 1, -3, 2], [-2, 1, -4, 2]))  # *
    MMdag_prime = MMdag_prime.reshape(D**2, D**2)

    # MMdag_prime = ncon((T,T,T,T),([-1,1,2,3], [-3,1,2,4], [-2,5,3,6], [-4,5,4,6]))
    # Above line is equivalent to three * marked lines.
    # But at least 6-8 times slower!

    w, U = LA.eigh(MMdag_prime)
    idx = w.argsort()[::-1]
    s1 = w[idx]
    U = U[:, idx]

    if np.size(U, 1) > D_cut:

        s = s1[:D_cut]
        U = U[:, :D_cut]

    U = U.reshape(D, D, D)
    AA = ncon((U, T, T, U),
              ([1, 2, -1], [1, 3, -3, 4], [2, 5, 4, -4], [3, 5, -2]))
    #TI = ncon((U, TI, T, U),([1,2,-1], [1,3,-3,4], [2,5,4,-4], [3,5,-2]))
    norm = np.max(AA)
    '''
    Za = ncon((TI, matrix),([-1,1,2,-2], [-3,1,2,-4])) 
    Zb = ncon((matrix, matrix),([-1,1,-2,2], [-3,1,-4,2])) 
    MMdag_prime = ncon((Za, Zb),([-1,1,-3,2], [-2,1,-4,2]))  
    MMdag_prime = MMdag_prime.reshape(D**2, D**2) 
    w, U = LA.eigh(MMdag_prime)
    idx = w.argsort()[::-1]
    s1 = w[idx]
    U = U[:,idx] 

    if np.size(U,1) > D_cut: 

        s = s1[:D_cut] 
        U = U[:,:D_cut]  
 
    U = U.reshape(D,D,D)
    '''
    BB = ncon((U, TI, T, U),
              ([1, 2, -1], [1, 3, -3, 4], [2, 5, 4, -4], [3, 5, -2]))

    AA = AA / norm
    BB = BB / norm

    return AA, BB, norm
Beispiel #2
0
def coarse_graining(matrix, eps, nc, count):

    T = matrix
    d = int(min(D_cut**2, N_r**(2 * (count + 1))))

    print("Iteration", int(count + 1), "of", Niters)
    Za = ncon((T, T), ([-1, 1, 2, -2], [-3, 1, 2, -4]))
    Zb = ncon((T, T), ([-1, 1, -2, 2], [-3, 1, -4, 2]))
    MMdag_prime = ncon((Za, Zb), ([-1, 1, -3, 2], [-2, 1, -4, 2]))
    MMdag_prime = MMdag_prime.reshape(d, d)

    w, U = LA.eigh(
        MMdag_prime)  # Slow alternative : U, s1, V = LA.svd(MMdag_prime)
    idx = w.argsort()[::-1]
    s1 = w[idx]
    U = U[:, idx]

    if np.size(U, 1) > D_cut:
        s = s1[:D_cut]
        U = U[:, :D_cut]

    else:
        s = s1

    count += 1

    U = U.reshape(int(sqrt(np.size(U, 0))), int(sqrt(np.size(U, 0))),
                  np.size(U, 1))
    M_new = ncon((U, T, T, U),
                 ([1, 2, -1], [1, 3, -3, 4], [2, 5, 4, -4], [3, 5, -2]))

    norm = LA.norm(M_new)
    nc += (2**((2 * Niters) - count)) * np.log(norm)

    if norm != 0:
        T = M_new / norm

    else:
        T = M_new

    return T, eps, nc, count
Beispiel #3
0
def get_site_mag():

    for i in range (-Dn,Dn+1):
        L[i+Dn] = np.sqrt(sp.special.iv(i, beta))
 
    out = ncon((L, L, L, L),([-1],[-2],[-3],[-4])) 
    for l in range (-Dn,Dn+1):
        for r in range (-Dn,Dn+1):
            for u in range (-Dn,Dn+1):
                for d in range (-Dn,Dn+1):
                    index = l+u-r-d
                    out[l+Dn][r+Dn][u+Dn][d+Dn] *= 0.50 * (sp.special.iv(index-1, beta*h) + sp.special.iv(index+1, beta*h))

    if D_cut > 47:
        return out.astype(np.float32)
    else: 
        return out
Beispiel #4
0
def get_tensor():

    for i in range(-Dn, Dn + 1):
        L[i + Dn] = np.sqrt(sp.special.iv(i, beta))

    out = ncon((L, L, L, L),
               ([-1], [-2], [-3],
                [-4]))  # Alt: T = np.einsum("i,j,k,l->ijkl", L, L, L, L)
    for l in range(-Dn, Dn + 1):
        for r in range(-Dn, Dn + 1):
            for u in range(-Dn, Dn + 1):
                for d in range(-Dn, Dn + 1):
                    index = l + u - r - d
                    out[l + Dn][r + Dn][u + Dn][d + Dn] *= sp.special.iv(
                        index, betah)

    return out
Beispiel #5
0
def get_site_mag():

    for i in range(-Dn, Dn + 1):
        L[i + Dn] = np.sqrt(sp.special.iv(i, beta))

    out = ncon((L, L, L, L),
               ([-1], [-2], [-3],
                [-4]))  # Alt: T = np.einsum("i,j,k,l->ijkl", L, L, L, L)
    for l in range(-Dn, Dn + 1):
        for r in range(-Dn, Dn + 1):
            for u in range(-Dn, Dn + 1):
                for d in range(-Dn, Dn + 1):
                    index = l + u - r - d
                    out[l + Dn][r + Dn][u + Dn][
                        d + Dn] *= 0.50 * (sp.special.iv(index - 1, beta * h) +
                                           sp.special.iv(index + 1, beta * h))

    return out
Beispiel #6
0
def CG_step(matrix, in2):

    T = matrix  
    TI = in2 

    AAdag = ncon([T,T,T,T],[[-2,1,2,5],[-1,5,3,4],[-4,1,2,6],[-3,6,3,4]])
    U, s, V = tensorsvd(AAdag,[0,1],[2,3],D_cut)  
    A = ncon([U,T,T,U],[[1,2,-1],[2,-2,4,3],[1,3,5,-4],[5,4,-3]])
    B = ncon([U,TI,T,U],[[1,2,-1],[2,-2,4,3],[1,3,5,-4],[5,4,-3]])
    AAdag = ncon([A,A,A,A],[[1,-1,2,3],[2,-2,4,5],[1,-3,6,3],[6,-4,4,5]]) # Reuse old memory allocated
    U, s, V = tensorsvd(AAAAdag,[0,1],[2,3],D_cut)  
    AA = ncon([U,A,A,U],[[1,2,-2],[-1,1,3,4],[3,2,-3,5],[4,5,-4]])
    #BA2 = ncon([U,B,A,U],[[1,2,-2],[-1,1,4,3],[4,2,-3,5],[3,5,-4]]) 
    BA = ncon([U,B,A,U],[[1,2,-2],[-1,1,3,4],[3,2,-3,5],[4,5,-4]]) 
    # BA and BA2 are same!
    
    maxAA = np.max(AA)
    AA = AA/maxAA # Normalize by largest element of the tensor
    BA = BA/maxAA
        
    return AA, BA, maxAA
Beispiel #7
0
    else: 
        return out


if __name__ == "__main__":

 
    betah=beta*h
    T = get_tensor()
    Tim = get_site_mag()

    norm = np.max(T)
    T /= norm 
    Tim /= norm 

    Z = ncon([T,T,T,T],[[7,5,3,1],[3,6,7,2],[8,1,4,5],[4,2,8,6]])
    C = 0.0
    N = 1.0
    C = np.log(norm)

    for i in range (Niters):

        
        T, Tim, norm = CG_step(T, Tim)
        N *= 4.0
        C += C + (np.log(norm)/4**(i+1))
         
        if i == Niters-1:

            Z1 = ncon([T,T],[[1,-1,2,-2],[2,-3,1,-4]])
            Z = ncon([Z1,Z1],[[1,2,3,4],[2,1,4,3]])
Beispiel #8
0
            Tmp = ATNR[k + 1]
            norm = ATNRnorm[k + 1]
            ''' 
            1st argument: Eigenvalue threshold for automatic truncate indication of indices
            (increase means less accurate!)
            2nd argument: Maximum number of iterations in disentangler optimization
            3rd argument: Minimum number of iterations in disentangler optimization
            4th argument: Display information during optimization
            5th argument: Threshold for relative error change to stop disentangler optimization 
            '''

        #Volume = 2**(2*np.int64(np.array(range(1,18)))-2)   # 4^n, where n runs from 0 ... max
        FreeEnergy = np.zeros(numlevels)

        for k in range(1, numlevels + 1):
            Hgauge = ncon([vC[k - 1], vC[k - 1]], [[1, 2, -1], [2, 1, -2]])
            Vgauge = ncon([wC[k - 1], wC[k - 1]], [[1, 2, -1], [2, 1, -2]])
            FreeEnergy[k-1] = -1.0*(sum((4**np.int64(np.array(range(k,-1,-1))))*np.log(ATNRnorm[:(k+1)]))+ \
            np.log(ncon([ATNR[k],Hgauge,Vgauge],[[1,3,2,4],[1,2],[3,4]])))

        ##### Change gauge on disentanglers 'u'
        a = int(np.sqrt(chiM))
        gaugeX = np.eye(chiM).reshape(a, a, a,
                                      a).transpose(1, 0, 2,
                                                   3).reshape(chiM, chiM)
        upC = [0 for x in range(numlevels)]
        upC[0] = ncon([uC[0], gaugeX], [[-1, 1, -3, -4], [1, -2]])
        for k in range(1, numlevels):
            uF, sF, vhF = LA.svd(
                ncon([wC[k - 1], wC[k - 1]], [[1, 2, -1], [2, 1, -2]]))
            gaugeX = np.dot(uF, vhF)
Beispiel #9
0
    # TODO

    T_SS = T_data[int(SS_size - 1)]
    T_S = T_data[int(S_size - 1)]

    print("TS shape", np.shape(T_SS))
    print("TS shape", np.shape(T_S))

    #T_SS = T_SS.transpose(2,3,1,0)    # Rotate both 'T' CCW 90 degrees **
    #print ("NORM 1", LA.norm(T_SS))
    # For ex.: D,D,5,5 to 5,5,D,D
    T_S = T_S.transpose(2, 3, 1, 0)
    T_SS = T_SS.transpose(2, 3, 1, 0)
    #print ("NORM 2", LA.norm(T_S))

    Tnew = ncon((T_SS, T_S), ([1, 2, -1, -3], [2, 1, -2, -4]))
    #Tnew = Tnew.transpose(2,3,1,0)
    Tnew = Tnew.reshape(int(np.shape(Tnew)[0] * np.shape(Tnew)[2]),
                        int(np.shape(Tnew)[1] * np.shape(Tnew)[3]))

    for i in range(0, Niters_time):

        Tnew = np.matmul(Tnew, Tnew)  # 0. Raise over the time slices
        norm = LA.norm(Tnew)
        if norm != 0:
            Tnew /= norm

    print(np.shape(Tnew))
    #print ("TR is", np.trace(Tnew))
    #Tnew = Tnew/np.trace(Tnew)                   # 1. Normalize to recognize (T)^Nt as \rho
    Tnew = Tnew.reshape(D_cut, D_cut, D_cut,