def test_write(): numpy.random.seed(7) nmo = 13 nelec = (4, 3) h1e, chol, enuc, eri = generate_hamiltonian(nmo, nelec, cplx=True, sym=4) sys = Generic(nelec=nelec, h1e=h1e, chol=chol, ecore=enuc) sys.write_integrals()
def test_walker_energy(): numpy.random.seed(7) nelec = (2, 2) nmo = 5 h1e, chol, enuc, eri = generate_hamiltonian(nmo, nelec, cplx=False) system = Generic(nelec=nelec, h1e=h1e, chol=chol, ecore=enuc, inputs={'integral_tensor': False}) (e0, ev), (d, oa, ob) = simple_fci(system, gen_dets=True) na = system.nup init = get_random_wavefunction(nelec, nmo) init[:, :na], R = reortho(init[:, :na]) init[:, na:], R = reortho(init[:, na:]) trial = MultiSlater(system, (ev[:, 0], oa, ob), init=init) trial.calculate_energy(system) walker = MultiDetWalker({}, system, trial) nume = 0 deno = 0 for i in range(trial.ndets): psia = trial.psi[i, :, :na] psib = trial.psi[i, :, na:] oa = numpy.dot(psia.conj().T, init[:, :na]) ob = numpy.dot(psib.conj().T, init[:, na:]) isa = numpy.linalg.inv(oa) isb = numpy.linalg.inv(ob) ovlp = numpy.linalg.det(oa) * numpy.linalg.det(ob) ga = numpy.dot(init[:, :system.nup], numpy.dot(isa, psia.conj().T)).T gb = numpy.dot(init[:, system.nup:], numpy.dot(isb, psib.conj().T)).T e = local_energy(system, numpy.array([ga, gb]), opt=False)[0] nume += trial.coeffs[i].conj() * ovlp * e deno += trial.coeffs[i].conj() * ovlp print(nume / deno, nume, deno, e0[0])
def test_real(): numpy.random.seed(7) nmo = 17 nelec = (4, 3) h1e, chol, enuc, eri = generate_hamiltonian(nmo, nelec, cplx=False) sys = Generic(nelec=nelec, h1e=h1e, chol=chol, ecore=enuc) assert sys.nup == 4 assert sys.ndown == 3 assert numpy.trace(h1e) == pytest.approx(9.38462274882365)
def test_complex(): numpy.random.seed(7) nmo = 17 nelec = (5, 3) h1e, chol, enuc, eri = generate_hamiltonian(nmo, nelec, cplx=True, sym=4) sys = Generic(nelec=nelec, h1e=h1e, chol=chol, ecore=enuc) assert sys.nup == 5 assert sys.ndown == 3 assert sys.nbasis == 17
def test_local_energy_cholesky_opt(): numpy.random.seed(7) nmo = 24 nelec = (4,2) h1e, chol, enuc, eri = generate_hamiltonian(nmo, nelec, cplx=False) sys = Generic(nelec=nelec, h1e=h1e, chol=chol, ecore=enuc) wfn = get_random_nomsd(sys, ndet=1, cplx=False) trial = MultiSlater(sys, wfn) sys.construct_integral_tensors_real(trial) e = local_energy_generic_cholesky_opt(sys, trial.G, Ghalf=trial.GH) assert e[0] == pytest.approx(20.6826247016273) assert e[1] == pytest.approx(23.0173528796140) assert e[2] == pytest.approx(-2.3347281779866)
def test_generic_single_det(): nmo = 11 nelec = (3, 3) options = { 'verbosity': 0, 'qmc': { 'timestep': 0.005, 'num_steps': 10, 'blocks': 10, 'rng_seed': 8, }, 'trial': { 'name': 'hartree_fock' }, 'estimator': { 'back_propagated': { 'tau_bp': 0.025, 'one_rdm': True }, 'mixed': { 'energy_eval_freq': 1 } } } numpy.random.seed(7) h1e, chol, enuc, eri = generate_hamiltonian(nmo, nelec, cplx=False) sys_opts = {'sparse': True} sys = Generic(nelec=nelec, h1e=h1e, chol=chol, ecore=enuc, inputs=sys_opts) comm = MPI.COMM_WORLD afqmc = AFQMC(comm=comm, system=sys, options=options) afqmc.run(comm=comm, verbose=0) afqmc.finalise(verbose=0) afqmc.estimators.estimators['mixed'].update(afqmc.system, afqmc.qmc, afqmc.trial, afqmc.psi, 0) enum = afqmc.estimators.estimators['mixed'].names numer = afqmc.estimators.estimators['mixed'].estimates[enum.enumer] denom = afqmc.estimators.estimators['mixed'].estimates[enum.edenom] weight = afqmc.estimators.estimators['mixed'].estimates[enum.weight] assert numer.real == pytest.approx(3.8763193646854273) data = extract_mixed_estimates('estimates.0.h5') assert numpy.mean( data.ETotal.values[:-1].real) == pytest.approx(1.5485077038208) rdm = extract_rdm('estimates.0.h5') assert rdm[0, 0].trace() == pytest.approx(nelec[0]) assert rdm[0, 1].trace() == pytest.approx(nelec[1]) assert rdm[11, 0, 1, 3].real == pytest.approx(-0.121883381144845)
def test_read(): numpy.random.seed(7) nmo = 13 nelec = (4, 3) h1e, chol, enuc, eri = generate_hamiltonian(nmo, nelec, cplx=True, sym=4) from pauxy.utils.io import write_qmcpack_dense chol_ = chol.reshape((-1, nmo * nmo)).T.copy() write_qmcpack_dense(h1e, chol_, nelec, nmo, enuc=enuc, filename='hamil.h5', real_chol=False) options = {'nup': nelec[0], 'ndown': nelec[1], 'integrals': 'hamil.h5'} sys = Generic(inputs=options) schol = sys.chol_vecs assert numpy.linalg.norm(chol - schol) == pytest.approx(0.0)
def test_phmsd(): numpy.random.seed(7) nmo = 10 nelec = (5, 5) options = {'sparse': False} h1e, chol, enuc, eri = generate_hamiltonian(nmo, nelec, cplx=False) system = Generic(nelec=nelec, h1e=h1e, chol=chol, ecore=0, inputs=options) wfn = get_random_nomsd(system, ndet=3) trial = MultiSlater(system, wfn) walker = MultiDetWalker({}, system, trial) qmc = dotdict({'dt': 0.005, 'nstblz': 5}) prop = GenericContinuous(system, trial, qmc) fb = prop.construct_force_bias(system, walker, trial) prop.construct_VHS(system, fb) # Test PH type wavefunction. wfn, init = get_random_phmsd(system, ndet=3, init=True) trial = MultiSlater(system, wfn, init=init) prop = GenericContinuous(system, trial, qmc) walker = MultiDetWalker({}, system, trial) fb = prop.construct_force_bias(system, walker, trial) vhs = prop.construct_VHS(system, fb)
def test_generic(): nmo = 11 nelec = (3, 3) options = { 'verbosity': 0, 'get_sha1': False, 'qmc': { 'timestep': 0.005, 'steps': 10, 'blocks': 10, 'rng_seed': 8, }, 'estimates': { 'mixed': { 'energy_eval_freq': 1 } }, 'trial': { 'name': 'MultiSlater' } } numpy.random.seed(7) h1e, chol, enuc, eri = generate_hamiltonian(nmo, nelec, cplx=False) sys = Generic(nelec=nelec, h1e=h1e, chol=chol, ecore=enuc) comm = MPI.COMM_WORLD afqmc = AFQMC(comm=comm, system=sys, options=options) afqmc.run(comm=comm, verbose=0) afqmc.finalise(verbose=0) afqmc.estimators.estimators['mixed'].update(afqmc.system, afqmc.qmc, afqmc.trial, afqmc.psi, 0) enum = afqmc.estimators.estimators['mixed'].names numer = afqmc.estimators.estimators['mixed'].estimates[enum.enumer] denom = afqmc.estimators.estimators['mixed'].estimates[enum.edenom] weight = afqmc.estimators.estimators['mixed'].estimates[enum.weight] assert numer.real == pytest.approx(3.8763193646854273) data = extract_mixed_estimates('estimates.0.h5') assert numpy.mean( data.ETotal.values[:-1].real) == pytest.approx(1.5485077038208)