Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions
serial Namespace Reference

Functions

def Serial_Computation
 
def Operation_Count
 
def compare_data
 
def Fit_Model
 
def Run_Serial_Fit
 

Function Documentation

def serial.compare_data (   constants,
  Num_Constants,
  Data,
  T_A,
  T_E 
)

Definition at line 107 of file serial.py.

108 def compare_data(constants, Num_Constants, Data, T_A, T_E):
109 
110  # Lemons make nice Lemonade (Needed a list to hold results)
111  lemons = []
112 
113  # Loop over data calculating difference between data and model, this will be minimised by the constants.
114  for i in range(0, len(Data)):
115 
116  if (Num_Constants == 1):
117  lemons.append(Data[i] - (T_A[i] + T_E[i])/constants)
118 
119  if (Num_Constants == 2):
120  lemons.append(Data[i] - (T_A[i] / constants[0] + T_E[i] / constants[1]))
121 
122  # Calculate the L_2 norm of the difference, this is the quantity to be minimised by the optimisation step
123  L_2_norm = np.linalg.norm(lemons, 2)
124 
125  return(L_2_norm)
126 
127 #------------------------------------
128 # New Function
129 #------------------------------------
130 
# Function to run the fmin optimisation algorithm to fit the model to the data.
def compare_data
Definition: serial.py:107
def serial.Fit_Model (   Num_Constants,
  Data,
  T_A,
  T_E 
)

Definition at line 131 of file serial.py.

Referenced by Run_Serial_Fit().

132 def Fit_Model(Num_Constants, Data, T_A, T_E):
133 
134  # Numpy arrays to hold the results and data.
135  Data = np.array(Data)
136  T_A = np.array(T_A)
137  T_E = np.array(T_E)
138 
139  # Set the initial values depending on how many constants are required
140  if (Num_Constants == 1):
141  inital = 1e6
142 
143  if (Num_Constants == 2):
144  inital = np.array([1e6, 1e06])
145 
146  # Run the optimisation algorithm
147  Fit = fmin(compare_data, inital, args=(Num_Constants, Data, T_A, T_E), xtol=0.0001, ftol=1, maxiter=1e04, maxfun=1e09)
148 
149  # Return the fitted constants.
150  return(Fit)
151 
152 #------------------------------------
153 # New Function
154 #------------------------------------
155 
# Function to run all the steps in order to fit the serial model to serially produced data.
def Fit_Model
Definition: serial.py:131
def serial.Operation_Count (   P,
  Num_Elements,
  Num_Modes,
  N_P,
  N_V_1,
  N_V_2,
  N_V_3,
  Scheme 
)

Definition at line 72 of file serial.py.

Referenced by Run_Serial_Fit().

72 
73 def Operation_Count(P, Num_Elements, Num_Modes, N_P, N_V_1, N_V_2, N_V_3, Scheme):
74 
75 # Operation Counts as per the thesis
76  O_A_1 = 9 * Num_Elements * (P + 1) ** 2 * Num_Modes * m.log(Num_Modes, 2)
77  O_A_2 = Num_Elements * Num_Modes * (P + 1) ** 2
78  O_A_3 = 6 * Num_Elements * (P + 1) ** 4 * Num_Modes
79  O_A_4 = 15 * Num_Elements * (P + 1) ** 2 * Num_Modes
80 
81  T_A = O_A_1 + O_A_2 + O_A_3 + O_A_4
82 
83  if (Scheme == 'IterativeFull'):
84  O_E_1 = 8 * Num_Elements * (P + 1) ** 2
85  O_E_2 = Num_Elements * (P + 1) ** 2
86  O_E_3 = Num_Elements * ((4 * P ** 3) + (18 * P ** 2) + (26 * P) + 12)
87  O_E_4 = 6 * Num_Elements * (P + 1) ** 2
88 
89  t_e = O_E_1 + O_E_2 + O_E_3 + O_E_4
90 
91  T_E = (N_P + N_V_1 + N_V_2 + N_V_3) * t_e
92 
93  if (Scheme == 'IterativeStaticCond'):
94  O_E_1 = 8 * ((P - 1) ** 2) * 4 * P * Num_Elements * Num_Modes
95  O_E_2 = (N_P + N_V_1 + N_V_2 + N_V_3) * 2 * 16 * (P ** 2) * Num_Elements
96  O_E_3 = (8 * 4 * ((P - 1) ** 2)) + (4 * ((P - 1) ** 2)) * Num_Elements * Num_Modes
97  O_E_4 = 8 * ((((P - 1) ** 2)) ** 2) * Num_Elements * Num_Modes
98 
99  T_E = O_E_1 + O_E_2 + O_E_3 + O_E_4
100 
101  return(T_A, T_E)
102 
103 #------------------------------------
104 # New Function
105 #------------------------------------
106 
# Find the L_2 norm of the difference between the data and model, used for fitting.
def Operation_Count
Definition: serial.py:72
def serial.Run_Serial_Fit (   Compare_Serial,
  Consider_Modes,
  Num_Constants,
  P,
  Num_Elements,
  Nektar_Modes,
  Timings,
  Pressure,
  Velocity_1,
  Velocity_2,
  Velocity_3,
  Scheme 
)

Definition at line 156 of file serial.py.

References Fit_Model(), Operation_Count(), and Serial_Computation().

157 def Run_Serial_Fit(Compare_Serial, Consider_Modes, Num_Constants, P, Num_Elements, Nektar_Modes, Timings, Pressure, Velocity_1, Velocity_2, Velocity_3, Scheme):
158 
159  # List to hold data from Nektar simulation
160  Data = []
161 
162  # Loop over modes to be considered in calibrating the model
163  for i in range(0, len(Consider_Modes)):
164  Data.append(np.mean(Timings[str(Consider_Modes[i])])/10)
165 
166  # Lists to hold the operation counts to be fed into the optimisation
167  T_A = []
168  T_E = []
169 
170  # Loop over modes to be used in the model
171  for i in range(0, len(Consider_Modes)):
172 
173  # Initialise CG counters to 0
174  N_P = 0
175  N_V_1 = 0
176  N_V_2 = 0
177  N_V_3 = 0
178 
179  # Loop over all the modes up to the mode being considered adding the CG iterations from each mode to the counter
180  for j in range(1, Consider_Modes[i] + 1):
181 
182  # Skip the 2nd mode as we do not get any data about it from Nektar
183  if (j == 2):
184  continue
185 
186  # We don't necessarily have data for all the CG iterations hence we use try
187  # The except case has to be included to keep python happy hence we pay homage to Alan Turing
188  try:
189  N_P += Pressure[str(j)][0]
190  except:
191  Turing = 'King of Computers'
192 
193  try:
194  N_V_1 += Velocity_1[str(j)][0]
195  except:
196  Turing = 'King of Computers'
197 
198  try:
199  N_V_2 += Velocity_2[str(j)][0]
200  except:
201  Turing = 'King of Computers'
202 
203  try:
204  N_V_3 += Velocity_3[str(j)][0]
205  except:
206  Turing = 'King of Computers'
207 
208  # Perform the operation counts for each mode and store these to be fed into the optimisation step
209  (t_a, t_e) = Operation_Count(P, Num_Elements, Consider_Modes[i], N_P, N_V_1, N_V_2, N_V_3, Scheme)
210  T_A.append(t_a)
211  T_E.append(t_e)
212 
213  # Now fit the model to the data
214  Fit = Fit_Model(Num_Constants, Data, T_A, T_E)
215 
216  # Print the fitted FLOPs
217  print(Fit)
218 
219  # Output the comparison the results if the user desires
220  if Compare_Serial is True:
221 
222  # Pharse the Nektar data as before
223  Data = []
224 
225  for i in range(1, len(Nektar_Modes)):
226  Data.append(np.mean(Timings[str(Nektar_Modes[i])])/10)
227 
228  Time = []
229 
230  for i in range(1, len(Nektar_Modes)):
231  N_P = 0
232  N_V_1 = 0
233  N_V_2 = 0
234  N_V_3 = 0
235 
236  for j in range(1, Nektar_Modes[i] + 1):
237 
238  if (j == 2):
239  continue
240 
241  try:
242  N_P += Pressure[str(j)][0]
243  except:
244  Turing = 'King of Computers'
245 
246  try:
247  N_V_1 += Velocity_1[str(j)][0]
248  except:
249  Turing = 'King of Computers'
250 
251  try:
252  N_V_2 += Velocity_2[str(j)][0]
253  except:
254  Turing = 'King of Computers'
255 
256  try:
257  N_V_3 += Velocity_3[str(j)][0]
258  except:
259  Turing = 'King of Computers'
260 
261  Time.append(Serial_Computation(P, Num_Elements, Nektar_Modes[i], N_P, N_V_1, N_V_2, N_V_3, Num_Constants, Fit, Scheme))
262 
263  Nektar_Modes = list(Nektar_Modes)
264  Nektar_Modes.pop(0)
265 
266  # Calculate the mean, standard deviation and variance of the difference between the data and the fitted model
267  difference = []
268 
269  for i in range(0, len(Nektar_Modes)):
270  difference.append(abs(Data[i] - Time[i]))
271 
272  mean_diff = np.mean(difference)
273  std_dev_diff = np.std(difference)
274  var_diff = np.var(difference)
275 
276  # Print these results for the user to see
277  print('The mean of the differences between the Data and the Model is ' + str(mean_diff))
278  print('The standard deviation of the differences between the Data and the Model is ' + str(std_dev_diff))
279  print('The variance of the differences between the Data and the Model is ' + str(var_diff))
280 
281  # Plot the two data sets together for a visual comparison
282  fig, ax = plt.subplots()
283  ax.plot(Nektar_Modes, Data, label = 'Data')
284  ax.errorbar(Nektar_Modes, Time, label = 'Model')
285  ax.set_xlabel('$ N_Z $')
286  ax.set_ylabel('Timestep (s)')
287  ax.set_title('Length of Single Timestep: Model vs Data')
288  plt.legend(loc=4)
289  fig.savefig("Output/Figures/Model_vs_Data.png")
290 
291  return(Fit)
292 
293 #------------------------------------
294 # End of Functions
#------------------------------------
def Fit_Model
Definition: serial.py:131
def Serial_Computation
Definition: serial.py:26
def Run_Serial_Fit
Definition: serial.py:156
def Operation_Count
Definition: serial.py:72
def serial.Serial_Computation (   P,
  Num_Elements,
  Num_Modes,
  N_P,
  N_V_1,
  N_V_2,
  N_V_3,
  Num_Constants,
  constants,
  Scheme 
)

Definition at line 26 of file serial.py.

Referenced by Run_Serial_Fit(), and class_topology.Serial_Compute().

26 
27 def Serial_Computation(P, Num_Elements, Num_Modes, N_P, N_V_1, N_V_2, N_V_3, Num_Constants, constants, Scheme):
28 
29 # Operation Counts as per the thesis
30  O_A_1 = 9 * Num_Elements * (P + 1) ** 2 * Num_Modes * m.log(Num_Modes, 2)
31  O_A_2 = Num_Elements * Num_Modes * (P + 1) ** 2
32  O_A_3 = 6 * Num_Elements * (P + 1) ** 4 * Num_Modes
33  O_A_4 = 15 * Num_Elements * (P + 1) ** 2 * Num_Modes
34 
35  T_A = O_A_1 + O_A_2 + O_A_3 + O_A_4
36 
37  if (Scheme == 'IterativeFull'):
38  O_E_1 = 8 * Num_Elements * (P + 1) ** 2
39  O_E_2 = Num_Elements * (P + 1) ** 2
40  O_E_3 = Num_Elements * ((4 * P ** 3) + (18 * P ** 2) + (26 * P) + 12)
41  O_E_4 = 6 * Num_Elements * (P + 1) ** 2
42 
43  t_e = O_E_1 + O_E_2 + O_E_3 + O_E_4
44 
45  T_E = (N_P + N_V_1 + N_V_2 + N_V_3) * t_e
46 
47  if (Scheme == 'IterativeStaticCond'):
48  O_E_1 = 8 * ((P - 1) ** 2) * 4 * P * Num_Elements * Num_Modes
49  O_E_2 = (N_P + N_V_1 + N_V_2 + N_V_3) * 2 * 16 * (P ** 2) * Num_Elements
50  O_E_3 = (8 * 4 * ((P - 1) ** 2)) + (4 * ((P - 1) ** 2)) * Num_Elements * Num_Modes
51  O_E_4 = 8 * ((((P - 1) ** 2)) ** 2) * Num_Elements * Num_Modes
52 
53  T_E = O_E_1 + O_E_2 + O_E_3 + O_E_4
54 
55 # Divide by operations per second.
56 
57  if (Num_Constants == 1):
58  T_A = T_A / constants
59  T_E = T_E / constants
60 
61  if (Num_Constants == 2):
62  T_A = T_A / constants[0]
63  T_E = T_E / constants[1]
64 
65  Time = T_A + T_E
66 
67  return(Time)
68 
69 #------------------------------------
70 # New Function
71 #------------------------------------
def Serial_Computation
Definition: serial.py:26