Coverage for ase / optimize / test / analyze.py: 10.81%
37 statements
« prev ^ index » next coverage.py v7.13.3, created at 2026-02-04 10:20 +0000
« prev ^ index » next coverage.py v7.13.3, created at 2026-02-04 10:20 +0000
1# fmt: off
3from collections import defaultdict
5from numpy import inf
7import ase.db
10def analyze(filename, tag='results'):
11 energies = defaultdict(list)
12 mintimes = defaultdict(lambda: 999999)
13 formulas = []
14 db = ase.db.connect(filename)
15 for row in db.select(sort='formula'):
16 if row.formula not in formulas:
17 formulas.append(row.formula)
18 energies[row.formula].append(row.get('energy', inf))
19 emin = {formula: min(energies[formula]) for formula in energies}
21 data = defaultdict(list)
22 for row in db.select(sort='formula'):
23 if row.get('energy', inf) - emin[row.formula] < 0.01:
24 t = row.t
25 if row.n < 100:
26 nsteps = row.n
27 mintimes[row.formula] = min(mintimes[row.formula], t)
28 else:
29 nsteps = 9999
30 t = inf
31 else:
32 nsteps = 9999
33 t = inf
34 data[row.optimizer].append((nsteps, t))
36 print(formulas)
38 D = sorted(data.items(), key=lambda x: sum(y[0] for y in x[1]))
39 with open(tag + '-iterations.csv', 'w') as fd:
40 print('optimizer,' + ','.join(formulas), file=fd)
41 for o, d in D:
42 print('{:18},{}'
43 .format(o, ','.join(f'{x[0]:3}'
44 if x[0] < 100 else ' '
45 for x in d)),
46 file=fd)
48 data = {opt: [(n, t / mintimes[f]) for (n, t), f in zip(x, formulas)]
49 for opt, x in data.items()}
50 D = sorted(data.items(), key=lambda x: sum(min(y[1], 999) for y in x[1]))
51 with open(tag + '-time.csv', 'w') as fd:
52 print('optimizer,' + ','.join(formulas), file=fd)
53 for o, d in D:
54 print('{:18},{}'
55 .format(o, ','.join(f'{x[1]:8.1f}'
56 if x[0] < 100 else ' '
57 for x in d)),
58 file=fd)
61if __name__ == '__main__':
62 analyze('results.db')