Skip to content

Commit f12b4ba

Browse files
committed
Allow for multiple canonical calculations to be averaged.
Add flag to specify when we want to separate out different simulations which have either been output to the same output file or to different output files. Useful for twist averaging for example.
1 parent d4510b9 commit f12b4ba

File tree

1 file changed

+39
-7
lines changed

1 file changed

+39
-7
lines changed

tools/dmqmc/analyse_canonical.py

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,43 @@
55
import pkgutil
66
import sys
77
import warnings
8+
import argparse
89

910
if not pkgutil.find_loader('pyhande'):
1011
_script_dir = os.path.dirname(os.path.abspath(__file__))
1112
sys.path.append(os.path.join(_script_dir, '../pyhande'))
1213
import pyhande
1314

14-
def main(filename):
15+
16+
def parse_args(args):
17+
'''Parse command-line arguments.
18+
19+
Parameters
20+
----------
21+
args : list of strings
22+
command-line arguments.
23+
24+
Returns
25+
-------
26+
options : :class:`ArgumentParser`
27+
Options read in from command line.
28+
'''
29+
parser = argparse.ArgumentParser(usage=__doc__)
30+
parser.add_argument('-s', '--sim', action='store_true', default=False,
31+
dest='multi_sim', help='Do not average over multiple '
32+
'simulations in the same or from multiple data files.')
33+
parser.add_argument('filename', nargs='+', help='HANDE output.')
34+
35+
options = parser.parse_args(args)
36+
37+
if not options.filename:
38+
parser.print_help()
39+
sys.exit(1)
40+
41+
return options
42+
43+
44+
def main(args):
1545
''' Analyse the output from a canonical estimates calculation.
1646
1747
Parameters
@@ -20,19 +50,17 @@ def main(filename):
2050
files to be analysed.
2151
'''
2252

23-
if len(filename) < 1:
24-
print("Usage: ./analyse_canonical.py files")
25-
sys.exit()
53+
args = parse_args(args)
2654

27-
hande_out = pyhande.extract.extract_data_sets(filename)
55+
hande_out = pyhande.extract.extract_data_sets(args.filename)
2856

2957
(metadata, data) = ([], [])
3058
for (md, df) in hande_out:
3159
# Handle old output with incorrect title...
3260
if md['calc_type'] == 'Canonical energy' or md['calc_type'] == 'RNG':
3361
metadata.append(md)
3462
data.append(df)
35-
if data:
63+
if data and not args.multi_sim:
3664
data = pd.concat(data)
3765

3866
# Sanity check: are all the calculations from the same calculation?
@@ -43,7 +71,11 @@ def main(filename):
4371
if 'beta' in md and md['beta'] != beta:
4472
warnings.warn('Beta values in input files not consistent.')
4573

46-
results = pyhande.canonical.estimates(metadata[0], data)
74+
if args.multi_sim:
75+
results = pd.concat([pyhande.canonical.estimates(m, d) for (m, d)
76+
in zip(metadata, data)])
77+
else:
78+
results = pyhande.canonical.estimates(metadata[0], data)
4779

4880
try:
4981
float_fmt = '{0:-#.8e}'.format

0 commit comments

Comments
 (0)