def h2_pyscf_equil_test(): jobs = [] xyz = open('structures/h2_equil.xyz', 'r') xyz.readline() # Remove headers. xyz.readline() scfman = PySCFManager(name='scf', path='test_h2eq_py', writer=PySCFWriter({ 'spin': 0, 'xyz': xyz.read() }), runner=PySCFRunnerPBS(queue='secondary', nn=1, np=16, walltime='0:01:00')) jobs.append(scfman) var = QWalkManager(name='var', path=scfman.path, writer=VarianceWriter(), reader=VarianceReader(), runner=RunnerPBS(nn=1, np=16, queue='secondary', walltime='0:05:00'), trialfunc=SlaterJastrow(scfman, kpoint=0)) jobs.append(var) lin = QWalkManager(name='linear', path=scfman.path, writer=LinearWriter(), reader=LinearReader(), runner=RunnerPBS(nn=1, np=16, queue='secondary', walltime='0:10:00'), trialfunc=SlaterJastrow(slatman=scfman, jastman=var, kpoint=0)) jobs.append(lin) dmc = QWalkManager(name='dmc', path=scfman.path, writer=DMCWriter(), reader=DMCReader(), runner=RunnerPBS( nn=1, np=16, queue='secondary', walltime='0:10:00', ), trialfunc=SlaterJastrow(slatman=scfman, jastman=lin)) jobs.append(dmc) return jobs
def si_pyscf_test(): ''' Simple tests that check PBC is working Crystal, and that QMC can be performed on the result.''' jobs=[] pwriter=PySCFPBCWriter({ 'gmesh':[16,16,16], 'cif':open('si.cif','r').read() }) pman=PySCFManager( name='scf', path='sipyscf', writer=pwriter, runner=PySCFRunnerPBS( queue='secondary', nn=1, np=16, walltime='4:00:00' ) ) jobs.append(pman) var=QWalkManager( name='var', path=pman.path, writer=VarianceWriter(), reader=VarianceReader(), runner=RunnerPBS( nn=1,queue='secondary',walltime='0:10:00' ), trialfunc=SlaterJastrow(pman,kpoint=0) ) jobs.append(var) lin=QWalkManager( name='lin', path=pman.path, writer=LinearWriter(), reader=LinearReader(), runner=RunnerPBS( nn=1,queue='secondary',walltime='0:30:00' ), trialfunc=SlaterJastrow(slatman=pman,jastman=var,kpoint=0) ) jobs.append(lin) return jobs
def si_crystal_test(): ''' Simple tests that check PBC is working Crystal, and that QMC can be performed on the result.''' jobs=[] cwriter=CrystalWriter({ 'xml_name':'../BFD_Library.xml', 'cutoff':0.2, 'kmesh':(4,4,4), }) cwriter.set_struct_fromcif(open('si.cif','r').read(),primitive=True) cwriter.set_options({}) cman=CrystalManager( name='crys', path='sicrys', writer=cwriter, runner=RunnerPBS( queue='secondary', nn=1, walltime='0:10:00' ) ) jobs.append(cman) var=QWalkManager( name='var', path=cman.path, writer=VarianceWriter(), reader=VarianceReader(), runner=RunnerPBS( nn=1,queue='secondary',walltime='0:10:00' ), trialfunc=SlaterJastrow(cman,kpoint=0) ) jobs.append(var) lin=QWalkManager( name='linear', path=cman.path, writer=LinearWriter(), reader=LinearReader(), runner=RunnerPBS( nn=1,queue='secondary',walltime='1:00:00' ), trialfunc=SlaterJastrow(slatman=cman,jastman=var,kpoint=0) ) jobs.append(lin) for kidx in cman.qwfiles['kpoints']: kpt=cman.qwfiles['kpoints'][kidx] dmc=QWalkManager( name='dmc_%d'%kidx, path=cman.path, writer=DMCWriter(), reader=DMCReader(), runner=RunnerPBS( nn=1,queue='secondary',walltime='1:00:00', ), trialfunc=SlaterJastrow(slatman=cman,jastman=lin,kpoint=kidx) ) jobs.append(dmc) return jobs
def mno_test(): ''' Test spinful calculations in PBC and real kpoint sampling. Also test trialfunc dependency. ''' jobs=[] cwriter=CrystalWriter({ 'xml_name':'../BFD_Library.xml', 'cutoff':0.2, 'kmesh':(4,4,4), 'total_spin':4 }) cwriter.set_struct_fromcif(open('mno.cif','r').read(),primitive=True) cwriter.set_options({}) cman=CrystalManager( name='crys', path='mnocrys', writer=cwriter, runner=RunnerPBS( queue='secondary', nn=1, walltime='1:00:00' ) ) jobs+=[cman] var=QWalkManager( name='var', path=cman.path, writer=VarianceWriter(), reader=VarianceReader(), runner=RunnerPBS( nn=1,queue='secondary',walltime='0:10:00' ), trialfunc=SlaterJastrow(cman,kpoint=(0,0,0)) ) lin=QWalkManager( name='linear', path=cman.path, writer=LinearWriter(), reader=LinearReader(), runner=RunnerPBS( nn=1,queue='secondary',walltime='1:00:00' ), trialfunc=SlaterJastrow(slatman=cman,jastman=var,kpoint=(0,0,0)) ) for kidx in cman.qwfiles['kpoints']: kpt=cman.qwfiles['kpoints'][kidx] if not sum(np.array(kpt)%(np.array(cman.kmesh)/2))<1e-14: print("complex kpt %d%d%d skipped"%kpt) continue dmc=QWalkManager( name='dmc_%d'%kidx, path=cman.path, writer=DMCWriter(), reader=DMCReader(), runner=RunnerPBS( nn=1,queue='secondary',walltime='1:00:00', ), trialfunc=SlaterJastrow(slatman=cman,jastman=lin,kpoint=kidx) ) jobs.append(dmc) return jobs
def mno_crystal_test(): ''' Test spinful calculations in PBC and real kpoint sampling. Also test trialfunc dependency. ''' cwriter = CrystalWriter({ 'xml_name': '../../BFD_Library.xml', 'cutoff': 0.2, 'kmesh': (3, 3, 3), 'initial_spins': [1, 0], 'total_spin': 5 }) cwriter.set_struct_fromcif(open('structures/mno.cif', 'r').read(), primitive=True) cwriter.set_options({}) cman = CrystalManager(name='crys', path='test_mno_crys', writer=cwriter, runner=RunnerPBS(queue='secondary', nn=1, np=20, walltime='2:00:00')) var = QWalkManager(name='var', path=cman.path, writer=VarianceWriter(), reader=VarianceReader(), runner=RunnerPBS(nn=1, np=20, queue='secondary', walltime='0:10:00'), trialfunc=SlaterJastrow(cman, kpoint=0)) lin = QWalkManager(name='linear', path=cman.path, writer=LinearWriter(), reader=LinearReader(), runner=RunnerPBS(nn=1, np=20, queue='secondary', walltime='1:00:00'), trialfunc=SlaterJastrow(slatman=cman, jastman=var, kpoint=0)) jobs = [cman, var, lin] for kidx in cman.qwfiles['kpoints']: kpt = cman.qwfiles['kpoints'][kidx] dmc = QWalkManager(name='dmc_%d' % kidx, path=cman.path, writer=DMCWriter(), reader=DMCReader(), runner=RunnerPBS( nn=1, np=16, queue='secondary', walltime='1:00:00', ), trialfunc=SlaterJastrow(slatman=cman, jastman=lin, kpoint=kidx)) jobs.append(dmc) return jobs
def h2_crystal_equil_test(): jobs = [] cwriter = CrystalWriter({ 'xml_name': '../../BFD_Library.xml', 'cutoff': 0.2, 'spin_polarized': False }) cwriter.set_struct_fromxyz(open('structures/h2_equil.xyz', 'r').read()) cman = CrystalManager(name='crys', path='test_h2eq_crys', writer=cwriter, runner=RunnerPBS(queue='secondary', nn=1, np=16, walltime='0:01:00')) jobs.append(cman) var = QWalkManager(name='var', path=cman.path, writer=VarianceWriter(), reader=VarianceReader(), runner=RunnerPBS(nn=1, np=16, queue='secondary', walltime='0:05:00'), trialfunc=SlaterJastrow(cman, kpoint=0)) jobs.append(var) lin = QWalkManager(name='linear', path=cman.path, writer=LinearWriter(), reader=LinearReader(), runner=RunnerPBS(nn=1, np=16, queue='secondary', walltime='0:10:00'), trialfunc=SlaterJastrow(slatman=cman, jastman=var, kpoint=0)) jobs.append(lin) for kidx in cman.qwfiles['kpoints']: kpt = cman.qwfiles['kpoints'][kidx] dmc = QWalkManager(name='dmc_%d' % kidx, path=cman.path, writer=DMCWriter(), reader=DMCReader(), runner=RunnerPBS( nn=1, np=16, queue='secondary', walltime='0:10:00', ), trialfunc=SlaterJastrow(slatman=cman, jastman=lin, kpoint=kidx)) jobs.append(dmc) return jobs
# Now we can set up the corresponding objects for QWalk. # In[ ]: from variance import VarianceWriter, VarianceReader from autorunner import RunnerLocal from qwalkmanager import QWalkManager from imp import reload import time vopt_writer = VarianceWriter({'iterations': 6}) vopt_manager = QWalkManager( name='h2_vopt', path=path, writer=vopt_writer, runner=RunnerLocal(np=4), reader=VarianceReader(), trialfunc=sj # This is new! ) while not vopt_manager.completed: vopt_manager.nextstep() print(vopt_manager.reader.output['sigma']) import matplotlib.pyplot as plt plt.plot(vopt_manager.reader.output['sigma']) plt.ylabel("Standard deviation of energy") plt.xlabel("Optimization iteration") plt.savefig("05-qwalk_variance.pdf", bbox_inches='tight') # So what just happened here? # After setting up the calculation, we called `nextstep` repeatedly and the QWalk manager:
'dm_generator': dm_set_spins([1, -1], []), 'pyscf_path': sys.path }) vmc_writer = VarianceWriter() # Manage the PySCF job. scfmanager = PySCFManager(name='h2_pbe', path=path, writer=pyscf_writer, runner=PySCFRunnerLocal()) # Manage the VMC job. voptmanager = QWalkManager(name='h2_vopt', path=path, writer=VarianceWriter(), reader=VarianceReader(), trialfunc=SlaterJastrow(scfmanager), runner=RunnerLocal(np=4)) # In[ ]: while not voptmanager.completed: voptmanager.nextstep() # In[ ]: import matplotlib.pyplot as plt get_ipython().run_line_magic('matplotlib', 'inline') fig, ax = plt.subplots(1, 1) ax.plot(voptmanager.reader.output['sigma']) ax.set_title('VMC variance optimization')