예제 #1
0
파일: testfermi.py 프로젝트: amilacsw/dmrg
    def test_nonint(self):
        #get the exact solution.
        h_exact=self.model_exact.hgen.H()
        E_excit=eigvalsh(h_exact)
        Emin_exact=sum(E_excit[E_excit<0])

        #the solution in occupation representation.
        h_occ=self.model_occ.hgen.H()
        Emin=eigsh(h_occ,which='SA',k=1)[0]
        print 'The Ground State Energy for hexagon(t = %s, t2 = %s) is %s, tolerence %s.'%(self.t,self.t2,Emin,Emin-Emin_exact)
        assert_almost_equal(Emin_exact,Emin)

        #the solution through updates
        H_serial=op2collection(op=self.model_occ.hgen.get_opH())
        H=get_H(H=H_serial,hgen=self.expander)
        H2,bm2=get_H_bm(H=H_serial,hgen=self.expander2,bstr='QM')
        Emin=eigsh(H,k=1,which='SA')[0]
        Emin2=eigsh(H2,k=1,which='SA')[0]
        print 'The Ground State Energy is %s, tolerence %s.'%(Emin,Emin-Emin2)
        assert_almost_equal(Emin_exact,Emin)
        assert_almost_equal(Emin_exact,Emin2)

        #the solution through dmrg.
        bmgen=get_bmgen(self.expander3.spaceconfig,'QM')
        dmrgegn=DMRGEngine(hchain=H_serial,hgen=self.expander3,tol=0,bmg=bmgen,symmetric=True)
        EG2=dmrgegn.run_finite(endpoint=(5,'<-',0),maxN=[10,20,30,40,40],tol=0)[-1]
        assert_almost_equal(Emin_exact,EG2*H_serial.nsite,decimal=4)
예제 #2
0
    def test_nonint(self):
        #get the exact solution.
        spaceconfig = self.spaceconfig1
        self.set_params(U=0., t=1., mu=0.2, t2=0., nsite=6)
        h_exact = self.model_exact.hgen.H()
        E_excit = eigvalsh(h_exact)
        Emin_exact = sum(E_excit[E_excit < 0])

        #the solution in occupation representation.
        h_occ = self.model_occ.hgen.H()
        Emin, Vmin1 = eigsh(h_occ, which='SA', k=1)
        print 'The Ground State Energy for hexagon(t = %s, t2 = %s) is %s, tolerence %s.' % (
            self.t, self.t2, Emin, Emin - Emin_exact)
        assert_almost_equal(Emin_exact, Emin)

        #the solution through updates
        H_serial = op2collection(op=self.model_occ.hgen.get_opH())
        H_serial_Z = copy.copy(H_serial)
        H_serial_Z.insert_Zs(spaceconfig=spaceconfig)
        expander = ExpandGenerator(spaceconfig=spaceconfig,
                                   H=H_serial_Z,
                                   evolutor_type='null',
                                   use_zstring=True)
        H = get_H(hgen=expander)
        expander2 = ExpandGenerator(spaceconfig=spaceconfig,
                                    H=H_serial_Z,
                                    evolutor_type='normal',
                                    use_zstring=True)
        H2, bm2 = get_H_bm(hgen=expander2, bstr='QM')
        Emin = eigsh(H, k=1, which='SA')[0]
        Emin2 = eigsh(H2, k=1, which='SA')[0]
        print 'The Ground State Energy is %s, tolerence %s.' % (Emin,
                                                                Emin - Emin2)
        assert_almost_equal(Emin_exact, Emin)
        assert_almost_equal(Emin_exact, Emin2)

        #the solution through dmrg.
        expander3 = ExpandGenerator(spaceconfig=spaceconfig,
                                    H=H_serial,
                                    evolutor_type='masked',
                                    use_zstring=True)
        dmrgegn = DMRGEngine(hgen=expander3, tol=0, reflect=False)
        dmrgegn.use_U1_symmetry('QM', target_block=(0, 0))
        EG2, Vmin2 = dmrgegn.run_finite(endpoint=(5, '<-', 0),
                                        maxN=[10, 30, 60, 100, 100],
                                        tol=0)
        Vmin2 = fix_tail(Vmin2, expander3.spaceconfig, 0)
        #check for states.
        assert_almost_equal(Emin_exact, EG2, decimal=4)
        Vmin1 = Vmin1[:, 0]
        assert_almost_equal(abs(Vmin2.state), abs(Vmin1), decimal=3)
        print(Vmin2.state / Vmin1)[abs(Vmin1) > 1e-2]
        pdb.set_trace()
예제 #3
0
파일: testdmrg.py 프로젝트: GiggleLiu/apps
 def test_lanczos(self):
     '''test for directly construct and solve the ground state energy.'''
     model=self.get_model(10,1)
     hgen1=RGHGen(spaceconfig=SpinSpaceConfig([2,1]),H=model.H_serial,evolutor_type='null')
     hgen2=RGHGen(spaceconfig=SpinSpaceConfig([2,1]),H=model.H_serial,evolutor_type='normal')
     dmrgegn=DMRGEngine(hgen=hgen1,tol=0)
     H=get_H(hgen=hgen1)
     H2,bm2=get_H_bm(hgen=hgen2,bstr='M')
     Emin=eigsh(H,k=1)[0]
     Emin2=eigsh(bm2.lextract_block(H2,(0.,0,)),k=1)[0]
     print 'The Ground State Energy is %s, tolerence %s.'%(Emin,Emin-Emin2)
     assert_almost_equal(Emin,Emin2)
예제 #4
0
파일: testdmrg.py 프로젝트: amilacsw/dmrg
 def test_lanczos(self):
     '''test for directly construct and solve the ground state energy.'''
     model=self.get_model(10,1)
     hgen1=SpinHGen(spaceconfig=SpinSpaceConfig([2,1]),evolutor=NullEvolutor(hndim=2))
     hgen2=SpinHGen(spaceconfig=SpinSpaceConfig([2,1]),evolutor=Evolutor(hndim=2))
     dmrgegn=DMRGEngine(hchain=model.H_serial,hgen=hgen1,tol=0)
     H=get_H(H=model.H_serial,hgen=hgen1)
     H2,bm2=get_H_bm(H=model.H_serial,hgen=hgen2,bstr='M')
     Emin=eigsh(H,k=1)[0]
     Emin2=eigsh(bm2.lextract_block(H2,0.),k=1)[0]
     print 'The Ground State Energy is %s, tolerence %s.'%(Emin,Emin-Emin2)
     assert_almost_equal(Emin,Emin2)
예제 #5
0
파일: testdmrg.py 프로젝트: GiggleLiu/apps
 def test_dmrg_finite(self):
     '''
     Run iDMFT for heisenberg model.
     '''
     nsite=10
     model=self.get_model(nsite,1)
     hgen1=RGHGen(spaceconfig=SpinSpaceConfig([2,1]),H=model.H_serial,evolutor_type='null')
     hgen2=RGHGen(spaceconfig=SpinSpaceConfig([2,1]),H=model.H_serial,evolutor_type='masked')
     H=get_H(hgen1)
     EG1=eigsh(H,k=1,which='SA')[0]
     dmrgegn=DMRGEngine(hgen=hgen2,tol=0,reflect=True)
     dmrgegn.use_U1_symmetry('M',target_block=0)
     EG2=dmrgegn.run_finite(endpoint=(5,'<-',0),maxN=[10,20,30,40,40],tol=0)[0]
     assert_almost_equal(EG1,EG2,decimal=4)
예제 #6
0
 def get_even_eop(self,spaceconfig):
     '''Get the evolution operator collection for even bonds.'''
     nsite=self.opc.nsite
     #query even bonds, like 1-2 or 1.
     res=None
     for i in xrange(1,nsite,2):
         bop=self.opc.query(i,i+1)
         sop=self.opc.query(i)
         op=bop+sop
         #get the hamiltonian
         hgen=ExpandGenerator(spaceconfig=spaceconfig,H=op,evolutor_type='null')
         H=get_H(hgen)
         #get the evolution matrix, exponential of H
         expH=expm(H)
         #SVD decompose to make it into .
     return res
예제 #7
0
 def test_lanczos(self):
     '''test for directly construct and solve the ground state energy.'''
     model = self.get_model(10, 1)
     hgen1 = ExpandGenerator(spaceconfig=SpinSpaceConfig([1, 2]),
                             H=model.H_serial,
                             evolutor_type='null')
     hgen2 = ExpandGenerator(spaceconfig=SpinSpaceConfig([1, 2]),
                             H=model.H_serial,
                             evolutor_type='normal')
     dmrgegn = DMRGEngine(hgen=hgen1, tol=0, iprint=10)
     H = get_H(hgen=hgen1)
     H2, bm2 = get_H_bm(hgen=hgen2, bstr='M')
     Emin = eigsh(H, k=1)[0]
     Emin2 = eigsh(bm2.extract_block(H2, (zeros(1), zeros(1)),
                                     uselabel=True),
                   k=1)[0]
     print 'The Ground State Energy is %s, tolerence %s.' % (Emin,
                                                             Emin - Emin2)
     assert_almost_equal(Emin, Emin2)
예제 #8
0
 def test_dmrg_finite(self):
     '''
     Run iDMFT for heisenberg model.
     '''
     nsite = 10
     model = self.get_model(nsite, 1)
     hgen1 = ExpandGenerator(spaceconfig=SpinSpaceConfig([1, 2]),
                             H=model.H_serial,
                             evolutor_type='null')
     hgen2 = ExpandGenerator(spaceconfig=SpinSpaceConfig([1, 2]),
                             H=model.H_serial,
                             evolutor_type='masked')
     H = get_H(hgen1)
     EG1 = eigsh(H, k=1, which='SA')[0]
     dmrgegn = DMRGEngine(hgen=hgen2, tol=0, reflect=True)
     dmrgegn.use_U1_symmetry('M', target_block=zeros(1))
     EG2 = dmrgegn.run_finite(endpoint=(5, '<-', 0),
                              maxN=[10, 20, 40, 40, 40],
                              tol=0)[0]
     assert_almost_equal(EG1, EG2, decimal=4)