Exemple #1
0
def inv(svd):
 bdi=uni10.Bond(uni10.BD_IN, svd.col())
 bdo=uni10.Bond(uni10.BD_OUT, svd.row())
 Landa=uni10.UniTensor([bdi,bdo])
 Landa.putBlock(svd)
 Landa=basic.inverse(Landa)
 return Landa
Exemple #2
0
def intialize_unitary_list(L, L_lay, d, delta):
    U_list = []
    bdi_spin = uni10.Bond(uni10.BD_IN, d)
    bdo_spin = uni10.Bond(uni10.BD_OUT, d)
    Svd = []
    matrix_random = uni10.Matrix(d * d, d * d)
    for i in xrange(d * d):
        for j in xrange(d * d):
            if (i == j):
                matrix_random[i * d * d + j] = 1.0
            else:
                matrix_random[i * d * d + j] = 0.0
    #matrix_random.setIdentity()
    for i in xrange(L / 2):
        U_list.append([])
    for i in xrange(L / 2):
        for j in xrange(len(L_lay)):
            U_uni10 = uni10.UniTensor([bdi_spin, bdi_spin, bdo_spin, bdo_spin],
                                      "Unitary_uni10")
            matrix_random1 = copy.copy(matrix_random)
            matrix_random1.randomize()
            matrix_random1 = matrix_random + (delta) * matrix_random1
            Svd = matrix_random1.svd()
            U_uni10.putBlock(Svd[0] * Svd[2])
            U_list[i].append(U_uni10)
    return U_list
Exemple #3
0
def pauli4body():
    '''
    Tensors for 4-body Pauli strings. 
    '''
    bond_dim = 2
    iden = matIden()
    sx = matSx()
    sy = matSy()
    sz = matSz()
    bdi = uni10.Bond(uni10.BD_IN, bond_dim)
    bdo = uni10.Bond(uni10.BD_OUT, bond_dim)

    pauli1b = [iden, sx, sy, sz]
    pauli4b = []
    pauli2b = []
    l2b = 16
    for i in xrange(4):
        for j in xrange(4):
            mat = uni10.otimes(pauli1b[i], pauli1b[j])
            pauli2b.append(mat)
    for i in xrange(l2b):
        for j in xrange(l2b):
            mat = uni10.otimes(pauli2b[i], pauli2b[j])
            P = uni10.UniTensor([bdi, bdi, bdi, bdi, bdo, bdo, bdo, bdo])
            P.putBlock(mat)
            pauli4b.append(P)

    return pauli4b
Exemple #4
0
def pauli6body():
    '''
    Tensors for 6-body Pauli strings. 
    '''
    bond_dim = 2
    iden = matIden()
    sx = matSx()
    sy = matSy()
    sz = matSz()
    bdi = uni10.Bond(uni10.BD_IN, bond_dim)
    bdo = uni10.Bond(uni10.BD_OUT, bond_dim)

    pauli1b = [iden, sx, sy, sz]
    pauli6b = []
    bonds = [bdi] * 6 + [bdo] * 6
    pauli3b = []

    for i in xrange(4):
        for j in xrange(4):
            for k in xrange(4):
                mat = uni10.otimes(uni10.otimes(pauli1b[i], pauli1b[j]),
                                   pauli1b[k])
                pauli3b.append(mat)
    l3b = 64
    for i in xrange(l3b):
        for j in xrange(l3b):
            mat = uni10.otimes(pauli3b[i], pauli3b[j])
            P = uni10.UniTensor(bonds)
            P.putBlock(mat)
            pauli6b.append(P)

    return pauli6b
Exemple #5
0
def vec2uni(v, L):
    bond_dim = 2
    vl = list(v)
    vl10 = uni10.Matrix(2**L, 1, vl)
    bdi = uni10.Bond(uni10.BD_IN, bond_dim)
    bdo = uni10.Bond(uni10.BD_OUT, bond_dim)
    vtensor = uni10.UniTensor([bdi] * L, 'GS')
    vtensor.putBlock(vl10)
    return vtensor
Exemple #6
0
def makeTab(chi, D):
    bdi = uni10.Bond(uni10.BD_IN, chi)
    bdi1 = uni10.Bond(uni10.BD_IN, D)
    bdo = uni10.Bond(uni10.BD_OUT, chi)
    Tem0 = uni10.UniTensor([bdi, bdi1, bdo])
    Tem0.randomize()
    Tem1 = uni10.UniTensor([bdi, bdi1, bdo])
    Tem1.randomize()

    return Tem0, Tem1
Exemple #7
0
    def __init__(self, physical=2, Dimension=2, Number=2, rand_fuc='rand'):
        self.N = Number
        self.D = Dimension
        self.d = physical
        self.tensor = [None] * Number
        bdi = uni10.Bond(uni10.BD_IN, self.D)
        bdo = uni10.Bond(uni10.BD_OUT, self.D)
        bdi1 = uni10.Bond(uni10.BD_IN, 1)
        bdo1 = uni10.Bond(uni10.BD_OUT, 1)
        bdi_pys = uni10.Bond(uni10.BD_IN, self.d)
        #print "Hi", bdi_pys
        A_fixed = uni10.UniTensor([bdi, bdi_pys, bdo], "A_middle")
        A_fixed.randomize()

        for i in xrange(self.N):
            if i == 0:
                A = uni10.UniTensor([bdi1, bdi_pys, bdo], "A_0")
                if rand_fuc is 'rand':
                    A.randomize()
                    self.tensor[i] = A
                    #print "Hi0A"
                elif rand_fuc is 'ortho':
                    A.orthoRand()
                    #print "Hi10"
                    self.tensor[i] = A
                elif rand_fuc is 'iden':
                    A.identity()
                    self.tensor[i] = A
                    #print "Hi20"

            elif i == ((self.N) - 1):
                A = uni10.UniTensor([bdi, bdi_pys, bdo1], "A_N")
                if rand_fuc is 'rand':
                    A.randomize()
                    self.tensor[i] = A
                elif rand_fuc is 'ortho':
                    A.orthoRand()
                    self.tensor[i] = A
                elif rand_fuc is 'iden':
                    #print "HIIIIIIIIIIIIIII"
                    A.identity()
                    self.tensor[i] = A
            else:
                A = uni10.UniTensor([bdi, bdi_pys, bdo], "A_middle")
                if rand_fuc is 'rand':
                    A.randomize()
                    self.tensor[i] = A
                elif rand_fuc is 'ortho':
                    A.orthoRand()
                    self.tensor[i] = A
                elif rand_fuc is 'randuni':
                    self.tensor[i] = copy.copy(A_fixed)
                elif rand_fuc is 'iden':
                    A.identity()
                    self.tensor[i] = A
Exemple #8
0
def get_umpo_up_1layer(Ulist,L,bond_idx,bond_dim=2):
    # Will not be called
    if (bond_idx%2 == 0):
        U = Ulist[bond_idx/2]
    else:
        bdi = uni10.Bond(uni10.BD_IN,  bond_dim)
        bdo = uni10.Bond(uni10.BD_OUT, bond_dim)
        U = uni10.UniTensor([bdi,bdi,bdo,bdo],'U0')
        I = matIden()
        U.putBlock(I)
    return U
Exemple #9
0
def transverseIsing(h):
    spin = 0.5
    sx = 0.5 * (matSp() + matSm())
    sz = matSz()
    iden = uni10.Matrix(2, 2, [1, 0, 0, 1])
    ham =uni10.otimes(2*sz,2*sz)*(-1) \
     +0.25*float(h)*(uni10.otimes(iden,2*sx)+uni10.otimes(2*sx,iden))
    dim = int(spin * 2 + 1)
    bdi = uni10.Bond(uni10.BD_IN, dim)
    bdo = uni10.Bond(uni10.BD_OUT, dim)
    H = uni10.UniTensor([bdi, bdi, bdo, bdo], "TFIM")
    H.putBlock(ham)
    return H
Exemple #10
0
def Ham(h):
    spin = 0.5
    sx = (matSp() + matSm())
    sz = matSz()
    iden = uni10.Matrix(2, 2, [1, 0, 0, 1])
    ham = uni10.otimes(sz, sz) * (-2.00) + (-0.500) * float(h) * (
        uni10.otimes(iden, sx) + uni10.otimes(sx, iden))
    dim = int(spin * 2 + 1)
    bdi = uni10.Bond(uni10.BD_IN, dim)
    bdo = uni10.Bond(uni10.BD_OUT, dim)
    H = uni10.UniTensor([bdi, bdi, bdo, bdo], "TFIM")
    H.putBlock(ham)
    return H
Exemple #11
0
def makec1(chi, D):
    bdi = uni10.Bond(uni10.BD_IN, chi)
    bdo = uni10.Bond(uni10.BD_OUT, chi)

    Tem0 = uni10.UniTensor([bdi, bdo])
    Tem0.randomize()
    Tem1 = uni10.UniTensor([bdi, bdo])
    Tem1.randomize()
    Tem2 = uni10.UniTensor([bdi, bdo])
    Tem2.randomize()
    Tem3 = uni10.UniTensor([bdi, bdo])
    Tem3.randomize()

    return Tem0, Tem1, Tem2, Tem3
Exemple #12
0
def Iden_uni10(d):
 bdi=uni10.Bond(uni10.BD_IN, d)
 bdo=uni10.Bond(uni10.BD_OUT, d)
 Iden_Matrix=uni10.Matrix(d*d,d)
 for i in xrange(d):
   for j in xrange(d):
    for m in xrange(d):
     if i is j and j is m: 
      Iden_Matrix[i*d+j,m]=1
     else:
      Iden_Matrix[i*d+j,m]=0
 Iden_uni10=uni10.UniTensor([bdi,bdi,bdo], 'Iden_uni10')
 Iden_uni10.putBlock(Iden_Matrix)   
 return Iden_uni10
Exemple #13
0
def transverseIsing(h):
    spin = 0.5
    sx = matSx()
    sy = matSy()
    sz = matSz()
    iden = uni10.Matrix(2, 2, [1, 0, 0, 1])
    ham = uni10.otimes(sz, sz) * (-1) + (-0.2500) * float(h) * (
        uni10.otimes(iden, sx) + uni10.otimes(sx, iden))
    dim = int(spin * 2 + 1)
    bdi = uni10.Bond(uni10.BD_IN, dim)
    bdo = uni10.Bond(uni10.BD_OUT, dim)
    H = uni10.UniTensor([bdi, bdi, bdo, bdo], "TFIM")
    H.putBlock(ham)
    return H
Exemple #14
0
def Heisenberg(h):
    spin = 0.5
    sx = matSx()
    sy = matSy()
    sz = matSz()
    iden = uni10.Matrix(2, 2, [1, 0, 0, 1])
    ham = (float(h) * uni10.otimes(sz, sz) * (1.00 / 4.00) +
           (1.00 / 4.00) * uni10.otimes(sx, sx) +
           (-1.00 / 4.00) * uni10.otimes(sy, sy))
    dim = int(spin * 2 + 1)
    bdi = uni10.Bond(uni10.BD_IN, dim)
    bdo = uni10.Bond(uni10.BD_OUT, dim)
    H = uni10.UniTensor([bdi, bdi, bdo, bdo], "Heisenberg")
    H.putBlock(ham)
    return H
def Heisenberg(D, Delta, h, J):
    iden = matId()
    sm = matSm()
    sp = matSp()
    sz = matSz()
    sz2 = matSz2()
    ham = float(J)*(0.5*(uni10.otimes(sm,sp)+uni10.otimes(sp,sm))+float(Delta)*uni10.otimes(sz,sz))
    ham += 0.5*float(h)*(uni10.otimes(iden,sz)+uni10.otimes(sz,iden))
    ham += 0.5*float(D)*(uni10.otimes(iden,sz2)+uni10.otimes(sz2,iden))
    spin = 1.0
    dim = int(spin * 2 + 1)
    bdi = uni10.Bond(uni10.BD_IN, dim);
    bdo = uni10.Bond(uni10.BD_OUT, dim);
    H = uni10.UniTensor([bdi, bdi, bdo, bdo], "Heisenberg")
    H.putBlock(ham)
    return H
Exemple #16
0
def setTruncation(theta, chi):
    #print theta
    LA = uni10.UniTensor(theta.bond())
    GA = uni10.UniTensor(theta.bond())
    GB = uni10.UniTensor(theta.bond())

    bond_In_list, bond_OUT_list = bond_list_dist(theta)
    #print bond_In_list,bond_OUT_list
    svds = {}
    blk_qnums = theta.blockQnum()
    dim_svd = []
    for qnum in blk_qnums:
        M_tem = theta.getBlock(qnum)
        svds[qnum] = M_tem.svd()
        #print qnum, svds[qnum][1]
        dim_svd.append(int(svds[qnum][1].col()))
    svs = []
    bidxs = []
    for bidx in xrange(len(blk_qnums)):
        svs, bidxs = sv_merge(svs, bidxs, bidx, svds[blk_qnums[bidx]][1], chi,
                              len(blk_qnums))
        #print "lol", svs, bidxs
    dims = [0] * len(blk_qnums)
    for bidx in bidxs:
        dims[bidx] += 1
    qnums = []
    for bidx in xrange(len(blk_qnums)):
        qnums += [blk_qnums[bidx]] * dims[bidx]
    bdi_mid = uni10.Bond(uni10.BD_IN, qnums)
    #print "Hi", chi, svs, qnums, bdi_mid
    #print bdi_mid
    bdo_mid = uni10.Bond(uni10.BD_OUT, qnums)
    bond_In_list.append(bdo_mid)
    GA.assign(bond_In_list)
    bond_OUT_list.insert(0, bdi_mid)
    GB.assign(bond_OUT_list)
    LA.assign([bdi_mid, bdo_mid])
    degs = bdi_mid.degeneracy()
    for qnum, dim in degs.iteritems():
        if qnum not in svds:
            raise Exception("In setTruncaton(): Fatal error.")
        svd = svds[qnum]
        GA.putBlock(qnum, svd[0].resize(svd[0].row(), dim))
        GB.putBlock(qnum, svd[2].resize(dim, svd[2].col()))
        LA.putBlock(qnum, svd[1].resize(dim, dim))
    #print LA
    return GA, GB, LA
Exemple #17
0
def magnetization(a_u):
    a_u.setLabel([0, 1, 2, 3, 4])
    a_uc = copy.copy(a_u)
    a_uc.setLabel([5, -1, -2, -3, -4])
    sz = matSz()
    bdi = uni10.Bond(uni10.BD_IN, 2)
    bdo = uni10.Bond(uni10.BD_OUT, 2)
    Z = uni10.UniTensor([bdi, bdo], "Z")
    Z.putBlock(sz)
    Z.setLabel([5, 0])
    result = a_uc * Z * a_u
    result.combineBond([1, -1])
    result.combineBond([2, -2])
    result.combineBond([3, -3])
    result.combineBond([4, -4])
    result.permute([1, 2, 3, 4], 2)

    return result
Exemple #18
0
def trgSVD(wch, T, chi):
    if wch % 2 == 0:
        T.permute([-4, -3, -1, -2], 2)
    else:
        T.permute([-1, -4, -2, -3], 2)

    svd = T.getBlock().svd()
    chi = chi if chi < svd[1].row() else svd[1].row()
    bdi_chi = uni10.Bond(uni10.BD_IN, chi)
    bdo_chi = uni10.Bond(uni10.BD_OUT, chi)
    S0 = uni10.UniTensor([T.bond(0), T.bond(1), bdo_chi])
    S1 = uni10.UniTensor([bdi_chi, T.bond(2), T.bond(3)])
    svd[1].resize(chi, chi)
    for i in xrange(chi):
        svd[1][i] = np.sqrt(svd[1][i])
    S0.putBlock(svd[0].resize(svd[0].row(), chi) * svd[1])
    S1.putBlock(svd[1] * svd[2].resize(chi, svd[2].col()))
    return S0, S1
Exemple #19
0
def   svd_parity(theta):
    #print theta,theta.getBlock().svd()
    bdo=uni10.Bond(uni10.BD_OUT,theta.bond(1).Qlist())
    bdo1=uni10.Bond(uni10.BD_OUT,theta.bond(2).Qlist())

    #A_{m<n}=U_{mm}S_{mm}V_{mn}

    LA=uni10.UniTensor([theta.bond(1), bdo])
    GA=uni10.UniTensor([theta.bond(0), theta.bond(1),bdo])
    GB=uni10.UniTensor([theta.bond(1), bdo1])
    svds = {}
    blk_qnums = theta.blockQnum()
    dim_svd=[]
    for qnum in blk_qnums:
        svds[qnum] = theta.getBlock(qnum).svd()
    for qnum in blk_qnums:
        svd = svds[qnum]
        GA.putBlock(qnum, svd[0])
        GB.putBlock(qnum, svd[2])
        LA.putBlock(qnum, svd[1])
#    print LA
    return GA, LA,GB
Exemple #20
0
def qr_parity(theta):

    #bd1=copy.copy(theta.bond(3))
    #bd1.change(uni10.BD_IN)
    bd1 = uni10.Bond(uni10.BD_IN, theta.bond(1).Qlist())

    GA = uni10.UniTensor(uni10.CTYPE, [theta.bond(0), theta.bond(1)])
    LA = uni10.UniTensor(uni10.CTYPE, [bd1, theta.bond(1)])

    svds = {}
    blk_qnums = theta.blockQnum()
    dim_svd = []
    for qnum in blk_qnums:
        svds[qnum] = theta.getBlock(qnum).qr()
        GA.putBlock(qnum, svds[qnum][0])
        LA.putBlock(qnum, svds[qnum][1])

    #    print LA
    return GA, LA
Exemple #21
0
def Equall_Dist(l, r,D,d_phys):
 
 bdiB=uni10.Bond(uni10.BD_IN, d_phys*D)
 bdoB=uni10.Bond(uni10.BD_OUT, d_phys*D)
 bdi_pys=uni10.Bond(uni10.BD_IN, d_phys)
 bdi_pyso=uni10.Bond(uni10.BD_OUT, d_phys)
 bdi=uni10.Bond(uni10.BD_IN, D)
 bdo=uni10.Bond(uni10.BD_OUT, D)

 lp=copy.copy(l)
 rp=copy.copy(r)
 rp.permute([3,20,1],1)
 lq_r=rp.getBlock().lq()
 
 
 
 lp.permute([2,40,3],2)
 qr_l=lp.getBlock().qr()
 
 
 
 
 #lp.setLabel([1,40,-3])
 Teta=qr_l[1]*lq_r[0]
 svd=Teta.svd()
 s=Sqrt(svd[1])
 U=svd[0]*s
 V=s*svd[2]
 #U.resize(U.row(),rp.bond()[2].dim() )
 #V.resize(rp.bond()[2].dim(), V.col())
 #rp=uni10.UniTensor([bdi, bdi_pys,bdoB])
 
 #print lq_r[1].col(),  U.row()
 A=V*lq_r[1]
 B=qr_l[0]*U
 rp.putBlock(A)
 lp.putBlock(B)
 
 rp.permute([3,20,1],2)
 lp.permute([2,40,3],2)
 
  
 lp_d=copy.copy(lp)
 rp_d=copy.copy(rp)
 rp_d.setLabel([-3,-20,-1])
 lp_d.setLabel([-2,-40,-3])
 
 return  lp, rp, lp_d, rp_d
Exemple #22
0
def  proper_bond(E1, E2, E3, E4, E5,E6,D,d_phys):
 bd=uni10.Bond(E1.bond()[1].type(), D)
 A=uni10.UniTensor([E1.bond()[0],bd,bd,E1.bond()[2]])
 A.putBlock(E1.getBlock())
 E1=copy.copy(A)
 E1.setLabel([7,3,-3,8])
 
 bd=uni10.Bond(E2.bond()[1].type(), D)
 A=uni10.UniTensor([E2.bond()[0],bd,bd,E2.bond()[2]])
 A.putBlock(E2.getBlock())
 E2=copy.copy(A)
 E2.setLabel([12,13,-13,7])


 bd=uni10.Bond(E3.bond()[1].type(), D)
 A=uni10.UniTensor([E3.bond()[0],bd,bd,E3.bond()[2]])
 A.putBlock(E3.getBlock())
 E3=copy.copy(A)
 E3.setLabel([11,1,-1,12])


 bd=uni10.Bond(E4.bond()[1].type(), D)
 A=uni10.UniTensor([E4.bond()[0],bd,bd,E4.bond()[2]])
 A.putBlock(E4.getBlock())
 E4=copy.copy(A)
 E4.setLabel([11,4,-4,10])


 bd=uni10.Bond(E5.bond()[1].type(), D)
 A=uni10.UniTensor([E5.bond()[0],bd,bd,E5.bond()[2]])
 A.putBlock(E5.getBlock())
 E5=copy.copy(A)
 E5.setLabel([10,5,-5,9])

 bd=uni10.Bond(E6.bond()[1].type(), D)
 A=uni10.UniTensor([E6.bond()[0],bd,bd,E6.bond()[2]])
 A.putBlock(E6.getBlock())
 E6=copy.copy(A)
 E6.setLabel([9,6,-6,8])

 return E1, E2, E3, E4, E5,E6
Exemple #23
0
def initialize_SVD_lrprime(l, r, l_d, r_d, N_uni,U,D,d_phys):
 
 bdiB=uni10.Bond(uni10.BD_IN, d_phys*D)
 bdoB=uni10.Bond(uni10.BD_OUT, d_phys*D)
 bdi_pys=uni10.Bond(uni10.BD_IN, d_phys)
 bdi_pyso=uni10.Bond(uni10.BD_OUT, d_phys)
 bdi=uni10.Bond(uni10.BD_IN, D)
 bdo=uni10.Bond(uni10.BD_OUT, D)

 U.setLabel([-20,-40,20,40])
 lp=copy.copy(l)
 rp=copy.copy(r)
 #lp.setLabel([1,40,-3])
 Teta=U*lp*rp
 Teta.permute([1,-20,2,-40],2)
 svd=Teta.getBlock().svd()
 s=Sqrt(svd[1])
 U=svd[0]*s
 V=s*svd[2]
 U.resize(U.row(),rp.bond()[0].dim() )
 V.resize(rp.bond()[0].dim(), V.col())
 
 rp=uni10.UniTensor([bdiB, bdi_pys, bdo ])
 rp.putBlock(U)
 rp.setLabel([1,20,3])
 rp.permute([3,20,1],2)
 
 lp=uni10.UniTensor([ bdi, bdoB, bdi_pyso])
 lp.putBlock(V)
 lp.setLabel([3,2,40])
 lp.permute([2,40,3],2)
 lp_d=copy.copy(lp)
 rp_d=copy.copy(rp)
 rp_d.setLabel([-3,-20,-1])
 lp_d.setLabel([-2,-40,-3])
 
 return  lp, rp, lp_d, rp_d
Exemple #24
0
def get_Hbond_tensor(model,bond_idx,L,J=1.0,Fieldz=1.0,hzlist=[],bond_dim=2,\
                     avebond=True):

    #TODO put Z terms only into the even bonds

    '''
    _________________________________________________________________
    Ising Model:                |    Heisenberg Model 
    -J XX - h Z    (h=Fieldz)   |    J(XX + ZZ - YY) + h Z (h=hzlist)
    ____________________________|____________________________________
                        Result in a tensor:
                              _____
                         0 __|     |__ 2
                         1 __|  H  |__ 3
                             |_____| 
    _________________________________________________________________

    '''

    # make matrix
    sx   = utils.matSx()
    sy   = utils.matSy()
    sz   = utils.matSz()
    s0   = utils.matIden()
    if (model == 'Ising'):
        Hbond_mat  = (-1.*J)*uni10.otimes(sx,sx)
        if avebond:
            if (bond_idx == 0):
                Hbond_mat += (-1.0*Fieldz)*uni10.otimes(sz,s0) 
                Hbond_mat += (-0.5*Fieldz)*uni10.otimes(s0,sz)
            elif (bond_idx == L-2):
                Hbond_mat += (-0.5*Fieldz)*uni10.otimes(sz,s0) 
                Hbond_mat += (-1.0*Fieldz)*uni10.otimes(s0,sz)
            else:
                Hbond_mat += (-0.5*Fieldz)*uni10.otimes(sz,s0) 
                Hbond_mat += (-0.5*Fieldz)*uni10.otimes(s0,sz)

        else:
            if (bond_idx%2 == 0):
                Hbond_mat += (-1.0*Fieldz)*uni10.otimes(sz,s0) 
                Hbond_mat += (-1.0*Fieldz)*uni10.otimes(s0,sz)

    elif (model == 'Heisenberg'):
        #TODO try evenly distributed bond
        Hbond_mat  =  (1.*J)*uni10.otimes(sx,sx)
        Hbond_mat += (-1.*J)*uni10.otimes(sy,sy)
        Hbond_mat +=  (1.*J)*uni10.otimes(sz,sz)
        if avebond:
            if (bond_idx == 0):
                Hbond_mat += (1. *hzlist[0])*uni10.otimes(sz,s0)
                Hbond_mat += (0.5*hzlist[1])*uni10.otimes(s0,sz)
            elif (bond_idx == L-2):
                Hbond_mat += (0.5*hzlist[L-2])*uni10.otimes(sz,s0)
                Hbond_mat += (1. *hzlist[L-1])*uni10.otimes(s0,sz)
            else:
                Hbond_mat += (0.5*hzlist[bond_idx])*uni10.otimes(sz,s0)
                Hbond_mat += (0.5*hzlist[bond_idx+1])*uni10.otimes(s0,sz)
        else:
            if (bond_idx%2 == 0):
                Hbond_mat += (1.*hzlist[bond_idx])*uni10.otimes(sz,s0)
                Hbond_mat += (1.*hzlist[bond_idx+1])*uni10.otimes(s0,sz)
    else:
        raise Exception("The model can only be Ising or Heisenberg!")

    # construct tensor
    bdi = uni10.Bond(uni10.BD_IN,  bond_dim)
    bdo = uni10.Bond(uni10.BD_OUT, bond_dim)

    Hbond = uni10.UniTensor([bdi,bdi,bdo,bdo],'Hbond')
    Hbond.putBlock(Hbond_mat)
    Hbond.setLabel([0,1,2,3])
    
    return Hbond
Exemple #25
0
def Qr_lQ_decom(a_u,b_u, E1, E2, E3, E4, E5,E6,D,d_phys):
 a_uc=copy.copy(a_u)
 a_uc.setLabel([20,13,1,2,3])
 a_uc.permute([3,13,1,20,2],3)
 mat=a_uc.getBlock()
 qr=mat.qr()
 
 bdiB=uni10.Bond(uni10.BD_IN, d_phys*D)
 bdoB=uni10.Bond(uni10.BD_OUT, d_phys*D)
 bdi_pys=uni10.Bond(uni10.BD_IN, d_phys)
 bdi_pyso=uni10.Bond(uni10.BD_OUT, d_phys)
 bdi=uni10.Bond(uni10.BD_IN, D)
 bdo=uni10.Bond(uni10.BD_OUT, D)


 q_uni=uni10.UniTensor([bdi,bdi,bdi,bdoB])
 r_uni=uni10.UniTensor([bdiB,bdi_pyso,bdo])

 q_uni.setLabel([3,13,1,100])
 r_uni.setLabel([100,20,2])

 q_uni.putBlock(qr[0])
 r_uni.putBlock(qr[1])


 b_uc=copy.copy(b_u)
 b_uc.setLabel([40,2,4,5,6])
 b_uc.permute([40,2,4,5,6],2)
 mat=b_uc.getBlock()
 lq=mat.lq()

 l_uni=uni10.UniTensor([bdi_pys,bdi,bdoB])
 qq_uni=uni10.UniTensor([bdiB,bdo,bdo,bdo])
 l_uni.setLabel([40,2,200])
 qq_uni.setLabel([200,4,5,6])

 

 l_uni.putBlock(lq[0])
 qq_uni.putBlock(lq[1])

 r_uni_d=copy.copy(r_uni)
 r_uni_d.setLabel([-100,-20,-2])

 l_uni_d=copy.copy(l_uni)
 l_uni_d.setLabel([-40,-2,-200])


 q_uni_d=copy.copy(q_uni)
 q_uni_d.setLabel([-3,-13,-1,-100])
 qq_uni_d=copy.copy(qq_uni)
 qq_uni_d.setLabel([-200,-4,-5,-6])
 N=((((E1*q_uni)*E2)*q_uni_d)*E3)*((((E6*qq_uni)*E5)*qq_uni_d)*E4)
 N.permute([100,-100,200,-200],2)

 N.setLabel([1,-1,2,-2])
 #r_uni.setLabel([100,20,2])
 r_uni.setLabel([1,20,3])
 r_uni.permute([3,20,1],2)
 
 r_uni_d=copy.copy(r_uni)
 r_uni_d.setLabel([-3,-20,-1])

 #l_uni.setLabel([40,2,200])
 l_uni.setLabel([40,3,2])
 l_uni.permute([2,40,3],2)
 
 l_uni_d=copy.copy(l_uni)
 l_uni_d.setLabel([-2,-40,-3])

 #q_uni.setLabel([3,13,1,100])
 q_uni.setLabel([2,4,5,1])
 #qq_uni.setLabel([200,4,5,6])
 qq_uni.setLabel([2,4,5,6])
 
 
 return   N, l_uni, l_uni_d, r_uni, r_uni_d, q_uni,qq_uni
Exemple #26
0
def  add_left(c1,c2,c3,c4,Ta1,Ta2,Ta3,Ta4,Tb1,Tb2,Tb3,Tb4,a,b,c,d,chi,D):

 c1.setLabel([4,1])
 c2.setLabel([3,7])
 c3.setLabel([4,24])
 c4.setLabel([18,22])
 Ta1.setLabel([2,6,3]) 
 Ta2.setLabel([14,10,7]) 
 Ta3.setLabel([22,19,23]) 
 Ta4.setLabel([18,15,-3]) 
 Tb1.setLabel([1,5,2]) 
 Tb2.setLabel([4,17,14]) 
 Tb3.setLabel([23,20,24]) 
 Tb4.setLabel([-1,8,4])
 a.setLabel([8,-2,9,5])
 b.setLabel([9,13,10,6])
 c.setLabel([15,19,16,-4])
 d.setLabel([16,20,17,13])
 Contract=(((((c3*Tb2)*Tb3)*(d))*(((c4*Ta3)*Ta4)*c))*(((c2*Ta2)*Ta1)*b))*(((c1*Tb1)*Tb4)*a)
 Contract.permute([-1,-2,-3,-4],2)
 #print Contract.trace()#, Contract.printDiagram()
 svd = Contract.getBlock()
 svd=svd.svd()
 bdo = uni10.Bond(uni10.BD_OUT, chi)
 U1x=uni10.UniTensor([Contract.bond()[0],Contract.bond()[1], bdo], "U1x")
 U1x.putBlock(svd[0].resize(svd[0].row(), chi))
 U1x_trans=copy.copy(U1x)
 U1x_trans.transpose()


 







 c1.setLabel([4,1])
 c2.setLabel([3,7])
 c3.setLabel([4,24])
 c4.setLabel([18,22])
 Ta1.setLabel([2,6,3]) 
 Ta2.setLabel([-1,10,7]) 
 Ta3.setLabel([22,19,23]) 
 Ta4.setLabel([18,15,11]) 
 Tb1.setLabel([1,5,2]) 
 Tb2.setLabel([4,17,-3]) 
 Tb3.setLabel([23,20,24]) 
 Tb4.setLabel([11,8,4])
 a.setLabel([8,12,9,5])
 b.setLabel([9,-2,10,6])
 c.setLabel([15,19,16,12])
 d.setLabel([16,20,17,-4])
 Contract=(((((c3*Tb2)*Tb3)*(d))*(((c4*Ta3)*Ta4)*c))*(((c1*Tb1)*Tb4)*a))*(((c2*Ta2)*Ta1)*b)
 Contract.permute([-1,-2,-3,-4],2)
 #print Contract.trace()#, Contract.printDiagram()
 svd = Contract.getBlock().svd()
 bdo = uni10.Bond(uni10.BD_OUT, chi)
 U2x=uni10.UniTensor([Contract.bond()[0],Contract.bond()[1], bdo], "U2x")
 U2x.putBlock(svd[0].resize(svd[0].row(), chi))
 U2x_trans=copy.copy(U2x)
 U2x_trans.transpose()




 Ta4p=copy.copy(Ta4)
 Tb4p=copy.copy(Tb4)
 Ta2p=copy.copy(Ta2)
 Tb2p=copy.copy(Tb2)
 U1xb=copy.copy(U1x)
 U1xb_trans=copy.copy(U1x_trans)
 U2xb=copy.copy(U2x)
 U2xb_trans=copy.copy(U2x_trans)
 ap=copy.copy(a)
 bp=copy.copy(b)
 cp=copy.copy(c)
 dp=copy.copy(d)
 c1.setLabel([4,1])
 c2.setLabel([3,7])
 c3.setLabel([47,50])
 c4.setLabel([44,48])
 Ta1.setLabel([2,6,3]) 
 Ta2.setLabel([14,10,7]) 
 Ta2p.setLabel([34,30,27]) 
 Ta3.setLabel([48,45,49]) 
 Ta4.setLabel([-1,21,17]) 
 Ta4p.setLabel([44,41,37]) 
 Tb1.setLabel([1,5,2]) 
 Tb2.setLabel([27,23,20])
 Tb2p.setLabel([47,43,40]) 
 Tb3.setLabel([49,46,50]) 
 Tb4.setLabel([11,8,4])
 Tb4p.setLabel([31,28,-3])
 a.setLabel([8,12,9,5])
 b.setLabel([9,13,10,6])
 c.setLabel([21,-2,22,18])
 d.setLabel([22,26,23,19])
 ap.setLabel([28,32,29,-4])
 bp.setLabel([29,33,30,26])
 cp.setLabel([41,45,42,38])
 dp.setLabel([42,46,43,39])
 U1x.setLabel([17,18,15])
 U1x_trans.setLabel([15,11,12])
 U2x.setLabel([20,19,16])
 U2x_trans.setLabel([16,14,13])
 U1xb.setLabel([37,38,35])
 U1xb_trans.setLabel([35,31,32])
 U2xb.setLabel([40,39,36])
 U2xb_trans.setLabel([36,34,33])

 Contract=( ( (((((c1*Tb1 )*Tb4)*a) * U1x_trans) * ((((c2*Ta1)*Ta2)*b)*  U2x_trans))
 *  ( (((((c4*Ta3)*Ta4p)*cp)*U1xb) * ((((c3*Tb3)*Tb2p)*dp)*U2xb)) *
( ((Tb2*U2x)*d)   *   ((Ta2p*U2xb_trans)*bp) ) ) ) * ((Ta4 *U1x) *c) ) * ((Tb4p* ap)* U1xb_trans) 

 Contract.permute([-1,-2,-3,-4],2)
 #print Contract.trace()
 #print Contract.printDiagram()
 svd = Contract.getBlock().svd()
 bdo = uni10.Bond(uni10.BD_OUT, chi)
 U3x=uni10.UniTensor([Contract.bond()[0],Contract.bond()[1], bdo], "U3x")
 U3x.putBlock(svd[0].resize(svd[0].row(), chi))
 U3x_trans=copy.copy(U3x)
 U3x_trans.transpose()



 c1.setLabel([4,1])
 c2.setLabel([3,7])
 c3.setLabel([47,50])
 c4.setLabel([44,48])
 Ta1.setLabel([2,6,3]) 
 Ta2.setLabel([14,10,7]) 
 Ta2p.setLabel([34,30,-3]) 
 Ta3.setLabel([48,45,49]) 
 Ta4.setLabel([24,21,17]) 
 Ta4p.setLabel([44,41,37]) 
 Tb1.setLabel([1,5,2]) 
 Tb2.setLabel([-1,23,20])
 Tb2p.setLabel([47,43,40]) 
 Tb3.setLabel([49,46,50]) 
 Tb4.setLabel([11,8,4])
 Tb4p.setLabel([31,28,24])
 a.setLabel([8,12,9,5])
 b.setLabel([9,13,10,6])
 c.setLabel([21,25,22,18])
 d.setLabel([22,-2,23,19])
 ap.setLabel([28,32,29,25])
 bp.setLabel([29,33,30,-4])
 cp.setLabel([41,45,42,38])
 dp.setLabel([42,46,43,39])
 U1x.setLabel([17,18,15])
 U1x_trans.setLabel([15,11,12])
 U2x.setLabel([20,19,16])
 U2x_trans.setLabel([16,14,13])
 U1xb.setLabel([37,38,35])
 U1xb_trans.setLabel([35,31,32])
 U2xb.setLabel([40,39,36])
 U2xb_trans.setLabel([36,34,33])



 Contract=( ( (((((c1*Tb1 )*Tb4)*a) * U1x_trans) * ((((c2*Ta1)*Ta2)*b)*  U2x_trans))
 *  ( (((((c4*Ta3)*Ta4p)*cp)*U1xb) * ((((c3*Tb3)*Tb2p)*dp)*U2xb)) *
( ((Ta4 *U1x) *c)    *  ((Tb4p* ap)* U1xb_trans)  ) ) ) * ((Tb2*U2x)*d) ) *((Ta2p*U2xb_trans)*bp)

 Contract.permute([-1,-2,-3,-4],2)
 #print Contract.trace()
 #print Contract.printDiagram()
 svd = Contract.getBlock().svd()
 bdo = uni10.Bond(uni10.BD_OUT, chi)
 U4x=uni10.UniTensor([Contract.bond()[0],Contract.bond()[1], bdo], "U4x")
 U4x.putBlock(svd[0].resize(svd[0].row(), chi))
 U4x_trans=copy.copy(U4x)
 U4x_trans.transpose()



###############################################################################
 c1.setLabel([0,1])
 Tb1.setLabel([1,2,3])
 c1bar=c1*Tb1
 c1bar.permute([0,2,3],2)

 c4.setLabel([0,1])
 Ta3.setLabel([1,2,3])
 c4bar=c4*Ta3
 c4bar.permute([0,2,3],1)

 ##############################
 U3x_trans.setLabel([4,0,2])
 c1bar=c1bar*U3x_trans
 c1bar.permute([4,3],1)
 ############################
 U3x.setLabel([0,2,4])
 c4bar=c4bar*U3x
 c4bar.permute([4,3],1)
 #############################
 Tb4.setLabel([0,1,2])
 a.setLabel([1,3,4,5])
 U3x.setLabel([2,5,6])
 U1x_trans.setLabel([7,0,3])
 Tb4bar=((Tb4*a)*U3x)*U1x_trans
 Tb4bar.permute([7,4,6],2)
 ###########################
 Ta4.setLabel([0,1,2])
 c.setLabel([1,3,4,5])
 U1x.setLabel([2,5,6])
 U3x_trans.setLabel([7,0,3])
 Ta4bar=((Ta4*c)*U3x_trans)*U1x
 Ta4bar.permute([7,4,6],2)
#############################

 #################3################################
 c2.setLabel([0,1])
 Ta1.setLabel([3,2,0])
 c2bar=c2*Ta1
 c2bar.permute([1,2,3],2)
 
 c3.setLabel([0,1])
 Tb3.setLabel([3,2,1])
 c3bar=c3*Tb3
 c3bar.permute([3,0,2],1)
 
 ##############################
 U4x_trans.setLabel([4,1,2])
 c2bar=c2bar*U4x_trans
 c2bar.permute([3,4],1)
 ############################
 U4x.setLabel([0,2,4])
 c3bar=c3bar*U4x
 c3bar.permute([4,3],1)
 #############################
 Ta2.setLabel([0,1,2])
 b.setLabel([4,5,1,3])
 U4x.setLabel([2,3,7])
 U2x_trans.setLabel([6,0,5])
 Ta2bar=((Ta2*b)*U4x)*U2x_trans
 Ta2bar.permute([6,4,7],2)
 ###########################
 Tb2.setLabel([0,1,2])
 d.setLabel([4,5,1,3])
 U2x.setLabel([2,3,7])
 U4x_trans.setLabel([6,0,5])
 Tb2bar=((Tb2*d)*U4x_trans)*U2x
 Tb2bar.permute([6,4,7],2)
 ###########################
 ###########################

 if ( (abs(c3bar.getBlock().absMax()) < 0.50e-1) or (abs(c3bar.getBlock().absMax()) > 0.50e+1)   ):
  c3=c3bar*(1.00/c3bar.getBlock().absMax()); 
 else: c3=c3bar;
 #print 'norm000', c3.norm(), c3.getBlock().absMax()
 
 if ( (abs(c2bar.getBlock().absMax()) < 0.50e-1) or (abs(c2bar.getBlock().absMax()) > 0.50e+1) ):
  c2=c2bar*(1.00/c2bar.getBlock().absMax()); 
 else: c2=c2bar;
 #print 'norm111', c2.norm(), c2.getBlock().absMax()
 
 if ( (abs(Ta2bar.getBlock().absMax()) < 0.50e-1) or (abs(Ta2bar.getBlock().absMax()) > 0.50e+1) ):
  Ta2=Ta2bar*(1.00/Ta2bar.getBlock().absMax()); 
 else: Ta2=Ta2bar;
 #print 'norm222', Ta2.norm(), Ta2.getBlock().absMax()

 if ( (abs(Tb2bar.getBlock().absMax()) < 0.50e-1) or (abs(Tb2bar.getBlock().absMax()) > 0.50e+1) ):
  Tb2=Tb2bar*(1.00/Tb2bar.getBlock().absMax()); 
 else: Tb2=Tb2bar;
 #print 'norm333', Tb2.norm(), Tb2.getBlock().absMax()



 if ( (abs(c1bar.getBlock().absMax()) < 0.50e-1) or (abs(c1bar.getBlock().absMax()) > 0.50e+1)   ):
  c1=c1bar*(1.00/c1bar.getBlock().absMax()); 
 else: c1=c1bar;
 #print 'norm0', c1.norm(), c1.getBlock().absMax()
 
 if ( (abs(c4bar.getBlock().absMax()) < 0.50e-1) or (abs(c4bar.getBlock().absMax()) > 0.50e+1) ):
  c4=c4bar*(1.00/c4bar.getBlock().absMax()); 
 else: c4=c4bar;
 #print 'norm1', c4.norm(), c4.getBlock().absMax()
 
 if ( (abs(Ta4bar.getBlock().absMax()) < 0.50e-1) or (abs(Ta4bar.getBlock().absMax()) > 0.50e+1) ):
  Ta4=Ta4bar*(1.00/Ta4bar.getBlock().absMax()); 
 else: Ta4=Ta4bar;
 #print 'norm2', Ta4.norm(), Ta4.getBlock().absMax()

 if ( (abs(Tb4bar.getBlock().absMax()) < 0.50e-1) or (abs(Tb4bar.getBlock().absMax()) > 0.50e+1) ):
  #print 'norm3', Tb4bar.norm(), Tb4bar.getBlock().absMax()
  Tb4=Tb4bar*(1.00/Tb4bar.getBlock().absMax()); 
 else: Tb4=Tb4bar;
 #print 'norm3', Tb4.norm(), Tb4.getBlock().absMax()

 ###############################







 return c1, Ta4, Tb4, c4, c2, Ta2, Tb2, c3
Exemple #27
0
# ### bond construction
sx = np.array([0.,1.,1.,0.]).reshape(2,2)
sy = np.array([0.,-1,1,0.]).reshape(2,2)
sz = np.array([1.,0.,0.,-1.]).reshape(2,2)
si = np.eye(2)
Sx = uni10.Matrix(2,2,[0.,1.,1.,0.])
Sy = uni10.Matrix(2,2,[0.,-1,1,0.])
Sz = uni10.Matrix(2,2,[1.,0.,0.,-1.])
Si = uni10.Matrix(2,2,[1.,0.,0.,1.])


hm = -1.* np.kron(sx,sx)-0.5*(np.kron(sz,si)+np.kron(si,sz))
hl = -1.* np.kron(sx,sx)-0.5*np.kron(si,sz)-np.kron(sz,si)
hr = -1.* np.kron(sx,sx)-np.kron(si,sz)-0.5*np.kron(sz,si)

bdi = uni10.Bond(uni10.BD_IN,2)
bdo = uni10.Bond(uni10.BD_OUT,2)

u11 = np.einsum('ij,kl->ikjl',sx,sz)
u12 = np.einsum('ij,kl->ikjl',si,sx)
u13 = np.einsum('ij,kl->ikjl',sz,sz)
u21 = np.einsum('ij,kl->ikjl',sz,sx)
u22 = np.einsum('ij,kl->ikjl',sz,si)
u23 = np.einsum('ij,kl->ikjl',sx,sx)


U11 = uni10.UniTensor([bdi,bdi,bdo,bdo])
U11.putBlock(uni10.otimes(Sx,Sz))
U12 = uni10.UniTensor([bdi,bdi,bdo,bdo])
U12.putBlock(uni10.otimes(Si,Sx))
U13 = uni10.UniTensor([bdi,bdi,bdo,bdo])
            if (abs(D[i])>lambda2):
                lambda2 = abs(D[i])
    return -1/np.log(lambda2/lambda1)

D = float(sys.argv[1])
chi = int(sys.argv[2])
istate = int(sys.argv[3])

delta = 0.01
N = 20000
Delta = 1.000
h = 0.000
J = 1.000
H = Heisenberg(D, Delta, h, J)

bdi_chi = uni10.Bond(uni10.BD_IN, chi)
bdo_chi = uni10.Bond(uni10.BD_OUT, chi)

# Gamma matrices: Gs=[Ga, Gb]
Gs = []
Gs.append(uni10.UniTensor([bdi_chi, bdo_chi, H.bond(2)], "Ga"))
Gs.append(uni10.UniTensor([bdi_chi, bdo_chi, H.bond(2)], "Gb"))
Gs[0].set_zero(), Gs[1].set_zero()
#Gs[0].randomize(), Gs[1].randomize()
#Gs.append(uni10.UniTensor([bdi_chi, bdo_chi, H.bond(2)], "Gc"))
#Gs.append(uni10.UniTensor([bdi_chi, bdo_chi, H.bond(2)], "Gd"))
#Gs[2].set_zero(), Gs[3].set_zero()

# Lambda matrices (diagonal): Ls=[La, Lb]
Ls = []
Ls.append(uni10.Matrix(chi, chi, True))  # Diagonal matrix
Exemple #29
0
Positive = 'Restrict'
Corner_method = 'CTMRG'  #CTM, CTMRG, CTMFull
Acc_E = 1.00e-6
Steps = [1.0e-1, 1.0e-2, 1.0e-3, 1.0e-4, 1.0e-5, 6.0e-6]  #,[Start,steps,End]
delta = 0.001
###################################################################
zlist = []
Elist = []
zlist1 = []
Elist1 = []
zlist2 = []
Elist2 = []

file = open("Data/varianceAll.txt", "w")

bdi = uni10.Bond(uni10.BD_IN, D)
bdo = uni10.Bond(uni10.BD_OUT, D)
bdi_pys = uni10.Bond(uni10.BD_IN, d_phys)
Truncation = [0]

Gamma_a = uni10.UniTensor([bdi_pys, bdi, bdi, bdo, bdo], "Gamma_a")
Gamma_b = uni10.UniTensor([bdi_pys, bdi, bdi, bdo, bdo], "Gamma_b")
Gamma_c = uni10.UniTensor([bdi_pys, bdi, bdi, bdo, bdo], "Gamma_c")
Gamma_d = uni10.UniTensor([bdi_pys, bdi, bdi, bdo, bdo], "Gamma_d")

Landa_1 = uni10.UniTensor([bdi, bdo], "Landa_1")
Landa_2 = uni10.UniTensor([bdi, bdo], "Landa_2")
Landa_3 = uni10.UniTensor([bdi, bdo], "Landa_3")
Landa_4 = uni10.UniTensor([bdi, bdo], "Landa_4")
Landa_5 = uni10.UniTensor([bdi, bdo], "Landa_5")
Landa_6 = uni10.UniTensor([bdi, bdo], "Landa_6")
Exemple #30
0
def initialize_Positiv_lrprime(l, r, l_d, r_d, N_uni, U, D, d_phys, q_u, qq_u,a_u,b_u,Positive):
 U.setLabel([-20,-40,20,40])
 bdiB=uni10.Bond(uni10.BD_IN, d_phys*D)
 bdoB=uni10.Bond(uni10.BD_OUT, d_phys*D)
 bdiBB=uni10.Bond(uni10.BD_IN, d_phys*D*d_phys*D)
 bdoBB=uni10.Bond(uni10.BD_OUT, d_phys*D*d_phys*D)
 bdi_pys=uni10.Bond(uni10.BD_IN, d_phys)
 bdi_pyso=uni10.Bond(uni10.BD_OUT, d_phys)
 bdi=uni10.Bond(uni10.BD_IN, D)
 bdo=uni10.Bond(uni10.BD_OUT, D)
 #A=(r*r_d)*U*(l*l_d)*N_uni
 #print 'test', A[0]
 #print N_uni
 N=copy.copy(N_uni)
 N.setLabel([1,-1,2,-2])
 N.permute([-1,-2,1,2], 2)
 N1=copy.copy(N)
 N1.transpose()
 N=(N+N1)*(1.00/2.00)
 if Positive is 'Restrict':
  M=N.getBlock()
  N_2=M*M 
  eig=N_2.eigh()
  #print eig[0]
  e=Sqrt(eig[0])
  #print e
  U_trans=copy.copy(eig[1])
  U_trans.transpose()
  M=U_trans*e*eig[1]
  N.putBlock(M)

 eig=N.getBlock()
 eig=eig.eigh() 
 e=Positiv(eig[0])
 
# print '\n','\n'
# for i1 in xrange(int(e.row())):
#  print e[i1]
# print '\n','\n'
 for q in xrange(int(eig[0].row())):
    e[q]=(e[q]**(1.00/2.00)) 
 X=e*eig[1]
 eig[1].transpose()
 X_tran=eig[1]*e
 X_u=uni10.UniTensor([bdiBB,bdoB,bdoB])
 X_u.putBlock(X)
 
 X_tran_u=uni10.UniTensor([bdiB,bdiB,bdoBB])
 X_tran_u.putBlock(X_tran)

#################################################
 X_u.permute([1,0,2],1)
 #print X_u
 lq1=X_u.getBlock().lq()
 l1=lq1[0]
 #print l1, l1[0] 
 l1_inv=l1.inverse()
 #print l1*l1_inv
 
 X_u.permute([1,0,2],2)
 qr1=X_u.getBlock().qr()
 r1=qr1[1]
 r1_inv=r1.inverse()

 r1_uni_inv=uni10.UniTensor([bdiB,bdoB])
 r1_uni_inv.putBlock(r1_inv)
 r1_uni_inv.setLabel([2,-2])
 qq_u=qq_u*r1_uni_inv
 qq_u.permute([-2,4,5,6],3)
 qq_u.setLabel([2,4,5,6])

 
 
 l1_uni_inv=uni10.UniTensor([bdiB,bdoB])
 l1_uni_inv.putBlock(l1_inv)
 l1_uni_inv.setLabel([-1,1])
 #print q_u.printDiagram()
 q_u=q_u*l1_uni_inv
 q_u.permute([2,4,5,-1],3)
 q_u.setLabel([2,4,5,1])
 
 
 X_u=X_u*l1_uni_inv*r1_uni_inv
 X_u.permute([0,-1,-2],1)
 X_u.setLabel([0,1,2])
 
##############################################
# X_tran_u.permute([0,2,1],1)
# lq2=X_tran_u.getBlock().lq()
# l2=lq2[0]
# l2_inv=l2.inverse()
# #print '1', distance_two(l2_inv, l1_inv)
# X_tran_u.permute([0,2,1],2)
# qr2=X_tran_u.getBlock().qr()
# r2=qr2[1]
# r2_inv=r2.inverse()
# #print '2', distance_two(r2_inv, r1_inv)

# r2_uni_inv=uni10.UniTensor([bdiB,bdoB])
# r2_uni_inv.putBlock(r2_inv)
# r2_uni_inv.setLabel([1,-2])
# 
# l2_uni_inv=uni10.UniTensor([bdiB,bdoB])
# l2_uni_inv.putBlock(l2_inv)
# l2_uni_inv.setLabel([-1,0])
# 
# X_tran_u=X_tran_u*l2_uni_inv*r2_uni_inv
# X_tran_u.permute([-1,-2,2],2)
# X_tran_u.setLabel([-1,-2,0])

 X_tran_u=copy.copy(X_u)
 X_tran_u.transpose()
 X_tran_u.setLabel([-1,-2,0])
 
#################################################
 
 #print l2.similar(l1)  
 #print r2.similar(r1)
# A=copy.copy(X_tran_u)
# A.transpose()
# dis=distance_two(X_u.getBlock(), A.getBlock())
# print 'hi', X_u.similar(A), dis
# 
 N=X_tran_u*X_u
 N.permute([1,-1,2,-2],2)
 r1_uni=uni10.UniTensor([bdiB,bdoB])
 r1_uni.putBlock(r1)

 l1_uni=uni10.UniTensor([bdiB,bdoB])
 l1_uni.putBlock(l1)

 #print l, r
 
 
 l1_uni.setLabel([1,0])
 r=r*l1_uni
 r.permute([3,20,0],2)
 r.setLabel([3,20,1])
 r_d=copy.copy(r)
 r_d.setLabel([-3,-20,-1])
 
 
 r1_uni.setLabel([0,2])
 l=r1_uni*l
 l.permute([0,40,3],2)
 l.setLabel([2,40,3])
 l_d=copy.copy(l)
 l_d.setLabel([-2,-40,-3])
 #A=(r*r_d)*U*(l*l_d)*N
 #print 'test', A[0]
 
# A=X_u*r*l*X_tran_u*r_d*l_d
# #print A, Tes1
# dis=distance_two(A.getBlock(),Tes1.getBlock() )

 lp=copy.copy(l)
 rp=copy.copy(r)
 lp_d=copy.copy(l_d)
 rp_d=copy.copy(r_d)

 rp_d.setLabel([-3,-20,-1])
 lp_d.setLabel([-2,-40,-3])

#######################################################
 
 U.setLabel([-20,-40,20,40])
 lp=copy.copy(l)
 rp=copy.copy(r)
 #lp.setLabel([1,40,-3])
 Teta=U*lp*rp
 Teta.permute([1,-20,2,-40],2)
 svd=Teta.getBlock().svd()
 s=Sqrt(svd[1])
 U=svd[0]*s
 V=s*svd[2]
 U.resize(U.row(),rp.bond()[0].dim() )
 V.resize(rp.bond()[0].dim(), V.col())
 
 rp=uni10.UniTensor([bdiB, bdi_pys, bdo ])
 rp.putBlock(U)
 rp.setLabel([1,20,3])
 rp.permute([3,20,1],2)
 
 lp=uni10.UniTensor([ bdi, bdoB, bdi_pyso])
 lp.putBlock(V)
 lp.setLabel([3,2,40])
 lp.permute([2,40,3],2)
 lp_d=copy.copy(lp)
 rp_d=copy.copy(rp)
 rp_d.setLabel([-3,-20,-1])
 lp_d.setLabel([-2,-40,-3])
##########################################################

 a_u=q_u*r
 a_u.permute([20,4,5,3,2],3)
 
 b_u=qq_u*l
 b_u.permute([40,3,4,5,6],3)
 
 return  lp, rp, lp_d, rp_d, N, l, r, l_d, r_d, q_u, qq_u, a_u, b_u