Exemplo n.º 1
0
    def moveL(self):
        # read As, Bs, Cl, Cr
        hf = h5py.File(self.dataname, 'r')
        As = df.readarr(hf, 'data/As_' + str(self.ix - 1))
        Cl = df.readarr(hf, 'data/Cl_' + str(self.ix - 1))
        Cr = df.readarr(hf, 'data/Cr_' + str(indexR(self.L, self.ix + 1)))
        hf.close()

        # energy of the present state
        newE = mpsE(Cl, Cr, self.Ms, self.M)
        self.adjust_alpha(newE)
        self.E = newE

        # construt single-site H and solve
        E, Ms = singlesite_hamilt(Cl, Cr, self.M, self.Ms)
        self.reducedE = self.E - E

        # subspace expansion
        P = self.alpha * obtainPL(Cr, Ms, self.M)
        Ms_tilde = np.append(Ms, P, axis=1)
        zeros = np.zeros((2, As.shape[1], P.shape[1]))
        As_tilde = np.append(As, zeros, axis=2)

        # truncation
        Ms_tilde = np.swapaxes(Ms_tilde, 0, 1)
        Ms_tilde = np.reshape(
            Ms_tilde,
            (Ms_tilde.shape[0], Ms_tilde.shape[1] * Ms_tilde.shape[2]))
        Ms_tilde_dag = Ms_tilde.T.conj()
        q, r = np.linalg.qr(Ms_tilde_dag)
        q, r = q.T.conj(), r.T.conj()
        Dl = self.Ms.shape[1]

        if q.shape[0] > Dl:
            q = np.compress([1] * Dl, q, axis=0)
            r = np.compress([1] * Dl, r, axis=1)

        # new Bs, Cr and new Ms
        newBs = np.reshape(q, (q.shape[0], 2, q.shape[1] // 2))
        newBs = np.swapaxes(newBs, 0, 1)
        newCr = contr.contractR(Cr, newBs, self.M)
        self.Ms = np.einsum('abc,cd->abd', As_tilde, r)

        # update datafile
        hf = h5py.File(self.dataname, 'r+')
        df.savearr(hf, 'data/Bs_' + str(indexR(self.L, self.ix)), newBs)
        df.savearr(hf, 'data/Cr_' + str(indexR(self.L, self.ix)), newCr)
        self.ix -= 1
        del hf['data/As_' + str(self.ix)]
        del hf['data/Cl_' + str(self.ix)]
        hf.close()
Exemplo n.º 2
0
    def moveR(self):
        # read As, Bs, Cl, Cr
        hf = h5py.File(self.dataname, 'r')
        Bs = df.readarr(hf, 'data/Bs_' + str(indexR(self.L, self.ix + 1)))
        Cl = df.readarr(hf, 'data/Cl_' + str(self.ix - 1))
        Cr = df.readarr(hf, 'data/Cr_' + str(indexR(self.L, self.ix + 1)))
        hf.close()

        # energy of the present state
        self.E = mpsE(Cl, Cr, self.Ms, self.M)
        self.adjust_alpha(self.E)

        # construt single-site H and solve
        E, Ms = singlesite_hamilt(Cl, Cr, self.M, self.Ms)
        self.reducedE = self.E - E

        # subspace expansion
        P = self.alpha * obtainPR(Cl, Ms, self.M)
        Ms_tilde = np.append(Ms, P, axis=2)
        zeros = np.zeros((2, P.shape[2], Bs.shape[2]))
        Bs_tilde = np.append(Bs, zeros, axis=1)

        # truncation
        Ms_tilde = np.reshape(
            Ms_tilde,
            (Ms_tilde.shape[0] * Ms_tilde.shape[1], Ms_tilde.shape[2]))
        q, r = np.linalg.qr(Ms_tilde)
        Dr = self.Ms.shape[2]
        if q.shape[1] > Dr:
            q = np.compress([1] * Dr, q, axis=1)
            r = np.compress([1] * Dr, r, axis=0)

        # new As,Cl and new Ms
        newAs = np.reshape(q, (2, q.shape[0] // 2, q.shape[1]))
        newCl = contr.contractL(Cl, newAs, self.M)
        self.Ms = np.einsum('bc,acd->abd', r, Bs_tilde)

        # update datafile
        hf = h5py.File(self.dataname, 'r+')
        df.savearr(hf, 'data/As_' + str(self.ix), newAs)
        df.savearr(hf, 'data/Cl_' + str(self.ix), newCl)
        self.ix += 1
        del hf['data/Bs_' + str(indexR(self.L, self.ix))]
        del hf['data/Cr_' + str(indexR(self.L, self.ix))]
        hf.close()
Exemplo n.º 3
0
    def __init__(self, L, D):
        self.L = L
        self.D = D
        self.dataname = 'data/xy_dmrg_D' + str(self.D) + '.h5'

        self.M = mpo.xy_mpo()
        self.alpha = 0.1
        self.E = 9.99e9
        self.reducedE = 9.99e9

        idmrgsol = idmrg.idmrg(self.D, self.L)
        idmrgsol.grow_to_target()

        self.ix = L // 2

        hf = h5py.File(self.dataname, 'r+')
        Ms = df.readarr(hf, 'data/Bs_' + str(indexR(self.L, self.ix)))
        self.Ms = np.einsum('bc,acd->abd', np.diag(hf['data/sigma']), Ms)
        df.savearr(hf, 'data/Cl_-1', np.reshape([1, 0, 0, 0], (1, 1, 4, 1)))
        df.savearr(hf, 'data/Cr_-1', np.reshape([0, 0, 0, 1], (1, 4, 1, 1)))
        del hf['data/Bs_' + str(indexR(self.L, self.ix))]
        del hf['data/Cr_' + str(indexR(self.L, self.ix))]
        hf.close()
Exemplo n.º 4
0
    def __init__(self, bondD, targetL):
        self.bondD = bondD
        self.M = mpo.xy_mpo()
        self.targetL = targetL
        if self.targetL % 2 != 0: 
            warnings.warn('idmrg: L must be even. L modified to L+1')
            self.targetL += 1

        self.dataname = 'data/xy_dmrg_D'+str(self.bondD)+'.h5'

        initL = 2*int(np.log2(self.bondD)) + 2
        self.currL = initL
        
        H0 = ed.xy_hamilt(initL)
        psi0 = ed.ground_state(H0)[1]
        A_list, B_list, sigma = canonical(psi0, initL)
        
        # truncate
        A_list[initL//2 - 1] = np.compress([1]*self.bondD, A_list[initL//2 - 1], axis=2)
        B_list[initL//2 - 1] = np.compress([1]*self.bondD, B_list[initL//2 - 1], axis=1)
        sigma = np.compress([1]*self.bondD, sigma)
        if not contr.check_Lnorm(A_list) or not contr.check_Rnorm(B_list):
            warnings.warn('idrmg: normalization condition violated due to truncation')

        self.As, self.Bs = A_list[initL//2 - 1], B_list[initL//2 - 1]
        self.sigma = sigma

        hf = h5py.File(self.dataname, 'w')
        hf['parameters/bondD']=self.bondD
        hf['parameters/currL']=self.currL

        self.Cl = np.reshape([1,0,0,0], (1,1,4,1)) 
        self.Cr = np.reshape([0,0,0,1], (1,4,1,1))
        for ix in range(initL//2):
            self.Cl = contr.contractL(self.Cl, A_list[ix], self.M)
            self.Cr = contr.contractR(self.Cr, B_list[ix], self.M)

            # save As, Bs, Cl, Cr
            df.savearr(hf, 'data/As_'+str(ix), A_list[ix])
            df.savearr(hf, 'data/Cl_'+str(ix), self.Cl)
            df.savearr(hf, 'data/Bs_'+str(ix), B_list[ix])
            df.savearr(hf, 'data/Cr_'+str(ix), self.Cr)
        hf['data/sigma'] = self.sigma

        hf.close()
Exemplo n.º 5
0
    def growby2(self):
        newAs, newBs, initpsi = sadd.init_newpsi(self.sigma, self.As, self.Bs)
        newCl = contr.contractL(self.Cl, newAs, self.M)
        newCr = contr.contractR(self.Cr, newBs, self.M)

        H2 = np.einsum('abde,cdfg->abcefg', newCl, newCr)
        dimH2 = newCl.shape[1]**2
        H2 = np.reshape(H2, (dimH2, dimH2))
        H2s = scipy.sparse.csr_matrix(H2)

        if not np.allclose(H2, H2.T.conj()):
            warnings.warn(str(self.currL)+': H2 not Hermitian')

        initpsi = np.reshape(initpsi, (dimH2, 1))
        newpsi = scipy.sparse.linalg.eigsh(H2s, k=1, which='SA', v0=initpsi)[1]
        newpsi = np.reshape(newpsi, (newCl.shape[1], newCl.shape[1]))
        u, s, vdag = np.linalg.svd(newpsi)

        # update
        self.currL += 2
        self.As = np.einsum('abc,cd->abd', newAs, u)
        self.Bs = np.einsum('ac,bcd->bad', vdag, newBs)
        self.sigma = s

        self.Cl = np.einsum('abcd,be->aecd', newCl, u.conj())
        self.Cl = np.einsum('abcd,de->abce', self.Cl, u)
        self.Cr = np.einsum('ab,bcde->acde', vdag.conj(), newCr)
        self.Cr = np.einsum('ad,bcde->bcae', vdag, self.Cr)

        # save data
        hf = h5py.File(self.dataname, 'r+')
        ix = self.currL // 2 - 1

        df.savearr(hf, 'data/As_'+str(ix), self.As)
        df.savearr(hf, 'data/Cl_'+str(ix), self.Cl)
        df.savearr(hf, 'data/Bs_'+str(ix), self.Bs)
        df.savearr(hf, 'data/Cr_'+str(ix), self.Cr)

        del hf['parameters/currL']
        hf['parameters/currL'] = self.currL
        del hf['data/sigma']
        hf['data/sigma'] = self.sigma

        hf.close()