Peano
Loading...
Searching...
No Matches
TimeseriesPlots.py
Go to the documentation of this file.
1# This file is part of the ExaHyPE2 project. For conditions of distribution and
2# use, please see the copyright notice at www.peano-framework.org
3from .PerformanceData import PerformanceData
4from .utils import next_symbol
5from .utils import next_markevery
6
7import matplotlib.pyplot as plt
8
9
10from enum import Enum
11class XAxis(Enum):
12 Iterations = 1
13 RealTime = 2
14 SimulatedTime = 3
15
16
17
18def plot_runtime_per_step(performance_data,label=None,xaxis=XAxis.RealTime):
19 """
20
21 Label: String or None
22
23 """
24 x_data = []
25 y_data = []
26 if xaxis.value>1:
27 i=0
28 while i<len(performance_data.get_time_step_real_time_stamps()) and i<len(performance_data.get_time_per_time_step()):
29 if 1:#i%xaxis.value==0:
30 x_data.append(performance_data.get_time_step_real_time_stamps()[i])
31 y_data.append(performance_data.get_time_per_time_step()[i])
32 else:
33 #x_data[-1] = performance_data.get_time_step_time_stamps()[i]
34 #y_data[-1] += performance_data.get_time_per_time_step()[i]
35 pass
36 i+=1
37
38 x_data = x_data[0:-1]
39 y_data = y_data[0:-1]
40 else:
41 x_data = performance_data.get_time_step_real_time_stamps()
42 y_data = performance_data.get_time_per_time_step()
43 plt.plot( x_data, y_data, next_symbol(), markevery=next_markevery(performance_data.timesteps()), label=label )
44
45 if len(performance_data.plotting_time_stamp)>0:
46 max_time_per_time_step = max(performance_data.get_time_per_time_step())
47 min_time_per_time_step = min(performance_data.get_time_per_time_step())
48 for i in performance_data.plotting_time_stamp:
49 plt.plot( [i,i], [min_time_per_time_step,max_time_per_time_step], "--", color="#000000" )
50 plt.plot( [performance_data.plotting_time_stamp[0],performance_data.plotting_time_stamp[0]], [min_time_per_time_step,max_time_per_time_step], "--", color="#000000", label="plot" )
51
52 plt.xlabel( "Runtime [t]=s" )
53 plt.ylabel( "Time per step [t]=s" )
54
55
56def plot_time_step_size_per_step(performance_data,label=None,xaxis=XAxis.RealTime):
57 """
58
59 """
60 if xaxis==XAxis.RealTime and not performance_data.uses_local_timestepping():
61 if len(performance_data.get_time_step_real_time_stamps()) != len(performance_data.get_time_step_time_step_size()):
62 raise Exception( "Size of fields do not match: " + str(len(performance_data.get_time_step_real_time_stamps())) + " vs. " + str(len(performance_data.get_time_step_time_step_size())))
63 plt.plot( performance_data.get_time_step_real_time_stamps(), performance_data.get_time_step_time_step_size(), next_symbol(), markevery=next_markevery(performance_data.timesteps()), label=label )
64 plt.xlabel( "Real time [t]=s" )
65 elif xaxis==XAxis.RealTime and performance_data.uses_local_timestepping():
66 symbol = next_symbol()
67 x_data = performance_data.get_time_step_real_time_stamps()
68 y_data = performance_data.get_time_step_time_step_size()[0]
69 if len(x_data)>len(y_data):
70 print( "WARNING: too many time stamps (does not fit to data points). Remove first entry")
71 x_data = x_data[1:]
72 plt.plot( x_data, y_data, symbol, markevery=next_markevery(len(y_data)), label=label )
73 y_data = performance_data.get_time_step_time_step_size()[1]
74 if len(x_data)>len(y_data):
75 print( "WARNING: too many time stamps (does not fit to data points). Remove first entry")
76 x_data = x_data[1:]
77 plt.plot( x_data, y_data, "-"+symbol, markevery=next_markevery(len(y_data)), label=label )
78 plt.xlabel( "Real time [t]=s" )
79 elif xaxis==XAxis.Iterations and not performance_data.uses_local_timestepping():
80 y_data = performance_data.get_time_step_time_step_size()
81 plt.plot( range(0,len(y_data)), y_data, next_symbol(), markevery=next_markevery(len(y_data)), label=label )
82 plt.xlabel( "Simulation step" )
83 elif xaxis==XAxis.Iterations and performance_data.uses_local_timestepping():
84 y_data = performance_data.get_time_step_time_step_size()[0]
85 symbol = next_symbol()
86 plt.plot( range(0,len(y_data)), y_data, symbol, markevery=next_markevery(len(y_data)), label=label )
87 y_data = performance_data.get_time_step_time_step_size()[1]
88 plt.plot( range(0,len(y_data)), y_data, "-" + symbol, markevery=next_markevery(len(y_data)), label=label )
89 plt.xlabel( "Simulation step" )
90 elif xaxis==XAxis.SimulatedTime and not performance_data.uses_local_timestepping():
91 if len(performance_data.get_time_step_simulated_time_stamps()) != len(performance_data.get_time_step_time_step_size()):
92 raise Exception( "Size of fields do not match: " + str(len(performance_data.get_time_step_simulated_time_stamps())) + " vs. " + str(len(performance_data.get_time_step_time_step_size())))
93 plt.plot( performance_data.get_time_step_simulated_time_stamps(), performance_data.get_time_step_time_step_size(), next_symbol(), markevery=next_markevery(performance_data.timesteps()), label=label )
94 plt.xlabel( "Simulated time" )
95 elif xaxis==XAxis.SimulatedTime and performance_data.uses_local_timestepping():
96 if len(performance_data.get_time_step_simulated_time_stamps()) != len(performance_data.get_time_step_time_step_size()):
97 raise Exception( "Size of fields do not match: " + str(len(performance_data.get_time_step_simulated_time_stamps())) + " vs. " + str(len(performance_data.get_time_step_time_step_size())))
98 symbol = next_symbol()
99 x_data = performance_data.get_time_step_simulated_time_stamps()[0]
100 y_data = performance_data.get_time_step_time_step_size()[0]
101 x_data = x_data[len(x_data)-len(y_data):]
102 plt.plot( x_data, y_data, symbol, markevery=next_markevery(len(y_data)), label=label )
103 y_data = performance_data.get_time_step_time_step_size()[1]
104 plt.plot( x_data, y_data, "-"+symbol, markevery=next_markevery(len(y_data)), label=label )
105 plt.xlabel( "Simulated time $T$" )
106 else:
107 raise Exception( "enum value not supported" )
108 plt.ylabel( "Time step size $\\Delta T$" )
109
110
111
112def plot_updates_per_step(performance_data,label=None,xaxis=XAxis.RealTime):
113 """
114
115 """
116 if xaxis==XAxis.RealTime:
117 plt.plot( performance_data.get_time_step_real_time_stamps(), performance_data.get_upates(), next_symbol(), markevery=next_markevery(performance_data.get_updates()), label=label )
118 plt.xlabel( "Real time [t]=s" )
119 elif xaxis==XAxis.Iterations:
120 y_data = performance_data.get_updates()
121 plt.plot( range(0,len(y_data)), y_data, next_symbol(), markevery=next_markevery(len(y_data)), label=label )
122 plt.xlabel( "Simulation step" )
123 elif xaxis==XAxis.SimulatedTime:
124 if performance_data.uses_local_timestepping():
125 x_data = performance_data.get_time_step_simulated_time_stamps()[0]
126 else:
127 x_data = performance_data.get_time_step_simulated_time_stamps()
128 plt.plot( x_data, performance_data.get_updates(), next_symbol(), markevery=next_markevery(performance_data.timesteps()), label=label )
129 plt.xlabel( "Simulated time" )
130 else:
131 raise Exception( "enum value not supported" )
132 plt.ylabel( "Updates" )