Skip to content

Commit 5f183fb

Browse files
committed
Add option -r tuningLength to isle show
1 parent c43ef8f commit 5f183fb

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

src/isle/scripts/show.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,67 @@ def _tuning(infname):
265265

266266
fig.tight_layout()
267267

268+
def _tuningLength(infname):
269+
"""!
270+
Show tuning results.
271+
"""
272+
273+
log = getLogger("isle.show")
274+
log.info("Showing tuning results in file %s", infname)
275+
276+
with h5.File(infname, "r") as h5f:
277+
if not "leapfrogTuner" in h5f:
278+
log.error("Can not show tuning results, no group 'leapfrogTuner' in input file.")
279+
return
280+
281+
registrar = isle.evolver.LeapfrogTuner.loadRecording(h5f["leapfrogTuner"])
282+
283+
fig = plt.figure(figsize=(12, 10))
284+
gspec = gridspec.GridSpec(1, 2, width_ratios=(2.8, 1))
285+
fitsGspec = gridspec.GridSpecFromSubplotSpec(4, 3, subplot_spec=gspec[0, 0],
286+
wspace=0.05)
287+
288+
if len(registrar) >= fitsGspec.get_geometry()[0]*fitsGspec.get_geometry()[1]:
289+
log.warning("The tuner performed %d runs with different leapfrog parameters "
290+
"but only the first %d are shown.",
291+
len(registrar), fitsGspec.get_geometry()[0]*fitsGspec.get_geometry()[1])
292+
293+
for idx, (x, y) in enumerate(np.ndindex(fitsGspec.get_geometry())):
294+
if idx >= len(registrar):
295+
break
296+
297+
ax = fig.add_subplot(fitsGspec[x, y])
298+
ax.set_title(r"Run {}, length={}, $N_{{\mathrm{{MD}}}}$={}" \
299+
.format(idx, registrar.records[idx].length, registrar.records[idx].nstep))
300+
ax.set_ylim((-0.1, 1.1))
301+
if y != 0:
302+
ax.tick_params(axis="y", which="both", labelleft=False)
303+
304+
# TODO handle different lengths
305+
probabilityPoints, trajPointPoints = registrar.gather(nstep=registrar.records[-1].nstep,
306+
maxRecord=idx + 1)
307+
invProbabilityPoints = []
308+
invTrajPointPoints = []
309+
for point in probabilityPoints:
310+
invProbabilityPoints.append((1./point[0],point[1],point[2]))
311+
for point in trajPointPoints:
312+
invTrajPointPoints.append((1./point[0],point[1],point[2]))
313+
314+
fitResult = registrar.fitResults[idx] if idx < len(registrar.fitResults) else None
315+
isle.plotting.plotTunerFit(ax, invProbabilityPoints, invTrajPointPoints, fitResult,
316+
registrar.records[idx].verification)
317+
if fitResult is not None:
318+
log.info("Best fit for run %d: %s", idx, fitResult.bestFit)
319+
320+
321+
if idx == 0:
322+
ax.legend()
323+
324+
ax = fig.add_subplot(gspec[0, 1])
325+
isle.plotting.plotTunerTrace(ax, registrar.records)
326+
327+
fig.tight_layout()
328+
268329
def _verifyIsleVersion(version, fname):
269330
"""!
270331
Check version of Isle, warn if it does not match.
@@ -331,6 +392,8 @@ def main(args):
331392
_correlator(fname, lattice, params, makeActionSrc)
332393
if "tuning" in args.report:
333394
_tuning(fname)
395+
if "tuningLength" in args.report:
396+
_tuningLength(fname)
334397

335398
except:
336399
getLogger("isle.show").exception("Show command failed with file %s.", fname)

0 commit comments

Comments
 (0)