]> SALOME platform Git repositories - modules/adao.git/blob - doc/fr/ref_observers_requirements.rst
Salome HOME
Detailed documentation of the observers
[modules/adao.git] / doc / fr / ref_observers_requirements.rst
1 ..
2    Copyright (C) 2008-2015 EDF R&D
3
4    This file is part of SALOME ADAO module.
5
6    This library is free software; you can redistribute it and/or
7    modify it under the terms of the GNU Lesser General Public
8    License as published by the Free Software Foundation; either
9    version 2.1 of the License, or (at your option) any later version.
10
11    This library is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14    Lesser General Public License for more details.
15
16    You should have received a copy of the GNU Lesser General Public
17    License along with this library; if not, write to the Free Software
18    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19
20    See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21
22    Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D
23
24 .. _ref_observers_requirements:
25
26 Exigences pour les fonctions décrivant un "*observer*"
27 ------------------------------------------------------
28
29 .. index:: single: Observer
30 .. index:: single: Observer Template
31
32 Certaines variables spéciales internes à l'optimisation, utilisées au cours des
33 calculs, peuvent être surveillées durant un calcul ADAO en YACS. Ces variables
34 peuvent être affichées, tracées, enregistrées, etc. C'est réalisable en
35 utilisant des "*observer*", qui sont des scripts, chacun associé à une
36 variable, qui sont activés à chaque modification de la variable.
37
38 Il y a 3 méthodes pratiques pour intégrer un "*observer*" dans un cas ADAO. La
39 méthode est choisie à l'aide du mot-clé "*NodeType*" de chaque entrée de type
40 *observer*, comme montré dans la figure qui suit :
41
42   .. eficas_observer_nodetype:
43   .. image:: images/eficas_observer_nodetype.png
44     :align: center
45     :width: 100%
46   .. centered::
47     **Choisir le type d'entrée**
48
49 L'"*observer*" peut être fourni sous la forme d'un script explicite (entrée de
50 type "*String*"), d'un script contenu dans un fichier externe (entrée de type
51 "*Script*"), ou en utilisant un modèle (entrée de type "*Template*") fourni par
52 défaut dans ADAO lors de l'édition dans l'éditeur graphique. Ces derniers sont
53 des scripts simples qui peuvent être adaptés par l'utilisateur, soit dans
54 l'étape d'édition intégrée, soit dans l'étape d'édition avant l'exécution, pour
55 améliorer l'adaptation du calcul ADAO dans le superviseur d'exécution de SALOME.
56
57 Forme générale d'un script permettant de définir un  *observer*
58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
59
60 Pour pouvoir utiliser cette capacité, l'utilisateur doit disposer ou construire
61 des scripts utilisant en entrée standard (i.e. disponible dans l'espace de
62 nommage) des variables ``var`` et ``info``. La variable ``var`` est à utiliser
63 comme un objet de type liste/tuple, contenant la variable d'intérêt indicée par
64 l'étape de mise à jour.
65
66 A titre d'exemple, voici un script très simple (similaire au modèle
67 "*ValuePrinter*") utilisable pour afficher la valeur d'une variable surveillée::
68
69     print "    --->",info," Value =",var[-1]
70
71 Stocké comme un fichier Python, ce script peut être associé à chaque variable
72 présente dans le mot-clé "*SELECTION*" de la commande "*Observers*":
73 "*Analysis*", "*CurrentState*", "*CostFunction*"... La valeur courante de la
74 variable sera affichée à chaque étape de l'algorithme d'optimisation ou
75 d'assimilation. Les "*observer*" peuvent inclure des capacités d'affichage
76 graphique, de stockage, d'affichage complexe, de traitement statistique, etc.
77
78 On donne ci-aprés l'identifiant et le contenu de chaque modèle disponible.
79
80 Inventaire des modèles d'*observer* disponibles ("*Template*")
81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
82
83 .. index:: single: ValueGnuPlotter (Observer)
84
85 Modèle **ValueGnuPlotter** :
86 ............................
87
88 ::
89
90     import numpy, Gnuplot
91     v=numpy.array(var[-1], ndmin=1)
92     global ifig, gp
93     try:
94         ifig += 1
95         gp('set style data lines')
96     except:
97         ifig = 0
98         gp = Gnuplot.Gnuplot(persist=1)
99         gp('set style data lines')
100     gp('set title  "%s (Figure %i)"'%(info,ifig))
101     gp.plot( Gnuplot.Data( v, with_='lines lw 2' ) )
102
103 .. index:: single: ValueMean (Observer)
104
105 Modèle **ValueMean** :
106 ......................
107
108 ::
109
110     import numpy
111     print info, numpy.nanmean(var[-1])
112
113 .. index:: single: ValuePrinter (Observer)
114
115 Modèle **ValuePrinter** :
116 .........................
117
118 Imprime sur la sortie standard la valeur courante de la variable.
119
120 ::
121
122     print info, var[-1]
123
124 .. index:: single: ValuePrinterAndGnuPlotter (Observer)
125
126 Modèle **ValuePrinterAndGnuPlotter** :
127 ......................................
128
129 ::
130
131     print info, var[-1]
132     import numpy, Gnuplot
133     v=numpy.array(var[-1], ndmin=1)
134     global ifig,gp
135     try:
136         ifig += 1
137         gp('set style data lines')
138     except:
139         ifig = 0
140         gp = Gnuplot.Gnuplot(persist=1)
141         gp('set style data lines')
142     gp('set title  "%s (Figure %i)"'%(info,ifig))
143     gp.plot( Gnuplot.Data( v, with_='lines lw 2' ) )
144
145 .. index:: single: ValuePrinterAndSaver (Observer)
146
147 Modèle **ValuePrinterAndSaver** :
148 .................................
149
150 ::
151
152     import numpy, re
153     v=numpy.array(var[-1], ndmin=1)
154     print info,v
155     global istep
156     try:
157         istep += 1
158     except:
159         istep = 0
160     f='/tmp/value_%s_%05i.txt'%(info,istep)
161     f=re.sub('\s','_',f)
162     print 'Value saved in "%s"'%f
163     numpy.savetxt(f,v)
164
165 .. index:: single: ValuePrinterSaverAndGnuPlotter (Observer)
166
167 Modèle **ValuePrinterSaverAndGnuPlotter** :
168 ...........................................
169
170 ::
171
172     print info, var[-1]
173     import numpy, re
174     v=numpy.array(var[-1], ndmin=1)
175     global istep
176     try:
177         istep += 1
178     except:
179         istep = 0
180     f='/tmp/value_%s_%05i.txt'%(info,istep)
181     f=re.sub('\s','_',f)
182     print 'Value saved in "%s"'%f
183     numpy.savetxt(f,v)
184     import Gnuplot
185     global ifig,gp
186     try:
187         ifig += 1
188         gp('set style data lines')
189     except:
190         ifig = 0
191         gp = Gnuplot.Gnuplot(persist=1)
192         gp('set style data lines')
193     gp('set title  "%s (Figure %i)"'%(info,ifig))
194     gp.plot( Gnuplot.Data( v, with_='lines lw 2' ) )
195
196 .. index:: single: ValueRMS (Observer)
197
198 Modèle **ValueRMS** :
199 .....................
200
201 ::
202
203     import numpy
204     v = numpy.matrix( numpy.ravel( var[-1] ) )
205     print info, float( numpy.sqrt((1./v.size)*(v*v.T)) )
206
207 .. index:: single: ValueSaver (Observer)
208
209 Modèle **ValueSaver** :
210 .......................
211
212 ::
213
214     import numpy, re
215     v=numpy.array(var[-1], ndmin=1)
216     global istep
217     try:
218         istep += 1
219     except:
220         istep = 0
221     f='/tmp/value_%s_%05i.txt'%(info,istep)
222     f=re.sub('\s','_',f)
223     print 'Value saved in "%s"'%f
224     numpy.savetxt(f,v)
225
226 .. index:: single: ValueSerieGnuPlotter (Observer)
227
228 Modèle **ValueSerieGnuPlotter** :
229 .................................
230
231 ::
232
233     import numpy, Gnuplot
234     v=numpy.array(var[:],  ndmin=1)
235     global ifig, gp
236     try:
237         ifig += 1
238         gp('set style data lines')
239     except:
240         ifig = 0
241         gp = Gnuplot.Gnuplot(persist=1)
242         gp('set style data lines')
243     gp('set title  "%s (Figure %i)"'%(info,ifig))
244     gp.plot( Gnuplot.Data( v, with_='lines lw 2' ) )
245
246 .. index:: single: ValueSeriePrinter (Observer)
247
248 Modèle **ValueSeriePrinter** :
249 ..............................
250
251 Imprime sur la sortie standard la série des valeurs de la variable.
252
253 ::
254
255     print info, var[:]
256
257 .. index:: single: ValueSeriePrinterAndGnuPlotter (Observer)
258
259 Modèle **ValueSeriePrinterAndGnuPlotter** :
260 ...........................................
261
262 ::
263
264     print info, var[:] 
265     import numpy, Gnuplot
266     v=numpy.array(var[:],  ndmin=1)
267     global ifig,gp
268     try:
269         ifig += 1
270         gp('set style data lines')
271     except:
272         ifig = 0
273         gp = Gnuplot.Gnuplot(persist=1)
274         gp('set style data lines')
275     gp('set title  "%s (Figure %i)"'%(info,ifig))
276     gp.plot( Gnuplot.Data( v, with_='lines lw 2' ) )
277
278 .. index:: single: ValueSeriePrinterAndSaver (Observer)
279
280 Modèle **ValueSeriePrinterAndSaver** :
281 ......................................
282
283 ::
284
285     import numpy, re
286     v=numpy.array(var[:],  ndmin=1)
287     print info,v
288     global istep
289     try:
290         istep += 1
291     except:
292         istep = 0
293     f='/tmp/value_%s_%05i.txt'%(info,istep)
294     f=re.sub('\s','_',f)
295     print 'Value saved in "%s"'%f
296     numpy.savetxt(f,v)
297
298 .. index:: single: ValueSeriePrinterSaverAndGnuPlotter (Observer)
299
300 Modèle **ValueSeriePrinterSaverAndGnuPlotter** :
301 ................................................
302
303 ::
304
305     print info, var[:] 
306     import numpy, re
307     v=numpy.array(var[:],  ndmin=1)
308     global istep
309     try:
310         istep += 1
311     except:
312         istep = 0
313     f='/tmp/value_%s_%05i.txt'%(info,istep)
314     f=re.sub('\s','_',f)
315     print 'Value saved in "%s"'%f
316     numpy.savetxt(f,v)
317     import Gnuplot
318     global ifig,gp
319     try:
320         ifig += 1
321         gp('set style data lines')
322     except:
323         ifig = 0
324         gp = Gnuplot.Gnuplot(persist=1)
325         gp('set style data lines')
326     gp('set title  "%s (Figure %i)"'%(info,ifig))
327     gp.plot( Gnuplot.Data( v, with_='lines lw 2' ) )
328
329 .. index:: single: ValueSerieSaver (Observer)
330
331 Modèle **ValueSerieSaver** :
332 ............................
333
334 ::
335
336     import numpy, re
337     v=numpy.array(var[:],  ndmin=1)
338     global istep
339     try:
340         istep += 1
341     except:
342         istep = 0
343     f='/tmp/value_%s_%05i.txt'%(info,istep)
344     f=re.sub('\s','_',f)
345     print 'Value saved in "%s"'%f
346     numpy.savetxt(f,v)
347
348 .. index:: single: ValueStandardError (Observer)
349
350 Modèle **ValueStandardError** :
351 ...............................
352
353 ::
354
355     import numpy
356     print info, numpy.nanstd(var[-1])
357
358 .. index:: single: ValueVariance (Observer)
359
360 Modèle **ValueVariance** :
361 ..........................
362
363 ::
364
365     import numpy
366     print info, numpy.nanvar(var[-1])