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

Functions

def loop (n)
 
def preloop (n)
 
def compute_btt ()
 
def compute_cmatWithBtt (Btt, nfilt)
 
def compute_cmatWithBtt2 (Btt, nfilt)
 
def cov_cor (P, noise, trunc, alias, H, bp, tomo)
 
def save_it (filename)
 

Variables

string error = 'command line should be at least:"python -i test.py parameters_filename"\n with "parameters_filename" the path to the parameters file'
 
 param_file = sys.argv[1]
 
 filename = param_file.split('/')[-1]
 
 param_path = param_file.split(filename)[0]
 
 savename = sys.argv[2]
 
string simul_name = ""
 
dictionary matricesToLoad = {}
 
int clean = 1
 
 param_dict = h5u.params_dictionary(config)
 
 c = ch.carmaWrap_context(devices=np.array([0, 1], dtype=np.int32))
 
 wfs
 
 tel
 
 atm
 
 dms = ao.dm_init(config.p_dms, config.p_wfss, wfs, config.p_geom, config.p_tel)
 
 tar
 
 rtc
 
bool error_flag = True in [w.roket for w in config.p_wfss]
 
 nfiltered = config.p_controllers[0].maxcond
 _ _ | |_ ___ ___| |_ ___ | __/ _ \/ __| __/ __| | || __/__ \ |___ \ _____||___/__|___/ More...
 
 niters = config.p_loop.niter
 
 Btt
 
 P
 
 Dm
 
 cmat
 
 R = rtc.get_cmat(0)
 
 imat = rtc.get_imat(0)
 
 RD = np.dot(R, imat).astype(np.float32)
 
tuple gRD = (np.identity(RD.shape[0]) - config.p_controllers[0].gain * RD).astype(np.float32)
 
 roket
 
 SR
 
 SR2
 

Function Documentation

◆ compute_btt()

def roket_gpu.compute_btt ( )

| _ ) __ _ __(_)___ | _ \/ _` (-< (_-< |___/_,_/__/_/__/

Definition at line 283 of file roket_gpu.py.

283 def compute_btt():
284  IF = rtc.get_IFsparse(1).T
285  N = IF.shape[0]
286  n = IF.shape[1]
287  #T = IF[:,-2:].copy()
288  T = rtc.get_IFtt(1)
289  #IF = IF[:,:n-2]
290  n = IF.shape[1]
291 
292  delta = IF.T.dot(IF).toarray() / N
293 
294  # Tip-tilt + piston
295  Tp = np.ones((T.shape[0], T.shape[1] + 1))
296  Tp[:, :2] = T.copy() #.toarray()
297  deltaT = IF.T.dot(Tp) / N
298  # Tip tilt projection on the pzt dm
299  tau = np.linalg.inv(delta).dot(deltaT)
300 
301  # Famille generatrice sans tip tilt
302  G = np.identity(n)
303  tdt = tau.T.dot(delta).dot(tau)
304  subTT = tau.dot(np.linalg.inv(tdt)).dot(tau.T).dot(delta)
305  G -= subTT
306 
307  # Base orthonormee sans TT
308  gdg = G.T.dot(delta).dot(G)
309  U, s, V = np.linalg.svd(gdg)
310  U = U[:, :U.shape[1] - 3]
311  s = s[:s.size - 3]
312  L = np.identity(s.size) / np.sqrt(s)
313  B = G.dot(U).dot(L)
314 
315  # Rajout du TT
316  TT = T.T.dot(T) / N #.toarray()/N
317  Btt = np.zeros((n + 2, n - 1))
318  Btt[:B.shape[0], :B.shape[1]] = B
319  mini = 1. / np.sqrt(TT)
320  mini[0, 1] = 0
321  mini[1, 0] = 0
322  Btt[n:, n - 3:] = mini
323 
324  # Calcul du projecteur actus-->modes
325  delta = np.zeros((n + T.shape[1], n + T.shape[1]))
326  #IF = rtc.get_IFsparse(1).T
327  delta[:-2, :-2] = IF.T.dot(IF).toarray() / N
328  delta[-2:, -2:] = T.T.dot(T) / N
329  P = Btt.T.dot(delta)
330 
331  return Btt.astype(np.float32), P.astype(np.float32)
332 
333 

◆ compute_cmatWithBtt()

def roket_gpu.compute_cmatWithBtt (   Btt,
  nfilt 
)

Definition at line 334 of file roket_gpu.py.

334 def compute_cmatWithBtt(Btt, nfilt):
335  D = rtc.get_imat(0)
336  #D = ao.imat_geom(wfs,config.p_wfss,config.p_controllers[0],dms,config.p_dms,meth=0)
337  # Filtering on Btt modes
338  Btt_filt = np.zeros((Btt.shape[0], Btt.shape[1] - nfilt))
339  Btt_filt[:, :Btt_filt.shape[1] - 2] = Btt[:, :Btt.shape[1] - (nfilt + 2)]
340  Btt_filt[:, Btt_filt.shape[1] - 2:] = Btt[:, Btt.shape[1] - 2:]
341 
342  # Modal interaction basis
343  Dm = D.dot(Btt_filt)
344  # Direct inversion
345  Dmp = np.linalg.inv(Dm.T.dot(Dm)).dot(Dm.T)
346  # Command matrix
347  cmat = Btt_filt.dot(Dmp)
348 
349  return Dm.astype(np.float32), cmat.astype(np.float32)
350 
351 

◆ compute_cmatWithBtt2()

def roket_gpu.compute_cmatWithBtt2 (   Btt,
  nfilt 
)

Definition at line 352 of file roket_gpu.py.

352 def compute_cmatWithBtt2(Btt, nfilt):
353  D = rtc.get_imat(0)
354 
355  # Modal interaction basis
356  Dm = D.dot(Btt)
357  # Filtering on modal imat
358  DmtDm = Dm.T.dot(Dm)
359  U, s, V = np.linalg.svd(DmtDm)
360  s = 1. / s
361  s[s.shape[0] - nfilt - 2:s.shape[0] - 2] = 0.
362  DmtDm1 = U.dot(np.diag(s)).dot(U.T)
363  Dmp = DmtDm1.dot(Dm.T)
364  # Command matrix
365  cmat = Btt.dot(Dmp)
366 
367  return Dm.astype(np.float32), cmat.astype(np.float32)
368 
369 

◆ cov_cor()

def roket_gpu.cov_cor (   P,
  noise,
  trunc,
  alias,
  H,
  bp,
  tomo 
)

/ __|_____ ____ _ _ _(_)__ _ _ _ __ ___ / _|___ __ ___ _ _ _ _ ___| |__ _| |_(_)___ _ _ | (__/ _ \ V / _‘ | ’_| / _‘ | ’ \/ _/ -_) > _|_ _| / _/ _ \ '_| '_/ -_) / _‘ | _| / _ \ ’ \ ______/_/__,_|_| |___,_|_||______| _____| _____/_| |_| ___|___,_|__|____/_||_|

Definition at line 379 of file roket_gpu.py.

379 def cov_cor(P, noise, trunc, alias, H, bp, tomo):
380  cov = np.zeros((6, 6))
381  bufdict = {
382  "0": noise.T,
383  "1": trunc.T,
384  "2": alias.T,
385  "3": H.T,
386  "4": bp.T,
387  "5": tomo.T
388  }
389  for i in range(cov.shape[0]):
390  for j in range(cov.shape[1]):
391  if (j >= i):
392  tmpi = P.dot(bufdict[str(i)])
393  tmpj = P.dot(bufdict[str(j)])
394  cov[i, j] = np.sum(
395  np.mean(tmpi * tmpj, axis=1) -
396  np.mean(tmpi, axis=1) * np.mean(tmpj, axis=1))
397  else:
398  cov[i, j] = cov[j, i]
399 
400  s = np.reshape(np.diag(cov), (cov.shape[0], 1))
401  sst = np.dot(s, s.T)
402  cor = cov / np.sqrt(sst)
403 
404  return cov, cor
405 
406 
Here is the caller graph for this function:

◆ loop()

def roket_gpu.loop (   n)

/_\ / _ \ | |___ ___ _ __ / _ \ (_) | | / _ \/ _ \ '_ \ /_/ ____/ |____/___/ .__/ |_|

Performs the main AO loop for n interations. First, initialize buffers for error breakdown computations. Then, at the end of each iteration, just before applying the new DM shape, calls the error_breakdown function.

:param n: (int) : number of iterations

:return: com (np.array((n,nactus))) : full command buffer

noise_com (np.array((n,nactus))) : noise contribution for error breakdown

alias_wfs_com (np.array((n,nactus))) : aliasing estimation in the WFS direction

tomo_com (np.array((n,nactus))) : tomography error estimation

H_com (np.array((n,nactus))) : Filtered modes contribution for error breakdown

trunc_com (np.array((n,nactus))) : Truncature and sampling error of WFS

bp_com (np.array((n,nactus))) : Bandwidth error estimation on target

mod_com (np.array((n,nactus))) : Commanded modes expressed on the actuators

fit (float) : fitting (mean variance of the residual target phase after projection)

SR (float) : final strehl ratio returned by the simulation

Definition at line 166 of file roket_gpu.py.

166  """
167  if (error_flag):
168  # Initialize buffers for error breakdown
169  nactu = rtc.get_command(0).size
170  nslopes = rtc.get_centroids(0).size
171  com = np.zeros((n, nactu), dtype=np.float32)
172  noise_com = np.zeros((n, nactu), dtype=np.float32)
173  alias_wfs_com = np.copy(noise_com)
174  wf_com = np.copy(noise_com)
175  tomo_com = np.copy(noise_com)
176  trunc_com = np.copy(noise_com)
177  H_com = np.copy(noise_com)
178  mod_com = np.copy(noise_com)
179  bp_com = np.copy(noise_com)
180  fit = np.zeros(n)
181  # covm = np.zeros((nslopes,nslopes))
182  # covv = np.zeros((nactu,nactu))
183 
184  t0 = time.time()
185  for i in range(-10, n):
186  atm.move_atmos()
187 
188  if (config.p_controllers[0].type == b"geo"):
189  for t in range(config.p_target.ntargets):
190  tar.atmos_trace(t, atm, tel)
191  rtc.docontrol_geo(0, dms, tar, 0)
192  rtc.applycontrol(0, dms)
193  tar.dmtrace(0, dms)
194  else:
195  for t in range(config.p_target.ntargets):
196  tar.atmos_trace(t, atm, tel)
197  tar.dmtrace(t, dms)
198  for w in range(len(config.p_wfss)):
199  wfs.sensors_trace(w, "all", tel, atm, dms)
200  wfs.sensors_compimg(w)
201  rtc.docentroids(0)
202  rtc.docontrol(0)
203  #m = np.reshape(rtc.get_centroids(0),(nslopes,1))
204  #v = np.reshape(rtc.get_command(0),(nactu,1))
205  if (error_flag and i > -1):
206  #compute the error breakdown for this iteration
207  #covm += m.dot(m.T)
208  #covv += v.dot(v.T)
209  roket.computeBreakdown()
210  rtc.applycontrol(0, dms)
211 
212  if ((i + 1) % 100 == 0 and i > -1):
213  strehltmp = tar.get_strehl(0)
214  print(i + 1, "\t", strehltmp[0], "\t", strehltmp[1], "\t",
215  np.exp(-strehltmp[2]), "\t", np.exp(-strehltmp[3]))
216  t1 = time.time()
217  print(" loop execution time:", t1 - t0, " (", n, "iterations), ", (t1 - t0) / n,
218  "(mean) ", n / (t1 - t0), "Hz")
219  if (error_flag):
220  #Returns the error breakdown
221  SR2 = np.exp(-tar.get_strehl(0, comp_strehl=False)[3])
222  SR = tar.get_strehl(0, comp_strehl=False)[1]
223  #bp_com[-1,:] = bp_com[-2,:]
224  #SR = tar.get_strehl(0,comp_strehl=False)[1]
225  return SR, SR2
226 
227 
228 def preloop(n):
229  """
230  Performs the main AO loop for n interations. First, initialize buffers
231  for error breakdown computations. Then, at the end of each iteration, just
232  before applying the new DM shape, calls the error_breakdown function.
233 
234  :param n: (int) : number of iterations
235 
236  :return:
237  com : (np.array((n,nactus))) : full command buffer
238 
239  noise_com : (np.array((n,nactus))) : noise contribution for error breakdown
240 
241  alias_wfs_com : (np.array((n,nactus))) : aliasing estimation in the WFS direction
242 
243  tomo_com : (np.array((n,nactus))) : tomography error estimation
244 
245  H_com : (np.array((n,nactus))) : Filtered modes contribution for error breakdown
246 
247  trunc_com : (np.array((n,nactus))) : Truncature and sampling error of WFS
248 
249  bp_com : (np.array((n,nactus))) : Bandwidth error estimation on target
250 
251  mod_com : (np.array((n,nactus))) : Commanded modes expressed on the actuators
252 
253  fit : (float) : fitting (mean variance of the residual target phase after projection)
254 
255  SR : (float) : final strehl ratio returned by the simulation

◆ preloop()

def roket_gpu.preloop (   n)

Definition at line 256 of file roket_gpu.py.

256  """
257  for i in range(0, n):
258  atm.move_atmos()
259 
260  if (config.p_controllers[0].type == b"geo"):
261  for t in range(config.p_target.ntargets):
262  tar.atmos_trace(t, atm, tel)
263  rtc.docontrol_geo(0, dms, tar, 0)
264  rtc.applycontrol(0, dms)
265  else:
266  for t in range(config.p_target.ntargets):
267  tar.atmos_trace(t, atm, tel)
268  for w in range(len(config.p_wfss)):
269  wfs.sensors_trace(w, "all", tel, atm, dms)
270  wfs.sensors_compimg(w)
271  rtc.docentroids(0)
272  rtc.docontrol(0)
273 
274  rtc.applycontrol(0, dms)
275 
276 

◆ save_it()

def roket_gpu.save_it (   filename)

/ __| __ ___ _____ __ \/ _` \ V / -_) |___/__,_|_/___|

Definition at line 415 of file roket_gpu.py.

415 def save_it(filename):
416  IF = rtc.get_IFsparse(1)
417  TT = rtc.get_IFtt(1)
418  noise_com = roket.getContributor("noise")
419  trunc_com = roket.getContributor("nonlinear")
420  alias_wfs_com = roket.getContributor("aliasing")
421  H_com = roket.getContributor("filtered")
422  bp_com = roket.getContributor("bandwidth")
423  tomo_com = roket.getContributor("tomo")
424  fit = roket.getContributor("fitting")
425 
426  tmp = (config.p_geom._ipupil.shape[0] -
427  (config.p_dms[0]._n2 - config.p_dms[0]._n1 + 1)) / 2
428  tmp_e0 = config.p_geom._ipupil.shape[0] - tmp
429  tmp_e1 = config.p_geom._ipupil.shape[1] - tmp
430  pup = config.p_geom._ipupil[tmp:tmp_e0, tmp:tmp_e1]
431  indx_pup = np.where(pup.flatten() > 0)[0].astype(np.int32)
432  dm_dim = config.p_dms[0]._n2 - config.p_dms[0]._n1 + 1
433  cov, cor = cov_cor(P, noise_com, trunc_com, alias_wfs_com, H_com, bp_com, tomo_com)
434  psf = tar.get_image(0, "le", fluxNorm=False)
435  psfortho = roket.get_tar_imageortho()
436  covv = roket.get_covv()
437  covm = roket.get_covm()
438 
439  fname = "/home/fferreira/Data/" + filename
440  pdict = {
441  "noise": noise_com.T,
442  "aliasing": alias_wfs_com.T,
443  "tomography": tomo_com.T,
444  "filtered modes": H_com.T,
445  "non linearity": trunc_com.T,
446  "bandwidth": bp_com.T,
447  "P": P,
448  "Btt": Btt,
449  "IF.data": IF.data,
450  "IF.indices": IF.indices,
451  "IF.indptr": IF.indptr,
452  "TT": TT,
453  "dm_dim": dm_dim,
454  "indx_pup": indx_pup,
455  "fitting": fit,
456  "SR": SR,
457  "SR2": SR2,
458  "cov": cov,
459  "cor": cor,
460  "psfortho": psfortho,
461  "covm": covm,
462  "covv": covv
463  }
464  h5u.save_h5(fname, "psf", config, psf)
465  #h5u.writeHdf5SingleDataset(fname,com.T,datasetName="com")
466  for k in list(pdict.keys()):
467  h5u.save_hdf5(fname, k, pdict[k])
468 
469 
Here is the call graph for this function:

Variable Documentation

◆ atm

roket_gpu.atm
Initial value:
1 = ao.atmos_init(c, config.p_atmos, config.p_tel, config.p_geom, config.p_loop,
2  config.p_wfss, wfs, config.p_target, rank=0, clean=clean,
3  load=matricesToLoad)

Definition at line 91 of file roket_gpu.py.

◆ Btt

roket_gpu.Btt

Definition at line 480 of file roket_gpu.py.

◆ c

roket_gpu.c = ch.carmaWrap_context(devices=np.array([0, 1], dtype=np.int32))

Definition at line 81 of file roket_gpu.py.

◆ clean

int roket_gpu.clean = 1

Definition at line 72 of file roket_gpu.py.

◆ cmat

roket_gpu.cmat

Definition at line 482 of file roket_gpu.py.

◆ Dm

roket_gpu.Dm

Definition at line 482 of file roket_gpu.py.

◆ dms

roket_gpu.dms = ao.dm_init(config.p_dms, config.p_wfss, wfs, config.p_geom, config.p_tel)

Definition at line 97 of file roket_gpu.py.

◆ error

string roket_gpu.error = 'command line should be at least:"python -i test.py parameters_filename"\n with "parameters_filename" the path to the parameters file'

Definition at line 22 of file roket_gpu.py.

◆ error_flag

bool roket_gpu.error_flag = True in [w.roket for w in config.p_wfss]

Definition at line 128 of file roket_gpu.py.

◆ filename

roket_gpu.filename = param_file.split('/')[-1]

Definition at line 28 of file roket_gpu.py.

◆ gRD

tuple roket_gpu.gRD = (np.identity(RD.shape[0]) - config.p_controllers[0].gain * RD).astype(np.float32)

Definition at line 488 of file roket_gpu.py.

◆ imat

roket_gpu.imat = rtc.get_imat(0)

Definition at line 485 of file roket_gpu.py.

◆ matricesToLoad

roket_gpu.matricesToLoad = {}

Definition at line 70 of file roket_gpu.py.

◆ nfiltered

roket_gpu.nfiltered = config.p_controllers[0].maxcond

_ _ | |_ ___ ___| |_ ___ | __/ _ \/ __| __/ __| | || __/__ \ |___ \ _____||___/__|___/

Definition at line 477 of file roket_gpu.py.

◆ niters

roket_gpu.niters = config.p_loop.niter

Definition at line 478 of file roket_gpu.py.

◆ P

roket_gpu.P

Definition at line 480 of file roket_gpu.py.

◆ param_dict

roket_gpu.param_dict = h5u.params_dictionary(config)

Definition at line 75 of file roket_gpu.py.

◆ param_file

roket_gpu.param_file = sys.argv[1]

Definition at line 26 of file roket_gpu.py.

◆ param_path

roket_gpu.param_path = param_file.split(filename)[0]

Definition at line 29 of file roket_gpu.py.

◆ R

roket_gpu.R = rtc.get_cmat(0)

Definition at line 484 of file roket_gpu.py.

◆ RD

roket_gpu.RD = np.dot(R, imat).astype(np.float32)

Definition at line 486 of file roket_gpu.py.

◆ roket

roket_gpu.roket
Initial value:
1 = ao.roket_init(rtc, wfs, tar, dms, tel, atm, 0, 1, Btt.shape[0], Btt.shape[1],
2  nfiltered, niters, Btt, P, gRD, RD)

Definition at line 489 of file roket_gpu.py.

◆ rtc

roket_gpu.rtc
Initial value:
1 = ao.rtc_init(tel, wfs, config.p_wfss, dms, config.p_dms, config.p_geom,
2  config.p_rtc, config.p_atmos, atm, config.p_tel, config.p_loop,
3  clean=clean, simul_name=simul_name, load=matricesToLoad)

Definition at line 106 of file roket_gpu.py.

◆ savename

string roket_gpu.savename = sys.argv[2]

Definition at line 48 of file roket_gpu.py.

◆ simul_name

string roket_gpu.simul_name = ""

(_)_ __ (_) |_ ___ | | '_ | | __/ __| | | | | | | |___ \ |_|_| |_|_|__|___/

Definition at line 63 of file roket_gpu.py.

◆ SR

roket_gpu.SR

Definition at line 498 of file roket_gpu.py.

◆ SR2

roket_gpu.SR2

Definition at line 498 of file roket_gpu.py.

◆ tar

roket_gpu.tar
Initial value:
1 = ao.target_init(c, tel, config.p_target, config.p_atmos, config.p_geom,
2  config.p_tel, config.p_dms)

Definition at line 101 of file roket_gpu.py.

◆ tel

roket_gpu.tel

Definition at line 86 of file roket_gpu.py.

◆ wfs

roket_gpu.wfs

Definition at line 86 of file roket_gpu.py.