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="string" 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">
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
71 from daYacsIntegration.daStudy import *
72 assim_study = daStudy(Name, Algorithm, Debug)
74 logging.debug("CREATE YI Data entered are:")
76 # Algorithm parameters
77 if "AlgorithmParameters" in locals():
78 logging.debug("CREATE YI AlgorithmParameters is %s"%AlgorithmParameters)
79 assim_study.setYIAlgorithmParameters(AlgorithmParameters)
82 if "Background" in locals():
83 logging.debug("CREATE YI Background is set")
84 logging.debug("CREATE YI BackgroundType is %s"%BackgroundType)
85 logging.debug("CREATE YI BackgroundStored is %s"%BackgroundStored)
86 assim_study.setYIBackgroundType(BackgroundType)
87 assim_study.setYIBackgroundStored(BackgroundStored)
88 assim_study.setYIBackground(Background)
91 if "CheckingPoint" in locals():
92 logging.debug("CREATE YI CheckingPoint is set")
93 logging.debug("CREATE YI CheckingPointType is %s"%CheckingPointType)
94 logging.debug("CREATE YI CheckingPointStored is %s"%CheckingPointStored)
95 assim_study.setYICheckingPointType(CheckingPointType)
96 assim_study.setYICheckingPointStored(CheckingPointStored)
97 assim_study.setYICheckingPoint(CheckingPoint)
100 if "ControlInput" in locals():
101 logging.debug("CREATE YI ControlInput is set")
102 logging.debug("CREATE YI ControlInputType is %s"%ControlInputType)
103 logging.debug("CREATE YI ControlInputStored is %s"%ControlInputStored)
104 assim_study.setYIControlInputType(ControlInputType)
105 assim_study.setYIControlInputStored(ControlInputStored)
106 assim_study.setYIControlInput(ControlInput)
109 if "Observation" in locals():
110 logging.debug("CREATE YI Observation is set")
111 logging.debug("CREATE YI ObservationType is %s"%ObservationType)
112 logging.debug("CREATE YI ObservationStored is %s"%ObservationStored)
113 assim_study.setYIObservationType(ObservationType)
114 assim_study.setYIObservationStored(ObservationStored)
115 assim_study.setYIObservation(Observation)
118 if "BackgroundError" in locals():
119 logging.debug("CREATE YI BackgroundError is set")
120 logging.debug("CREATE YI BackgroundErrorType is %s"%BackgroundErrorType)
121 logging.debug("CREATE YI BackgroundErrorStored is %s"%BackgroundErrorStored)
122 assim_study.setYIBackgroundErrorType(BackgroundErrorType)
123 assim_study.setYIBackgroundErrorStored(BackgroundErrorStored)
124 assim_study.setYIBackgroundError(BackgroundError)
127 if "ObservationError" in locals():
128 logging.debug("CREATE YI ObservationError is set")
129 logging.debug("CREATE YI ObservationErrorType is %s"%ObservationErrorType)
130 logging.debug("CREATE YI ObservationErrorStored is %s"%ObservationErrorStored)
131 assim_study.setYIObservationErrorType(ObservationErrorType)
132 assim_study.setYIObservationErrorStored(ObservationErrorStored)
133 assim_study.setYIObservationError(ObservationError)
136 if "EvolutionError" in locals():
137 logging.debug("CREATE YI EvolutionError is set")
138 logging.debug("CREATE YI EvolutionErrorType is %s"%EvolutionErrorType)
139 logging.debug("CREATE YI EvolutionErrorStored is %s"%EvolutionErrorStored)
140 assim_study.setYIEvolutionErrorType(EvolutionErrorType)
141 assim_study.setYIEvolutionErrorStored(EvolutionErrorStored)
142 assim_study.setYIEvolutionError(EvolutionError)
144 # ObservationOperator
145 ObservationOperatorOk = 0
146 if "ObservationOperator" in locals():
147 logging.debug("CREATE YI ObservationOperator is set")
148 logging.debug("CREATE YI ObservationOperatorType is %s"%ObservationOperatorType)
149 assim_study.setYIObservationOperatorType("Matrix", ObservationOperatorType)
150 assim_study.setYIObservationOperator("Matrix", ObservationOperator)
151 ObservationOperatorOk = 1
153 if ObservationOperatorOk == 0:
154 if "ObservationOperatorDirect" in locals():
155 logging.debug("CREATE YI ObservationOperatorDirect is %s"%ObservationOperatorDirect)
156 assim_study.setYIObservationOperatorType("Direct", "Function")
157 assim_study.setYIObservationOperator("Direct", ObservationOperatorDirect)
158 if "ObservationOperatorTangent" in locals():
159 logging.debug("CREATE YI ObservationOperatorTangent is %s"%ObservationOperatorTangent)
160 assim_study.setYIObservationOperatorType("Tangent", "Function")
161 assim_study.setYIObservationOperator("Tangent", ObservationOperatorTangent)
162 if "ObservationOperatorAdjoint" in locals():
163 logging.debug("CREATE YI ObservationOperatorAdjoint is %s"%ObservationOperatorAdjoint)
164 assim_study.setYIObservationOperatorType("Adjoint", "Function")
165 assim_study.setYIObservationOperator("Adjoint", ObservationOperatorAdjoint)
169 if "EvolutionModel" in locals():
170 logging.debug("CREATE YI EvolutionModel is set")
171 logging.debug("CREATE YI EvolutionModelType is %s"%EvolutionModelType)
172 assim_study.setYIEvolutionModelType("Matrix", EvolutionModelType)
173 assim_study.setYIEvolutionModel("Matrix", EvolutionModel)
176 if EvolutionModelOk == 0:
177 if "EvolutionModelDirect" in locals():
178 logging.debug("CREATE YI EvolutionModelDirect is %s"%EvolutionModelDirect)
179 assim_study.setYIEvolutionModelType("Direct", "Function")
180 assim_study.setYIEvolutionModel("Direct", EvolutionModelDirect)
181 if "EvolutionModelTangent" in locals():
182 logging.debug("CREATE YI EvolutionModelTangent is %s"%EvolutionModelTangent)
183 assim_study.setYIEvolutionModelType("Tangent", "Function")
184 assim_study.setYIEvolutionModel("Tangent", EvolutionModelTangent)
185 if "EvolutionModelAdjoint" in locals():
186 logging.debug("CREATE YI EvolutionModelAdjoint is %s"%EvolutionModelAdjoint)
187 assim_study.setYIEvolutionModelType("Adjoint", "Function")
188 assim_study.setYIEvolutionModel("Adjoint", EvolutionModelAdjoint)
191 for name, size in zip(InputVariablesNames, InputVariablesSizes):
192 assim_study.setYIInputVariable(name, size)
193 for name, size in zip(OutputVariablesNames, OutputVariablesSizes):
194 assim_study.setYIOutputVariable(name, size)
197 logging.debug("CREATE YI Observers keys are %s"%observers.keys())
198 # Adding observers to the study
199 for observer_name in observers.keys():
202 number = str(observers[observer_name]["number"])
203 if "scheduler" in observers[observer_name].keys():
204 scheduler = observers[observer_name]["scheduler"]
205 if "info" in observers[observer_name].keys():
206 info = observers[observer_name]["info"]
207 assim_study.addYIObserver(observer_name, scheduler, info, number)
209 except Exception as e:
210 if isinstance(e, SyntaxError): msg = "at %s: %s"%(e.offset, e.text)
212 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))
218 <inport name="Name" type="string"/>
219 <inport name="Algorithm" type="string"/>
220 <inport name="Debug" type="bool"/>
221 <inport name="InputVariablesNames" type="stringvec"/>
222 <inport name="InputVariablesSizes" type="intvec"/>
223 <inport name="OutputVariablesNames" type="stringvec"/>
224 <inport name="OutputVariablesSizes" type="intvec"/>
225 <inport name="has_observers" type="bool"/>
226 <inport name="observers" type="pyobj"/>
227 <outport name="Study" type="pyobj"/>
230 <inline name="CreateNumpyMatrixFromString">
231 <script><code><![CDATA[
232 import numpy, logging
233 logging.debug("CREATE YI Entering in CreateNumpyMatrixFromString")
234 if (matrix_in_string.find("array")>-1) or (matrix_in_string.find("matrix")>-1):
235 matrix_in_string=matrix_in_string.replace("array","numpy.array")
236 matrix_in_string=matrix_in_string.replace("matrix","numpy.matrix")
237 exec("matrix="+matrix_in_string)
238 matrix = numpy.matrix(matrix)
240 matrix = numpy.matrix(matrix_in_string)
242 logging.debug("CREATE YI Matrix is %s"%matrix)
244 <inport name="matrix_in_string" type="string"/>
245 <outport name="matrix" type="pyobj"/>
246 <outport name="type" type="string"/>
247 <outport name="stored" type="bool"/>
250 <inline name="CreateNumpyScalarSparseMatrixFromString">
251 <script><code><![CDATA[
252 import numpy, logging
253 logging.debug("CREATE YI Entering in CreateNumpyScalarSparseMatrixFromString")
254 if (matrix_in_string.find("array")>-1) or (matrix_in_string.find("matrix")>-1):
255 matrix_in_string=matrix_in_string.replace("array","numpy.array")
256 matrix_in_string=matrix_in_string.replace("matrix","numpy.matrix")
257 exec("matrix="+matrix_in_string)
258 matrix = numpy.matrix(matrix)
260 matrix = numpy.matrix(matrix_in_string)
261 type = "ScalarSparseMatrix"
262 logging.debug("CREATE YI ScalarSparseMatrix is %s"%matrix)
264 <inport name="matrix_in_string" type="string"/>
265 <outport name="matrix" type="pyobj"/>
266 <outport name="type" type="string"/>
267 <outport name="stored" type="bool"/>
270 <inline name="CreateNumpyDiagonalSparseMatrixFromString">
271 <script><code><![CDATA[
272 import numpy, logging
273 logging.debug("CREATE YI Entering in CreateNumpyDiagonalSparseMatrixFromString")
274 if (matrix_in_string.find("array")>-1) or (matrix_in_string.find("matrix")>-1):
275 matrix_in_string=matrix_in_string.replace("array","numpy.array")
276 matrix_in_string=matrix_in_string.replace("matrix","numpy.matrix")
277 exec("matrix="+matrix_in_string)
278 matrix = numpy.matrix(matrix)
280 matrix = numpy.matrix(matrix_in_string)
281 type = "DiagonalSparseMatrix"
282 logging.debug("CREATE YI DiagonalSparseMatrix is %s"%matrix)
284 <inport name="matrix_in_string" type="string"/>
285 <outport name="matrix" type="pyobj"/>
286 <outport name="type" type="string"/>
287 <outport name="stored" type="bool"/>
290 <inline name="CreateNumpyMatrixFromScript">
291 <script><code><![CDATA[
292 import logging, sys, os
293 logging.debug("CREATE YI Entering in CreateNumpyMatrixFromScript")
296 # Get file path and filename
298 if sys.path.count(studydir)==0 or (sys.path.count(studydir)>0 and sys.path.index(studydir)>0):
299 sys.path.insert(0,studydir)
302 filepath = os.path.dirname(script)
303 filename = os.path.basename(script)
304 module_name = os.path.splitext(filename)[0]
305 if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index(filepath)>0):
306 sys.path.insert(0,filepath)
309 <inport name="script" type="string"/>
310 <outport name="type" type="string"/>
311 <outport name="stored" type="bool"/>
314 <inline name="CreateNumpyScalarSparseMatrixFromScript">
315 <script><code><![CDATA[
316 import logging, sys, os
317 logging.debug("CREATE YI Entering in CreateNumpyScalarSparseMatrixFromScript")
318 type = "ScalarSparseMatrix"
320 # Get file path and filename
322 if sys.path.count(studydir)==0 or (sys.path.count(studydir)>0 and sys.path.index(studydir)>0):
323 sys.path.insert(0,studydir)
326 filepath = os.path.dirname(script)
327 filename = os.path.basename(script)
328 module_name = os.path.splitext(filename)[0]
329 if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index(filepath)>0):
330 sys.path.insert(0,filepath)
333 <inport name="script" type="string"/>
334 <outport name="type" type="string"/>
335 <outport name="stored" type="bool"/>
338 <inline name="CreateNumpyDiagonalSparseMatrixFromScript">
339 <script><code><![CDATA[
340 import logging, sys, os
341 logging.debug("CREATE YI Entering in CreateNumpyDiagonalSparseMatrixFromScript")
342 type = "DiagonalSparseMatrix"
344 # Get file path and filename
346 if sys.path.count(studydir)==0 or (sys.path.count(studydir)>0 and sys.path.index(studydir)>0):
347 sys.path.insert(0,studydir)
350 filepath = os.path.dirname(script)
351 filename = os.path.basename(script)
352 module_name = os.path.splitext(filename)[0]
353 if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index(filepath)>0):
354 sys.path.insert(0,filepath)
357 <inport name="script" type="string"/>
358 <outport name="type" type="string"/>
359 <outport name="stored" type="bool"/>
362 <inline name="CreateNumpyVectorFromString">
363 <script><code><![CDATA[
364 import numpy, logging
365 logging.debug("CREATE YI Entering in CreateNumpyVectorFromString")
366 if (vector_in_string.find("array")>-1) or (vector_in_string.find("matrix")>-1):
367 vector_in_string=vector_in_string.replace("array","numpy.array")
368 vector_in_string=vector_in_string.replace("matrix","numpy.matrix")
369 exec("vector="+vector_in_string)
370 vector = numpy.matrix(vector)
372 vector = numpy.matrix(vector_in_string)
374 logging.debug("Vector is %s"%vector)
376 <inport name="vector_in_string" type="string"/>
377 <outport name="vector" type="pyobj"/>
378 <outport name="type" type="string"/>
379 <outport name="stored" type="bool"/>
382 <inline name="CreateNumpyVectorFromScript">
383 <script><code><![CDATA[
384 import logging, sys, os
385 logging.debug("CREATE YI Entering in CreateNumpyVectorFromScript")
388 # Get file path and filename
390 if sys.path.count(studydir)==0 or (sys.path.count(studydir)>0 and sys.path.index(studydir)>0):
391 sys.path.insert(0,studydir)
394 filepath = os.path.dirname(script)
395 filename = os.path.basename(script)
396 module_name = os.path.splitext(filename)[0]
397 if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index(filepath)>0):
398 sys.path.insert(0,filepath)
401 <inport name="script" type="string"/>
402 <outport name="type" type="string"/>
403 <outport name="stored" type="bool"/>
406 <inline name="CreateNumpyVectorSerieFromString">
407 <script><code><![CDATA[
408 import numpy, logging
409 logging.debug("CREATE YI Entering in CreateNumpyVectorSerieFromString")
410 vector_in_list = eval(str(vector_in_string),{},{})
411 vector = numpy.matrix(vector_in_list)
413 logging.debug("VectorSerie is %s"%vector)
415 <inport name="vector_in_string" type="string"/>
416 <outport name="vector" type="pyobj"/>
417 <outport name="type" type="string"/>
418 <outport name="stored" type="bool"/>
421 <inline name="CreateNumpyVectorSerieFromScript">
422 <script><code><![CDATA[
423 import logging, sys, os
424 logging.debug("CREATE YI Entering in CreateNumpyVectorSerieFromScript")
427 # Get file path and filename
429 if sys.path.count(studydir)==0 or (sys.path.count(studydir)>0 and sys.path.index(studydir)>0):
430 sys.path.insert(0,studydir)
433 filepath = os.path.dirname(script)
434 filename = os.path.basename(script)
435 module_name = os.path.splitext(filename)[0]
436 if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index(filepath)>0):
437 sys.path.insert(0,filepath)
440 <inport name="script" type="string"/>
441 <outport name="type" type="string"/>
442 <outport name="stored" type="bool"/>
445 <inline name="SimpleExecuteDirectAlgorithm">
446 <script><code><![CDATA[
448 logging.debug("EXECUTE Entering in SimpleExecuteDirectAlgorithm")
449 from daYacsIntegration.daStudy import *
450 ADD = Study.getResults()
453 <inport name="Study" type="pyobj"/>
454 <outport name="Study" type="pyobj"/>
457 <inline name="SimpleUserAnalysis">
458 <script><code><![CDATA[
459 #-*- coding: utf-8 -*-
461 logging.debug("TERMINATE Entering in SimpleUserAnalysis")
462 ADD = Study.getResults()
466 <inport name="Study" type="pyobj"/>
469 <inline name="FakeOptimizerLoopNode">
470 <script><code><![CDATA[
472 logging.debug("EXECUTE Entering in FakeOptimizerLoopNode")
475 <inport name="computation" type="SALOME_TYPES/ParametricInput"/>
476 <outport name="result" type="SALOME_TYPES/ParametricOutput"/>
479 <inline name="CreateDictFromString">
480 <script><code><![CDATA[
481 import logging, sys, os
482 logging.debug("CREATE YI Entering in CreateDictFromString")
483 dico = eval(dict_in_string)
485 <inport name="dict_in_string" type="string"/>
488 <inline name="CreateDictFromScript">
489 <script><code><![CDATA[
490 import logging, sys, os
491 logging.debug("CREATE YI Entering in CreateDictFromScript")
493 # Get file path and filename
495 if sys.path.count(studydir)==0 or (sys.path.count(studydir)>0 and sys.path.index(studydir)>0):
496 sys.path.insert(0,studydir)
499 filepath = os.path.dirname(script)
500 filename = os.path.basename(script)
501 module_name = os.path.splitext(filename)[0]
502 if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index(filepath)>0):
503 sys.path.insert(0,filepath)
506 <inport name="script" type="string"/>
509 <inline name="UserDataInitFromScript">
510 <script><code><![CDATA[
511 import logging, sys, os
512 logging.debug("CREATE YI Entering in UserDataInitFromScript")
514 # Get file path and filename
516 if sys.path.count(studydir)==0 or (sys.path.count(studydir)>0 and sys.path.index(studydir)>0):
517 sys.path.insert(0,studydir)
520 filepath = os.path.dirname(script)
521 filename = os.path.basename(script)
522 module_name = os.path.splitext(filename)[0]
523 if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index(filepath)>0):
524 sys.path.insert(0,filepath)
527 <inport name="script" type="string"/>
528 <outport name="init_data" type="pyobj"/>
531 <inline name="ReadForSwitchNode">
532 <script><code><![CDATA[
534 logging.debug("CREATE YI Entering in ReadForSwitchNode")
535 logging.debug(" with input data : "+str(data["specificParameters"]))
537 for param in data["specificParameters"]:
538 if param["name"] == "switch_value":
539 switch_value = int(param["value"])
540 logging.debug(" switching to value : "+str(switch_value))
542 <inport name="data" type="SALOME_TYPES/ParametricInput"/>
543 <outport name="data" type="SALOME_TYPES/ParametricInput"/>
544 <outport name="switch_value" type="int"/>
547 <inline name="ExtractDataNode">
548 <script><code><![CDATA[
550 logging.debug("TERMINATE Entering in ExtractDataNode")
552 import cPickle as pickle
555 from daCore.AssimilationStudy import AssimilationStudy
558 for param in data["specificParameters"]:
559 if param["name"] == "var":
560 var = pickle.loads(param["value"])
561 if param["name"] == "info":
562 info = param["value"]
564 <inport name="data" type="SALOME_TYPES/ParametricInput"/>
565 <outport name="var" type="pyobj"/>
566 <outport name="info" type="pyobj"/>
569 <inline name="ObservationNodeString">
570 <script><code><![CDATA[]]></code></script>
571 <inport name="var" type="pyobj"/>
572 <inport name="info" type="pyobj"/>
575 <inline name="ObservationNodeFile">
576 <script><code><![CDATA[execfile(script)]]></code></script>
577 <inport name="var" type="pyobj"/>
578 <inport name="info" type="pyobj"/>
579 <inport name="script" type="string"/>
582 <inline name="EndObservationNode">
583 <script><code><![CDATA[
584 # Create a fake output object.
585 # An observer is always successful.
587 output["outputValues"] = [[[[]]]]
588 output["specificOutputInfos"] = []
589 output["returnCode"] = 0
590 output["errorMessage"] = ""
592 <outport name="output" type="SALOME_TYPES/ParametricOutput"/>
595 <inline name="SetObserversNode">
596 <script><code><![CDATA[
597 #print("Setting observers")
599 <outport name="has_observers" type="bool"/>
600 <outport name="observers" type="pyobj"/>