-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #764 from Paul-St-Young/dat-h5
Add sofk estimator test and manual entry about how estimator works
- Loading branch information
Showing
10 changed files
with
703 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?xml version="1.0"?> | ||
<simulation> | ||
<project id="dat-h5_allp" series="0"> | ||
<application name="qmcapp" role="molecu" class="serial" version="1.0"/> | ||
</project> | ||
<qmcsystem> | ||
<simulationcell> | ||
<parameter name="lattice" units="bohr"> | ||
3.77945227 0.00000000 0.00000000 | ||
-0.00000000 3.77945227 0.00000000 | ||
-0.00000000 -0.00000000 3.77945227 | ||
</parameter> | ||
<parameter name="bconds"> | ||
p p p | ||
</parameter> | ||
<parameter name="LR_dim_cutoff" > 15 </parameter> | ||
</simulationcell> | ||
<particleset name="e" random="yes"> | ||
<group name="u" size="1" mass="1.0"> | ||
<parameter name="charge" > -1 </parameter> | ||
<parameter name="mass" > 1.0 </parameter> | ||
</group> | ||
<group name="d" size="1" mass="1.0"> | ||
<parameter name="charge" > -1 </parameter> | ||
<parameter name="mass" > 1.0 </parameter> | ||
</group> | ||
</particleset> | ||
<particleset name="ion0"> | ||
<group name="H" size="2" mass="1837.36221934"> | ||
<parameter name="charge" > 1 </parameter> | ||
<parameter name="valence" > 1 </parameter> | ||
<parameter name="atomicnumber" > 1 </parameter> | ||
<parameter name="mass" > 1837.36221934 </parameter> | ||
<attrib name="position" datatype="posArray" condition="0"> | ||
0.00000000 0.00000000 0.00000000 | ||
1.88972614 1.88972614 1.88972614 | ||
</attrib> | ||
</group> | ||
</particleset> | ||
<wavefunction name="psi0" target="e"> | ||
<determinantset type="einspline" href="pwscf.pwscf.h5" tilematrix="1 0 0 0 1 0 0 0 1" twistnum="0" source="ion0" meshfactor="1.0" precision="float"> | ||
<slaterdeterminant> | ||
<determinant id="updet" size="1"> | ||
<occupation mode="ground" spindataset="0"/> | ||
</determinant> | ||
<determinant id="downdet" size="1"> | ||
<occupation mode="ground" spindataset="0"/> | ||
</determinant> | ||
</slaterdeterminant> | ||
</determinantset> | ||
<jastrow type="One-Body" name="J1" function="bspline" source="ion0" print="yes"> | ||
<correlation elementType="H" size="8" cusp="1.0"> | ||
<coefficients id="eH" type="Array"> | ||
0.00206602038 -0.002841926986 0.0036266191 -0.001913930279 8.457152991e-06 | ||
0.0007380321824 3.635172529e-05 0.0001299635851 | ||
</coefficients> | ||
</correlation> | ||
</jastrow> | ||
<jastrow type="Two-Body" name="J2" function="bspline" print="yes"> | ||
<correlation speciesA="u" speciesB="d" size="8"> | ||
<coefficients id="ud" type="Array"> | ||
0.5954603818 0.5062051797 0.3746940461 0.2521010502 0.1440163317 0.07796688253 | ||
0.03804420551 0.01449320872 | ||
</coefficients> | ||
</correlation> | ||
</jastrow> | ||
</wavefunction> | ||
<hamiltonian name="h0" type="generic" target="e"> | ||
<pairpot type="coulomb" name="ElecElec" source="e" target="e"/> | ||
<pairpot type="coulomb" name="IonIon" source="ion0" target="ion0"/> | ||
<pairpot type="coulomb" name="ElecIon" source="ion0" target="e"/> | ||
<estimator type="sk" name="sk" hdf5="no"/> | ||
<estimator type="sk" name="h5sk" hdf5="yes"/> | ||
</hamiltonian> | ||
</qmcsystem> | ||
<qmc method="vmc" move="byp"> | ||
<parameter name="walkers" > 64 </parameter> | ||
<parameter name="blocks" > 16 </parameter> | ||
<parameter name="steps" > 2 </parameter> | ||
<parameter name="subSteps" > 2 </parameter> | ||
<parameter name="timestep" > 2.0 </parameter> | ||
<parameter name="warmupSteps" > 16 </parameter> | ||
</qmc> | ||
<qmc method="dmc" move="byp"> | ||
<parameter name="targetwalkers" > 64 </parameter> | ||
<parameter name="blocks" > 16 </parameter> | ||
<parameter name="steps" > 1 </parameter> | ||
<parameter name="timestep" > 2.0 </parameter> | ||
<parameter name="warmupSteps" > 0 </parameter> | ||
</qmc> | ||
</simulation> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#!/usr/bin/env python | ||
import sys | ||
import os | ||
import h5py | ||
import numpy as np | ||
from check_properties_h5dat import read | ||
|
||
|
||
def get_last_sk(fdat,fh5): | ||
""" extract S(k) at the longest k vector from scalar.dat and stat.h5 | ||
Args: | ||
fdat (str): name of scalar.dat file | ||
fh5 (str): name of stat.h5 file | ||
Return: | ||
tuple: (myy, h5y), S(k_max) at each block from scalar.dat and stat.h5 | ||
""" | ||
|
||
# get S(k) from scalar.dat | ||
df = read(fdat) | ||
sk_cols = [col for col in df.columns if col.startswith('sk')] | ||
myy = df[sk_cols[-1]].values | ||
|
||
# get S(k) from stat.h5 | ||
fp = h5py.File(fh5, 'r') | ||
h5y = fp['h5sk/value'].value.T[-1] | ||
fp.close() | ||
|
||
return myy, h5y | ||
# end def | ||
|
||
|
||
def show_scalar_trace(data, seriesl): | ||
import matplotlib.pyplot as plt | ||
method_map = {0:'VMC',1:'DMC'} | ||
fig,ax_arr = plt.subplots(1, 2, sharey=True) | ||
ax_arr[0].set_ylabel('S(k->inf)') | ||
iplot = 0 | ||
for iseries in seriesl: | ||
ax = ax_arr[iplot] | ||
ax.set_title(method_map[iseries]) | ||
ax.set_xlabel('block') | ||
ax.set_ylim(0.3, 1.2) | ||
|
||
entry = data[iseries] | ||
daty = entry['daty'] | ||
h5y = entry['h5y'] | ||
|
||
sline = ax.plot(daty) | ||
hline = ax.plot(h5y, ls='--', lw=2, alpha=0.8) | ||
|
||
ax.legend( | ||
handles = [sline[0], hline[0]] | ||
,labels = ['scalar.dat', 'stat.h5'] | ||
,loc=0 | ||
) | ||
|
||
iplot += 1 | ||
# end for iseries | ||
plt.show() | ||
|
||
|
||
if __name__ == '__main__': | ||
|
||
prefix = sys.argv[1] | ||
seriesl= [0,1] # a list of series IDs to check | ||
|
||
# check Properties v.s. Collectables | ||
collectable_success_map = {} | ||
data = {} | ||
for iseries in seriesl: | ||
|
||
# define files to read | ||
fdat = '%s.s00%d.scalar.dat' % (prefix, iseries) | ||
fh5 = '%s.s00%d.stat.h5' % (prefix, iseries) | ||
|
||
daty, h5y = get_last_sk(fdat, fh5) | ||
success = np.allclose(daty, h5y, atol=0.1) | ||
collectable_success_map[iseries] = success | ||
|
||
# save data for plotting | ||
data[iseries] = {'daty':daty, 'h5y':h5y} | ||
# end for | ||
all_success = np.all( collectable_success_map.values() ) | ||
|
||
if all_success: | ||
sys.exit(0) | ||
else: | ||
#show_scalar_trace(data, seriesl) | ||
sys.exit(1) | ||
|
||
# end __main__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#!/usr/bin/env python | ||
import os | ||
import sys | ||
import h5py | ||
import numpy as np | ||
import pandas as pd | ||
|
||
|
||
def read(fdat): | ||
""" read the scalar.dat file in table format readable by numpy.loadtxt. | ||
The header line should start with '#' and contain column labels. | ||
Args: | ||
dat_fname (str): name of input file | ||
Return: | ||
pd.DataFrame: df containing the table of data | ||
""" | ||
with open(fdat, 'r') as fp: | ||
header = fp.readline() | ||
# end with | ||
cols = header.replace('#', '').split() | ||
df = pd.read_table(fdat, sep='\s+', comment='#', header=None, names=cols) | ||
return df | ||
# end def read | ||
|
||
|
||
def compare_columns_dat_h5(fdat, fh5): | ||
""" compare mutual data columns in scalar.dat and stat.h5 files | ||
Args: | ||
fdat (str): name of scalar.dat file | ||
fh5 (str): name of stat.h5 file | ||
Return: | ||
dict: a dictionary holding mutual columns names as key | ||
""" | ||
|
||
# open database | ||
df = read(fdat) | ||
dat_cols = df.columns | ||
|
||
fp = h5py.File(fh5,'r') | ||
h5_cols = fp.keys() | ||
|
||
# compare mutual columns in .dat v.s. .h5 | ||
agree_map = {} # keep track of which columns agree | ||
for col in h5_cols: | ||
if col not in dat_cols: | ||
continue | ||
|
||
# check if col agree between .dat and .h5 | ||
|
||
# get .h5 values | ||
h5_loc = os.path.join(col, 'value') | ||
h5y = fp[h5_loc].value[:,-1] | ||
|
||
# get .dat values | ||
daty = df.loc[:,col].values | ||
agree_map[col] = np.allclose(h5y,daty) | ||
# end for col | ||
|
||
# close database | ||
fp.close() | ||
|
||
if len(agree_map) == 0: | ||
raise RuntimeError('%s and %s have no mutual column' % (fdat, fh5)) | ||
|
||
return agree_map | ||
# end def | ||
|
||
|
||
if __name__ == '__main__': | ||
|
||
prefix = sys.argv[1] | ||
seriesl= [0,1] | ||
|
||
# check Properties | ||
series_success_map = {} | ||
for iseries in seriesl: | ||
|
||
# define files to read | ||
fdat = '%s.s00%d.scalar.dat' % (prefix, iseries) | ||
fh5 = '%s.s00%d.stat.h5' % (prefix, iseries) | ||
|
||
agree_map = compare_columns_dat_h5(fdat, fh5) | ||
success = np.all( agree_map.values() ) | ||
series_success_map[iseries] = success | ||
# end for iseries | ||
|
||
all_success = np.all( series_success_map.values() ) | ||
if all_success: | ||
sys.exit(0) | ||
else: | ||
sys.exit(1) | ||
|
||
# end __main__ |
Oops, something went wrong.