Skip to content

Commit

Permalink
S. Riette 17 May 2024: add flexibility to plot_perf
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastienRietteMTO committed May 17, 2024
1 parent 914a1b2 commit ff25761
Showing 1 changed file with 35 additions and 12 deletions.
47 changes: 35 additions & 12 deletions tools/plot_perf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@ def __init__(self, perffile):
self._df = pandas.read_csv(perffile, sep=' ',
names=['commit', 'model', 'case', 'time', 'time2'])

def plotPerf(self, outfile, model=None, title=None, num=None, allTimes=False):
def plotPerf(self, outfile, model=None, title=None, num=None, allTimes=False,
logScale=True, reverse=False, xIsNum=False):
"""
:param outfile: output file
:param model: None to plot each model on a subplot or the model to plot
:param title: custom title to use (%M will be replaced by the model name)
:param num: plot only last num values (None to plot all values)
:param allTimes: True to plot alternative metrics
:param logScale: True to use a log scale for y axis
:param reverse: True to plot gp/ms instead of ms/gp
:param xIsNum: If True commits are replaced by numeric values
"""
models = [model] if model is not None else sorted(set(self._df['model']))
fig, ax = plt.subplots(nrows=len(models), sharex=True, sharey=True,
Expand All @@ -41,19 +45,28 @@ def plotPerf(self, outfile, model=None, title=None, num=None, allTimes=False):
commits.append(commit)
if num is not None:
commits = commits[-num:]
shortCommits = [self.shortenCommit(c) for c in commits]
if xIsNum:
commits = [float(c) for c in commits]
xpos = commits
else:
shortCommits = [self.shortenCommit(c) for c in commits]
xpos = range(len(commits))

df = self._df.groupby('model')
for igrpM, grpM in enumerate(models):
if title is None:
if reverse:
btitle = 'Mean number of gridpoints per ms'
else:
btitle = 'Mean elapsed computational time per gp'
if len(models) == 1:
ax[igrpM].set_title('Mean elapsed computational time')
ax[igrpM].set_title(btitle)
else:
ax[igrpM].set_title('Mean elapsed computational time for ' + grpM)
ax[igrpM].set_title(btitle + ' for ' + grpM)
else:
ax[igrpM].set_title(title.replace('%M', grpM))
ax[igrpM].set_ylabel('time')
ax[igrpM].set_yscale('log')
ax[igrpM].set_ylabel('gridpoints (gp/ms)' if reverse else 'time (ms/gp)')
if logScale: ax[igrpM].set_yscale('log')

dfp = df.get_group(grpM).groupby('case')
for grp in dfp.groups:
Expand All @@ -67,12 +80,15 @@ def plotPerf(self, outfile, model=None, title=None, num=None, allTimes=False):
time.append(numpy.nan if len(l) == 0 else numpy.ma.array(l).mean())
l = [numpy.nan if t < 0. else t for t in dfp.get_group(grp)[f]['time2']]
time2.append(numpy.nan if len(l) == 0 else numpy.ma.array(l).mean())
p = ax[igrpM].plot(range(len(commits)), numpy.ma.array(time), 'o-', label=grp)
if reverse:
time = [1. / t for t in time]
time2 = [1. / t for t in time2]
p = ax[igrpM].plot(xpos, numpy.ma.array(time), 'o-', label=grp)
if allTimes:
ax[igrpM].plot(range(len(commits)), numpy.ma.array(time2), 'o:', color=p[0].get_color())
if igrpM == len(models) - 1:
ax[igrpM].plot(xpos, numpy.ma.array(time2), 'o:', color=p[0].get_color())
if igrpM == len(models) - 1 and not xIsNum:
ax[igrpM].set_xlabel('PHYEX version')
ax[igrpM].set_xticks(range(len(commits)))
ax[igrpM].set_xticks(xpos)
ax[igrpM].set_xticklabels(shortCommits, rotation=45, ha='right')
ax[igrpM].legend()
fig.tight_layout()
Expand Down Expand Up @@ -108,10 +124,17 @@ def listModels(self):
parser.add_argument('--listModels', default=False, action='store_true',
help="returns the list of models present in the performance file")
parser.add_argument('--allTimes', default=False, action='store_true',
help="to also plot the alternative metrics")
help="to also plot the alternative metrics")
parser.add_argument('--no-log', default=False, action='store_true',
help="Do not use lo scale for y axis")
parser.add_argument('--reverse', default=False, action='store_true',
help="Plot gp/ms instead og ms/gp")
parser.add_argument('--x-is-num', default=False, action='store_true',
help="Instead of commits hashes, the file contain numbers")
args = parser.parse_args()
perf = Perf(args.PERF_FILE)
if args.plot is not None:
perf.plotPerf(args.plot, args.model, args.title, args.num, args.allTimes)
perf.plotPerf(args.plot, args.model, args.title, args.num, args.allTimes,
not args.no_log, args.reverse, args.x_is_num)
if args.listModels:
print(' '.join(perf.listModels()))

0 comments on commit ff25761

Please sign in to comment.