Skip to content

Commit 347b40a

Browse files
committed
Lots of debugging with simple_test.
- Better track of progress by calling `recover` more often. - queue ID checking had an issue in some cases. - Less useless messages. - Other small fixes here and there.
1 parent dde51cd commit 347b40a

File tree

8 files changed

+85
-61
lines changed

8 files changed

+85
-61
lines changed

TODO.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
- [ ] Comparable defaults between PySCF and Crystal are not the same.
66
- [ ] Cannot yet do different paths with QMC and crystal because the basis and the orb file needs to be in the same place.
77
- May need to have the crystal manager export the results to the same directory (this means there are redundant files then).
8+
- [ ] test case where the trial function gets called before the function itself.

autopyscf.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ def __init__(self,options={}):
223223
self.direct_scf_tol=1e-7
224224
self.pyscf_path=[]
225225
self.spin=0
226-
self.gs=[4,4,4]
226+
self.gmesh=[4,4,4]
227227
self.xyz=""
228228
self.latticevec=""
229229
self.kpts=[2,2,2]
@@ -331,7 +331,7 @@ def pyscf_input(self,fname,chkfile):
331331
# The cell/molecule
332332
outlines+=[
333333
"mol=gto.M(verbose=4,",
334-
"gs="+str(self.gs)+",",
334+
"mesh="+str(self.gmesh)+",",
335335
"atom='''"+self.xyz+"''',",
336336
"a='''"+str(self.latticevec) +"''',",
337337
"basis=basis,",

autorunner.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ def submit(self,jobname=None):
360360
f.write('\n'.join(qsublines))
361361
try:
362362
result = sub.check_output("qsub %s"%(qsubfile),shell=True)
363-
self.queueid.append(result.decode().split()[0])
363+
self.queueid.append(result.decode().split()[0].split('.')[0])
364364
print(self.__class__.__name__,": Submitted as %s"%self.queueid)
365365
except sub.CalledProcessError:
366366
print(self.__class__.__name__,": Error submitting job. Check queue settings.")

crystal2qmc.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ def convert_crystal(
758758

759759
# All the files that will get produced.
760760
files={
761-
'kpoints':[],
761+
'kpoints':{},
762762
'basis':base+".basis",
763763
'jastrow2':base+".jast2",
764764
'orbplot':{},
@@ -772,7 +772,7 @@ def convert_crystal(
772772
for kpt in eigsys['kpt_coords']:
773773
if eigsys['ikpt_iscmpx'][kpt] and kset=='real': continue
774774
kidx=eigsys['kpt_index'][kpt]
775-
files['kpoints'].append(kpt)
775+
files['kpoints'][kidx]=kpt
776776
files['orbplot'][kidx]="%s_%d.plot"%(base,kidx)
777777
files['slater'][kidx]="%s_%d.slater"%(base,kidx)
778778
files['orb'][kidx]="%s_%d.orb"%(base,kidx)

dmc.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ def qwalk_input(self,infile):
6767

6868
with open(infile,'w') as f:
6969
f.write('\n'.join(outlines))
70-
self.completed=True
70+
71+
self.completed=True
7172

7273

7374
####################################################

linear.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ def qwalk_input(self,infile):
6666
f.write("total_fit %i \n"%self.total_fit)
6767
f.write("}\n")
6868
f.write(self.trialfunc)
69-
70-
self.completed=True
69+
self.completed=True
7170

7271

7372
####################################################

manager.py

+60-40
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
''' Manager classes handle the file maintainance of various runs.
2+
3+
They:
4+
- Call write, run, and read in the appropriate order.
5+
- Keep a record of progress on disk.
6+
- Hold a list of all file paths together in one place.
7+
- Report progress to the user.
8+
9+
All choices revolving around file names should be handled here.
10+
11+
Tips on avoiding bugs with the write/run/read cycle:
12+
- Every time data is updated, write the updates to the disk.
13+
- Every time the data is used, update the Manager from the disk.
14+
'''
115
import crystal
216
import propertiesreader
317
import os
@@ -122,7 +136,7 @@ def __init__(self,writer,runner,creader=None,name='crystal_run',path=None,
122136

123137
self.logname="%s@%s"%(self.__class__.__name__,self.path+self.name)
124138

125-
print(self.logname,": initializing")
139+
#print(self.logname,": initializing")
126140

127141
# Handle reader and runner defaults.
128142
self.writer=writer
@@ -163,7 +177,7 @@ def __init__(self,writer,runner,creader=None,name='crystal_run',path=None,
163177

164178
# Handle old results if present.
165179
if os.path.exists(self.path+self.pickle):
166-
print(self.logname,": rebooting old manager.")
180+
#print(self.logname,": rebooting old manager.")
167181
old=pkl.load(open(self.path+self.pickle,'rb'))
168182
self.recover(old)
169183

@@ -188,7 +202,7 @@ def recover(self,other):
188202
update_attributes(copyto=self.runner,copyfrom=other.runner,
189203
skip_keys=['queue','walltime','np','nn','jobname'],
190204
take_keys=['queueid'])
191-
update_attributes(copyto=self.runner,copyfrom=other.runner,
205+
update_attributes(copyto=self.prunner,copyfrom=other.prunner,
192206
skip_keys=['queue','walltime','np','nn','jobname'],
193207
take_keys=['queueid'])
194208

@@ -209,6 +223,7 @@ def recover(self,other):
209223
#----------------------------------------
210224
def nextstep(self):
211225
''' Determine and perform the next step in the calculation.'''
226+
self.recover(pkl.load(open(self.path+self.pickle,'rb')))
212227

213228
print(self.logname,": next step.")
214229
cwd=os.getcwd()
@@ -321,6 +336,9 @@ def write_summary(self):
321336
#------------------------------------------------
322337
def export_qwalk(self):
323338
''' Export QWalk input files into current directory.'''
339+
self.recover(pkl.load(open(self.path+self.pickle,'rb')))
340+
341+
ready=False
324342
if len(self.qwfiles['slater'])==0:
325343
self.nextstep()
326344

@@ -336,6 +354,7 @@ def export_qwalk(self):
336354
status=resolve_status(self.prunner,self.preader,self.propoutfn)
337355
print(self.logname,": properties status= %s"%(status))
338356
if status=='not_started':
357+
ready=False
339358
self.prunner.add_command("cp %s INPUT"%self.propinpfn)
340359
self.prunner.add_task("Pproperties &> %s"%self.propoutfn)
341360

@@ -348,14 +367,18 @@ def export_qwalk(self):
348367
self.preader.collect(self.propoutfn)
349368

350369
if self.preader.completed:
370+
ready=True
351371
self.qwfiles=crystal2qmc.convert_crystal(base=self.name,propoutfn=self.propoutfn)
352372
print(self.logname,": crystal converted to QWalk input.")
353373

354374
os.chdir(cwd)
375+
else:
376+
ready=True
377+
355378
with open(self.path+self.pickle,'wb') as outf:
356379
pkl.dump(self,outf)
357380

358-
return True
381+
return ready
359382

360383
#----------------------------------------
361384
def status(self):
@@ -388,7 +411,7 @@ def __init__(self,writer,reader=None,runner=None,name='psycf_run',path=None,bund
388411

389412
self.logname="%s@%s"%(self.__class__.__name__,self.path+self.name)
390413

391-
print(self.logname,": initializing")
414+
#print(self.logname,": initializing")
392415

393416
self.writer=writer
394417
if reader is not None: self.reader=reader
@@ -417,24 +440,33 @@ def __init__(self,writer,reader=None,runner=None,name='psycf_run',path=None,bund
417440
if os.path.exists(self.path+self.pickle):
418441
print(self.logname,": rebooting old manager.")
419442
old=pkl.load(open(self.path+self.pickle,'rb'))
420-
if False: #not self.is_consistent(old): TODO check consistency.
421-
raise NotImplementedError("Handling updated input files is not implemented yet.")
422-
else:
423-
self.__dict__=old.__dict__
443+
self.recover(old)
424444

425445
# Update the file.
426446
if not os.path.exists(self.path): os.mkdir(self.path)
427447
with open(self.path+self.pickle,'wb') as outf:
428448
pkl.dump(self,outf)
429449

430450
#------------------------------------------------
431-
def update_options(self,other):
451+
def recover(self,other):
432452
''' Safe copy options from other to self. '''
433-
updated=update_attributes(old=self.writer,new=other.writer,
434-
safe_keys=['max_cycle'],
435-
skip_keys=['completed','chkfile','dm_generator'])
436-
if updated:
437-
self.writer.completed=False
453+
# Practically speaking, the run will preserve old `take_keys` and allow new changes to `skip_keys`.
454+
# This is because you are taking the attributes from the older instance, and copying into the new instance.
455+
updated=update_attributes(copyto=self,copyfrom=other,
456+
skip_keys=['writer','runner','reader', 'path','logname','name','max_restarts','bundle'],
457+
take_keys=['restarts','completed','qwfiles'])
458+
459+
update_attributes(copyto=self.runner,copyfrom=other.runner,
460+
skip_keys=['queue','walltime','np','nn','jobname'],
461+
take_keys=['queueid'])
462+
463+
update_attributes(copyto=self.reader,copyfrom=other.reader,
464+
skip_keys=[],
465+
take_keys=['completed','output'])
466+
467+
updated=update_attributes(copyto=self.writer,copyfrom=other.writer,
468+
skip_keys=['max_cycle'],
469+
take_keys=['completed','dm_generator'])
438470

439471
# Update the file.
440472
with open(self.path+self.pickle,'wb') as outf:
@@ -443,6 +475,9 @@ def update_options(self,other):
443475
#------------------------------------------------
444476
def nextstep(self):
445477
''' Determine and perform the next step in the calculation.'''
478+
# Recover old data.
479+
self.recover(pkl.load(open(self.path+self.pickle,'rb')))
480+
446481
print(self.logname,": next step.")
447482
cwd=os.getcwd()
448483
os.chdir(self.path)
@@ -495,6 +530,9 @@ def update_queueid(self,qid):
495530
#------------------------------------------------
496531
def export_qwalk(self):
497532
''' Export QWalk input files into current directory.'''
533+
# Recover old data.
534+
self.recover(pkl.load(open(self.path+self.pickle,'rb')))
535+
498536
if len(self.qwfiles['slater'])==0:
499537
self.nextstep()
500538
if not self.completed:
@@ -546,7 +584,7 @@ def __init__(self,writer,reader,runner=None,trialfunc=None,
546584

547585
self.logname="%s@%s"%(self.__class__.__name__,self.path+self.name)
548586

549-
print(self.logname,": initializing")
587+
#print(self.logname,": initializing")
550588

551589
self.writer=writer
552590
self.reader=reader
@@ -604,42 +642,23 @@ def recover(self,other):
604642
if updated:
605643
self.writer.completed=False
606644

607-
#------------------------------------------------
608-
def update_options(self,other):
609-
''' Safe copy options from other to self.
610-
611-
Args:
612-
other (QWRunManager): New object to copy attributes from.
613-
'''
614-
615-
update_attributes(old=self.runner,new=other.runner,
616-
safe_keys=['queue','walltime','np','nn','jobname','prefix','postfix'],
617-
skip_keys=['queueid'])
618-
619-
# trialfunc gets updated as the manager generating it finishes its calculation.
620-
update_attributes(old=self.writer,new=other.writer,
621-
skip_keys=['completed','trialfunc'])
622-
623-
# Update the file.
624-
with open(self.path+self.pickle,'wb') as outf:
625-
pkl.dump(self,outf)
626-
627645
#------------------------------------------------
628646
def nextstep(self):
629647
''' Perform next step in calculation. trialfunc managers are updated if they aren't completed yet.'''
648+
# Recover old data.
649+
self.recover(pkl.load(open(self.path+self.pickle,'rb')))
630650

631651
print(self.logname,": next step.")
632652

633653
# Check dependency is completed first.
634654
if self.writer.trialfunc=='':
655+
print(self.logname,": checking trial function.")
635656
self.writer.trialfunc=self.trialfunc.export(self.path)
636657

637658
# Work on this job.
638659
cwd=os.getcwd()
639660
os.chdir(self.path)
640661

641-
dir(self.reader)
642-
643662
# Write the input file.
644663
if not self.writer.completed:
645664
self.writer.qwalk_input(self.infile)
@@ -662,8 +681,6 @@ def nextstep(self):
662681
self.runner.add_task(exestr)
663682
elif status=='done':
664683
self.completed=True
665-
else:
666-
print(self.logname,": %s status= %s"%(self.name,status))
667684

668685
# Ready for bundler or else just submit the jobs as needed.
669686
if self.bundle:
@@ -717,6 +734,9 @@ def export_qwalk(self):
717734
''' Extract jastrow from the optimization run and return that file name.'''
718735
# Theoretically more than just Jastrow can be provided, but practically that's the only type of wavefunction we tend to export.
719736

737+
# Recover old data.
738+
self.recover(pkl.load(open(self.path+self.pickle,'rb')))
739+
720740
assert self.writer.qmc_abr!='dmc',"DMC doesn't provide a wave function."
721741

722742
if self.qwfiles['wfout']=='':

tests/simple_test/simple_test.py

+16-13
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def h2_tests():
4646
name='scf',
4747
path='h2stretch',
4848
writer=stwriter,
49-
runner=PySCFRunnerPBS(nn=1,np=2,ppath=sys.path),
49+
runner=PySCFRunnerPBS(nn=1,walltime='0:05:00',np=16,queue='secondary',ppath=sys.path),
5050
)
5151

5252
return [eqman,stman]
@@ -82,7 +82,7 @@ def si_crystal_test():
8282
runner=RunnerPBS(
8383
nn=1,queue='secondary',walltime='0:10:00'
8484
),
85-
trialfunc=SlaterJastrow(cman,kpoint=(0,0,0))
85+
trialfunc=SlaterJastrow(cman,kpoint=0)
8686
)
8787

8888
jobs.append(var)
@@ -95,21 +95,22 @@ def si_crystal_test():
9595
runner=RunnerPBS(
9696
nn=1,queue='secondary',walltime='1:00:00'
9797
),
98-
trialfunc=SlaterJastrow(slatman=cman,jastman=var,kpoint=(0,0,0))
98+
trialfunc=SlaterJastrow(slatman=cman,jastman=var,kpoint=0)
9999
)
100100

101101
jobs.append(lin)
102102

103-
for kpt in cman.qwfiles['kpts']:
103+
for kidx in cman.qwfiles['kpoints']:
104+
kpt=cman.qwfiles['kpoints'][kidx]
104105
dmc=QWalkManager(
105-
name='dmc_%d%d%d'%kpt,
106+
name='dmc_%d'%kidx,
106107
path=cman.path,
107108
writer=DMCWriter(),
108109
reader=DMCReader(),
109110
runner=RunnerPBS(
110111
nn=1,queue='secondary',walltime='1:00:00',
111112
),
112-
trialfunc=SlaterJastrow(slatman=cman,jastman=lin,kpoint=kpt)
113+
trialfunc=SlaterJastrow(slatman=cman,jastman=lin,kpoint=kidx)
113114
)
114115
jobs.append(dmc)
115116

@@ -129,7 +130,8 @@ def si_pyscf_test():
129130
runner=PySCFRunnerPBS(
130131
queue='secondary',
131132
nn=1,
132-
walltime='0:20:00',
133+
np=16,
134+
walltime='4:00:00',
133135
ppath=sys.path
134136
)
135137
)
@@ -205,29 +207,30 @@ def mno_test():
205207
trialfunc=SlaterJastrow(slatman=cman,jastman=var,kpoint=(0,0,0))
206208
)
207209

208-
for ki,kpt in enumerate(cman.qwfiles['kpoints']):
210+
for kidx in cman.qwfiles['kpoints']:
211+
kpt=cman.qwfiles['kpoints'][kidx]
209212
if not sum(np.array(kpt)%(np.array(cman.kmesh)/2))<1e-14:
210213
print("complex kpt %d%d%d skipped"%kpt)
211214
continue
212215
dmc=QWalkManager(
213-
name='dmc_%d%d%d'%kpt,
216+
name='dmc_%d'%kidx,
214217
path=cman.path,
215218
writer=DMCWriter(),
216219
reader=DMCReader(),
217220
runner=RunnerPBS(
218221
nn=1,queue='secondary',walltime='1:00:00',
219222
),
220-
trialfunc=SlaterJastrow(slatman=cman,jastman=lin,kpoint=kpt)
223+
trialfunc=SlaterJastrow(slatman=cman,jastman=lin,kpoint=kidx)
221224
)
222225
jobs.append(dmc)
223226
return jobs
224227

225228
def run_tests():
226229
''' Choose which tests to run and execute `nextstep()`.'''
227230
jobs=[]
228-
#jobs+=h2_tests()
229-
#jobs+=si_crystal_test()
230-
#jobs+=si_pyscf_test()
231+
jobs+=h2_tests()
232+
jobs+=si_crystal_test()
233+
jobs+=si_pyscf_test()
231234
jobs+=mno_test()
232235

233236
for job in jobs:

0 commit comments

Comments
 (0)