def find_basis_evaluate(mfchk, hdf_opt, hdf_vmc, hdf_final): """Given a wave function in hdf_opt, compute the 1-RDM (stored in hdf_vmc) , generate a minimal atomic basis and compute the energy/OBDM/TBDM and store in hdf_final """ from pyqmc.obdm import OBDMAccumulator from pyqmc.tbdm import TBDMAccumulator from pyqmc import EnergyAccumulator sys = pyqmc_from_hdf(mfchk) mol = sys["mol"] a = lo.orth_ao(mol, "lowdin") obdm_up = OBDMAccumulator(mol=mol, orb_coeff=a, spin=0) obdm_down = OBDMAccumulator(mol=mol, orb_coeff=a, spin=1) with h5py.File(hdf_opt, "r") as hdf_in: if f"wf" in hdf_in.keys(): print("reading in wave function") grp = hdf_in[f"wf"] for k in grp.keys(): sys["wf"].parameters[k] = np.array(grp[k]) configs = pyqmc.initial_guess(sys["mol"], 1000) pyqmc.vmc( sys["wf"], configs, nsteps=500, hdf_file=hdf_vmc, accumulators={ "obdm_up": obdm_up, "obdm_down": obdm_down }, ) with h5py.File(hdf_vmc, "r") as vmc_hdf: obdm_up = np.mean(np.array(vmc_hdf["obdm_upvalue"]), axis=0) obdm_down = np.mean(np.array(vmc_hdf["obdm_downvalue"]), axis=0) basis_up = gen_basis(mol, sys["mf"], obdm_up) basis_down = gen_basis(mol, sys["mf"], obdm_down) obdm_up_acc = OBDMAccumulator(mol=mol, orb_coeff=basis_up, spin=0) obdm_down_acc = OBDMAccumulator(mol=mol, orb_coeff=basis_down, spin=1) tbdm = TBDMAccumulator(mol, np.array([basis_up, basis_down]), spin=(0, 1)) acc = { "energy": EnergyAccumulator(mol), "obdm_up": obdm_up_acc, "obdm_down": obdm_down_acc, "tbdm": tbdm, } configs = pyqmc.initial_guess(sys["mol"], 1000) pyqmc.vmc(sys["wf"], configs, nsteps=500, hdf_file=hdf_final, accumulators=acc)
wf=pyqmc.slater_jastrow(mol,mf) return mol,mf,wf if __name__=="__main__": cluster = LocalCluster(n_workers=ncore, threads_per_worker=1) client = Client(cluster) mol,mf,wf=generate_wfs() from pyqmc.mc import vmc from pyqmc.dasktools import distvmc,line_minimization from pyqmc.dmc import rundmc from pyqmc import EnergyAccumulator df,coords=distvmc(wf,pyqmc.initial_guess(mol,nconfig),client=client,nsteps_per=10,nsteps=10) line_minimization(wf,coords,pyqmc.gradient_generator(mol,wf,["wf2acoeff", "wf2bcoeff"]),client=client) dfdmc, configs, weights = rundmc( wf, coords, nsteps=5000, branchtime=5, accumulators={"energy": EnergyAccumulator(mol)}, ekey=("energy", "total"), tstep=0.02, verbose=True, propagate=pyqmc.dasktools.distdmc_propagate, client=client, ) dfdmc = pd.DataFrame(dfdmc).to_json("dmc.json")
def test(): import parsl from pyscf import lib, gto, scf import numpy as np import pandas as pd import logging from parsl.config import Config from parsl.providers import LocalProvider from parsl.channels import LocalChannel from parsl.launchers import SimpleLauncher from parsl.executors import ExtremeScaleExecutor ncore = 4 config = Config( executors=[ ExtremeScaleExecutor(label="Extreme_Local", worker_debug=True, ranks_per_node=ncore, provider=LocalProvider( channel=LocalChannel(), init_blocks=1, max_blocks=1, launcher=SimpleLauncher())) ], strategy=None, ) parsl.load(config) mol = gto.M(atom='H 0. 0. 0.; H 0. 0. 2.0', unit='bohr', ecp='bfd', basis='bfd_vtz') mf = scf.RHF(mol).run() mol.output = None mol.stdout = None mf.output = None mf.stdout = None mf.chkfile = None from pyqmc import ExpCuspFunction, GaussianFunction, MultiplyWF, PySCFSlaterRHF, JastrowSpin, initial_guess, EnergyAccumulator from pyqmc.accumulators import PGradTransform, LinearTransform nconf = 1600 basis = [ ExpCuspFunction(2.0, 1.5), GaussianFunction(0.5), GaussianFunction(2.0), GaussianFunction(.25), GaussianFunction(1.0), GaussianFunction(4.0), GaussianFunction(8.0) ] wf = MultiplyWF(PySCFSlaterRHF(mol, mf), JastrowSpin(mol, basis, basis)) coords = initial_guess(mol, nconf) energy_acc = EnergyAccumulator(mol) pgrad_acc = PGradTransform( energy_acc, LinearTransform(wf.parameters, ['wf2acoeff', 'wf2bcoeff'])) from pyqmc.optsr import gradient_descent gradient_descent(wf, coords, pgrad_acc, vmc=distvmc, vmcoptions={ 'npartitions': ncore, 'nsteps': 100, 'nsteps_per': 100 })