Beispiel #1
0
def ITE_FCI(H_,db,bmax,psi0=None,omega=None):

 Hm    = Hmat(H_)
 N     = Hm.shape[0]
 nbit  = int(np.log2(N))
 eps,U = SciLA.eigh(Hm)
 m0    = np.argmin(eps)
 zeta  = np.exp(-db*(eps-eps[m0]))

 fout = open('ITE_FCI.out','w')
 fout.write("FCI gs energy %.6f \n" % eps[m0])
 fout.write("FCI gs wfn \n")
 print_state(U[:,m0],nbit,fout)

 if(psi0 is None):
  i0          = np.argmin(np.diag(Hm))
  psi_FCI     = np.zeros(N,dtype=complex)
  psi_FCI[i0] = 1.0
 else:
  psi_FCI     = psi0.copy()

 nbeta    = int(bmax/db)+1
 fout.write("FCI ITE\n")
 data = np.zeros((nbeta,2))
 for ib in range(nbeta):
  ea,ev    = Hmoms(H_,psi_FCI)
  #print (ib*db,ea,ev)
  psi_FCI  = np.dot(np.conj(U.T),psi_FCI)
  psi_FCI  = zeta*psi_FCI
  psi_FCI  = np.dot(U,psi_FCI)
  psi_FCI /= LA.norm(psi_FCI)
  if(omega is None): fide = fidelity(psi_FCI,U[:,m0])
  else:              fide = LA.norm(psi_FCI[omega])**2
  fout.write("%.6f %.6f %.6f %.6f \n" % (ib*db,ea,ev,fide))
  #print(ea)
  data[ib, 0] = ib*db
  data[ib, 1] = ea
  if ea < 0.01 and ea > -0.01:
      print('wf: ',psi_FCI)
  # if ea < 1e-3:
  #     print("%.6f %.6f %.6f %.6f \n" % (ib*db,ea,ev,fide))

 fout.write("FCI ITE gs wfn \n")
 #print_state(psi_FCI,nbit,fout)

 fout.close()
 
 return data
Beispiel #2
0
def QITE(H_, db, bmax, lanczos=False, psi0=None, omega=None, ncheck=1):
    Hm = Hmat(H_)
    N = Hm.shape[0]
    nbit = int(np.log2(N))
    eps, U = SciLA.eigh(Hm)
    m0 = np.argmin(eps)
    zeta = np.exp(-db * (eps - eps[m0]))
    fide = 1.0

    fout = open('QITE.out', 'w')
    fout.write("FCI gs energy %.6f \n" % eps[m0])
    fout.write("FCI gs wfn \n")
    print_state(U[:, m0], nbit, fout)

    psi_QITE = psi0[:]

    nbeta = int(bmax / db) + 1
    hvect_LANZ = np.zeros(nbeta + 1)
    svect_LANZ = np.zeros(nbeta + 1)

    xv = None
    fout.write("QITE\n")
    for ib in range(nbeta):
        ea, ev = Hmoms(H_, psi_QITE)
        hvect_LANZ[ib] = ea

        if (omega is None): fide = fidelity(psi_QITE, U[:, m0])
        else: fide = LA.norm(psi_QITE[omega])**2

        if (lanczos):
            ea_ = Lanczos_QITE(hvect_LANZ[:ib + 1], svect_LANZ[:ib + 1], db)
            fout.write("%.6f %.6f %.6f %.6f %.6f \n" %
                       (ib * db, ea, ev, fide, ea_))
        else:
            fout.write("%.6f %.6f %.6f %.6f \n" % (ib * db, ea, ev, fide))
        fout.flush()

        psi_QITE, dnorm, xv = QITE_step(H_, psi_QITE, db, xv, ib % ncheck == 0)
        svect_LANZ[ib + 1] = svect_LANZ[ib] + np.log(dnorm)

    fout.write("QITE gs wfn \n")
    print_state(psi_QITE, nbit, fout)
    dump_state(psi_QITE, nbit, 'qite.psi')
    dump_lanz_vecs(hvect_LANZ[:nbeta], svect_LANZ[:nbeta], 'qlanz.vecs')

    fout.close()
Beispiel #3
0
def ITE(H_,db,bmax,lanczos=False,psi0=None):

 N     = H_[0][2].shape[1]
 nbit  = int(np.log2(N))
 hdiag = np.zeros(N,dtype=complex)
 for i in range(N):
  hdiag[i] = Hii(H_,i)

 precond = lambda x,e, *args: x/(hdiag-e+1e-4)

 def hop(c_):
  return Hpsi(H_,c_)

 if(psi0 is None):
  i0       = np.argmin(hdiag)
  psi0     = np.zeros(N,dtype=complex)
  psi0[i0] = 1.0
 
 from pyscf.lib import davidson
 epsm0,Um0 = davidson(hop,psi0,precond)
 
 fout = open('ITE.out','w')
 fout.write("FCI gs energy %.6f \n" % epsm0)
 fout.write("FCI gs wfn \n")
 print_state(Um0,nbit,fout)

 if(psi0 is None):
  i0          = np.argmin(hdiag)
  psi_ITE     = np.zeros(N,dtype=complex)
  psi_ITE[i0] = 1.0
 else:
  psi_ITE     = psi0.copy()

 nbeta = int(bmax/db)+1
 hvect_LANZ = np.zeros(nbeta+1)
 svect_LANZ = np.zeros(nbeta+1)

 if(lanczos):
  space_LANZ = np.zeros((N,nbeta),dtype=complex)

 fout.write("ITE\n")
 for ib in range(nbeta):
  ea,ev          = Hmoms(H_,psi_ITE)
  hvect_LANZ[ib] = ea
  fide           = fidelity(psi_ITE,Um0)

  if(lanczos):
   space_LANZ[:,ib] = psi_ITE.copy()
   psi_LANZ         = Lanczos_kernel(UH,space_LANZ[:,:ib+1])
   ea_,ev_          = Hmoms(H_,psi_LANZ)
   fide_            = fidelity(psi_LANZ,Um0)
   fout.write("%.6f %.6f %.6f %.6f %.6f %.6f %.6f \n" % (ib*db,ea,ev,fide,ea_,ev_,fide_))
  else:
   fout.write("%.6f %.6f %.6f %.6f \n" % (ib*db,ea,ev,fide)) 

  psi_ITE,dn = ExpmbH(H_,psi_ITE,db)
  svect_LANZ[ib+1]  = svect_LANZ[ib]+np.log(dn)

 fout.write("ITE gs wfn \n")
 print_state(psi_ITE,nbit,fout)
 dump_state(psi_ITE,nbit,'ite.psi')
 dump_lanz_vecs(hvect_LANZ[:nbeta],svect_LANZ[:nbeta],'qlanz.vecs')

 fout.close()
def QITE(H_, db, bmax, lanczos=False, psi0=None, omega=None, ncheck=1):

    Hm = Hmat(H_)
    N = Hm.shape[0]
    nbit = int(np.log2(N))
    eps, U = SciLA.eigh(Hm)
    m0 = np.argmin(eps)
    epsm0 = eps[m0]
    Um0 = U[:, m0]
    zeta = np.exp(-db * (eps - eps[m0]))
    fide = 1.0

    fout = open('QITE.out', 'w')
    fout.write("FCI gs energy %.6f \n" % epsm0)
    fout.write("FCI gs wfn \n")
    print_state(Um0, nbit, fout)

    psi_QITE = psi0[:]

    nbeta = int(bmax / db) + 1
    hvect_LANZ = np.zeros(nbeta + 1)
    svect_LANZ = np.zeros(nbeta + 1)

    xv = None
    hpauli = {}
    fout.write("QITE\n")
    data = np.zeros((nbeta, 2))
    for ib in range(nbeta):
        print('B: ', ib * db)
        ea, ev = Hmoms(H_, psi_QITE)
        print('Energy: ', ea)
        hvect_LANZ[ib] = ea

        if (omega is None):
            fide = fidelity(psi_QITE, Um0)
        else:
            fide = LA.norm(psi_QITE[omega])**2

        if (lanczos):
            ea_ = Lanczos_QITE(hvect_LANZ[:ib + 1], svect_LANZ[:ib + 1], db)
            fout.write("%.6f %.6f %.6f %.6f %.6f \n" %
                       (ib * db, ea, ev, fide, ea_))
        else:
            fout.write("%.6f %.6f %.6f %.6f \n" % (ib * db, ea, ev, fide))
            #print("%.6f %.6f %.6f %.6f \n" % (ib*db,ea,ev,fide))
        fout.flush()

        b = ib * db
        data[ib, 0] = b
        data[ib, 1] = ea
        if (ncheck > 0):
            check = (ib % ncheck == 0)
        else:
            check = False
        psi_QITE, dnorm, xv, Xop = QITE_step(H_, psi_QITE, db, xv, check)
        hpauli[b] = Xop
        # Feedback portion
        # Number of applications of the unitary to get ground state

        svect_LANZ[ib + 1] = svect_LANZ[ib] + np.log(dnorm)

    fout.write("QITE gs wfn \n")
    print_state(psi_QITE, nbit, fout)
    dump_state(psi_QITE, nbit, 'qite.psi')
    dump_lanz_vecs(hvect_LANZ[:nbeta], svect_LANZ[:nbeta], 'qlanz.vecs')

    fout.close()

    return data, hpauli
Beispiel #5
0
def QITE(H_,
         db,
         bmax,
         lanczos=False,
         psi0=None,
         omega=None,
         ncheck=1,
         davidson=True):

    if (davidson):
        N = H_[0][2].shape[1]
        nbit = int(np.log2(N))
        hdiag = np.zeros(N, dtype=complex)
        for i in range(N):
            hdiag[i] = Hii(H_, i)
            print i, hdiag[i]

        precond = lambda x, e, *args: x / (hdiag - e + 1e-4)

        def hop(c_):
            return Hpsi(H_, c_)

        if (psi0 is None):
            i0 = np.argmin(hdiag)
            psi0 = np.zeros(N, dtype=complex)
            psi0[i0] = 1.0

        from pyscf.lib import davidson
        epsm0, Um0 = davidson(hop, psi0, precond)
    else:
        Hm = Hmat(H_)
        N = Hm.shape[0]
        nbit = int(np.log2(N))
        eps, U = SciLA.eigh(Hm)
        m0 = np.argmin(eps)
        epsm0 = eps[m0]
        Um0 = U[:, m0]
        zeta = np.exp(-db * (eps - eps[m0]))
        fide = 1.0

    fout = open('QITE.out', 'w')
    fout.write("FCI gs energy %.6f \n" % epsm0)
    fout.write("FCI gs wfn \n")
    print_state(Um0, nbit, fout)

    psi_QITE = psi0[:]

    nbeta = int(bmax / db) + 1
    hvect_LANZ = np.zeros(nbeta + 1)
    svect_LANZ = np.zeros(nbeta + 1)

    xv = None
    fout.write("QITE\n")
    for ib in range(nbeta):
        ea, ev = Hmoms(H_, psi_QITE)
        hvect_LANZ[ib] = ea

        if (omega is None): fide = fidelity(psi_QITE, Um0)
        else: fide = LA.norm(psi_QITE[omega])**2

        if (lanczos):
            ea_ = Lanczos_QITE(hvect_LANZ[:ib + 1], svect_LANZ[:ib + 1], db)
            fout.write("%.6f %.6f %.6f %.6f %.6f \n" %
                       (ib * db, ea, ev, fide, ea_))
        else:
            fout.write("%.6f %.6f %.6f %.6f \n" % (ib * db, ea, ev, fide))
        fout.flush()

        if (ncheck > 0): check = (ib % ncheck == 0)
        else: check = False
        psi_QITE, dnorm, xv = QITE_step(H_, psi_QITE, db, xv, check)
        svect_LANZ[ib + 1] = svect_LANZ[ib] + np.log(dnorm)

    fout.write("QITE gs wfn \n")
    print_state(psi_QITE, nbit, fout)
    dump_state(psi_QITE, nbit, 'qite.psi')
    dump_lanz_vecs(hvect_LANZ[:nbeta], svect_LANZ[:nbeta], 'qlanz.vecs')

    fout.close()