COMPASS  5.0.0
End-to-end AO simulation tool using GPU acceleration
benchmark_script Namespace Reference

Functions

def get_processor_name ()
 
def script4bench (param_file, centroider, controller, devices, fwrite=True)
 

Variables

string error
 
 SHESHA = os.environ.get('SHESHA_ROOT')
 
string SHESHA_SAVEPATH = SHESHA + "/data"
 
string PARPATH = SHESHA_SAVEPATH + "/par/par4bench"
 
string BENCH_SAVEPATH = SHESHA_SAVEPATH + "/bench-results"
 
 store = HDFStore(BENCH_SAVEPATH + "/benchmarks.h5")
 
string filename = PARPATH + "/" + sys.argv[1]
 
 centroider = sys.argv[2]
 
 controller = sys.argv[3]
 
int device = 5
 
bool fwrite = True
 
list devices = []
 

Function Documentation

◆ get_processor_name()

def benchmark_script.get_processor_name ( )

Definition at line 20 of file benchmark_script.py.

20 def get_processor_name():
21  command = "cat /proc/cpuinfo"
22  all_info = check_output(command, shell=True).strip().decode("utf-8")
23  nb_cpu = 0
24  cpu = []
25  for line in all_info.split("\n"):
26  if "model name" in line:
27  cpu.append(re.sub(".*model name.*:", "", line, 1))
28  nb_cpu += 1
29  return nb_cpu, cpu
30 
31 
32 def script4bench(param_file, centroider, controller, devices, fwrite=True):
33  """
34 
35  :parameters:
36  param_file: (str) : parameters filename
37 
38  centroider: (str) : centroider type
39 
40  controller: (str) : controller type
Here is the caller graph for this function:

◆ script4bench()

def benchmark_script.script4bench (   param_file,
  centroider,
  controller,
  devices,
  fwrite = True 
)

Definition at line 41 of file benchmark_script.py.

41  """
42 
43  c = carmaWrap_context(devices=np.array(devices, dtype=np.int32))
44  # c.set_active_device(device)
45 
46  timer = carmaWrap_timer()
47 
48  # times measured
49  synctime = 0.
50  move_atmos_time = 0.
51  t_raytrace_atmos_time = 0.
52  t_raytrace_dm_time = 0.
53  s_raytrace_atmos_time = 0.
54  s_raytrace_dm_time = 0.
55  comp_img_time = 0.
56  docentroids_time = 0.
57  docontrol_time = 0.
58  applycontrol_time = 0.
59 
60  # reading parfile
61  filename = param_file.split('/')[-1]
62  param_path = param_file.split(filename)[0]
63  sys.path.insert(0, param_path)
64  #exec("import %s as config" % filename.split(".py")[0])
65  config = __import__(filename.split(".py")[0])
66  sys.path.remove(param_path)
67 
68  config.p_centroiders[0].set_type(centroider)
69 
70  if (centroider == "tcog"):
71  config.p_centroiders[0].set_thresh(0.)
72  elif (centroider == "bpcog"):
73  config.p_centroiders[0].set_nmax(16)
74  elif (centroider == "geom"):
75  config.p_centroiders[0].set_type("cog")
76  elif (centroider == "wcog"):
77  config.p_centroiders[0].set_type_fct("gauss")
78  config.p_centroiders[0].set_width(2.0)
79  elif (centroider == "corr"):
80  config.p_centroiders[0].set_type_fct("gauss")
81  config.p_centroiders[0].set_width(2.0)
82 
83  if (controller == "modopti"):
84  config.p_controllers[0].set_type("ls")
85  config.p_controllers[0].set_modopti(1)
86  else:
87  config.p_controllers[0].set_type(controller)
88 
89  config.p_loop.set_niter(2000)
90 
91  threadSync()
92  timer.start()
93  threadSync()
94  synctime = timer.stop()
95  timer.reset()
96 
97  # init system
98  timer.start()
99  tel = init.tel_init(c, config.p_geom, config.p_tel, config.p_atmos.r0,
100  config.p_loop.ittime, config.p_wfss)
101  threadSync()
102  tel_init_time = timer.stop() - synctime
103  timer.reset()
104 
105  timer.start()
106  atm = init.atmos_init(c, config.p_atmos, config.p_tel, config.p_geom,
107  config.p_loop.ittime)
108  threadSync()
109  atmos_init_time = timer.stop() - synctime
110  timer.reset()
111 
112  timer.start()
113  dms = init.dm_init(c, config.p_dms, config.p_tel, config.p_geom, config.p_wfss)
114  threadSync()
115  dm_init_time = timer.stop() - synctime
116  timer.reset()
117 
118  timer.start()
119  target = init.target_init(c, tel, config.p_target, config.p_atmos, config.p_tel,
120  config.p_geom, config.p_dms)
121  threadSync()
122  target_init_time = timer.stop() - synctime
123  timer.reset()
124 
125  timer.start()
126  wfs = init.wfs_init(c, tel, config.p_wfss, config.p_tel, config.p_geom, config.p_dms,
127  config.p_atmos)
128  threadSync()
129  wfs_init_time = timer.stop() - synctime
130  timer.reset()
131 
132  timer.start()
133  rtc = init.rtc_init(c, tel, wfs, dms, atm, config.p_wfss, config.p_tel,
134  config.p_geom, config.p_atmos, config.p_loop.ittime,
135  config.p_centroiders, config.p_controllers, config.p_dms)
136  threadSync()
137  rtc_init_time = timer.stop() - synctime
138  timer.reset()
139 
140  print("... Done with inits !")
141  # h5u.validDataBase(os.environ["SHESHA_ROOT"]+"/data/",matricesToLoad)
142 
143  strehllp = []
144  strehlsp = []
145  ############################################################
146  # _ _
147  # (_) | |
148  # _ __ ___ __ _ _ _ __ | | ___ ___ _ __
149  # | '_ ` _ \ / _` | | '_ \ | |/ _ \ / _ \| '_ \
150  # | | | | | | (_| | | | | | | | (_) | (_) | |_) |
151  # |_| |_| |_|\__,_|_|_| |_| |_|\___/ \___/| .__/
152  # | |
153  # |_|
154  ###########################################################
155  if (controller == "modopti"):
156  for zz in range(2048):
157  atm.move_atmos()
158 
159  for cc in range(config.p_loop.niter):
160  threadSync()
161  timer.start()
162  atm.move_atmos()
163  threadSync()
164  move_atmos_time += timer.stop() - synctime
165  timer.reset()
166 
167  if (config.p_controllers[0].type != b"geo"):
168  if ((config.p_target is not None) and (rtc is not None)):
169  for i in range(config.p_target.ntargets):
170  timer.start()
171  target.raytrace(i, b"atmos", tel, atm)
172  threadSync()
173  t_raytrace_atmos_time += timer.stop() - synctime
174  timer.reset()
175 
176  if (dms is not None):
177  timer.start()
178  target.raytrace(i, b"dm", tel, dms=dms)
179  threadSync()
180  t_raytrace_dm_time += timer.stop() - synctime
181  timer.reset()
182 
183  if (config.p_wfss is not None and wfs is not None):
184  for i in range(len(config.p_wfss)):
185  timer.start()
186  wfs.raytrace(i, b"atmos", tel, atm)
187  threadSync()
188  s_raytrace_atmos_time += timer.stop() - synctime
189  timer.reset()
190 
191  if (not config.p_wfss[i].open_loop and dms is not None):
192  timer.start()
193  wfs.raytrace(i, b"dm", tel, atm, dms)
194  threadSync()
195  s_raytrace_dm_time += timer.stop() - synctime
196  timer.reset()
197 
198  timer.start()
199  wfs.comp_img(i)
200  threadSync()
201  comp_img_time += timer.stop() - synctime
202  timer.reset()
203 
204  if (rtc is not None and config.p_wfss is not None and wfs is not None):
205  if (centroider == "geom"):
206  timer.start()
207  rtc.do_centroids_geom(0)
208  threadSync()
209  docentroids_time += timer.stop() - synctime
210  timer.reset()
211  else:
212  timer.start()
213  rtc.do_centroids(0)
214  threadSync()
215  docentroids_time += timer.stop() - synctime
216  timer.reset()
217 
218  if (dms is not None):
219  timer.start()
220  rtc.do_control(0)
221  threadSync()
222  docontrol_time += timer.stop() - synctime
223  timer.reset()
224 
225  timer.start()
226  rtc.apply_control(0)
227  threadSync()
228  applycontrol_time += timer.stop() - synctime
229  timer.reset()
230 
231  else:
232  if (config.p_target is not None and target is not None):
233  for i in range(config.p_target.ntargets):
234  timer.start()
235  target.raytrace(i, b"atmos", tel, atm)
236  threadSync()
237  t_raytrace_atmos_time += timer.stop() - synctime
238  timer.reset()
239 
240  if (dms is not None):
241  timer.start()
242  rtc.do_control_geo(0, dms, target, i)
243  threadSync()
244  docontrol_time += timer.stop() - synctime
245  timer.reset()
246 
247  timer.start()
248  rtc.apply_control(0)
249  threadSync()
250  applycontrol_time += timer.stop() - synctime
251  timer.reset()
252 
253  timer.start()
254  target.raytrace(i, b"dm", tel, atm, dms)
255  threadSync()
256  t_raytrace_dm_time += timer.stop() - synctime
257  timer.reset()
258  target.comp_image(0)
259  strehltmp = target.get_strehl(0)
260  strehlsp.append(strehltmp[0])
261  if (cc > 50):
262  strehllp.append(strehltmp[1])
263 
264  print("\n done with simulation \n")
265  print("\n Final strehl : \n", strehllp[len(strehllp) - 1])
266  ###################################################################
267  # _ _
268  # | | (_)
269  # | |_ _ _ __ ___ ___ _ __ ___
270  # | __| | '_ ` _ \ / _ \ '__/ __|
271  # | |_| | | | | | | __/ | \__ \
272  # \__|_|_| |_| |_|\___|_| |___/
273  ###################################################################
274 
275  move_atmos_time /= config.p_loop.niter / 1000.
276  t_raytrace_atmos_time /= config.p_loop.niter / 1000.
277  t_raytrace_dm_time /= config.p_loop.niter / 1000.
278  s_raytrace_atmos_time /= config.p_loop.niter / 1000.
279  s_raytrace_dm_time /= config.p_loop.niter / 1000.
280  comp_img_time /= config.p_loop.niter / 1000.
281  docentroids_time /= config.p_loop.niter / 1000.
282  docontrol_time /= config.p_loop.niter / 1000.
283  applycontrol_time /= config.p_loop.niter / 1000.
284 
285  time_per_iter = move_atmos_time + t_raytrace_atmos_time +\
286  t_raytrace_dm_time + s_raytrace_atmos_time +\
287  s_raytrace_dm_time + comp_img_time +\
288  docentroids_time + docontrol_time +\
289  applycontrol_time
290 
291  ###########################################################################
292  # _ _ __ _____
293  # | | | |/ _| ____|
294  # | |__ __| | |_| |__ ___ __ ___ _____
295  # | '_ \ / _` | _|___ \ / __|/ _` \ \ / / _ \
296  # | | | | (_| | | ___) | \__ \ (_| |\ V / __/
297  # |_| |_|\__,_|_| |____/ |___/\__,_| \_/ \___|
298  ###############################################################################
299 
300  if (config.p_wfss[0].gsalt > 0):
301  stype = "lgs "
302  else:
303  stype = "ngs "
304 
305  if (config.p_wfss[0].gsmag > 3):
306  stype += "noisy "
307 
308  stype += str(config.p_wfss[0].type)
309 
310  if (controller == "modopti"):
311  G = np.mean(rtc.get_modal_gains(0))
312  else:
313  G = 0.
314 
315  date = datetime.datetime.now()
316  date = [date.year, date.month, date.day]
317 
318  version = check_output(["git", "rev-parse", "--short", "HEAD"]).decode('utf8')
319 
320  # version=str(check_output(["svnversion",os.getenv("COMPASS_ROOT")]).replace("\n",""))
321  hostname = check_output("hostname").replace(b"\n", b"").decode('UTF-8')
322  nb_cpu, cpu = get_processor_name()
323  keys_dict = {
324  "date": date,
325  "simulname": config.simul_name,
326  "hostname": hostname,
327  "ndevices": c.get_ndevice(),
328  "device": c.get_device_names()[0],
329  "cuda_version": c.get_cuda_runtime_get_version(),
330  "magma_version": c.get_magma_info(),
331  "platform": platform.platform(),
332  "ncpu": nb_cpu,
333  "processor": cpu[0],
334  "tel.diam": config.p_tel.diam,
335  "sensor_type": config.p_wfss[0].type.decode('UTF-8'),
336  "LGS": config.p_wfss[0].gsalt > 0,
337  "noisy": config.p_wfss[0].gsmag > 3,
338  "nxsub": config.p_wfss[0].nxsub,
339  "npix": config.p_wfss[0].npix,
340  "nphotons": config.p_wfss[0]._nphotons,
341  "controller": controller,
342  "centroider": centroider,
343  "finalSRLE": strehllp[len(strehllp) - 1],
344  "rmsSRLE": np.std(strehllp),
345  "wfs_init": wfs_init_time,
346  "atmos_init": atmos_init_time,
347  "dm_init": dm_init_time,
348  "target_init": target_init_time,
349  "rtc_init": rtc_init_time,
350  "move_atmos": move_atmos_time,
351  "target_trace_atmos": t_raytrace_atmos_time,
352  "target_trace_dm": t_raytrace_dm_time,
353  "sensor_trace_atmos": s_raytrace_atmos_time,
354  "sensor_trace_dm": s_raytrace_dm_time,
355  "comp_img": comp_img_time,
356  "docentroids": docentroids_time,
357  "docontrol": docontrol_time,
358  "applycontrol": applycontrol_time,
359  "iter_time": time_per_iter,
360  "Avg.gain": G,
361  "residualPhase": target.get_phase(0)
362  }
363 
364  store = HDFStore(BENCH_SAVEPATH + "/benchmarks.h5")
365  try:
366  df = store.get(version)
367  except KeyError:
368  df = DataFrame(columns=list(keys_dict.keys()), dtype=object)
369 
370  ix = len(df.index)
371 
372  if (fwrite):
373  print("writing files")
374  for i in list(keys_dict.keys()):
375  df.loc[ix, i] = keys_dict[i]
376  store.put(version, df)
377  store.close()
378 
379 
Here is the call graph for this function:

Variable Documentation

◆ BENCH_SAVEPATH

string benchmark_script.BENCH_SAVEPATH = SHESHA_SAVEPATH + "/bench-results"

Definition at line 401 of file benchmark_script.py.

◆ centroider

benchmark_script.centroider = sys.argv[2]

Definition at line 406 of file benchmark_script.py.

◆ controller

benchmark_script.controller = sys.argv[3]

Definition at line 407 of file benchmark_script.py.

◆ device

int benchmark_script.device = 5

Definition at line 408 of file benchmark_script.py.

◆ devices

list benchmark_script.devices = []

Definition at line 411 of file benchmark_script.py.

◆ error

string benchmark_script.error
Initial value:
1 = "wrong number of argument. Got %d (expect 4)\ncommande line should be: 'python benchmark_script.py <filename> <centroider> <controller>" % len(
2  sys.argv)
            _
           | |

___ _ __ __| | / _ \ '_ \ / _` | | __/ | | | (_| | ___|_| |_|__,_|

Definition at line 391 of file benchmark_script.py.

◆ filename

string benchmark_script.filename = PARPATH + "/" + sys.argv[1]

Definition at line 405 of file benchmark_script.py.

◆ fwrite

benchmark_script.fwrite = True

Definition at line 409 of file benchmark_script.py.

◆ PARPATH

string benchmark_script.PARPATH = SHESHA_SAVEPATH + "/par/par4bench"

Definition at line 400 of file benchmark_script.py.

◆ SHESHA

benchmark_script.SHESHA = os.environ.get('SHESHA_ROOT')

Definition at line 395 of file benchmark_script.py.

◆ SHESHA_SAVEPATH

string benchmark_script.SHESHA_SAVEPATH = SHESHA + "/data"

Definition at line 399 of file benchmark_script.py.

◆ store

benchmark_script.store = HDFStore(BENCH_SAVEPATH + "/benchmarks.h5")

Definition at line 403 of file benchmark_script.py.