def kernel_ft(h1e, g2e, norb, nelec, T, m=50, nsamp=100, Tmin=10e-4): '''E at temperature T ''' if T < Tmin: e, c = kernel(h1e, g2e, norb, nelec) return e h2e = direct_spin1.absorb_h1e(h1e, g2e, norb, nelec, .5) if isinstance(nelec, (int, numpy.integer)): nelecb = nelec // 2 neleca = nelec - nelecb else: neleca, nelecb = nelec na = cistring.num_strings(norb, neleca) nb = cistring.num_strings(norb, nelecb) def vecgen(n1=na, n2=nb): ci0 = numpy.random.randn(n1, n2) return ci0.reshape(-1) def hop(c): hc = direct_spin1.contract_2e(h2e, c, norb, nelec) return hc.reshape(-1) E = flan.ftlan_E(hop, vecgen, T, m, nsamp) return E
def ft_smpl_rdm12s(qud, hop, ci0, T, norb, nsamp=100, M=50, **kwargs): N_per_proc = nsamp // MPI_size beta = 1. / T E0 = _ftlan.ftlan_E(hop, ci0) ld = len(ci0) def ftrdm12s(v0): dm1, dm2, E, Z = _ftlan.ftlan_rdm12s1c(qud, hop, v0, T, norb, m=M, E0=E0) return np.asarray(dm1), np.asarray(dm2), E, Z RDM1, RDM2, _, _, = _ftlan.ftlan_rdm12s1c(qud, hop, ci0, T, norb, m=20, E0=E0) RDM1 *= 0. RDM2 *= 0. E, Z = 0., 0. for i in range(N_per_proc): ci0 = np.random.randn(ld) rdm1, rdm2, e, z = ftrdm12s(ci0) RDM1 += rdm1 RDM2 += rdm2 E += e Z += z RDM1 = RDM1 / (1. * N_per_proc) RDM2 = RDM2 / (1. * N_per_proc) E = E / (1. * N_per_proc) Z = Z / (1. * N_per_proc) comm.Barrier() RDM1 = comm.gather(RDM1, root=0) RDM2 = comm.gather(RDM2, root=0) E = comm.gather(E, root=0) Z = comm.gather(Z, root=0) if MPI_rank == 0: Z = np.sum(np.asarray(Z), axis=0).copy() / MPI_size E = np.sum(np.asarray(E), axis=0).copy() / (MPI_size * Z) RDM1 = np.sum(np.asarray(RDM1), axis=0).copy() / (MPI_size * Z) RDM2 = np.sum(np.asarray(RDM2), axis=0).copy() / (MPI_size * Z) RDM1 = comm.bcast(RDM1, root=0) RDM2 = comm.bcast(RDM2, root=0) E = comm.bcast(E, root=0) return RDM1, RDM2, E
def kernel_ft(h1e, g2e, norb, nelec, T, m=50, nsamp=40): '''E at temperature T ''' h2e = absorb_h1e(h1e, g2e, norb, nelec, .5) neleca, nelecb = nelec na = cistring.num_strings(norb, neleca) nb = cistring.num_strings(norb, nelecb) def vecgen(n1=na, n2=nb): ci0 = numpy.random.rand(n1, n2) return ci0.reshape(-1) def hop(c): hc = contract_2e(h2e, c, norb, nelec) return hc.reshape(-1) E = ftlan_E(hop, vecgen, T, m, nsamp) return E
def kernel_ft(h1e, g2e, norb, nelec, T, m=50, nsamp=100, Tmin=10e-4): '''E at temperature T ''' if T < Tmin: e, c = kernel(h1e, g2e, norb, nelec) return e h2e = direct_spin1.absorb_h1e(h1e, g2e, norb, nelec, .5) if isinstance(nelec, (int, numpy.integer)): nelecb = nelec//2 neleca = nelec - nelecb else: neleca, nelecb = nelec na = cistring.num_strings(norb, neleca) nb = cistring.num_strings(norb, nelecb) def vecgen(n1=na, n2=nb): ci0 = numpy.random.randn(n1, n2) return ci0.reshape(-1) def hop(c): hc = direct_spin1.contract_2e(h2e, c, norb, nelec) return hc.reshape(-1) E = flan.ftlan_E(hop, vecgen, T, m, nsamp) return E
def ft_smpl_E(hop, ci0, T, nsamp=20000, M=50, **kwargs): N_per_proc = nsamp // MPI_size ci0 = ci0.reshape(-1).copy() ftlan = _ftlan.ftlan_E1c beta = 1. / T ld = len(ci0) E0 = _ftlan.ftlan_E(hop, ci0) def lanczosE(v0): return _ftlan.ftlan_E1c(hop, v0, T, E0=E0) E, Z = 0., 0. for i in range(N_per_proc): ci0 = np.random.randn(ld) e, z = lanczosE(ci0) E += e Z += z E /= (1. * N_per_proc) Z /= (1. * N_per_proc) comm.Barrier() E = comm.gather(E, root=0) Z = comm.gather(Z, root=0) if MPI_rank == 0: E = np.asarray(E) Z = np.asarray(Z) E = np.mean(E) Z = np.mean(Z) E = E / Z else: E = None Z = None E = comm.bcast(E, root=0) Z = comm.bcast(Z, root=0) return E