2 Copyright (C) 2008-2015 EDF R&D
4 This file is part of SALOME ADAO module.
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.
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.
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
20 See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D
24 .. _ref_observers_requirements:
26 Exigences pour les fonctions décrivant un "*observer*"
27 ------------------------------------------------------
29 .. index:: single: Observer
30 .. index:: single: Observer Template
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.
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 :
42 .. eficas_observer_nodetype:
43 .. image:: images/eficas_observer_nodetype.png
47 **Choisir le type d'entrée**
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.
57 Forme générale d'un script permettant de définir un *observer*
58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
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.
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::
69 print " --->",info," Value =",var[-1]
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.
78 On donne ci-aprés l'identifiant et le contenu de chaque modèle disponible.
80 Inventaire des modèles d'*observer* disponibles ("*Template*")
81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
83 .. index:: single: ValueGnuPlotter (Observer)
85 Modèle **ValueGnuPlotter** :
86 ............................
91 v=numpy.array(var[-1], ndmin=1)
95 gp('set style data lines')
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' ) )
103 .. index:: single: ValueMean (Observer)
105 Modèle **ValueMean** :
106 ......................
111 print info, numpy.nanmean(var[-1])
113 .. index:: single: ValuePrinter (Observer)
115 Modèle **ValuePrinter** :
116 .........................
118 Imprime sur la sortie standard la valeur courante de la variable.
124 .. index:: single: ValuePrinterAndGnuPlotter (Observer)
126 Modèle **ValuePrinterAndGnuPlotter** :
127 ......................................
132 import numpy, Gnuplot
133 v=numpy.array(var[-1], ndmin=1)
137 gp('set style data lines')
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' ) )
145 .. index:: single: ValuePrinterAndSaver (Observer)
147 Modèle **ValuePrinterAndSaver** :
148 .................................
153 v=numpy.array(var[-1], ndmin=1)
160 f='/tmp/value_%s_%05i.txt'%(info,istep)
162 print 'Value saved in "%s"'%f
165 .. index:: single: ValuePrinterSaverAndGnuPlotter (Observer)
167 Modèle **ValuePrinterSaverAndGnuPlotter** :
168 ...........................................
174 v=numpy.array(var[-1], ndmin=1)
180 f='/tmp/value_%s_%05i.txt'%(info,istep)
182 print 'Value saved in "%s"'%f
188 gp('set style data lines')
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' ) )
196 .. index:: single: ValueRMS (Observer)
198 Modèle **ValueRMS** :
199 .....................
204 v = numpy.matrix( numpy.ravel( var[-1] ) )
205 print info, float( numpy.sqrt((1./v.size)*(v*v.T)) )
207 .. index:: single: ValueSaver (Observer)
209 Modèle **ValueSaver** :
210 .......................
215 v=numpy.array(var[-1], ndmin=1)
221 f='/tmp/value_%s_%05i.txt'%(info,istep)
223 print 'Value saved in "%s"'%f
226 .. index:: single: ValueSerieGnuPlotter (Observer)
228 Modèle **ValueSerieGnuPlotter** :
229 .................................
233 import numpy, Gnuplot
234 v=numpy.array(var[:], ndmin=1)
238 gp('set style data lines')
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' ) )
246 .. index:: single: ValueSeriePrinter (Observer)
248 Modèle **ValueSeriePrinter** :
249 ..............................
251 Imprime sur la sortie standard la série des valeurs de la variable.
257 .. index:: single: ValueSeriePrinterAndGnuPlotter (Observer)
259 Modèle **ValueSeriePrinterAndGnuPlotter** :
260 ...........................................
265 import numpy, Gnuplot
266 v=numpy.array(var[:], ndmin=1)
270 gp('set style data lines')
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' ) )
278 .. index:: single: ValueSeriePrinterAndSaver (Observer)
280 Modèle **ValueSeriePrinterAndSaver** :
281 ......................................
286 v=numpy.array(var[:], ndmin=1)
293 f='/tmp/value_%s_%05i.txt'%(info,istep)
295 print 'Value saved in "%s"'%f
298 .. index:: single: ValueSeriePrinterSaverAndGnuPlotter (Observer)
300 Modèle **ValueSeriePrinterSaverAndGnuPlotter** :
301 ................................................
307 v=numpy.array(var[:], ndmin=1)
313 f='/tmp/value_%s_%05i.txt'%(info,istep)
315 print 'Value saved in "%s"'%f
321 gp('set style data lines')
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' ) )
329 .. index:: single: ValueSerieSaver (Observer)
331 Modèle **ValueSerieSaver** :
332 ............................
337 v=numpy.array(var[:], ndmin=1)
343 f='/tmp/value_%s_%05i.txt'%(info,istep)
345 print 'Value saved in "%s"'%f
348 .. index:: single: ValueStandardError (Observer)
350 Modèle **ValueStandardError** :
351 ...............................
356 print info, numpy.nanstd(var[-1])
358 .. index:: single: ValueVariance (Observer)
360 Modèle **ValueVariance** :
361 ..........................
366 print info, numpy.nanvar(var[-1])