forked from INM-6/beNNch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_helper.py
144 lines (119 loc) · 5.38 KB
/
plot_helper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
"""
beNNch - Unified execution, collection, analysis and
comparison of neural network simulation benchmarks.
Copyright (C) 2021 Forschungszentrum Juelich GmbH, INM-6
This program is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program. If not, see <https://www.gnu.org/licenses/>.
SPDX-License-Identifier: GPL-3.0-or-later
"""
import numpy as np
import bennchplot as bp
from matplotlib import pyplot as plt
import matplotlib.gridspec as gridspec
import matplotlib.transforms as mtransforms
def plot(scaling_type, timer_hash, timer_file, save_path):
if scaling_type == 'nodes':
args = {
'data_file': timer_file,
'x_axis': ['num_nodes'],
'time_scaling': 1e3
}
# Instantiate class
B = bp.Plot(**args)
# Plotting
widths = [1, 1]
heights = [3, 1]
fig = plt.figure(figsize=(12, 6), constrained_layout=True)
spec = gridspec.GridSpec(ncols=2, nrows=2, figure=fig,
width_ratios=widths,
height_ratios=heights)
ax1 = fig.add_subplot(spec[:, 0])
ax2 = fig.add_subplot(spec[0, 1])
ax3 = fig.add_subplot(spec[1, 1])
trans = mtransforms.ScaledTranslation(-20 /
72, 7 / 72, fig.dpi_scale_trans)
ax1.text(0.0, 1.0, 'A', transform=ax1.transAxes + trans,
fontsize='medium', va='bottom', fontweight='bold')
ax2.text(0.0, 1.0, 'B', transform=ax2.transAxes + trans,
fontsize='medium', va='bottom', fontweight='bold')
ax3.text(0.0, 1.0, 'C', transform=ax3.transAxes + trans,
fontsize='medium', va='bottom', fontweight='bold')
B.plot_fractions(axis=ax1,
fill_variables=[
'wall_time_create+wall_time_connect',
'wall_time_sim', ],
interpolate=True,
step=None,
error=True)
B.plot_main(quantities=['sim_factor'], axis=ax2,
error=True)
B.plot_fractions(axis=ax2,
fill_variables=[
'phase_update_factor',
'phase_collocate_factor',
'phase_communicate_factor',
'phase_deliver_factor'
])
B.plot_fractions(axis=ax3,
fill_variables=[
'frac_phase_update',
'frac_phase_collocate',
'frac_phase_communicate',
'frac_phase_deliver'
])
ax1.set_xlabel('Number of Nodes')
ax1.set_ylabel(r'$T_{\mathrm{wall}}$ [s] for $T_{\mathrm{model}} =$'
+ f'{np.unique(B.df.model_time_sim.values)[0]} s')
ax2.set_ylabel(r'real-time factor $T_{\mathrm{wall}}/$'
r'$T_{\mathrm{model}}$')
ax3.set_xlabel('Number of Nodes')
ax3.set_ylabel(r'relative $T_{\mathrm{wall}}$ [%]')
handles1, labels1 = ax1.get_legend_handles_labels()
handles2, labels2 = ax2.get_legend_handles_labels()
ax1.legend(handles1[::-1], labels1[::-1])
ax2.legend(handles2[::-1], labels2[::-1], loc='upper right')
ax3.set_ylim(0, 100)
for ax in [ax1, ax2, ax3]:
ax.margins(x=0)
for ax in [ax1, ax2]:
B.simple_axis(ax)
plt.savefig(f'{save_path}/{timer_hash}.png', dpi=400)
elif scaling_type == 'threads':
args = {
'data_file': timer_file,
'x_axis': ['num_nvp'],
'time_scaling': 1e3
}
# Instantiate class
B = bp.Plot(**args)
# Plotting
widths = [1]
heights = [3, 1]
fig = plt.figure(figsize=(6, 6), constrained_layout=True)
spec = gridspec.GridSpec(ncols=1, nrows=2, figure=fig,
width_ratios=widths,
height_ratios=heights)
ax1 = fig.add_subplot(spec[0, :])
ax2 = fig.add_subplot(spec[1, :])
B.plot_main(quantities=['sim_factor'], axis=ax1, log=(False, True))
B.plot_fractions(axis=ax2,
fill_variables=[
'frac_phase_update',
'frac_phase_collocate',
'frac_phase_communicate',
'frac_phase_deliver'
],
)
ax1.set_ylabel(r'$T_{\mathrm{wall}}$ [s] for $T_{\mathrm{model}} =$'
+ f'{np.unique(B.df.model_time_sim.values)[0]} s')
ax1.set_xlabel('number of vps')
ax2.set_ylabel(r'$T_{\mathrm{wall}}$ [%]')
B.merge_legends(ax1, ax2)
plt.savefig(f'{save_path}/{timer_hash}.png', dpi=600)