Beispiel #1
0
    def test_vmps(self):
        '''
        Run vMPS for Heisenberg model.
        '''
        nsite=10
        nspin=2
        model=self.get_model(nsite,nspin=nspin)
        #EG,mps=self.dmrgrun(model)

        #run vmps
        #generate a random mps as initial vector
        bmg=SimpleBMG(spaceconfig=model.spaceconfig,qstring='M')
        #k0=product_state(config=random.randint(0,2,nsite),hndim=2)
        if nspin==2:
            k0=product_state(config=repeat([0,1],nsite/2),hndim=model.spaceconfig.hndim,bmg=bmg)
        else:
            k0=product_state(config=repeat([0,2],nsite/2),hndim=model.spaceconfig.hndim,bmg=bmg)

        #setting up the engine
        vegn=VMPSEngine(H=model.H.use_bm(bmg),k0=k0,eigen_solver='JD')
        #check the label setting is working properly
        assert_(all([ai.shape==(ai.labels[0].bm.N,ai.labels[1].bm.N,ai.labels[2].bm.N) for ai in vegn.ket.ML]))
        assert_(all([ai.shape==(ai.labels[0].bm.N,ai.labels[1].bm.N,ai.labels[2].bm.N,ai.labels[3].bm.N) for ai in vegn.H.OL]))
        #warm up
        vegn.warmup(10)
        vegn.eigen_solver='LC'
        vegn.run(5,maxN=[40,100,200,200,200,200,200],which='SA')
        pdb.set_trace()
        vegn.run(5,maxN=80,which='SA')
        pdb.set_trace()
Beispiel #2
0
    def test_iterator(self):
        nsite=4
        model=self.get_model(nsite)
        k0=product_state(config=repeat([0,1],nsite/2),hndim=model.spaceconfig.hndim)

        vegn=VMPSEngine(H=model.H,k0=k0,eigen_solver='LC')
        start=(1,'->',2)
        stop=(3,'<-',1)
        print 'Testing iterator start = %s, stop= %s'%(start,stop)
        iterator=vegn._get_iterator(start=start,stop=stop)
        order=[(1,'->',2),(1,'<-',1),(1,'<-',0),
                (2,'->',1),(2,'->',2),(2,'<-',1),(2,'<-',0),
                (3,'->',1),(3,'->',2),(3,'<-',1),
                ]
        for od,it in zip(order,iterator):
            assert_(od==it)

        print 'Testing 2-site iterator.'
        nsite=2
        model=self.get_model(nsite)
        k0=product_state(config=repeat([0,1],nsite/2),hndim=model.spaceconfig.hndim)

        vegn=VMPSEngine(H=model.H,k0=k0,eigen_solver='LC')
        start=(1,'->',0)
        stop=(3,'->',0)
        order=[(1,'->',0),(2,'->',0),(3,'->',0)]
        iterator=vegn._get_iterator(start=start,stop=stop)
        for od,it in zip(order,iterator):
            assert_(od==it)
Beispiel #3
0
    def test_2d(self):
        '''
        Run vMPS for Heisenberg model.
        '''
        N1,N2=4,4
        nsite=N1*N2
        nspin=2
        model=self.get_model2d(N=N1,nspin=nspin)
        #EG,mps=self.dmrgrun(model)

        #run vmps
        #generate a random mps as initial vector
        bmg=SimpleBMG(spaceconfig=model.spaceconfig,qstring='M')
        #k0=product_state(config=random.randint(0,2,nsite),hndim=2)
        if nspin==2:
            k0=product_state(config=repeat([0,1],nsite/2),hndim=model.spaceconfig.hndim,bmg=bmg)
        else:
            k0=product_state(config=repeat([0,2],nsite/2),hndim=model.spaceconfig.hndim,bmg=bmg)

        #setting up the engine
        #mpo1=copy.deepcopy(model.H).compress(kernel='svd',tol=1e-8)[0]
        mpo=copy.deepcopy(model.H).compress(kernel='dpl',tol=1e-8)[0]
        #mpo3=copy.deepcopy(model.H).compress(kernel='ldu',tol=1e-8)[0]
        vegn=VMPSEngine(H=mpo.use_bm(bmg),k0=k0,eigen_solver='JD')
        #check the label setting is working properly
        assert_(all([ai.shape==(ai.labels[0].bm.N,ai.labels[1].bm.N,ai.labels[2].bm.N) for ai in vegn.ket.ML]))
        assert_(all([ai.shape==(ai.labels[0].bm.N,ai.labels[1].bm.N,ai.labels[2].bm.N,ai.labels[3].bm.N) for ai in vegn.H.OL]))
        #warm up
        vegn.warmup(10)
        vegn.run(5,maxN=[40,100,150,150,150,150,150],which='SA')
        pdb.set_trace()
        vegn.run(5,maxN=80,which='SA')
        pdb.set_trace()
Beispiel #4
0
def solve1(hl,nsite,config,Jz=1.,J=1.,save=True):
    '''
    Run vMPS for Heisenberg model.
    '''
    #generate the model
    print 'SOLVING %s'%config
    model=HeisenbergModel(J=J,Jz=Jz,h=hl,nsite=nsite)

    #run vmps
    #generate a random mps as initial vector
    spaceconfig=SpinSpaceConfig([2,1])
    bmg=SimpleBMG(spaceconfig=spaceconfig,qstring='M')
    H=model.H.use_bm(bmg)
    k0=product_state(config=config,hndim=2,bmg=bmg)

    #setting up the engine
    vegn=VMPSEngine(H=H,k0=k0.toket(),eigen_solver='JD')
    eng,ket=vegn.run(endpoint=(6,'->',0),maxN=20,which='SL',nsite_update=2)
    #save to file
    if save:
        ind=sum(2**arange(nsite-1,-1,-1)*asarray(config))
        filename='data/ket%s_h%.2fN%s.dat'%(ind,mean(hl),nsite)
        quicksave(filename,(eng,ket))
    overlap=abs((k0.tobra()*ket).item())
    print 'OVERLAP %s'%overlap
    return eng,ket,overlap
Beispiel #5
0
def test_nonint():
    '''
    Run vMPS for Heisenberg model.
    '''
    nsite=10
    model=ChainN(t=1.,U=0.,nsite=nsite)
    spaceconfig1=SuperSpaceConfig([1,2,1])
    #exact result
    h0=zeros([nsite,nsite])
    fill_diagonal(h0[1:,:-1],1.); h0=h0+h0.T
    e_=2*eigvalsh(h0)
    e_exact=sum(e_[e_<0])
    pdb.set_trace()

    #run vmps
    #generate a random mps as initial vector
    bmg=SimpleBMG(spaceconfig=spaceconfig1,qstring='QM')
    #k0=product_state(config=random.randint(0,2,nsite),hndim=2)
    k0=product_state(config=repeat([1,2],nsite/2),hndim=spaceconfig1.hndim,bmg=bmg)
    mpo=model.hchain.toMPO(bmg=bmg,method='direct')
    #k0=product_state(config=repeat([0,2],nsite/2),hndim=model.spaceconfig.hndim,bmg=bmg)

    #setting up the engine
    vegn=VMPSEngine(H=mpo,k0=k0,eigen_solver='LC')
    #check the label setting is working properly
    assert_(all([ai.shape==(ai.labels[0].bm.N,ai.labels[1].bm.N,ai.labels[2].bm.N) for ai in vegn.ket.ML]))
    assert_(all([ai.shape==(ai.labels[0].bm.N,ai.labels[1].bm.N,ai.labels[2].bm.N,ai.labels[3].bm.N) for ai in vegn.H.OL]))
    #warm up
    vegn.warmup(10)
    vegn.eigen_solver='JD'
    e,v=vegn.run(maxN=[40,60,80,100,100,100,100],which='SA',nsite_update=2,endpoint=(5,'->',0))
    assert_almost_equal(e,e_exact,rtol=1e-4)
Beispiel #6
0
def test_inff(mode='save'):
    '''
    Run infinite vMPS for Heisenberg model.
    '''
    t=1.
    U=100.
    mu=U/2.
    #generate a random mps as initial vector
    spaceconfig1=SuperSpaceConfig([1,2,1])
    bmg=SimpleBMG(spaceconfig=spaceconfig1,qstring='QM')
    k0=product_state(config=array([1,2]),hndim=spaceconfig1.hndim,bmg=bmg)

    model2=ChainN(t=t,U=U,nsite=2,mu=mu)
    mpo2=model2.hchain.toMPO(bmg=bmg,method='direct')

    model=ChainN(t=t,U=U,nsite=4,mu=mu)
    mpo4=model.hchain.toMPO(bmg=bmg,method='direct')

    mpo=model.hchain.toMPO(bmg=bmg,method='direct')
    #setting up the engine
    vegn=VMPSEngine(H=mpo2,k0=k0,eigen_solver='LC')
    vegn.run(1)
    #H2=mpo2.H
    #print eigvalsh(H2)[0]
    #print model2.hchain
    #print model2.hchain.H()-mpo2.H
    #pdb.set_trace()
    filetoken='data/con_dump_U%s_t%s_mu%s'%(U,t,mu)
    if mode=='save':
        vegn.generative_run(HP=mpo4.OL[1:3],ngen=100,niter_inner=1,maxN=100,trunc_mps=True,which='SA')
        vegn.con.dump_data(filetoken)
    else:
        vegn.con.load_data(filetoken)
    pdb.set_trace()
Beispiel #7
0
def test_int():
    '''
    Run vMPS for Heisenberg model.
    '''
    nsite=32
    U=10.0
    model=ChainN(t=1.,U=U,mu=U/2.,nsite=nsite)
    spaceconfig1=SuperSpaceConfig([1,2,1])
    #EG,mps=self.dmrgrun(model)

    #run vmps
    #generate a random mps as initial vector
    bmg=SimpleBMG(spaceconfig=spaceconfig1,qstring='QM')
    #k0=product_state(config=random.randint(0,2,nsite),hndim=2)
    k0=product_state(config=repeat([1,2],nsite/2),hndim=spaceconfig1.hndim,bmg=bmg)
    #mpo=model.hchain.toMPO(bmg=bmg,method='addition').compress(kernel='ldu')[0]
    #mpo.eliminate_zeros(1e-8)
    mpo=model.hchain.toMPO(bmg=bmg,method='direct')
    #mpo3=model.hchain.toMPO(bmg=bmg,method='direct').compress(kernel='ldu')[0]
    #mpo4=model.hchain.toMPO(bmg=bmg,method='direct').compress(kernel='dpl')[0]
    #k0=product_state(config=repeat([0,2],nsite/2),hndim=model.spaceconfig.hndim,bmg=bmg)

    #warm up the engine
    #vegn=VMPSEngine(H=mpo,k0=k0,eigen_solver='LC')
    #vegn.warmup(12)

    #generative run
    model2=ChainN(t=1,U=U,mu=U/2.,nsite=2)
    k02=product_state(config=array([1,2]),hndim=spaceconfig1.hndim,bmg=bmg)
    mpo2=model2.hchain.toMPO(bmg=bmg,method='direct')
    vegn=VMPSEngine(H=mpo2,k0=k02,eigen_solver='LC')
    vegn.generative_run(HP=mpo.OL[1:3],ngen=nsite/2-1,niter_inner=1,maxN=50,trunc_mps=False,which='SA')

    vegn.run(6,maxN=[40,50,50,50,50,50,50])
    #vegn.run(maxN=80,which='SA',nsite_update=1,endpoint=(3,'->',0))
    pdb.set_trace()
Beispiel #8
0
    def test_vmps2(self):
        '''
        Run vMPS for Heisenberg model.
        '''
        nsite=20
        model=self.get_model(nsite)
        #EG,mps=self.dmrgrun(model)

        #run vmps
        #generate a random mps as initial vector
        #k0=product_state(config=random.randint(0,2,nsite),hndim=3)
        k0=product_state(config=repeat([0,1],nsite/2),hndim=model.spaceconfig.hndim)

        #setting up the engine
        vegn=VMPSEngine(H=model.H,k0=k0,eigen_solver='LC',nsite_update=2)
        #check the label setting is working properly
        vegn.run(4,maxN=40,which='SA')
        pdb.set_trace()
        vegn.run(4,maxN=40,which='SA')
        pdb.set_trace()
Beispiel #9
0
    def test_generative(self,trunc_mps):
        '''
        Run vMPS for Heisenberg model.
        '''
        nsite=4
        nspin=2
        model=self.get_model(nsite,nspin=nspin)
        model2=self.get_model(nsite*2,nspin=nspin)
        #EG,mps=self.dmrgrun(model)

        #run vmps
        #generate a random mps as initial vector
        bmg=SimpleBMG(spaceconfig=model.spaceconfig,qstring='M')
        #k0=product_state(config=random.randint(0,2,nsite),hndim=2)
        k0=product_state(config=repeat([0,nspin-1],nsite/2),hndim=model.spaceconfig.hndim,bmg=bmg)

        #setting up the engine
        vegn=VMPSEngine(H=model.H.use_bm(bmg),k0=k0,eigen_solver='JD',iprint=1)
        niter_inner=4 if nsite>2 else 1
        vegn.run(niter_inner,maxN=50,which='SA')
        #warm up
        vegn.generative_run(HP=model2.H.OL[nsite/2:nsite*3/2],ngen=100,niter_inner=niter_inner,maxN=50,trunc_mps=trunc_mps,which='SA')
        pdb.set_trace()