COMPASS  5.4.4
End-to-end AO simulation tool using GPU acceleration
util/tao/__init__.py
1 from importlib import reload
2 import numpy as np
3 from astropy.io import fits
4 
5 from shesha.ao import imats
6 from shesha.ao import cmats
7 
8 from shesha.util.tao import writer
9 from shesha.util.tao import ltao
10 from shesha.util.tao import mcao
11 reload(ltao)
12 reload(mcao)
13 
14 TILE_SIZE="1000"
15 
16 STARPU_FLAGS=""
17 
18 #variable necessary to run TAO
19 TAO_SETTINGS={"SCHED":"dmdas",
20  "STARPU_FLAGS":"",
21  "GPU_IDS":0,
22  "TILE_SIZE":TILE_SIZE,
23  "INPUT_PATH":0,
24  "TAO_PATH":0
25  }
26 
27 
28 def check():
29  """Checks that variable are initialized
30  """
31  stop=0
32  try :
33  if (not isinstance(TAO_SETTINGS["SCHED"], str)):
34  print("you must select a scheduler (dmda,dmdas,dmdar...)\n\tex: TAO_SETTINGS[\"SCHED\"]=\"dmdas\"")
35  stop=1
36  except:
37  print("you must select a scheduler (dmda,dmdas,dmdar...)\n\tex: TAO_SETTINGS[\"SCHED\"]=\"dmdas\"")
38  stop=1
39  try :
40  if( not isinstance(TAO_SETTINGS["GPU_IDS"], str)):
41  print("you must define the GPUs to use as a string \n\tex:TAO_SETTINGS[\"GPU_IDS\"]=\"1,2\"")
42  stop=1
43  except:
44  print("you must define the GPUs to use as a string \n\tex:TAO_SETTINGS[\"GPU_IDS\"]=\"1,2\"")
45  stop=1
46  try :
47  if( not isinstance(TAO_SETTINGS["INPUT_PATH"], str)):
48  print("you must define the location of the system parameters \n\tex: TAO_SETTINGS[\"INPUT_PATH\"]=\"~/workspace/compass/params\"")
49  stop=1
50  except:
51  print("you must define the location of the system parameters \n\tex: TAO_SETTINGS[\"INPUTPATH\"]=\"~/workspace/compass/params\"")
52  stop=1
53  try :
54  if( not isinstance(TAO_SETTINGS["TAO_PATH"], str)):
55  print("you must define the location of the tao executables \n\tex: TAO_SETTINGS[\"TAO_PATH\"]=\"~/workspace/tao/install/bin\"")
56  stop=1
57  except:
58  print("you must define the location of the tao executables \n\tex: TAO_SETTINGS[\"TAOPATH\"]=\"~/workspace/tao/install/bin\"")
59  stop=1
60  try :
61  TAO_SETTINGS["STARPU_FLAGS"]
62  except:
63  TAO_SETTINGS["STARPU_FLAGS"]=""
64 
65  return stop
66 
67 
68 def init(sup, mod, *,wfs="all", dm_use_tt=False, n_filt=None):
69  """ Set up the compass loop
70 
71  set the interaction matrix, loop gain and write parameter files for TAO
72 
73  Args:
74 
75  sup : (CompassSupervisor) : current supervisor
76 
77  mod : (module) : AO mode requested (among: ltao , mcao)
78 
79  Kwargs:
80  wfs : (str) : (optional), default "all" wfs used by tao ( among "all", "lgs", "ngs")
81 
82  dm_use_tt : (bool) :(optional), default False using a TT DM
83 
84  n_filt : (int) : (optional), default None number of meta interaction matrix singular values filtered out
85  """
86 
87  #setting open loop
88  sup.rtc._rtc.d_control[0].set_polc(True)
89 
90  if n_filt is None:
91  mod.init(TAO_SETTINGS, sup, dm_use_tt=dm_use_tt, wfs=wfs)
92  else:
93  mod.init(TAO_SETTINGS, sup, dm_use_tt=dm_use_tt, wfs=wfs, n_filt=n_filt)
94 
95 def reconstructor(mod):
96  """ Compute the TAO reconstructor for a given AO mode
97 
98  Args:
99  mod : (module) : AO mode requested (among: ltao , mcao)
100  """
101  return mod.reconstructor(TAO_SETTINGS)
102 
103 
104 def run(sup, mod, *, n_iter=1000, initialisation=True, reset=True, wfs="all",
105  dm_use_tt=False, n_filt=None):
106  """ Computes a tao reconstructor and run a compass loop with it
107 
108  Args:
109  sup : (CompassSupervisor) : current supervisor
110 
111  mod : (module) : AO mode requested (among: ltao , mcao)
112 
113  Kwargs
114  n_iter : (int) : (optional), default 1000 number of iteration of the ao loop
115 
116  initialisation : (bool) : (optional), default True initialise tao (include comptation of meta matrices of interaction/command)
117 
118  reset : (bool) : (optional), default True reset the supervisor before the loop
119 
120  wfs : (str) : (optional), default "all" wfs used by tao ( among "all", "lgs", "ngs")
121 
122  dm_use_tt : (bool) :(optional), default False using a TT DM
123 
124  n_filt : (int) : (optional), default None number of meta interaction matrix singular values filtered out
125  """
126  check()
127 
128  #setting open loop
129  sup.rtc._rtc.d_control[0].set_polc(True)
130 
131  #if generic: need to update imat in controller
132  if(np.abs(np.array(sup.rtc._rtc.d_control[0].d_imat)).max()==0):
133  #imat not set yet for controller
134  sup.rtc._rtc.d_control[0].set_imat(sup.config.p_controllers[0]._imat)
135  #update gain
136  sup.rtc._rtc.set_gain(0,sup.config.p_controllers[0].gain)
137 
138  if(initialisation):
139  init(sup, mod, wfs=wfs, dm_use_tt=dm_use_tt, n_filt=n_filt)
140  M=reconstructor(mod)
141  if(reset):
142  sup.reset()
143  cmat_shape=sup.rtc.get_command_matrix(0).shape
144  if(M.shape[0] != cmat_shape[0] or M.shape[1] != cmat_shape[1]):
145  print("ToR shape is not valid:\n\twaiting for:",cmat_shape,"\n\tgot :",M.shape)
146  else:
147  sup.rtc.set_command_matrix(0,M)
148  if(n_iter>0):
149  sup.loop(n_iter)
Python package for AO operations on COMPASS simulation.
Definition: ao/__init__.py:1
def reconstructor(mod)
Compute the TAO reconstructor for a given AO mode.
def check()
Checks that variable are initialized.
def init(sup, mod, *wfs="all", dm_use_tt=False, n_filt=None)
Set up the compass loop.
def run(sup, mod, *n_iter=1000, initialisation=True, reset=True, wfs="all", dm_use_tt=False, n_filt=None)
Computes a tao reconstructor and run a compass loop with it.