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
70 from daYacsIntegration.daStudy import *
71 assim_study = daStudy(Name, Algorithm, Debug)
73 logging.debug("CREATE YI Data entered are:")
75 # Algorithm parameters
76 if "AlgorithmParameters" in locals():
77 logging.debug("CREATE YI AlgorithmParameters is %s"%AlgorithmParameters)
78 assim_study.setYIAlgorithmParameters(AlgorithmParameters)
81 if "Background" in locals():
82 logging.debug("CREATE YI Background is set")
83 logging.debug("CREATE YI BackgroundType is %s"%BackgroundType)
84 logging.debug("CREATE YI BackgroundStored is %s"%BackgroundStored)
85 assim_study.setYIBackgroundType(BackgroundType)
86 assim_study.setYIBackgroundStored(BackgroundStored)
87 assim_study.setYIBackground(Background)
90 if "CheckingPoint" in locals():
91 logging.debug("CREATE YI CheckingPoint is set")
92 logging.debug("CREATE YI CheckingPointType is %s"%CheckingPointType)
93 logging.debug("CREATE YI CheckingPointStored is %s"%CheckingPointStored)
94 assim_study.setYICheckingPointType(CheckingPointType)
95 assim_study.setYICheckingPointStored(CheckingPointStored)
96 assim_study.setYICheckingPoint(CheckingPoint)
99 if "ControlInput" in locals():
100 logging.debug("CREATE YI ControlInput is set")
101 logging.debug("CREATE YI ControlInputType is %s"%ControlInputType)
102 logging.debug("CREATE YI ControlInputStored is %s"%ControlInputStored)
103 assim_study.setYIControlInputType(ControlInputType)
104 assim_study.setYIControlInputStored(ControlInputStored)
105 assim_study.setYIControlInput(ControlInput)
108 if "Observation" in locals():
109 logging.debug("CREATE YI Observation is set")
110 logging.debug("CREATE YI ObservationType is %s"%ObservationType)
111 logging.debug("CREATE YI ObservationStored is %s"%ObservationStored)
112 assim_study.setYIObservationType(ObservationType)
113 assim_study.setYIObservationStored(ObservationStored)
114 assim_study.setYIObservation(Observation)
117 if "BackgroundError" in locals():
118 logging.debug("CREATE YI BackgroundError is set")
119 logging.debug("CREATE YI BackgroundErrorType is %s"%BackgroundErrorType)
120 logging.debug("CREATE YI BackgroundErrorStored is %s"%BackgroundErrorStored)
121 assim_study.setYIBackgroundErrorType(BackgroundErrorType)
122 assim_study.setYIBackgroundErrorStored(BackgroundErrorStored)
123 assim_study.setYIBackgroundError(BackgroundError)
126 if "ObservationError" in locals():
127 logging.debug("CREATE YI ObservationError is set")
128 logging.debug("CREATE YI ObservationErrorType is %s"%ObservationErrorType)
129 logging.debug("CREATE YI ObservationErrorStored is %s"%ObservationErrorStored)
130 assim_study.setYIObservationErrorType(ObservationErrorType)
131 assim_study.setYIObservationErrorStored(ObservationErrorStored)
132 assim_study.setYIObservationError(ObservationError)
135 if "EvolutionError" in locals():
136 logging.debug("CREATE YI EvolutionError is set")
137 logging.debug("CREATE YI EvolutionErrorType is %s"%EvolutionErrorType)
138 logging.debug("CREATE YI EvolutionErrorStored is %s"%EvolutionErrorStored)
139 assim_study.setYIEvolutionErrorType(EvolutionErrorType)
140 assim_study.setYIEvolutionErrorStored(EvolutionErrorStored)
141 assim_study.setYIEvolutionError(EvolutionError)
143 # ObservationOperator
144 ObservationOperatorOk = 0
145 if "ObservationOperator" in locals():
146 logging.debug("CREATE YI ObservationOperator is set")
147 logging.debug("CREATE YI ObservationOperatorType is %s"%ObservationOperatorType)
148 assim_study.setYIObservationOperatorType("Matrix", ObservationOperatorType)
149 assim_study.setYIObservationOperator("Matrix", ObservationOperator)
150 ObservationOperatorOk = 1
152 if ObservationOperatorOk == 0:
153 if "ObservationOperatorDirect" in locals():
154 logging.debug("CREATE YI ObservationOperatorDirect is %s"%ObservationOperatorDirect)
155 assim_study.setYIObservationOperatorType("Direct", "Function")
156 assim_study.setYIObservationOperator("Direct", ObservationOperatorDirect)
157 if "ObservationOperatorTangent" in locals():
158 logging.debug("CREATE YI ObservationOperatorTangent is %s"%ObservationOperatorTangent)
159 assim_study.setYIObservationOperatorType("Tangent", "Function")
160 assim_study.setYIObservationOperator("Tangent", ObservationOperatorTangent)
161 if "ObservationOperatorAdjoint" in locals():
162 logging.debug("CREATE YI ObservationOperatorAdjoint is %s"%ObservationOperatorAdjoint)
163 assim_study.setYIObservationOperatorType("Adjoint", "Function")
164 assim_study.setYIObservationOperator("Adjoint", ObservationOperatorAdjoint)
168 if "EvolutionModel" in locals():
169 logging.debug("CREATE YI EvolutionModel is set")
170 logging.debug("CREATE YI EvolutionModelType is %s"%EvolutionModelType)
171 assim_study.setYIEvolutionModelType("Matrix", EvolutionModelType)
172 assim_study.setYIEvolutionModel("Matrix", EvolutionModel)
175 if EvolutionModelOk == 0:
176 if "EvolutionModelDirect" in locals():
177 logging.debug("CREATE YI EvolutionModelDirect is %s"%EvolutionModelDirect)
178 assim_study.setYIEvolutionModelType("Direct", "Function")
179 assim_study.setYIEvolutionModel("Direct", EvolutionModelDirect)
180 if "EvolutionModelTangent" in locals():
181 logging.debug("CREATE YI EvolutionModelTangent is %s"%EvolutionModelTangent)
182 assim_study.setYIEvolutionModelType("Tangent", "Function")
183 assim_study.setYIEvolutionModel("Tangent", EvolutionModelTangent)
184 if "EvolutionModelAdjoint" in locals():
185 logging.debug("CREATE YI EvolutionModelAdjoint is %s"%EvolutionModelAdjoint)
186 assim_study.setYIEvolutionModelType("Adjoint", "Function")
187 assim_study.setYIEvolutionModel("Adjoint", EvolutionModelAdjoint)
190 for name, size in zip(InputVariablesNames, InputVariablesSizes):
191 assim_study.setYIInputVariable(name, size)
192 for name, size in zip(OutputVariablesNames, OutputVariablesSizes):
193 assim_study.setYIOutputVariable(name, size)
196 logging.debug("CREATE YI Observers keys are %s"%observers.keys())
197 # Adding observers to the study
198 for observer_name in observers.keys():
201 number = str(observers[observer_name]["number"])
202 if "scheduler" in observers[observer_name].keys():
203 scheduler = observers[observer_name]["scheduler"]
204 if "info" in observers[observer_name].keys():
205 info = observers[observer_name]["info"]
206 assim_study.addYIObserver(observer_name, scheduler, info, number)
208 except Exception as e:
209 if isinstance(e, SyntaxError): msg = "at %s: %s"%(e.offset, e.text)
211 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))
217 <inport name="Name" type="string"/>
218 <inport name="Algorithm" type="string"/>
219 <inport name="Debug" type="bool"/>
220 <inport name="InputVariablesNames" type="stringvec"/>
221 <inport name="InputVariablesSizes" type="intvec"/>
222 <inport name="OutputVariablesNames" type="stringvec"/>
223 <inport name="OutputVariablesSizes" type="intvec"/>
224 <inport name="has_observers" type="bool"/>
225 <inport name="observers" type="pyobj"/>
226 <outport name="Study" type="pyobj"/>
229 <inline name="CreateNumpyMatrixFromString">
230 <script><code><![CDATA[
231 import numpy, logging
232 logging.debug("CREATE YI Entering in CreateNumpyMatrixFromString")
233 if (matrix_in_string.find("array")>-1) or (matrix_in_string.find("matrix")>-1):
234 matrix_in_string=matrix_in_string.replace("array","numpy.array")
235 matrix_in_string=matrix_in_string.replace("matrix","numpy.matrix")
236 exec("matrix="+matrix_in_string)
237 matrix = numpy.matrix(matrix)
239 matrix = numpy.matrix(matrix_in_string)
241 logging.debug("CREATE YI Matrix is %s"%matrix)
243 <inport name="matrix_in_string" type="string"/>
244 <outport name="matrix" type="pyobj"/>
245 <outport name="type" type="string"/>
246 <outport name="stored" type="bool"/>
249 <inline name="CreateNumpyScalarSparseMatrixFromString">
250 <script><code><![CDATA[
251 import numpy, logging
252 logging.debug("CREATE YI Entering in CreateNumpyScalarSparseMatrixFromString")
253 if (matrix_in_string.find("array")>-1) or (matrix_in_string.find("matrix")>-1):
254 matrix_in_string=matrix_in_string.replace("array","numpy.array")
255 matrix_in_string=matrix_in_string.replace("matrix","numpy.matrix")
256 exec("matrix="+matrix_in_string)
257 matrix = numpy.matrix(matrix)
259 matrix = numpy.matrix(matrix_in_string)
260 type = "ScalarSparseMatrix"
261 logging.debug("CREATE YI ScalarSparseMatrix is %s"%matrix)
263 <inport name="matrix_in_string" type="string"/>
264 <outport name="matrix" type="pyobj"/>
265 <outport name="type" type="string"/>
266 <outport name="stored" type="bool"/>
269 <inline name="CreateNumpyDiagonalSparseMatrixFromString">
270 <script><code><![CDATA[
271 import numpy, logging
272 logging.debug("CREATE YI Entering in CreateNumpyDiagonalSparseMatrixFromString")
273 if (matrix_in_string.find("array")>-1) or (matrix_in_string.find("matrix")>-1):
274 matrix_in_string=matrix_in_string.replace("array","numpy.array")
275 matrix_in_string=matrix_in_string.replace("matrix","numpy.matrix")
276 exec("matrix="+matrix_in_string)
277 matrix = numpy.matrix(matrix)
279 matrix = numpy.matrix(matrix_in_string)
280 type = "DiagonalSparseMatrix"
281 logging.debug("CREATE YI DiagonalSparseMatrix is %s"%matrix)
283 <inport name="matrix_in_string" type="string"/>
284 <outport name="matrix" type="pyobj"/>
285 <outport name="type" type="string"/>
286 <outport name="stored" type="bool"/>
289 <inline name="CreateNumpyMatrixFromScript">
290 <script><code><![CDATA[
291 import logging, sys, os
292 logging.debug("CREATE YI Entering in CreateNumpyMatrixFromScript")
295 # Get file path and filename
297 if sys.path.count(studydir)==0 or (sys.path.count(studydir)>0 and sys.path.index(studydir)>0):
298 sys.path.insert(0,studydir)
301 filepath = os.path.dirname(script)
302 filename = os.path.basename(script)
303 module_name = os.path.splitext(filename)[0]
304 if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index(filepath)>0):
305 sys.path.insert(0,filepath)
308 <inport name="script" type="string"/>
309 <outport name="type" type="string"/>
310 <outport name="stored" type="bool"/>
313 <inline name="CreateNumpyScalarSparseMatrixFromScript">
314 <script><code><![CDATA[
315 import logging, sys, os
316 logging.debug("CREATE YI Entering in CreateNumpyScalarSparseMatrixFromScript")
317 type = "ScalarSparseMatrix"
319 # Get file path and filename
321 if sys.path.count(studydir)==0 or (sys.path.count(studydir)>0 and sys.path.index(studydir)>0):
322 sys.path.insert(0,studydir)
325 filepath = os.path.dirname(script)
326 filename = os.path.basename(script)
327 module_name = os.path.splitext(filename)[0]
328 if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index(filepath)>0):
329 sys.path.insert(0,filepath)
332 <inport name="script" type="string"/>
333 <outport name="type" type="string"/>
334 <outport name="stored" type="bool"/>
337 <inline name="CreateNumpyDiagonalSparseMatrixFromScript">
338 <script><code><![CDATA[
339 import logging, sys, os
340 logging.debug("CREATE YI Entering in CreateNumpyDiagonalSparseMatrixFromScript")
341 type = "DiagonalSparseMatrix"
343 # Get file path and filename
345 if sys.path.count(studydir)==0 or (sys.path.count(studydir)>0 and sys.path.index(studydir)>0):
346 sys.path.insert(0,studydir)
349 filepath = os.path.dirname(script)
350 filename = os.path.basename(script)
351 module_name = os.path.splitext(filename)[0]
352 if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index(filepath)>0):
353 sys.path.insert(0,filepath)
356 <inport name="script" type="string"/>
357 <outport name="type" type="string"/>
358 <outport name="stored" type="bool"/>
361 <inline name="CreateNumpyVectorFromString">
362 <script><code><![CDATA[
363 import numpy, logging
364 logging.debug("CREATE YI Entering in CreateNumpyVectorFromString")
365 if (vector_in_string.find("array")>-1) or (vector_in_string.find("matrix")>-1):
366 vector_in_string=vector_in_string.replace("array","numpy.array")
367 vector_in_string=vector_in_string.replace("matrix","numpy.matrix")
368 exec("vector="+vector_in_string)
369 vector = numpy.matrix(vector)
371 vector = numpy.matrix(vector_in_string)
373 logging.debug("Vector is %s"%vector)
375 <inport name="vector_in_string" type="string"/>
376 <outport name="vector" type="pyobj"/>
377 <outport name="type" type="string"/>
378 <outport name="stored" type="bool"/>
381 <inline name="CreateNumpyVectorFromScript">
382 <script><code><![CDATA[
383 import logging, sys, os
384 logging.debug("CREATE YI Entering in CreateNumpyVectorFromScript")
387 # Get file path and filename
389 if sys.path.count(studydir)==0 or (sys.path.count(studydir)>0 and sys.path.index(studydir)>0):
390 sys.path.insert(0,studydir)
393 filepath = os.path.dirname(script)
394 filename = os.path.basename(script)
395 module_name = os.path.splitext(filename)[0]
396 if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index(filepath)>0):
397 sys.path.insert(0,filepath)
400 <inport name="script" type="string"/>
401 <outport name="type" type="string"/>
402 <outport name="stored" type="bool"/>
405 <inline name="CreateNumpyVectorSerieFromString">
406 <script><code><![CDATA[
407 import numpy, logging
408 logging.debug("CREATE YI Entering in CreateNumpyVectorSerieFromString")
409 vector_in_list = eval(str(vector_in_string),{},{})
410 vector = numpy.matrix(vector_in_list)
412 logging.debug("VectorSerie is %s"%vector)
414 <inport name="vector_in_string" type="string"/>
415 <outport name="vector" type="pyobj"/>
416 <outport name="type" type="string"/>
417 <outport name="stored" type="bool"/>
420 <inline name="CreateNumpyVectorSerieFromScript">
421 <script><code><![CDATA[
422 import logging, sys, os
423 logging.debug("CREATE YI Entering in CreateNumpyVectorSerieFromScript")
426 # Get file path and filename
428 if sys.path.count(studydir)==0 or (sys.path.count(studydir)>0 and sys.path.index(studydir)>0):
429 sys.path.insert(0,studydir)
432 filepath = os.path.dirname(script)
433 filename = os.path.basename(script)
434 module_name = os.path.splitext(filename)[0]
435 if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index(filepath)>0):
436 sys.path.insert(0,filepath)
439 <inport name="script" type="string"/>
440 <outport name="type" type="string"/>
441 <outport name="stored" type="bool"/>
444 <inline name="SimpleExecuteDirectAlgorithm">
445 <script><code><![CDATA[
447 logging.debug("EXECUTE Entering in SimpleExecuteDirectAlgorithm")
448 from daYacsIntegration.daStudy import *
449 ADD = Study.getResults()
452 <inport name="Study" type="pyobj"/>
453 <outport name="Study" type="pyobj"/>
456 <inline name="SimpleUserAnalysis">
457 <script><code><![CDATA[
458 #-*- coding: utf-8 -*-
460 logging.debug("TERMINATE Entering in SimpleUserAnalysis")
461 ADD = Study.getResults()
465 <inport name="Study" type="pyobj"/>
468 <inline name="FakeOptimizerLoopNode">
469 <script><code><![CDATA[
471 logging.debug("EXECUTE Entering in FakeOptimizerLoopNode")
474 <inport name="computation" type="SALOME_TYPES/ParametricInput"/>
475 <outport name="result" type="SALOME_TYPES/ParametricOutput"/>
478 <inline name="CreateDictFromString">
479 <script><code><![CDATA[
480 import logging, sys, os
481 logging.debug("CREATE YI Entering in CreateDictFromString")
482 dico = eval(dict_in_string)
484 <inport name="dict_in_string" type="string"/>
487 <inline name="CreateDictFromScript">
488 <script><code><![CDATA[
489 import logging, sys, os
490 logging.debug("CREATE YI Entering in CreateDictFromScript")
492 # Get file path and filename
494 if sys.path.count(studydir)==0 or (sys.path.count(studydir)>0 and sys.path.index(studydir)>0):
495 sys.path.insert(0,studydir)
498 filepath = os.path.dirname(script)
499 filename = os.path.basename(script)
500 module_name = os.path.splitext(filename)[0]
501 if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index(filepath)>0):
502 sys.path.insert(0,filepath)
505 <inport name="script" type="string"/>
508 <inline name="UserDataInitFromScript">
509 <script><code><![CDATA[
510 import logging, sys, os
511 logging.debug("CREATE YI Entering in UserDataInitFromScript")
513 # Get file path and filename
515 if sys.path.count(studydir)==0 or (sys.path.count(studydir)>0 and sys.path.index(studydir)>0):
516 sys.path.insert(0,studydir)
519 filepath = os.path.dirname(script)
520 filename = os.path.basename(script)
521 module_name = os.path.splitext(filename)[0]
522 if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index(filepath)>0):
523 sys.path.insert(0,filepath)
526 <inport name="script" type="string"/>
527 <outport name="init_data" type="pyobj"/>
530 <inline name="ReadForSwitchNode">
531 <script><code><![CDATA[
533 logging.debug("CREATE YI Entering in ReadForSwitchNode")
534 logging.debug(" with input data : "+str(data["specificParameters"]))
536 for param in data["specificParameters"]:
537 if param["name"] == "switch_value":
538 switch_value = int(param["value"])
539 logging.debug(" switching to value : "+str(switch_value))
541 <inport name="data" type="SALOME_TYPES/ParametricInput"/>
542 <outport name="data" type="SALOME_TYPES/ParametricInput"/>
543 <outport name="switch_value" type="int"/>
546 <inline name="ExtractDataNode">
547 <script><code><![CDATA[
549 logging.debug("TERMINATE Entering in ExtractDataNode")
551 from daCore.AssimilationStudy import AssimilationStudy
554 for param in data["specificParameters"]:
555 if param["name"] == "var":
556 var = cPickle.loads(param["value"])
557 if param["name"] == "info":
558 info = param["value"]
560 <inport name="data" type="SALOME_TYPES/ParametricInput"/>
561 <outport name="var" type="pyobj"/>
562 <outport name="info" type="pyobj"/>
565 <inline name="ObservationNodeString">
566 <script><code><![CDATA[]]></code></script>
567 <inport name="var" type="pyobj"/>
568 <inport name="info" type="pyobj"/>
571 <inline name="ObservationNodeFile">
572 <script><code><![CDATA[execfile(script)]]></code></script>
573 <inport name="var" type="pyobj"/>
574 <inport name="info" type="pyobj"/>
575 <inport name="script" type="string"/>
578 <inline name="EndObservationNode">
579 <script><code><![CDATA[
580 # Create a fake output object.
581 # An observer is always successful.
583 output["outputValues"] = [[[[]]]]
584 output["specificOutputInfos"] = []
585 output["returnCode"] = 0
586 output["errorMessage"] = ""
588 <outport name="output" type="SALOME_TYPES/ParametricOutput"/>
591 <inline name="SetObserversNode">
592 <script><code><![CDATA[
593 #print("Setting observers")
595 <outport name="has_observers" type="bool"/>
596 <outport name="observers" type="pyobj"/>