1 <?xml version='1.0' encoding='utf-8' ?>
3 Copyright (C) 2008-2018 EDF R&D
5 This file is part of SALOME ADAO module
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License.
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D
27 <objref name="computeAD" id="python:computeAD:1.0">
31 <!-- Types for parametric computations -->
32 <!-- TODO On devrait pouvoir le lire depuis le KERNEL !!!-->
33 <type name="long" kind="int"/>
34 <struct name="SALOME_TYPES/Parameter">
35 <member type="string" name="name"></member>
36 <member type="pyobj" name="value"></member>
38 <sequence content="SALOME_TYPES/Parameter" name="SALOME_TYPES/ParameterList"></sequence>
39 <sequence content="double" name="SALOME_TYPES/Variable"></sequence>
40 <sequence content="SALOME_TYPES/Variable" name="SALOME_TYPES/VariableSequence"></sequence>
41 <sequence content="SALOME_TYPES/VariableSequence" name="SALOME_TYPES/StateSequence"></sequence>
42 <sequence content="SALOME_TYPES/StateSequence" name="SALOME_TYPES/TimeSequence"></sequence>
43 <sequence content="string" name="SALOME_TYPES/VarList"></sequence>
44 <struct name="SALOME_TYPES/ParametricInput">
45 <member type="SALOME_TYPES/VarList" name="inputVarList"></member>
46 <member type="SALOME_TYPES/VarList" name="outputVarList"></member>
47 <member type="SALOME_TYPES/TimeSequence" name="inputValues"></member>
48 <member type="SALOME_TYPES/ParameterList" name="specificParameters"></member>
50 <struct name="SALOME_TYPES/ParametricOutput">
51 <member type="SALOME_TYPES/TimeSequence" name="outputValues"></member>
52 <member type="SALOME_TYPES/ParameterList" name="specificOutputInfos"></member>
53 <member type="long" name="returnCode"></member>
54 <member type="string" name="errorMessage"></member>
58 <inline name="CreateAssimilationStudy">
62 import sys, numpy, logging
63 logging.debug("CREATE YI Entering in CreateAssimilationStudy")
64 print("Entering in the assimilation study")
65 print("Name is set to........:", Name)
66 print("Algorithm is set to...:", Algorithm)
69 # Create Assimilation study
70 if sys.version_info.major > 2:
72 from daYacsIntegration.daStudy import *
73 assim_study = daStudy(Name, Algorithm, Debug)
75 logging.debug("CREATE YI Data entered are:")
77 # Algorithm parameters
78 if "AlgorithmParameters" in locals():
79 logging.debug("CREATE YI AlgorithmParameters is %s"%AlgorithmParameters)
80 assim_study.setYIAlgorithmParameters(AlgorithmParameters)
83 if "Background" in locals():
84 logging.debug("CREATE YI Background is set")
85 logging.debug("CREATE YI BackgroundType is %s"%BackgroundType)
86 logging.debug("CREATE YI BackgroundStored is %s"%BackgroundStored)
87 assim_study.setYIBackgroundType(BackgroundType)
88 assim_study.setYIBackgroundStored(BackgroundStored)
89 assim_study.setYIBackground(Background)
92 if "CheckingPoint" in locals():
93 logging.debug("CREATE YI CheckingPoint is set")
94 logging.debug("CREATE YI CheckingPointType is %s"%CheckingPointType)
95 logging.debug("CREATE YI CheckingPointStored is %s"%CheckingPointStored)
96 assim_study.setYICheckingPointType(CheckingPointType)
97 assim_study.setYICheckingPointStored(CheckingPointStored)
98 assim_study.setYICheckingPoint(CheckingPoint)
101 if "ControlInput" in locals():
102 logging.debug("CREATE YI ControlInput is set")
103 logging.debug("CREATE YI ControlInputType is %s"%ControlInputType)
104 logging.debug("CREATE YI ControlInputStored is %s"%ControlInputStored)
105 assim_study.setYIControlInputType(ControlInputType)
106 assim_study.setYIControlInputStored(ControlInputStored)
107 assim_study.setYIControlInput(ControlInput)
110 if "Observation" in locals():
111 logging.debug("CREATE YI Observation is set")
112 logging.debug("CREATE YI ObservationType is %s"%ObservationType)
113 logging.debug("CREATE YI ObservationStored is %s"%ObservationStored)
114 assim_study.setYIObservationType(ObservationType)
115 assim_study.setYIObservationStored(ObservationStored)
116 assim_study.setYIObservation(Observation)
119 if "BackgroundError" in locals():
120 logging.debug("CREATE YI BackgroundError is set")
121 logging.debug("CREATE YI BackgroundErrorType is %s"%BackgroundErrorType)
122 logging.debug("CREATE YI BackgroundErrorStored is %s"%BackgroundErrorStored)
123 assim_study.setYIBackgroundErrorType(BackgroundErrorType)
124 assim_study.setYIBackgroundErrorStored(BackgroundErrorStored)
125 assim_study.setYIBackgroundError(BackgroundError)
128 if "ObservationError" in locals():
129 logging.debug("CREATE YI ObservationError is set")
130 logging.debug("CREATE YI ObservationErrorType is %s"%ObservationErrorType)
131 logging.debug("CREATE YI ObservationErrorStored is %s"%ObservationErrorStored)
132 assim_study.setYIObservationErrorType(ObservationErrorType)
133 assim_study.setYIObservationErrorStored(ObservationErrorStored)
134 assim_study.setYIObservationError(ObservationError)
137 if "EvolutionError" in locals():
138 logging.debug("CREATE YI EvolutionError is set")
139 logging.debug("CREATE YI EvolutionErrorType is %s"%EvolutionErrorType)
140 logging.debug("CREATE YI EvolutionErrorStored is %s"%EvolutionErrorStored)
141 assim_study.setYIEvolutionErrorType(EvolutionErrorType)
142 assim_study.setYIEvolutionErrorStored(EvolutionErrorStored)
143 assim_study.setYIEvolutionError(EvolutionError)
145 # ObservationOperator
146 ObservationOperatorOk = 0
147 if "ObservationOperator" in locals():
148 logging.debug("CREATE YI ObservationOperator is set")
149 logging.debug("CREATE YI ObservationOperatorType is %s"%ObservationOperatorType)
150 assim_study.setYIObservationOperatorType("Matrix", ObservationOperatorType)
151 assim_study.setYIObservationOperator("Matrix", ObservationOperator)
152 ObservationOperatorOk = 1
154 if ObservationOperatorOk == 0:
155 if "ObservationOperatorDirect" in locals():
156 logging.debug("CREATE YI ObservationOperatorDirect is %s"%ObservationOperatorDirect)
157 assim_study.setYIObservationOperatorType("Direct", "Function")
158 assim_study.setYIObservationOperator("Direct", ObservationOperatorDirect)
159 if "ObservationOperatorTangent" in locals():
160 logging.debug("CREATE YI ObservationOperatorTangent is %s"%ObservationOperatorTangent)
161 assim_study.setYIObservationOperatorType("Tangent", "Function")
162 assim_study.setYIObservationOperator("Tangent", ObservationOperatorTangent)
163 if "ObservationOperatorAdjoint" in locals():
164 logging.debug("CREATE YI ObservationOperatorAdjoint is %s"%ObservationOperatorAdjoint)
165 assim_study.setYIObservationOperatorType("Adjoint", "Function")
166 assim_study.setYIObservationOperator("Adjoint", ObservationOperatorAdjoint)
170 if "EvolutionModel" in locals():
171 logging.debug("CREATE YI EvolutionModel is set")
172 logging.debug("CREATE YI EvolutionModelType is %s"%EvolutionModelType)
173 assim_study.setYIEvolutionModelType("Matrix", EvolutionModelType)
174 assim_study.setYIEvolutionModel("Matrix", EvolutionModel)
177 if EvolutionModelOk == 0:
178 if "EvolutionModelDirect" in locals():
179 logging.debug("CREATE YI EvolutionModelDirect is %s"%EvolutionModelDirect)
180 assim_study.setYIEvolutionModelType("Direct", "Function")
181 assim_study.setYIEvolutionModel("Direct", EvolutionModelDirect)
182 if "EvolutionModelTangent" in locals():
183 logging.debug("CREATE YI EvolutionModelTangent is %s"%EvolutionModelTangent)
184 assim_study.setYIEvolutionModelType("Tangent", "Function")
185 assim_study.setYIEvolutionModel("Tangent", EvolutionModelTangent)
186 if "EvolutionModelAdjoint" in locals():
187 logging.debug("CREATE YI EvolutionModelAdjoint is %s"%EvolutionModelAdjoint)
188 assim_study.setYIEvolutionModelType("Adjoint", "Function")
189 assim_study.setYIEvolutionModel("Adjoint", EvolutionModelAdjoint)
192 for name, size in zip(InputVariablesNames, InputVariablesSizes):
193 assim_study.setYIInputVariable(name, size)
194 for name, size in zip(OutputVariablesNames, OutputVariablesSizes):
195 assim_study.setYIOutputVariable(name, size)
198 logging.debug("CREATE YI Observers keys are %s"%observers.keys())
199 # Adding observers to the study
200 for observer_name in observers.keys():
203 number = str(observers[observer_name]["number"])
204 if "scheduler" in observers[observer_name].keys():
205 scheduler = observers[observer_name]["scheduler"]
206 if "info" in observers[observer_name].keys():
207 info = observers[observer_name]["info"]
208 assim_study.addYIObserver(observer_name, scheduler, info, number)
210 except Exception as e:
211 if isinstance(e, SyntaxError): msg = "at %s: %s"%(e.offset, e.text)
213 raise ValueError("during execution, the following error occurs:\n\n%s %s\n\nSee also the potential messages, which can show the origin of the above error, in the launching terminal."%(str(e),msg))
219 <inport name="Name" type="string"/>
220 <inport name="Algorithm" type="string"/>
221 <inport name="Debug" type="bool"/>
222 <inport name="InputVariablesNames" type="stringvec"/>
223 <inport name="InputVariablesSizes" type="intvec"/>
224 <inport name="OutputVariablesNames" type="stringvec"/>
225 <inport name="OutputVariablesSizes" type="intvec"/>
226 <inport name="has_observers" type="bool"/>
227 <inport name="observers" type="pyobj"/>
228 <outport name="Study" type="pyobj"/>
231 <inline name="CreateNumpyMatrixFromString">
232 <script><code><![CDATA[
233 import numpy, logging
234 logging.debug("CREATE YI Entering in CreateNumpyMatrixFromString")
235 if (matrix_in_string.find("array")>-1) or (matrix_in_string.find("matrix")>-1):
236 matrix_in_string=matrix_in_string.replace("array","numpy.array")
237 matrix_in_string=matrix_in_string.replace("matrix","numpy.matrix")
238 exec("matrix="+matrix_in_string)
239 matrix = numpy.matrix(matrix)
241 matrix_in_string=matrix_in_string.replace("'","").replace('"','')
242 matrix = numpy.matrix(matrix_in_string)
244 logging.debug("CREATE YI Matrix is %s"%matrix)
246 <inport name="matrix_in_string" type="string"/>
247 <outport name="matrix" type="pyobj"/>
248 <outport name="type" type="string"/>
249 <outport name="stored" type="bool"/>
252 <inline name="CreateNumpyScalarSparseMatrixFromString">
253 <script><code><![CDATA[
254 import numpy, logging
255 logging.debug("CREATE YI Entering in CreateNumpyScalarSparseMatrixFromString")
256 if (matrix_in_string.find("array")>-1) or (matrix_in_string.find("matrix")>-1):
257 matrix_in_string=matrix_in_string.replace("array","numpy.array")
258 matrix_in_string=matrix_in_string.replace("matrix","numpy.matrix")
259 exec("matrix="+matrix_in_string)
260 matrix = numpy.matrix(matrix)
262 matrix_in_string=matrix_in_string.replace("'","").replace('"','')
263 matrix = numpy.matrix(matrix_in_string)
264 type = "ScalarSparseMatrix"
265 logging.debug("CREATE YI ScalarSparseMatrix is %s"%matrix)
267 <inport name="matrix_in_string" type="string"/>
268 <outport name="matrix" type="pyobj"/>
269 <outport name="type" type="string"/>
270 <outport name="stored" type="bool"/>
273 <inline name="CreateNumpyDiagonalSparseMatrixFromString">
274 <script><code><![CDATA[
275 import numpy, logging
276 logging.debug("CREATE YI Entering in CreateNumpyDiagonalSparseMatrixFromString")
277 if (matrix_in_string.find("array")>-1) or (matrix_in_string.find("matrix")>-1):
278 matrix_in_string=matrix_in_string.replace("array","numpy.array")
279 matrix_in_string=matrix_in_string.replace("matrix","numpy.matrix")
280 exec("matrix="+matrix_in_string)
281 matrix = numpy.matrix(matrix)
283 matrix_in_string=matrix_in_string.replace("'","").replace('"','')
284 matrix = numpy.matrix(matrix_in_string)
285 type = "DiagonalSparseMatrix"
286 logging.debug("CREATE YI DiagonalSparseMatrix is %s"%matrix)
288 <inport name="matrix_in_string" type="string"/>
289 <outport name="matrix" type="pyobj"/>
290 <outport name="type" type="string"/>
291 <outport name="stored" type="bool"/>
294 <inline name="CreateNumpyMatrixFromScript">
295 <script><code><![CDATA[
296 import logging, sys, os
297 logging.debug("CREATE YI Entering in CreateNumpyMatrixFromScript")
300 # Get file path and filename
302 if sys.path.count(studydir)==0 or (sys.path.count(studydir)>0 and sys.path.index(studydir)>0):
303 sys.path.insert(0,studydir)
306 filepath = os.path.dirname(script)
307 filename = os.path.basename(script)
308 module_name = os.path.splitext(filename)[0]
309 if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index(filepath)>0):
310 sys.path.insert(0,filepath)
313 <inport name="script" type="string"/>
314 <outport name="type" type="string"/>
315 <outport name="stored" type="bool"/>
318 <inline name="CreateNumpyScalarSparseMatrixFromScript">
319 <script><code><![CDATA[
320 import logging, sys, os
321 logging.debug("CREATE YI Entering in CreateNumpyScalarSparseMatrixFromScript")
322 type = "ScalarSparseMatrix"
324 # Get file path and filename
326 if sys.path.count(studydir)==0 or (sys.path.count(studydir)>0 and sys.path.index(studydir)>0):
327 sys.path.insert(0,studydir)
330 filepath = os.path.dirname(script)
331 filename = os.path.basename(script)
332 module_name = os.path.splitext(filename)[0]
333 if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index(filepath)>0):
334 sys.path.insert(0,filepath)
337 <inport name="script" type="string"/>
338 <outport name="type" type="string"/>
339 <outport name="stored" type="bool"/>
342 <inline name="CreateNumpyDiagonalSparseMatrixFromScript">
343 <script><code><![CDATA[
344 import logging, sys, os
345 logging.debug("CREATE YI Entering in CreateNumpyDiagonalSparseMatrixFromScript")
346 type = "DiagonalSparseMatrix"
348 # Get file path and filename
350 if sys.path.count(studydir)==0 or (sys.path.count(studydir)>0 and sys.path.index(studydir)>0):
351 sys.path.insert(0,studydir)
354 filepath = os.path.dirname(script)
355 filename = os.path.basename(script)
356 module_name = os.path.splitext(filename)[0]
357 if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index(filepath)>0):
358 sys.path.insert(0,filepath)
361 <inport name="script" type="string"/>
362 <outport name="type" type="string"/>
363 <outport name="stored" type="bool"/>
366 <inline name="CreateNumpyVectorFromString">
367 <script><code><![CDATA[
368 import numpy, logging
369 logging.debug("CREATE YI Entering in CreateNumpyVectorFromString")
370 if (vector_in_string.find("array")>-1) or (vector_in_string.find("matrix")>-1):
371 vector_in_string=vector_in_string.replace("array","numpy.array")
372 vector_in_string=vector_in_string.replace("matrix","numpy.matrix")
373 exec("vector="+vector_in_string)
374 vector = numpy.matrix(vector)
376 vector_in_string=vector_in_string.replace("'","").replace('"','')
377 vector = numpy.matrix(vector_in_string)
379 logging.debug("Vector is %s"%vector)
381 <inport name="vector_in_string" type="string"/>
382 <outport name="vector" type="pyobj"/>
383 <outport name="type" type="string"/>
384 <outport name="stored" type="bool"/>
387 <inline name="CreateNumpyVectorFromScript">
388 <script><code><![CDATA[
389 import logging, sys, os
390 logging.debug("CREATE YI Entering in CreateNumpyVectorFromScript")
393 # Get file path and filename
395 if sys.path.count(studydir)==0 or (sys.path.count(studydir)>0 and sys.path.index(studydir)>0):
396 sys.path.insert(0,studydir)
399 filepath = os.path.dirname(script)
400 filename = os.path.basename(script)
401 module_name = os.path.splitext(filename)[0]
402 if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index(filepath)>0):
403 sys.path.insert(0,filepath)
406 <inport name="script" type="string"/>
407 <outport name="type" type="string"/>
408 <outport name="stored" type="bool"/>
411 <inline name="CreateNumpyVectorSerieFromString">
412 <script><code><![CDATA[
413 import numpy, logging
414 logging.debug("CREATE YI Entering in CreateNumpyVectorSerieFromString")
415 vector_in_list = eval(str(vector_in_string),{},{})
416 vector = numpy.matrix(vector_in_list)
418 logging.debug("VectorSerie is %s"%vector)
420 <inport name="vector_in_string" type="string"/>
421 <outport name="vector" type="pyobj"/>
422 <outport name="type" type="string"/>
423 <outport name="stored" type="bool"/>
426 <inline name="CreateNumpyVectorSerieFromScript">
427 <script><code><![CDATA[
428 import logging, sys, os
429 logging.debug("CREATE YI Entering in CreateNumpyVectorSerieFromScript")
432 # Get file path and filename
434 if sys.path.count(studydir)==0 or (sys.path.count(studydir)>0 and sys.path.index(studydir)>0):
435 sys.path.insert(0,studydir)
438 filepath = os.path.dirname(script)
439 filename = os.path.basename(script)
440 module_name = os.path.splitext(filename)[0]
441 if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index(filepath)>0):
442 sys.path.insert(0,filepath)
445 <inport name="script" type="string"/>
446 <outport name="type" type="string"/>
447 <outport name="stored" type="bool"/>
450 <inline name="SimpleExecuteDirectAlgorithm">
451 <script><code><![CDATA[
453 logging.debug("EXECUTE Entering in SimpleExecuteDirectAlgorithm")
454 from daYacsIntegration.daStudy import *
455 ADD = Study.getResults()
458 <inport name="Study" type="pyobj"/>
459 <outport name="Study" type="pyobj"/>
462 <inline name="SimpleUserAnalysis">
463 <script><code><![CDATA[
464 #-*- coding: utf-8 -*-
466 logging.debug("TERMINATE Entering in SimpleUserAnalysis")
467 if sys.version_info.major < 3:
468 ADD = Study.getResults()
474 <inport name="Study" type="pyobj"/>
477 <inline name="FakeOptimizerLoopNode">
478 <script><code><![CDATA[
480 logging.debug("EXECUTE Entering in FakeOptimizerLoopNode")
483 <inport name="computation" type="SALOME_TYPES/ParametricInput"/>
484 <outport name="result" type="SALOME_TYPES/ParametricOutput"/>
487 <inline name="CreateDictFromString">
488 <script><code><![CDATA[
489 import logging, sys, os
490 logging.debug("CREATE YI Entering in CreateDictFromString")
491 dico = eval(dict_in_string)
493 <inport name="dict_in_string" type="string"/>
496 <inline name="CreateDictFromScript">
497 <script><code><![CDATA[
498 import logging, sys, os
499 logging.debug("CREATE YI Entering in CreateDictFromScript")
501 # Get file path and filename
503 if sys.path.count(studydir)==0 or (sys.path.count(studydir)>0 and sys.path.index(studydir)>0):
504 sys.path.insert(0,studydir)
507 filepath = os.path.dirname(script)
508 filename = os.path.basename(script)
509 module_name = os.path.splitext(filename)[0]
510 if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index(filepath)>0):
511 sys.path.insert(0,filepath)
514 <inport name="script" type="string"/>
517 <inline name="UserDataInitFromScript">
518 <script><code><![CDATA[
519 import logging, sys, os
520 logging.debug("CREATE YI Entering in UserDataInitFromScript")
522 # Get file path and filename
524 if sys.path.count(studydir)==0 or (sys.path.count(studydir)>0 and sys.path.index(studydir)>0):
525 sys.path.insert(0,studydir)
528 filepath = os.path.dirname(script)
529 filename = os.path.basename(script)
530 module_name = os.path.splitext(filename)[0]
531 if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index(filepath)>0):
532 sys.path.insert(0,filepath)
535 <inport name="script" type="string"/>
536 <outport name="init_data" type="pyobj"/>
539 <inline name="ReadForSwitchNode">
540 <script><code><![CDATA[import sys, logging
541 if sys.version_info.major > 3: import adao
542 logging.debug("CREATE YI Entering in ReadForSwitchNode")
543 logging.debug(" with input data : ",list(data["specificParameters"]))
545 for param in data["specificParameters"]:
546 if param["name"] == "switch_value":
547 switch_value = int(param["value"])
548 logging.debug(" switching to value : "+str(switch_value))
550 <inport name="data" type="SALOME_TYPES/ParametricInput"/>
551 <outport name="data" type="SALOME_TYPES/ParametricInput"/>
552 <outport name="switch_value" type="int"/>
555 <inline name="ExtractDataNode">
556 <script><code><![CDATA[import sys, logging
557 if sys.version_info.major > 3: import adao
558 logging.debug("TERMINATE Entering in ExtractDataNode")
559 from daCore.AssimilationStudy import AssimilationStudy
562 for param in data["specificParameters"]:
563 if param["name"] == "var":
565 if param["name"] == "info":
566 info = param["value"]
568 <inport name="data" type="SALOME_TYPES/ParametricInput"/>
569 <outport name="var" type="pyobj"/>
570 <outport name="info" type="pyobj"/>
573 <inline name="ObservationNodeString">
574 <script><code><![CDATA[]]></code></script>
575 <inport name="var" type="pyobj"/>
576 <inport name="info" type="pyobj"/>
579 <inline name="ObservationNodeFile">
580 <script><code><![CDATA[execfile(script)]]></code></script>
581 <inport name="var" type="pyobj"/>
582 <inport name="info" type="pyobj"/>
583 <inport name="script" type="string"/>
586 <inline name="EndObservationNode">
587 <script><code><![CDATA[
588 # Create a fake output object.
589 # An observer is always successful.
591 output["outputValues"] = [[[[]]]]
592 output["specificOutputInfos"] = []
593 output["returnCode"] = 0
594 output["errorMessage"] = ""
596 <outport name="output" type="SALOME_TYPES/ParametricOutput"/>
599 <inline name="SetObserversNode">
600 <script><code><![CDATA[
601 #print("Setting observers")
603 <outport name="has_observers" type="bool"/>
604 <outport name="observers" type="pyobj"/>