Ejemplo n.º 1
0
def contract_cpeps(cpeps,auxbond):
    cmps0 = get_boundaryMPS(cpeps,'d')
    for i in range(1,cpeps.shape[0]-1):
        cmpo = get_rowMPO(cpeps,i)
        cmps0 = mpo.mapply(cmpo,cmps0)
	if auxbond is not None: # compress
            cmps0 = mps.compress(cmps0,auxbond)
    cmps1 = get_boundaryMPS(cpeps,'u')
    return mps.dot(cmps0,cmps1)
Ejemplo n.º 2
0
def contract(mpo,mpsb,side,thresh,ncanonical=1):
    """
    mapply->canonicalise->compress
    """
    ret=mapply(mpo,mpsb)
    # roundoff can cause problems, 
    # so do multiple canonicalisations
    for i in xrange(ncanonical):
        ret=mps.canonicalise(ret,side)
    ret=mps.compress(ret,side,thresh)
    return ret
Ejemplo n.º 3
0
def contract_cpeps(cpeps, auxbond):
    cmps0 = [None] * cpeps.shape[1]
    for i in range(cpeps.shape[1]):
        l, u, d, r = cpeps[0, i].shape
        cmps0[i] = np.reshape(cpeps[0, i], (l, u * d, r))

    for i in range(1, cpeps.shape[0]):
        cmpo = [None] * cpeps.shape[1]
        for j in range(cpeps.shape[1]):
            l, u, d, r = cpeps[i, j].shape
            cmpo[j] = cpeps[i, j]

        cmps0 = mpo.mapply(cmpo, cmps0)

        if auxbond is not None:  # compress
            #print "compressing"
            cmps0 = mps.compress(cmps0, "l", auxbond)

    return mps.ceval(cmps0, [0] * cpeps.shape[1])
Ejemplo n.º 4
0
def contract(mpo,
             mpsb,
             side,
             thresh,
             mpsa=None,
             ncanonical=1,
             compress_method="svd"):

    assert compress_method in ["svd", "variational"]

    if compress_method == "svd":
        """
        mapply->canonicalise->compress
        """
        ret = mapply(mpo, mpsb)
        # roundoff can cause problems,
        # so do multiple canonicalisations
        for i in xrange(ncanonical):
            ret = mps.canonicalise(ret, side)
        ret = mps.compress(ret, side, thresh)

    elif compress_method == "variational":
        if mpsa == None:
            #mpsa = mps.add(mpsb,None)
            mpox = mps.canonicalise(mpo, side)
            mpsa = mapply(mpox, mpsb)
            nloops = 1
        ret = mps.variational_compress(mpsb,
                                       mpsa,
                                       mpo,
                                       side,
                                       nloops,
                                       trunc=thresh,
                                       method="1site")

    return ret
def genBPEPO(pepo, Lphys, nf, auxbond=20):
    auxbond_hor = auxbond
    print '\n[genPEPOsmall.genBPEPO] auxbond=', auxbond, ' auxbond_hor=', auxbond_hor
    ntot = pepo.shape[0]
    Ltot = Lphys + nf * (Lphys - 1)
    dist = nf + 1
    nl = (ntot - Ltot) / 2
    nr = ntot - nl - Ltot  # >= nl
    print ' ntot=', pepo.shape[0], '(Lphys,nf)=', (Lphys, nf)
    print ' Ltot=', Ltot, ' dist=', dist, ' nl=', nl, ' nr=', nr, ' ratio=', float(
        ntot) / Ltot
    # Bottom MPS
    bmps = [None] * ntot
    for j in range(ntot):
        l, u, d, r = pepo[0, j][0, 0].shape
        assert d == 1
        bmps[j] = pepo[0, j][0, 0].reshape(l, u * d, r)
    # Compression
    for i in range(1, nl):
        cmpo = [None] * ntot
        for j in range(ntot):
            cmpo[j] = pepo[i, j][0, 0].copy()
        bmps = contraction2d.mpo_mapply(cmpo, bmps)
        if auxbond is not None:  # compress
            bmps = mps.compress(bmps, auxbond)
    # Upper MPS -> Note that the MPO is not upper-lower symmetric !
    umps = [None] * ntot
    for j in range(ntot):
        l, u, d, r = pepo[ntot - 1, j][0, 0].shape
        assert u == 1
        umps[j] = pepo[ntot - 1, j][0, 0].reshape(l, u * d, r)
    # Compression
    for i in range(ntot - 2, ntot - nr - 1, -1):
        cmpo = [None] * ntot
        for j in range(ntot):
            cmpo[j] = pepo[i, j][0, 0].transpose(0, 2, 1,
                                                 3).copy()  # ludr->ldur
        umps = contraction2d.mpo_mapply(cmpo, umps)
        if auxbond is not None:  # compress
            umps = mps.compress(umps, auxbond)
    #
    # TPEPO
    #
    tpepo = numpy.empty((Ltot + 2, ntot), dtype=numpy.object)
    for j in range(ntot):
        l, u, r = bmps[j].shape
        tpepo[0, j] = bmps[j].reshape((1, 1, l, u, 1, r))  # Add physical index
    for j in range(ntot):
        l, d, r = umps[j].shape
        tpepo[Ltot + 1, j] = umps[j].reshape(
            (1, 1, l, 1, d, r))  # Add physical index
    for i in range(Ltot):
        for j in range(ntot):
            tpepo[i + 1, j] = pepo[i + nl, j].copy()
    # Left MPS
    lmps = [None] * (Ltot + 2)
    for i in range(Ltot + 2):
        l, u, d, r = tpepo[i, 0][0, 0].shape
        assert l == 1
        lmps[i] = numpy.reshape(tpepo[i, 0][0, 0],
                                (u, d, r)).transpose(1, 2, 0)  # udr->dru
    for j in range(1, nl):
        cmpo = [None] * (Ltot + 2)
        for i in range(Ltot + 2):
            cmpo[i] = tpepo[i, j][0, 0].transpose(2, 3, 0, 1)  # ludr->drlu
        lmps = contraction2d.mpo_mapply(cmpo, lmps)
        if auxbond is not None:  # compress
            lmps = mps.compress(lmps, auxbond_hor)
    # Right MPS
    rmps = [None] * (Ltot + 2)
    for i in range(Ltot + 2):
        l, u, d, r = tpepo[i, ntot - 1][0, 0].shape
        assert r == 1
        rmps[i] = numpy.reshape(tpepo[i, ntot - 1][0, 0],
                                (l, u, d)).transpose(2, 0, 1)  # lud->dlu
    for i in range(1, nr):
        cmpo = [None] * (Ltot + 2)
        for j in range(Ltot + 2):
            cmpo[j] = tpepo[j, ntot - i - 1][0, 0].transpose(2, 0, 3,
                                                             1)  # ludr->dlru
        rmps = contraction2d.mpo_mapply(cmpo, rmps)
        if auxbond is not None:  # compress
            rmps = mps.compress(rmps, auxbond_hor)
    #
    # Assemble SPEPO
    #
    spepo = numpy.empty((Ltot + 2, Ltot + 2), dtype=numpy.object)
    # Middle
    for i in range(Ltot):
        for j in range(Ltot):
            spepo[i + 1, j + 1] = tpepo[i + 1, j + nl].copy()
    # Left
    for i in range(Ltot + 2):
        d, r, u = lmps[i].shape
        l = 1
        tmp = numpy.reshape(lmps[i], (l, d, r, u)).transpose(0, 3, 1,
                                                             2)  # ldru->ludr
        spepo[i, 0] = tmp.reshape((1, 1, l, u, d, r))
    # Right
    for i in range(Ltot + 2):
        d, l, u = rmps[i].shape
        r = 1
        tmp = numpy.reshape(rmps[i], (d, l, u, r)).transpose(1, 2, 0,
                                                             3)  # dlur->ludr
        spepo[i, Ltot + 1] = tmp.reshape((1, 1, l, u, d, r))
    # Bottom
    for j in range(Ltot):
        spepo[0, j + 1] = tpepo[0, j + nl].copy()
    # Up
    for j in range(Ltot):
        spepo[Ltot + 1, j + 1] = tpepo[Ltot + 1, j + nl].copy()
    return spepo