Salome HOME
Extending sampling test algorithm
[modules/adao.git] / doc / en / advanced.rst
1 ..
2    Copyright (C) 2008-2014 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 .. _section_advanced:
25
26 ================================================================================
27 **[DocU]** Advanced usage of the ADAO module
28 ================================================================================
29
30 This section presents advanced methods to use the ADAO module, how to get more
31 information during calculation, or how to use it without the graphical user
32 interface (GUI). It requires to know how to find files or commands included
33 inside the whole SALOME installation. All the names to be replaced by user are
34 indicated by the syntax ``<...>``.
35
36 Converting and executing an ADAO command file (JDC) using a shell script
37 ------------------------------------------------------------------------
38
39 It is possible to convert and execute an ADAO command file (JDC, or ".comm/.py"
40 files pair, which resides in ``<ADAO JDC file directory>``) automatically by
41 using a template shell script containing all the required steps. The user has to
42 know where are the main SALOME launching files, and in particular the
43 ``runAppli`` one. The directory in which this script resides is symbolically
44 named ``<SALOME main installation dir>`` and has to be replaced by the good one
45 in the shell file template.
46
47 When an ADAO command file is build by the ADAO GUI EFICAS editor and saved, if
48 it is named for example "AdaoStudy1.comm", then a companion file named
49 "AdaoStudy1.py" is automatically created in the same directory. It is named
50 ``<ADAO Python file>`` in the template, and it is converted to YACS as an
51 ``<ADAO YACS xml scheme>``. After that, it can be executed in console mode using
52 the standard YACS console command (see YACS documentation for more information).
53
54 In the example, we choose to start and stop the SALOME application server in the
55 same script, which is not necessary, but useful to avoid stalling SALOME
56 sessions. We choose also to remove the ``<ADAO YACS xml scheme>`` file because
57 it is a generated one. The user of this script only need to replace the text
58 between these symbols ``<...>``.
59
60 The template of the shell script is the following::
61
62     #!/bin/bash
63     export USERDIR=<ADAO JDC file directory>
64     export SALOMEDIR=<SALOME main installation directory>
65     $SALOMEDIR/runAppli -k -t
66     $SALOMEDIR/runSession python \
67         $SALOMEDIR/bin/salome/AdaoYacsSchemaCreator.py \
68         $USERDIR/<ADAO Python file> $USERDIR/<ADAO YACS xml scheme>
69     $SALOMEDIR/runSession driver $USERDIR/<ADAO YACS xml scheme>
70     $SALOMEDIR/runSession killSalome.py
71     rm -f $USERDIR/<ADAO YACS xml scheme>
72
73 Standard output and errors come on console.
74
75 Running an ADAO calculation scheme in YACS using a TUI user mode
76 ----------------------------------------------------------------
77
78 This section describes how to execute in TUI (Text User Interface) mode a YACS
79 calculation scheme, obtained using the ADAO "Export to YACS" function. It uses
80 the standard YACS TUI mode, which is briefly recalled here (see YACS
81 documentation for more information) through a simple example. As described in
82 documentation, a XML scheme can be loaded in a Python. We give here a whole
83 sequence of command lines to test the validity of the scheme before executing
84 it, adding some initial supplementary ones to explicitly load the types catalog
85 to avoid weird difficulties::
86
87     import pilot
88     import SALOMERuntime
89     import loader
90     SALOMERuntime.RuntimeSALOME_setRuntime()
91
92     r = pilot.getRuntime()
93     xmlLoader = loader.YACSLoader()
94     xmlLoader.registerProcCataLoader()
95     try:
96      catalogAd = r.loadCatalog("proc", "<ADAO YACS xml scheme>")
97     except:
98       pass
99     r.addCatalog(catalogAd)
100
101     try:
102         p = xmlLoader.load("<ADAO YACS xml scheme>")
103     except IOError,ex:
104         print "IO exception:",ex
105
106     logger = p.getLogger("parser")
107     if not logger.isEmpty():
108         print "The imported file has errors :"
109         print logger.getStr()
110
111     if not p.isValid():
112         print "The schema is not valid and can not be executed"
113         print p.getErrorReport()
114
115     info=pilot.LinkInfo(pilot.LinkInfo.ALL_DONT_STOP)
116     p.checkConsistency(info)
117     if info.areWarningsOrErrors():
118         print "The schema is not consistent and can not be executed"
119         print info.getGlobalRepr()
120
121     e = pilot.ExecutorSwig()
122     e.RunW(p)
123     if p.getEffectiveState() != pilot.DONE:
124         print p.getErrorReport()
125
126 This method allows for example to edit the YACS XML scheme in TUI, or to gather
127 results for further use.
128
129 Getting information on special variables during the ADAO calculation in YACS
130 -----------------------------------------------------------------------------
131
132 .. index:: single: Observer
133 .. index:: single: Observers
134 .. index:: single: Observer Template
135
136 Some special internal optimization variables, used during calculations, can be
137 monitored during the ADAO calculation in YACS. These variables can be printed,
138 plotted, saved, etc. This can be done using "*observers*", that are scripts,
139 each associated with one variable. In order to use this feature, the user has to
140 build scripts using as standard inputs (e.g. available in the namespace) the
141 variables ``var`` and ``info``. The variable ``var`` is to be used in the same
142 way as for the final ADD object, that is as a list/tuple object.
143
144 Some templates are available when editing the ADAO case in EFICAS editor. These
145 simple scripts can be customized by the user, either at the EFICAS edition
146 stage, or at the YACS edition stage, to improve the tuning of the ADAO
147 calculation in YACS.
148
149 As an example, here is one very simple script (similar to the "*ValuePrinter*"
150 template) used to print the value of one monitored variable::
151
152     print "    --->",info," Value =",var[-1]
153
154 Stored in a Python file, this script can be associated to each variable
155 available in the "*SELECTION*" keyword of the "*Observers*" command:
156 "*Analysis*", "*CurrentState*", "*CostFunction*"... The current value of the
157 variable will be printed at each step of the optimization or assimilation
158 algorithm. The observers can embed plotting capabilities, storage, complex
159 printing, statistical treatment, etc.
160
161 Getting more information when running a calculation
162 ---------------------------------------------------
163
164 When running a calculation, useful data and messages are logged. There are two
165 ways to obtain theses information.
166
167 The first one, and the preferred way, is to use the built-in variable "*Debug*"
168 available in every ADAO case. It is available through the edition GUI of the
169 module. Setting it to "*1*" will send messages in the log window of the YACS
170 scheme execution.
171
172 The second one consist in using the "*logging*" native module of Python (see the
173 Python documentation http://docs.python.org/library/logging.html for more
174 information on this module). Everywhere in the YACS scheme, mainly through the
175 scripts entries, the user can set the logging level in accordance to the needs
176 of detailed information. The different logging levels are: "*DEBUG*", "*INFO*",
177 "*WARNING*", "*ERROR*", "*CRITICAL*". All the information flagged with a
178 certain level will be printed for whatever activated level above this particular
179 one (included). The easiest way is to change the log level by using the
180 following Python lines::
181
182     import logging
183     logging.getLogger().setLevel(logging.DEBUG)
184
185 The standard logging module default level is "*WARNING*", the default level in
186 the ADAO module is "*INFO*". 
187
188 It is also recommended to include some logging or debug mechanisms in the
189 simulation code, and use them in conjunction with the two previous methods. But
190 be careful not to store too big variables because it cost time, whatever logging
191 level is chosen (that is, even if these variables are not printed).
192
193 Accelerating numerical derivatives calculations by using a parallel mode
194 ------------------------------------------------------------------------
195
196 When setting an operator, as described in :ref:`section_reference`, the user can
197 choose a functional form "*ScriptWithOneFunction*". This form explicitly leads
198 to approximate the tangent and adjoint operators by a finite differences
199 calculation. It requires several calls to the direct operator (user defined
200 function), at least as many times as the dimension of the state vector. This are
201 these calls that can potentially be executed in parallel.
202
203 Under some conditions, it is then possible to accelerate the numerical
204 derivatives calculations by using a parallel mode for the finite differences
205 approximation. When setting up an ADAO case, it is done by adding the optional
206 sub-command "*EnableMultiProcessing*", set to "1", for the
207 "*SCRIPTWITHONEFUNCTION*" command in the operator definition. The parallel mode
208 will only use local resources (both multi-cores or multi-processors) of the
209 computer on which SALOME is running, requiring as many resources as available.
210 By default, this parallel mode is disabled ("*EnableMultiProcessing=0*").
211
212 The main conditions to perform parallel calculations come from the user defined
213 function, that represents the direct operator. This function has at least to be
214 "thread safe" to be executed in Python parallel environment (notions out of
215 scope of this paragraph). It is not obvious to give general rules, so it's
216 recommended, for the user who enable this internal parallelism, to carefully
217 verify his function and the obtained results.
218
219 From a user point of view, some conditions, that have to be met to set up
220 parallel calculations for tangent and the adjoint operators approximations, are
221 the following ones:
222
223 #. The dimension of the state vector is more than 2 or 3.
224 #. Unitary calculation of user defined direct function "last for long time", that is, more than few minutes.
225 #. The user defined direct function doesn't already use parallelism (or parallel execution is disabled in the user calculation).
226 #. The user defined direct function doesn't requires read/write access to common resources, mainly stored data or memory capacities.
227
228 If these conditions are satisfied, the user can choose to enable the internal
229 parallelism for the numerical derivative calculations. Despite the simplicity of
230 activating, by setting one variable only, the user is urged to verify the
231 results of its calculations. One must at least doing them one time with
232 parallelism enabled, and an another time with parallelism disabled, to compare
233 the results. If it does fail somewhere, you have to know that this parallel
234 scheme is working for complex codes, like *Code_Aster* in *SalomeMeca*
235 [SalomeMeca]_ for example. So check your operator function before and during
236 enabling parallelism...
237
238 **In case of doubt, it is recommended NOT TO ACTIVATE this parallelism.**
239
240 Switching from a version of ADAO to a newer one
241 -----------------------------------------------
242
243 The ADAO module and its ".comm" case files are identified by versions, with
244 "Major", "Minor" and "Revision" characteristics. A particular version is
245 numbered as "Major.Minor.Revision", with strong link with the numbering of the
246 SALOME platform.
247
248 Each version "Major.Minor.Revision" of the ADAO module can read ADAO case files
249 of the previous minor version "Major.Minor-1.*". In general, it can also read
250 ADAO case files of all the previous minor versions for one major branch, but it
251 is not guaranteed for all the commands or keywords. In general also, an ADAO
252 case file for one version can not be read by a previous minor or major version
253 of the ADAO module.
254
255 Switching from 7.3 to 7.4
256 +++++++++++++++++++++++++
257
258 There is no known incompatibility for the ADAO case files. The upgrade procedure
259 is to read the old ADAO case file with the new SALOME/ADAO module, and save it
260 with a new name.
261
262
263 Switching from 7.2 to 7.3
264 +++++++++++++++++++++++++
265
266 There is no known incompatibility for the ADAO case files. The upgrade procedure
267 is to read the old ADAO case file with the new SALOME/ADAO module, and save it
268 with a new name.
269
270 Switching from 6.6 to 7.2
271 +++++++++++++++++++++++++
272
273 There is no known incompatibility for the ADAO case files. The upgrade procedure
274 is to read the old ADAO case file with the new SALOME/ADAO module, and save it
275 with a new name.
276
277 There is one incompatibility introduced for the post-processing or observer
278 script files. The old syntax to call a result object, such as the "*Analysis*"
279 one (in a script provided through the "*UserPostAnalysis*" keyword), was for
280 example::
281
282     Analysis = ADD.get("Analysis").valueserie(-1)
283     Analysis = ADD.get("Analysis").valueserie()
284
285 The new syntax is entirely similar to the (classical) one of a list or tuple
286 object::
287
288     Analysis = ADD.get("Analysis")[-1]
289     Analysis = ADD.get("Analysis")[:]
290
291 The post-processing scripts has to be modified.
292
293 Switching from 6.5 to 6.6
294 +++++++++++++++++++++++++
295
296 There is no known incompatibility for the ADAO case file. The upgrade procedure
297 is to read the old ADAO case file with the new SALOME/ADAO module, and save it
298 with a new name.
299
300 There is one incompatibility introduced for the naming of operators used to for
301 the observation operator. The new mandatory names are "*DirectOperator*",
302 "*TangentOperator*" and "*AdjointOperator*", as described in the last subsection
303 of the chapter :ref:`section_reference`. The operator scripts has to be
304 modified.
305
306 Switching from 6.4 to 6.5
307 +++++++++++++++++++++++++
308
309 There is no known incompatibility for the ADAO case file or the accompanying
310 scripts. The upgrade procedure is to read the old ADAO case file with the new
311 SALOME/ADAO module, and save it with a new name.
312
313 Switching from 6.3 to 6.4
314 +++++++++++++++++++++++++
315
316 There is no known incompatibility for the ADAO case file or the accompanying
317 scripts. The upgrade procedure is to read the old ADAO case file with the new
318 SALOME/ADAO module, and save it with a new name.