Example #1
0
def zero_site_H_psi(psi, L, R):
    psi = cytnx.from_numpy(psi)
    psi = psi.reshape(L.shape()[1], R.shape()[1])
    psi = cyx.CyTensor(psi, 1)
    anet = cyx.Network("Network/C_L_R.net")
    anet.PutCyTensor("C", psi)
    anet.PutCyTensor("L", L)
    anet.PutCyTensor('R', R)
    H_psi = anet.Launch(optimal=True).get_block().reshape(-1).numpy()
    return H_psi
def get_H_psi(psi, L, M1, M2, R):
    ''' psi is Tensor, while L,M1,M2,R are CyTensor.
    Return: h|psi> (Tensor)'''
    psi = cytnx.from_numpy(psi)
    psi = cyx.CyTensor(psi, 0)
    psi = psi.reshape(L.shape()[1], M1.shape()[2], M2.shape()[2], R.shape()[1])
    anet = cyx.Network(path + "Network/psi_L_M1_M2_R.net")
    anet.PutCyTensor("psi", psi)
    anet.PutCyTensor("L", L)
    anet.PutCyTensor("M1", M1)
    anet.PutCyTensor('M2', M2)
    anet.PutCyTensor('R', R)
    H_psi = anet.Launch(optimal=True).reshape(-1).get_block().numpy()
    return H_psi
Example #3
0
def one_site_H_psi(psi, L, W, R):
    ''' psi is Tensor, while L,M1,M2,R are CyTensor.
    Return: h|psi> (Tensor)'''
    psi = cytnx.from_numpy(psi)
    # print(psi.shape())
    # print(L.shape(), W.shape(), R.shape())
    psi = psi.reshape(L.shape()[1], W.shape()[2], R.shape()[1])
    psi = cyx.CyTensor(psi, 2)
    anet = cyx.Network("Network/psi_L_W_R.net")
    anet.PutCyTensor("psi", psi)
    anet.PutCyTensor("L", L)
    anet.PutCyTensor("W", W)
    anet.PutCyTensor('R', R)
    H_psi = anet.Launch(optimal=True).get_block().reshape(-1).numpy()
    return H_psi
Example #4
0
def create_w_imp_cns_tms(ham,ten_a, ten_b, l_three_dir):
    'Create weight, impurity, cns, and tms with the imput ten_a, ten_b, l_three_dir'
    D = l_three_dir[0].shape()[0]
    for i in ('weight', 'impurity'):
        ## Clone and prepare the tesnors needed for contraction
        ten_a1 = ten_a.clone(); ten_a2 = ten_a.clone()
        ten_b1 = ten_b.clone(); ten_b2 = ten_b.clone()
        lx1 =  l_three_dir[0].clone(); lx2 = l_three_dir[0].clone()
        ly = l_three_dir[1].clone(); lz = l_three_dir[2].clone()

        ly_tmp = ly.get_block().numpy(); ly_tmp = cytnx.from_numpy(np.sqrt(ly_tmp))
        ly_sqrt_a1 = cyx.CyTensor([cyx.Bond(D),cyx.Bond(D)],rowrank = 0, is_diag=True)
        ly_sqrt_a1.put_block(ly_tmp); ly_sqrt_a2 = ly_sqrt_a1.clone()
        ly_sqrt_b1 = ly_sqrt_a1.clone(); ly_sqrt_b2 = ly_sqrt_a1.clone()

        lz_tmp = lz.get_block().numpy(); lz_tmp = cytnx.from_numpy(np.sqrt(lz_tmp))
        lz_sqrt_a1 = cyx.CyTensor([cyx.Bond(D),cyx.Bond(D)],rowrank = 0, is_diag=True)
        lz_sqrt_a1.put_block(lz_tmp); lz_sqrt_a2 = lz_sqrt_a1.clone()
        lz_sqrt_b1 = lz_sqrt_a1.clone(); lz_sqrt_b2 = lz_sqrt_a1.clone()

        ## Set labels
        lx1.set_labels([-3,-6]); lx2.set_labels([-9,-12])
        ly_sqrt_a1.set_labels([-4,4]); ly_sqrt_b1.set_labels([-7,0])
        lz_sqrt_a1.set_labels([-5,6]); lz_sqrt_b1.set_labels([-8,2])
        ly_sqrt_a2.set_labels([-10,5]); ly_sqrt_b2.set_labels([-13,1])
        lz_sqrt_a2.set_labels([-11,7]); lz_sqrt_b2.set_labels([-14,3])
        
        if i == 'weight':
            ## Calculate weights
            ten_a1.set_labels([-1,-3,-4,-5]); ten_b1.set_labels([-2,-6,-7,-8])
            ten_a2.set_labels([-1,-9,-10,-11]); ten_b2.set_labels([-2,-12,-13,-14])
            ## Contract
            # a1_xyz = cyx.Contract(cyx.Contract(cyx.Contract(ten_a1, lx1), ly_sqrt_a1), lz_sqrt_a1)
            # b1_yz = cyx.Contract(cyx.Contract(ten_b1, ly_sqrt_b1), lz_sqrt_b1)
            # upper_half = cyx.Contract(a1_xyz, b1_yz)
            #
            # a2_xyz = cyx.Contract(cyx.Contract(cyx.Contract(ten_a2, lx2), ly_sqrt_a2), lz_sqrt_a2)
            # b2_yz = cyx.Contract(cyx.Contract(ten_b2, ly_sqrt_b2), lz_sqrt_b2)
            #
            # lower_half = cyx.Contract(a2_xyz, b2_yz)
            # weight = cyx.Contract(upper_half, lower_half.Conj())
            # weight = sort_label(weight)
            # weight1 = weight.clone().get_block().numpy()
            anet = cyx.Network("Network/weight.net")
            # lz_sqrt_a1.print_diagram()
            anet.PutCyTensor("a1", ten_a1); anet.PutCyTensor("b1", ten_b1);
            anet.PutCyTensor("a2", ten_a2.Conj()); anet.PutCyTensor("b2", ten_b2.Conj());
            anet.PutCyTensor("lx1", lx1); anet.PutCyTensor("lx2", lx2);
            anet.PutCyTensor("ly_sqrt_a1", ly_sqrt_a1); anet.PutCyTensor("ly_sqrt_b1", ly_sqrt_b1);
            anet.PutCyTensor("ly_sqrt_a2", ly_sqrt_a2.Conj()); anet.PutCyTensor("ly_sqrt_b2", ly_sqrt_b2.Conj());
            anet.PutCyTensor("lz_sqrt_a1", lz_sqrt_a1); anet.PutCyTensor("lz_sqrt_b1", lz_sqrt_b1);
            anet.PutCyTensor("lz_sqrt_a2", lz_sqrt_a2.Conj()); anet.PutCyTensor("lz_sqrt_b2", lz_sqrt_b2.Conj());
            weight = anet.Launch(optimal = True)
            # weight2 = weight.clone().get_block().numpy()
            # print(linalg.norm(weight1-weight2))
        elif i == 'impurity':
            ## Calculate impurities
            d = ten_a.shape()[0]
            spin = constants_cy.physical_dimension_to_spin(d)
            sx,sy,sz,one = constants_cy.Get_spin_operators(spin)
            H = ham[0] 
            #H = - k *cytnx.linalg.Kron(sx, sx) - h * (cytnx.linalg.Kron(sz, one) + cytnx.linalg.Kron(one, sz)) / 2
            # H = cytnx.linalg.Kron(one,sx)
            H = H.reshape(d,d,d,d).permute(0,2,1,3)
            H = cyx.CyTensor(H,0)
            H.set_labels([-1,-15,-2,-16])
            #op1 = cyx.CyTensor(1j*sx.clone(), 0)
            #op2 = op1.clone()
            #op1.set_labels([-1,-15])
            #op2.set_labels([-2,-16])
            # ten_a1.set_labels([-1,-3,-4,-5]); ten_b1.set_labels([-2,-6,-7,-8])
            # ten_a2.set_labels([-15,-9,-10,-11]); ten_b2.set_labels([-16,-12,-13,-14])
            # # ## Contract
            # a1_xyz = cyx.Contract(cyx.Contract(cyx.Contract(ten_a1, lx1), ly_sqrt_a1), lz_sqrt_a1)
            # b1_yz = cyx.Contract(cyx.Contract(ten_b1, ly_sqrt_b1), lz_sqrt_b1)
            # upper_half = cyx.Contract(cyx.Contract(a1_xyz, b1_yz), H)
            #
            # a2_xyz = cyx.Contract(cyx.Contract(cyx.Contract(ten_a2, lx2), ly_sqrt_a2), lz_sqrt_a2)
            # b2_yz = cyx.Contract(cyx.Contract(ten_b2, ly_sqrt_b2), lz_sqrt_b2)
            # lower_half = cyx.Contract(a2_xyz, b2_yz)
            #
            # weight_imp = cyx.Contract(upper_half, lower_half.Conj())
            # weight_imp = sort_label(weight_imp)
            anet = cyx.Network("Network/impurity.net")
            # lz_sqrt_a1.print_diagram()
            anet.PutCyTensor("a1", ten_a1);
            anet.PutCyTensor("b1", ten_b1);
            anet.PutCyTensor("a2", ten_a2.Conj());
            anet.PutCyTensor("b2", ten_b2.Conj());
            anet.PutCyTensor("lx1", lx1);
            anet.PutCyTensor("lx2", lx2);
            anet.PutCyTensor("ly_sqrt_a1", ly_sqrt_a1);
            anet.PutCyTensor("ly_sqrt_b1", ly_sqrt_b1);
            anet.PutCyTensor("ly_sqrt_a2", ly_sqrt_a2.Conj());
            anet.PutCyTensor("ly_sqrt_b2", ly_sqrt_b2.Conj());
            anet.PutCyTensor("lz_sqrt_a1", lz_sqrt_a1);
            anet.PutCyTensor("lz_sqrt_b1", lz_sqrt_b1);
            anet.PutCyTensor("lz_sqrt_a2", lz_sqrt_a2.Conj());
            anet.PutCyTensor("lz_sqrt_b2", lz_sqrt_b2.Conj());
            anet.PutCyTensor('H', H)
            weight_imp = anet.Launch(optimal = True)
            #weight_imp.reshape_(D**2, D**2, D**2, D**2)
        w = weight.get_block().numpy()
        # print(w.shape)
        # Here we use np.einsum() to calculate cns and tms, for cytnx doesn't support contraction 
        # itself. An alternative is using cytnx.linalg.Trace(); however, it is still not that 
        # convenient
        dy = dz = w.shape[0]
        c1 = w.reshape((dy, dy, dz * dz, dy * dy, dz, dz))
        c1 = np.einsum('i i j k l l->j k', c1)
        c2 = w.reshape((dy, dy, dz, dz, dy * dy, dz * dz))
        c2 = np.einsum('i i j j k l->k l', c2)
        c3 = w.reshape((dy * dy, dz, dz, dy, dy, dz * dz))
        c3 = np.einsum('i j j k k l->l i', c3)
        c4 = w.reshape((dy * dy, dz * dz, dy, dy, dz, dz))
        c4 = np.einsum('i j k k l l->i j', c4)

        t1 = np.einsum('i i j k l->j k l', w.reshape((dy, dy, dz * dz, dy * dy, dz * dz)))
        t2 = np.einsum('i j j k l->k l i', w.reshape((dy * dy, dz, dz, dy * dy, dz * dz)))
        t3 = np.einsum('i j k k l->l i j', w.reshape((dy * dy, dz * dz, dy, dy, dz * dz)))
        t4 = np.einsum('i j k l l->i j k', w.reshape((dy * dy, dz * dz, dy * dy, dz, dz)))
        def normalize(x):
            return x / np.max(np.abs(x))
        corners = tuple(map(normalize, (c1, c2, c3, c4)))
        corners = tuple(cyx.CyTensor(cytnx.from_numpy(c),0) for c in corners)
        transfer_matrices = tuple(map(normalize, (t1, t2, t3, t4)))
        transfer_matrices = tuple(cyx.CyTensor(cytnx.from_numpy(t),0) for t in transfer_matrices)


    return weight, weight_imp, corners, transfer_matrices
def dmrg_two_sites(A,
                   ML,
                   M,
                   MR,
                   dim_cut,
                   numsweeps=10,
                   dispon=2,
                   updateon=True,
                   maxit=2,
                   krydim=4):
    '''
    :param A: list of initial CyTensor
    :param ML: Left boundary
    :param M: MPO, M.shape() = (D,D,d,d)
    :param MR: Right boundary
    :return: Ekeep, A, s_weight, B
    '''
    d = M.shape()[2]  # physical dimension
    Nsites = len(A)  # A is a list
    L = [0] * Nsites
    # Left boundary for each MPS
    L[0] = ML
    R = [0] * Nsites
    # Right boundary for each MPS
    R[Nsites - 1] = MR
    '''
    ########## Warm up: Put A into left orthogonal form ##########
    '''
    for p in range(Nsites - 1):
        s_diag, A[p], vt = cyx.xlinalg.Svd(A[p])

        A[p + 1] = absorb_right(s_diag, vt, A[p + 1])

        L[p + 1] = get_new_L(L[p], A[p], M, A[p].Conj())
    ## Initialiaze s_weight
    s_weight = [0] * (Nsites + 1)
    ## Specify A[final] and s[final]
    dim_l = A[Nsites - 1].shape()[0]
    dim_r = A[Nsites - 1].shape()[2]
    # =1
    A[Nsites - 1] = A[Nsites - 1].get_block().reshape(
        dim_l * d, dim_r)  ## CyTensor -> Tensor
    # This is because A[Nsites-1].shape() = [dim_l*d,1]
    _, A[Nsites - 1], _ = cytnx.linalg.Svd(A[Nsites - 1])
    ##[1], [4,1], [1,1] = svd([4,1)
    ## Just to make A[final] left orthogonal and renorm s to 1
    A[Nsites - 1] = cyx.CyTensor(A[Nsites - 1].reshape(dim_l, d, dim_r), 2)

    s_weight[Nsites] = cyx.CyTensor([cyx.Bond(1), cyx.Bond(1)],
                                    rowrank=1,
                                    is_diag=True)
    s_weight[Nsites].put_block(cytnx.ones(1))
    Ekeep = []  # Store the energy of each two sites
    B = [0] * Nsites
    '''
            ########## DMRG sweep begin ##########
    '''
    for k in range(1, numsweeps + 2):
        ##### final sweep is only for orthogonalization (disable updates)
        if k == numsweeps + 1:
            updateon = False
            dispon = 0
        print('-' * 50, k)
        '''
        ########## Optimization sweep: right-to-left ##########
        '''
        for p in range(Nsites - 2, -1, -1):
            ##### two-site update
            dim_l = A[p].shape()[0]
            dim_r = A[p + 1].shape()[2]
            psi_gs = get_psi_from_left(A[p], A[p + 1], s_weight[p + 2])
            if updateon:
                ## put psi_gs to Tensor for Lanczos algorithm

                psi_gs = psi_gs.reshape(-1).get_block().numpy()
                # psi_gs2 = copy.deepcopy(psi_gs)
                # psi_gs2, Entemp2 = gs_Arnoldi_numpy(psi_gs2, get_H_psi, (L[p], M, M, R[p + 1]), maxit=maxit,
                #                               krydim=krydim)
                # print(psi_gs.shape)
                psi_gs, Entemp = gs_Lanczos_numpy(psi_gs,
                                                  get_H_psi,
                                                  (L[p], M, M, R[p + 1]),
                                                  maxit=maxit,
                                                  krydim=krydim)
                # print(Entemp2 - Entemp)
                Ekeep.append(Entemp)
                psi_gs = cytnx.from_numpy(psi_gs)
                psi_gs = cyx.CyTensor(psi_gs.reshape(dim_l, d, d, dim_r), 2)

            dim_new = min(dim_l * d, dim_r * d, dim_cut)
            s_weight[p + 1], A[p], B[p + 1] = cyx.xlinalg.Svd_truncate(
                psi_gs, dim_new)
            norm = s_weight[p + 1].get_block().Norm().item()
            s_weight[p + 1] = s_weight[p + 1] / norm

            # ##### new block Hamiltonian

            R[p] = get_new_R(R[p + 1], B[p + 1], M, B[p + 1].Conj())
            if dispon == 2:
                print('Sweep: %d of %d, Loc: %d,Energy: %f' %
                      (k, numsweeps, p, Ekeep[-1]))

        ###### left boundary tensor
        Btemp = cyx.Contract(A[0], s_weight[1])
        dim_l = A[0].shape()[0]
        ## dim_l = 1
        dim_r = A[0].shape()[2]
        Btemp = Btemp.get_block().reshape(dim_l, d * dim_r)

        _, _, B[0] = cytnx.linalg.Svd(Btemp)
        ##[1], [1,1], [1,4] = svd([1,4)
        ## Just to make A[final] left orthogonal and renorm s to 1
        B[0] = B[0].reshape(1, d, dim_r)
        B[0] = cyx.CyTensor(B[0], 1)
        s_weight[0] = cyx.CyTensor([cyx.Bond(1), cyx.Bond(1)],
                                   rowrank=1,
                                   is_diag=True)
        s_weight[0].put_block(cytnx.ones(1))
        '''
        ########## Optimization sweep: left-to-right ##########
        '''
        for p in range(Nsites - 1):
            ##### two-site update
            dim_l = s_weight[p].shape()[0]
            dim_r = B[p + 1].shape()[2]

            psi_gs = get_psi_from_right(s_weight[p], B[p], B[p + 1])
            if updateon:
                ## put psi_gs to Tensor for Lanczos algorithm
                psi_gs = psi_gs.reshape(-1).get_block().numpy()
                psi_gs, Entemp = gs_Lanczos_numpy(psi_gs,
                                                  get_H_psi,
                                                  (L[p], M, M, R[p + 1]),
                                                  maxit=maxit,
                                                  krydim=krydim)
                Ekeep.append(Entemp)
                psi_gs = cytnx.from_numpy(psi_gs)
                psi_gs = cyx.CyTensor(psi_gs.reshape(dim_l, d, d, dim_r), 2)

            dim_new = min(dim_l * d, dim_r * d, dim_cut)
            s_weight[p + 1], A[p], B[p + 1] = cyx.xlinalg.Svd_truncate(
                psi_gs, dim_new)
            norm = s_weight[p + 1].get_block().Norm().item()
            s_weight[p + 1] = s_weight[p + 1] / norm

            ##### new block Hamiltonian
            L[p + 1] = get_new_L(L[p], A[p], M, A[p].Conj())

            ##### display energy
            if dispon == 2:
                print('Sweep: %d of %d, Loc: %d,Energy: %f' %
                      (k, numsweeps, p, Ekeep[-1]))
        ###### right boundary tensor
        Atemp = cyx.Contract(B[Nsites - 1], s_weight[Nsites - 1])
        # Atemp.print_diagram()
        dim_l = B[Nsites - 1].shape()[0]
        dim_r = B[Nsites - 1].shape()[2]
        # dim_r = 1
        Atemp = Atemp.get_block().reshape(dim_l * d, dim_r)
        _, A[Nsites - 1], _ = cytnx.linalg.Svd(Atemp)
        ##[1], [4,1], [1,1] = svd([4,1)
        # print(A[Nsites-1].shape())
        A[Nsites - 1] = A[Nsites - 1].reshape(dim_l, d, 1)
        A[Nsites - 1] = cyx.CyTensor(A[Nsites - 1], 2)
        s_weight[Nsites] = cyx.CyTensor([cyx.Bond(1), cyx.Bond(1)],
                                        rowrank=1,
                                        is_diag=True)
        s_weight[Nsites].put_block(cytnx.ones(1))

        if dispon == 1:
            print('Sweep: %d of %d, Energy: %.8f, Bond dim: %d' %
                  (k, numsweeps, Ekeep[-1], dim_cut))

    return Ekeep, A, s_weight, B
Example #6
0
def tdvp_one_site(M,
                  WL,
                  W,
                  WR,
                  dt,
                  numsweeps=10,
                  dispon=2,
                  updateon=True,
                  maxit=1,
                  krydim=10):
    d = M[0].shape()[2]  # physical dimension
    Nsites = len(M)  # M is a list
    A = [None] * Nsites  # left orthogonal tensor
    B = [None] * Nsites  # right orthogonal tensor
    # EE = [[None]*Nsites]*(2*numsweeps+1)
    # EE = np.zeros([Nsites-2, 2*numsweeps+1])
    EE_all_time = []
    EE = np.zeros([Nsites - 1])
    L = [None] * Nsites
    # Left boundary for each MPS
    L[0] = WL
    R = [None] * Nsites
    # Right boundary for each MPS
    R[Nsites - 1] = WR
    '''
        ########## Warm up: Put M into right orthogonal form ##########
    '''
    for p in range(Nsites - 1, 0, -1):
        stemp, utemp, B[p] = cyx.xlinalg.Svd(M[p])
        M[p - 1] = absorb_remain(M[p - 1], utemp, stemp)
        R[p - 1] = get_new_R(R[p], B[p], W, B[p].Conj())
    dim_l = 1
    dim_r = M[0].shape()[2]
    Mtemp = M[0].get_block().reshape(dim_l, d * dim_r)
    _, _, B[0] = cytnx.linalg.Svd(Mtemp)
    B[0] = B[0].reshape(dim_l, d, dim_r)
    B[0] = cyx.CyTensor(B[0], 1)
    Ac = B[0]  ## One-site center to do update
    '''
            ########## TDVP sweep begin ##########
    '''
    for k in range(1, numsweeps + 2):
        ##### final sweep is only for orthogonalization (disable updates)
        if k == numsweeps + 1:
            updateon = False
            dispon = 0
        print('-' * 50, k)
        '''
        ########## Optimization sweep: left-to-right ##########
        '''
        for p in range(Nsites - 1):
            ##### two-site update
            # print('p = ', p)
            if updateon:
                ## put psi_gs to Tensor for Lanczos algorithm
                dim_l = Ac.shape()[0]
                # Used to reshape Ac_new later
                dim_r = Ac.shape()[2]
                ############ Numpy Begin: Update one site
                Ac_old = Ac.get_block().reshape(-1).numpy()
                Ac_new, E = exp_Lanczos_numpy(Ac_old,
                                              one_site_H_psi, (L[p], W, R[p]),
                                              dt,
                                              maxit=maxit,
                                              krydim=krydim)
                Ac_new = cytnx.from_numpy(Ac_new)
                ############ Numpy End
                Ac_new = cyx.CyTensor(Ac_new.reshape(dim_l, d, dim_r), 2)
                stemp, A[p], vTtemp = cyx.xlinalg.Svd(Ac_new)
                ############ Entanglement entropy
                s_np = stemp.get_block().numpy()
                s_np[s_np < 1.e-20] = 0.
                assert abs(np.linalg.norm(s_np) - 1.) < 1.e-14
                S2 = s_np**2
                EE[p] = -np.sum(S2 * np.log(S2))
                # print(EE[2*k-2,p])

                C_old = cyx.Contract(stemp, vTtemp)
                dim_l = C_old.shape()[0]
                dim_r = C_old.shape()[1]
                L[p + 1] = get_new_L(L[p], A[p], W, A[p].Conj())
                ############ Numpy Begin: Update zero site
                C_old = C_old.get_block().reshape(-1).numpy()
                C_new, E = exp_Lanczos_numpy(C_old, zero_site_H_psi,
                                             (L[p + 1], R[p]), -dt)
                C_new = cytnx.from_numpy(C_new)
                ############ Numpy End
                C_new = C_new.reshape(dim_l, dim_r)
                C_new = cyx.CyTensor(C_new, 1)
                C_new.set_labels([0, -2])
                if p == Nsites - 2:
                    B[Nsites - 1].set_labels([-2, 2, 3])
                Ac = cyx.Contract(C_new, B[p + 1])
            ##### display energy
            if dispon == 2:
                print('Sweep: %d of %d, Loc: %d,Energy: %f' %
                      (k, numsweeps, p, E[0]))
        EE_all_time.append(EE.copy())
        # print(EE_all_time)
        # C_new.print_diagram()
        # B[p+1].print_diagram()
        # Ac.print_diagram()
        dim_l = Ac.shape()[0]
        dim_r = Ac.shape()[2]
        # print(Ac.shape())
        Ac_old = Ac.get_block().reshape(-1).numpy()
        Ac_new, E = exp_Lanczos_numpy(Ac_old, one_site_H_psi, (L[Nsites-1], W, R[Nsites-1]),\
                                      0, maxit=maxit, krydim=krydim)
        Ac_new = cytnx.from_numpy(Ac_new)
        Ac = cyx.CyTensor(Ac_new.reshape(dim_l, d, dim_r), 1)

        for p in range(Nsites - 2, -1, -1):
            if updateon:
                stemp, utemp, B[p + 1] = cyx.xlinalg.Svd(Ac)
                ############ Entanglement entropy
                s_np = stemp.get_block().numpy()
                s_np[s_np < 1.e-20] = 0.
                assert abs(np.linalg.norm(s_np) - 1.) < 1.e-14
                S2 = s_np**2
                EE[p] = -np.sum(S2 * np.log(S2))
                C_old = cyx.Contract(stemp, utemp)
                dim_l = C_old.shape()[0]
                dim_r = C_old.shape()[1]

                R[p] = get_new_R(R[p + 1], B[p + 1], W, B[p + 1].Conj())
                ############ Numpy Begin: Update zero site
                C_old = C_old.get_block().reshape(-1).numpy()
                C_new, E = exp_Lanczos_numpy(C_old, zero_site_H_psi,
                                             (L[p + 1], R[p]), -dt)
                C_new = cytnx.from_numpy(C_new)
                ############ Numpy Enf
                C_new = C_new.reshape(dim_l, dim_r)
                C_new = cyx.CyTensor(C_new, 1)

                C_new.set_labels([-1, 2])

                Ac_old = cyx.Contract(A[p], C_new).get_block()
                dim_l = Ac_old.shape()[0]
                dim_r = Ac_old.shape()[2]
                ############ Numpy Begin: Update one site
                Ac_old = Ac_old.reshape(-1).numpy()
                Ac_new, E = exp_Lanczos_numpy(Ac_old, one_site_H_psi, (L[p], W, R[p]),\
                                              dt, maxit=maxit, krydim=krydim)
                Ac_new = cytnx.from_numpy(Ac_new)
                ############ Numpy End
                Ac_new = cyx.CyTensor(Ac_new.reshape(dim_l, d, dim_r), 1)
                Ac = Ac_new
        if dispon == 1:
            print('Sweep: %d of %d, Energy: %.8f, Bond dim: %d' %
                  (k, numsweeps, E[0], chi))
        EE_all_time.append(EE.copy())
        # EE = 0
        # EE_all_time.append(EE)
        # print(EE_all_time)
        # exit()

    return EE_all_time, A, B
Example #7
0
##### Import cytnx module
from setting import *
import cytnx
from cytnx import cytnx_extension as cyx
import numpy as np
from numpy import linalg as LA
ten_a = np.random.randn(2,3,3)
ten_a = cytnx.from_numpy(ten_a)
ten_a = ten_a.astype(cytnx.Type.ComplexDouble)
s = 0.5
sy = cytnx.physics.spin(s, 'y')
sx = cytnx.physics.spin(s, 'x')
ten_a = cyx.CyTensor(ten_a, 0);
# print(ten_a)
# print(ten_a.Trace(1,2))
Test = cytnx.random.normal([2,3],0.,1.)
print(Test)
test2 = cytnx.Tensor([2,3])
print(test2)
cytnx.random.Make_normal(test2, 0.,1.)
test3 = cytnx.random.Make_normal(0.,1.)
print(test2)
Example #8
0
import cytnx
import numpy as np

A = cytnx.random.normal(12, 0, 0.2).reshape(3, 4).astype(cytnx.Type.Int64)
B = A.numpy()
print(B)
print(B.dtype)

x = np.arange(100).reshape(10, 10)

print(x.dtype)
C = cytnx.from_numpy(x)
print(x)
print(C)