예제 #1
0
def test_basic():
    print '[test_basic]'
    np.random.seed(5)
    nr = 4
    nc = 4
    pdim = 2
    bond = 1
    auxbond = 8
    shape = (nr, nc)
    # simple peps
    pepsc = peps.zeros(shape, pdim, bond)
    pepsc[1, 1].prt()
    pepsc[2, 2].prt()
    p = einsum('pijkl,pijkl', pepsc[1, 1], pepsc[1, 1])
    print p
    p = einsum('pijkl,pklmn->ijmn', pepsc[1, 1], pepsc[2, 2])
    p.prt()
    # random peps
    pepsn = peps.random(shape, pdim, bond)
    pepsn[1, 1].prt()
    # add peps
    peps0 = peps.add(pepsn, pepsn)
    pepsn[0, 0].prt()
    peps0[0, 0].prt()
    peps1 = peps.add(peps0, pepsn)
    peps1[0, 0].prt()
    return 0
예제 #2
0
파일: mps.py 프로젝트: zhendongli2008/fPEPS
def dot(mpsa,mpsb):
    """
    dot product of two mps
    """
    assert len(mpsa)==len(mpsb)
    nsites = len(mpsa)
    e0 = PArray([[0],[0]],[[1],[1]])
    e0[0,0] = np.ones(1).reshape(1,1) 
    for i in xrange(nsites):
        tmp = einsum('ij,jnr->inr',e0,mpsb[i])
	e0 = einsum('inl,inr->lr',mpsa[i],tmp)
    return e0[0,0][0,0]
예제 #3
0
def epeps(pepsa,pepsb):
    shape = pepsa.shape
    epeps = np.empty(shape, dtype=np.object)
    for i in range(shape[0]):
        for j in range(shape[1]):
            epeps[i,j]=einsum("pludr,pLUDR->lLuUdDrR",pepsa[i,j],pepsb[i,j])
	    epeps[i,j] = epeps[i,j].merge([[0,1],[2,3],[4,5],[6,7]])
    return epeps
예제 #4
0
파일: mpo.py 프로젝트: zhendongli2008/fPEPS
def mapply(mpo, mps):
    """
    apply mpo to mps, or apply mpo to mpo
    """
    nsites = len(mpo)
    assert len(mps) == nsites
    ret = [None] * nsites
    if len(mps[0].shape) == 3:
        # mpo x mps
        for i in xrange(nsites):
            mt = einsum("apqb,cqd->acpbd", mpo[i], mps[i])
            ret[i] = mt.merge([[0, 1], [2], [3, 4]])
    elif len(mps[0].shape) == 4:
        # mpo x mpo
        for i in xrange(nsites):
            mt = einsum("apqb,cqrd->acprbd", mpo[i], mps[i])
            ret[i] = mt.merge([[0, 1], [2], [3], [4, 5]])
    return ret
예제 #5
0
def eval_vbond(pepsa0, pepsa, i, j, auxbond):
    debug = False
    # Sz*Sz
    pepsb = peps.copy(pepsa)
    pepsb[i, j] = einsum("pq,qludr->pludr", Sz, pepsa[i, j])
    pepsb[i + 1, j] = einsum("pq,qludr->pludr", Sz, pepsa[i + 1, j])
    valzz = peps.dot(pepsa0, pepsb, auxbond)
    if debug: print(i, j), 'valzz=', valzz
    # Sp*Sm
    pepsb = peps.copy(pepsa)
    pepsb[i, j] = einsum("xpq,qludr->plxudr", Sp,
                         pepsa[i, j]).merge_adjpair(2, 3)
    pepsb[i + 1, j] = einsum("xpq,qludr->pluxdr", Sm,
                             pepsa[i + 1, j]).merge_adjpair(3, 4)
    valpm = peps.dot(pepsa0, pepsb, auxbond)
    if debug: print(i, j), 'valpm=', valpm
    # Sm*Sp
    pepsb = peps.copy(pepsa)
    pepsb[i, j] = einsum("xpq,qludr->plxudr", Sm,
                         pepsa[i, j]).merge_adjpair(2, 3)
    pepsb[i + 1, j] = einsum("xpq,qludr->pluxdr", Sp,
                             pepsa[i + 1, j]).merge_adjpair(3, 4)
    valmp = peps.dot(pepsa0, pepsb, auxbond)
    if debug: print(i, j), 'valmp=', valmp
    return valzz + 0.5 * (valpm + valmp)
예제 #6
0
def test_conf():
    np.random.seed(5)
    nr = 3
    nc = 3
    pdim = 2
    bond = 2
    auxbond = 4
    # Initialization:
    # [[0 1 0 1]
    #  [1 0 1 0]
    #  [0 1 0 1]
    #  [1 0 1 0]
    #  [0 1 0 1]
    #  [1 0 1 0]]
    configa = np.zeros([nr, nc], dtype=np.int)
    for i in range(nr):
        for j in range(nc):
            configa[i, j] = (i + j) % 2
    pepsa = peps.create(pdim, configa)
    #for i in range(nr):
    #    for j in range(nc):
    #        print '(i,j)=',(i,j)
    #        pepsa[i,j].prt()
    print "CEVAL =", peps.ceval(pepsa, configa, auxbond)
    PP = peps.dot(pepsa, pepsa, None)
    print "<P|P> =", PP

    Sp = peps_h.get_Sp()
    Sm = peps_h.get_Sm()
    Sz = peps_h.get_Sz()
    i = j = 0

    # Sm*Sp
    pepsb = peps.copy(pepsa)
    pepsb[i, j] = einsum("xpq,qludr->plxudr", Sm,
                         pepsa[i, j]).merge_adjpair(2, 3)
    pepsb[i, j].prt()
    pepsb[i, j + 1] = einsum("xpq,qludr->pluxdr", Sp,
                             pepsa[i, j + 1]).merge_adjpair(3, 4)
    valmp = peps.dot(pepsb, pepsa, auxbond)
    print 'valmp=', valmp
    # Sz*Sz
    pepsb = peps.copy(pepsa)
    pepsb[i, j] = einsum("pq,qludr->pludr", Sz, pepsa[i, j])
    pepsb[i, j + 1] = einsum("pq,qludr->pludr", Sz, pepsa[i, j + 1])
    valzz = peps.dot(pepsb, pepsa, auxbond)
    print 'valzz=', valzz
    # Sp*Sm
    pepsb = peps.copy(pepsa)
    pepsb[i, j] = einsum("xpq,qludr->plxudr", Sp,
                         pepsa[i, j]).merge_adjpair(2, 3)
    pepsb[i, j + 1] = einsum("xpq,qludr->pluxdr", Sm,
                             pepsa[i, j + 1]).merge_adjpair(3, 4)
    valpm = peps.dot(pepsb, pepsa, auxbond)
    print 'valpm=', valpm
    return 0
예제 #7
0
파일: mps.py 프로젝트: zhendongli2008/fPEPS
def compress_left(mps,trunc=1.e-12,debug=False):
    nrm2 = dot(mps, mps)
    nsites = len(mps)
    ret_mps = [None]*nsites
    # Note: in EPEPS, the physical dim can be O(D^2); 
    #       auxbond O(D^4) after MPO apply to MPS. 
    res0 = mps[0] 
    for i in xrange(1,nsites):
	# Merge (l,n,r)
	res = res0.merge_adjpair(0,1)
        u0,sigma0,vt0 = autograd.numpy.linalg.svd(res[0,0],full_matrices=False)
	u1,sigma1,vt1 = autograd.numpy.linalg.svd(res[1,1],full_matrices=False)
        assert len(sigma0) == len(sigma1)
        if trunc==0:
            m_trunc=len(sigma0)
        elif trunc<1.:
            # count how many sing vals < trunc    
	    total = np.sqrt(np.sum(sigma0**2)+np.sum(sigma1**2))
            normed_sigma0=sigma0/total
            normed_sigma1=sigma1/total
            m_trunc=max(len([s for s in normed_sigma0 if s >trunc]),\
			len([s for s in normed_sigma1 if s >trunc]))
        else:
            m_trunc=int(trunc)
            m_trunc=min(m_trunc,len(sigma0))
	if debug:
           s0r = np.sum(sigma0[0:m_trunc]**2)
	   s0t = np.sum(sigma0**2)
           s1r = np.sum(sigma1[0:m_trunc]**2)
	   s1t = np.sum(sigma1**2)
	   print ' i=',i,' len(sig0)=',len(sigma0),' m_trunc=',m_trunc,' trunc=',trunc
	   print ' sigma0^2[tot,rem,dis] =',(s0t,s0r,s0t-s0r)
	   print ' sigma1^2[tot,rem,dis] =',(s1t,s1r,s1t-s1r)
	u0=u0[:,0:m_trunc]
        sigma0=np.diag(sigma0[0:m_trunc])
        vt0=vt0[0:m_trunc,:]
        u1=u1[:,0:m_trunc]
        sigma1=np.diag(sigma1[0:m_trunc])
        vt1=vt1[0:m_trunc,:]
	# Update site
	ptys = res0.ptys
	dims = res0.dims
	dimr = [m_trunc,m_trunc]
	site = PArray([ptys[0],ptys[1],[0,1]],[dims[0],dims[1],dimr])
	if len(ptys[0]) == 1:
	   site[0,0,0] = u0.reshape(site[0,0,0].shape) # parity-0
	   site[0,1,1] = u1.reshape(site[0,1,1].shape) # parity-1
  	else:
	   nblk00 = dims[0][0]*dims[1][0]
	   nblk01 = dims[0][0]*dims[1][1]
	   site[0,0,0] = u0[:nblk00,:].reshape(site[0,0,0].shape) # parity-0 
	   site[1,1,0] = u0[nblk00:,:].reshape(site[1,1,0].shape) # parity-0
	   site[0,1,1] = u1[:nblk01,:].reshape(site[0,1,1].shape) # parity-1 
	   site[1,0,1] = u1[nblk01:,:].reshape(site[1,1,0].shape) # parity-1
	ret_mps[i-1] = site
	# Assignment of vt
	vt = PArray([[0,1],[0,1]],[dimr,dims[2]])
	vt[0,0] = np.dot(sigma0,vt0)
	vt[1,1] = np.dot(sigma1,vt1)
	res0 = einsum('ij,jnr->inr',vt,mps[i])
    # Last one
    ret_mps[nsites-1] = res0
    # Check
    fidelity = dot(ret_mps, mps)/(nrm2+1.e-10) # zero-EPES
    if debug: print ' nrm2=',nrm2,' fidelity=',fidelity
    return fidelity,ret_mps