1 <?xml version='1.0' encoding='iso-8859-1' ?>
3 Copyright (C) 2008-2017 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 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 Data entered are:")
75 # Algorithm parameters
76 if "AlgorithmParameters" in locals():
77 logging.debug("CREATE AlgorithmParameters is %s"%AlgorithmParameters)
78 assim_study.setAlgorithmParameters(AlgorithmParameters)
81 if "Background" in locals():
82 logging.debug("CREATE Background is set")
83 logging.debug("CREATE BackgroundType is %s"%BackgroundType)
84 logging.debug("CREATE BackgroundStored is %s"%BackgroundStored)
85 assim_study.setBackgroundType(BackgroundType)
86 assim_study.setBackgroundStored(BackgroundStored)
87 assim_study.setBackground(Background)
90 if "CheckingPoint" in locals():
91 logging.debug("CREATE CheckingPoint is set")
92 logging.debug("CREATE CheckingPointType is %s"%CheckingPointType)
93 logging.debug("CREATE CheckingPointStored is %s"%CheckingPointStored)
94 assim_study.setCheckingPointType(CheckingPointType)
95 assim_study.setCheckingPointStored(CheckingPointStored)
96 assim_study.setCheckingPoint(CheckingPoint)
99 if "ControlInput" in locals():
100 logging.debug("CREATE ControlInput is set")
101 logging.debug("CREATE ControlInputType is %s"%ControlInputType)
102 logging.debug("CREATE ControlInputStored is %s"%ControlInputStored)
103 assim_study.setControlInputType(ControlInputType)
104 assim_study.setControlInputStored(ControlInputStored)
105 assim_study.setControlInput(ControlInput)
108 if "Observation" in locals():
109 logging.debug("CREATE Observation is set")
110 logging.debug("CREATE ObservationType is %s"%ObservationType)
111 logging.debug("CREATE ObservationStored is %s"%ObservationStored)
112 assim_study.setObservationType(ObservationType)
113 assim_study.setObservationStored(ObservationStored)
114 assim_study.setObservation(Observation)
117 if "BackgroundError" in locals():
118 logging.debug("CREATE BackgroundError is set")
119 logging.debug("CREATE BackgroundErrorType is %s"%BackgroundErrorType)
120 logging.debug("CREATE BackgroundErrorStored is %s"%BackgroundErrorStored)
121 assim_study.setBackgroundErrorType(BackgroundErrorType)
122 assim_study.setBackgroundErrorStored(BackgroundErrorStored)
123 assim_study.setBackgroundError(BackgroundError)
126 if "ObservationError" in locals():
127 logging.debug("CREATE ObservationError is set")
128 logging.debug("CREATE ObservationErrorType is %s"%ObservationErrorType)
129 logging.debug("CREATE ObservationErrorStored is %s"%ObservationErrorStored)
130 assim_study.setObservationErrorType(ObservationErrorType)
131 assim_study.setObservationErrorStored(ObservationErrorStored)
132 assim_study.setObservationError(ObservationError)
135 if "EvolutionError" in locals():
136 logging.debug("CREATE EvolutionError is set")
137 logging.debug("CREATE EvolutionErrorType is %s"%EvolutionErrorType)
138 logging.debug("CREATE EvolutionErrorStored is %s"%EvolutionErrorStored)
139 assim_study.setEvolutionErrorType(EvolutionErrorType)
140 assim_study.setEvolutionErrorStored(EvolutionErrorStored)
141 assim_study.setEvolutionError(EvolutionError)
143 # ObservationOperator
144 ObservationOperatorOk = 0
145 if "ObservationOperator" in locals():
146 logging.debug("CREATE ObservationOperator is set")
147 logging.debug("CREATE ObservationOperatorType is %s"%ObservationOperatorType)
148 assim_study.setObservationOperatorType("Matrix", ObservationOperatorType)
149 assim_study.setObservationOperator("Matrix", ObservationOperator)
150 ObservationOperatorOk = 1
152 if ObservationOperatorOk == 0:
153 if "ObservationOperatorDirect" in locals():
154 logging.debug("CREATE ObservationOperatorDirect is %s"%ObservationOperatorDirect)
155 assim_study.setObservationOperatorType("Direct", "Function")
156 assim_study.setObservationOperator("Direct", ObservationOperatorDirect)
157 if "ObservationOperatorTangent" in locals():
158 logging.debug("CREATE ObservationOperatorTangent is %s"%ObservationOperatorTangent)
159 assim_study.setObservationOperatorType("Tangent", "Function")
160 assim_study.setObservationOperator("Tangent", ObservationOperatorTangent)
161 if "ObservationOperatorAdjoint" in locals():
162 logging.debug("CREATE ObservationOperatorAdjoint is %s"%ObservationOperatorAdjoint)
163 assim_study.setObservationOperatorType("Adjoint", "Function")
164 assim_study.setObservationOperator("Adjoint", ObservationOperatorAdjoint)
168 if "EvolutionModel" in locals():
169 logging.debug("CREATE EvolutionModel is set")
170 logging.debug("CREATE EvolutionModelType is %s"%EvolutionModelType)
171 assim_study.setEvolutionModelType("Matrix", EvolutionModelType)
172 assim_study.setEvolutionModel("Matrix", EvolutionModel)
175 if EvolutionModelOk == 0:
176 if "EvolutionModelDirect" in locals():
177 logging.debug("CREATE EvolutionModelDirect is %s"%EvolutionModelDirect)
178 assim_study.setEvolutionModelType("Direct", "Function")
179 assim_study.setEvolutionModel("Direct", EvolutionModelDirect)
180 if "EvolutionModelTangent" in locals():
181 logging.debug("CREATE EvolutionModelTangent is %s"%EvolutionModelTangent)
182 assim_study.setEvolutionModelType("Tangent", "Function")
183 assim_study.setEvolutionModel("Tangent", EvolutionModelTangent)
184 if "EvolutionModelAdjoint" in locals():
185 logging.debug("CREATE EvolutionModelAdjoint is %s"%EvolutionModelAdjoint)
186 assim_study.setEvolutionModelType("Adjoint", "Function")
187 assim_study.setEvolutionModel("Adjoint", EvolutionModelAdjoint)
190 for name, size in zip(InputVariablesNames, InputVariablesSizes):
191 assim_study.setInputVariable(name, size)
192 for name, size in zip(OutputVariablesNames, OutputVariablesSizes):
193 assim_study.setOutputVariable(name, size)
196 logging.debug("CREATE 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.addObserver(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 Entering in CreateNumpyMatrixFromString")
233 matrix = numpy.matrix(matrix_in_string)
235 logging.debug("CREATE Matrix is %s"%matrix)
237 <inport name="matrix_in_string" type="string"/>
238 <outport name="matrix" type="pyobj"/>
239 <outport name="type" type="string"/>
240 <outport name="stored" type="bool"/>
243 <inline name="CreateNumpyScalarSparseMatrixFromString">
244 <script><code><![CDATA[
245 import numpy, logging
246 logging.debug("CREATE Entering in CreateNumpyScalarSparseMatrixFromString")
247 matrix = numpy.matrix(matrix_in_string)
248 type = "ScalarSparseMatrix"
249 logging.debug("CREATE ScalarSparseMatrix is %s"%matrix)
251 <inport name="matrix_in_string" type="string"/>
252 <outport name="matrix" type="pyobj"/>
253 <outport name="type" type="string"/>
254 <outport name="stored" type="bool"/>
257 <inline name="CreateNumpyDiagonalSparseMatrixFromString">
258 <script><code><![CDATA[
259 import numpy, logging
260 logging.debug("CREATE Entering in CreateNumpyDiagonalSparseMatrixFromString")
261 matrix = numpy.matrix(matrix_in_string)
262 type = "DiagonalSparseMatrix"
263 logging.debug("CREATE DiagonalSparseMatrix is %s"%matrix)
265 <inport name="matrix_in_string" type="string"/>
266 <outport name="matrix" type="pyobj"/>
267 <outport name="type" type="string"/>
268 <outport name="stored" type="bool"/>
271 <inline name="CreateNumpyMatrixFromScript">
272 <script><code><![CDATA[
273 import logging, sys, os
274 logging.debug("CREATE Entering in CreateNumpyMatrixFromScript")
277 # Get file path and filename
279 if sys.path.count(studydir)==0 or (sys.path.count(studydir)>0 and sys.path.index(studydir)>0):
280 sys.path.insert(0,studydir)
283 filepath = os.path.dirname(script)
284 filename = os.path.basename(script)
285 module_name = os.path.splitext(filename)[0]
286 if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index(filepath)>0):
287 sys.path.insert(0,filepath)
290 <inport name="script" type="string"/>
291 <outport name="type" type="string"/>
292 <outport name="stored" type="bool"/>
295 <inline name="CreateNumpyScalarSparseMatrixFromScript">
296 <script><code><![CDATA[
297 import logging, sys, os
298 logging.debug("CREATE Entering in CreateNumpyScalarSparseMatrixFromScript")
299 type = "ScalarSparseMatrix"
301 # Get file path and filename
303 if sys.path.count(studydir)==0 or (sys.path.count(studydir)>0 and sys.path.index(studydir)>0):
304 sys.path.insert(0,studydir)
307 filepath = os.path.dirname(script)
308 filename = os.path.basename(script)
309 module_name = os.path.splitext(filename)[0]
310 if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index(filepath)>0):
311 sys.path.insert(0,filepath)
314 <inport name="script" type="string"/>
315 <outport name="type" type="string"/>
316 <outport name="stored" type="bool"/>
319 <inline name="CreateNumpyDiagonalSparseMatrixFromScript">
320 <script><code><![CDATA[
321 import logging, sys, os
322 logging.debug("CREATE Entering in CreateNumpyDiagonalSparseMatrixFromScript")
323 type = "DiagonalSparseMatrix"
325 # Get file path and filename
327 if sys.path.count(studydir)==0 or (sys.path.count(studydir)>0 and sys.path.index(studydir)>0):
328 sys.path.insert(0,studydir)
331 filepath = os.path.dirname(script)
332 filename = os.path.basename(script)
333 module_name = os.path.splitext(filename)[0]
334 if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index(filepath)>0):
335 sys.path.insert(0,filepath)
338 <inport name="script" type="string"/>
339 <outport name="type" type="string"/>
340 <outport name="stored" type="bool"/>
343 <inline name="CreateNumpyVectorFromString">
344 <script><code><![CDATA[
345 import numpy, logging
346 logging.debug("CREATE Entering in CreateNumpyVectorFromString")
347 vector = numpy.matrix(vector_in_string)
349 logging.debug("Vector is %s"%vector)
351 <inport name="vector_in_string" type="string"/>
352 <outport name="vector" type="pyobj"/>
353 <outport name="type" type="string"/>
354 <outport name="stored" type="bool"/>
357 <inline name="CreateNumpyVectorFromScript">
358 <script><code><![CDATA[
359 import logging, sys, os
360 logging.debug("CREATE Entering in CreateNumpyVectorFromScript")
363 # Get file path and filename
365 if sys.path.count(studydir)==0 or (sys.path.count(studydir)>0 and sys.path.index(studydir)>0):
366 sys.path.insert(0,studydir)
369 filepath = os.path.dirname(script)
370 filename = os.path.basename(script)
371 module_name = os.path.splitext(filename)[0]
372 if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index(filepath)>0):
373 sys.path.insert(0,filepath)
376 <inport name="script" type="string"/>
377 <outport name="type" type="string"/>
378 <outport name="stored" type="bool"/>
381 <inline name="CreateNumpyVectorSerieFromString">
382 <script><code><![CDATA[
383 import numpy, logging
384 logging.debug("CREATE Entering in CreateNumpyVectorSerieFromString")
385 vector_in_list = eval(str(vector_in_string),{},{})
386 vector = numpy.matrix(vector_in_list)
388 logging.debug("VectorSerie is %s"%vector)
390 <inport name="vector_in_string" type="string"/>
391 <outport name="vector" type="pyobj"/>
392 <outport name="type" type="string"/>
393 <outport name="stored" type="bool"/>
396 <inline name="CreateNumpyVectorSerieFromScript">
397 <script><code><![CDATA[
398 import logging, sys, os
399 logging.debug("CREATE Entering in CreateNumpyVectorSerieFromScript")
402 # Get file path and filename
404 if sys.path.count(studydir)==0 or (sys.path.count(studydir)>0 and sys.path.index(studydir)>0):
405 sys.path.insert(0,studydir)
408 filepath = os.path.dirname(script)
409 filename = os.path.basename(script)
410 module_name = os.path.splitext(filename)[0]
411 if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index(filepath)>0):
412 sys.path.insert(0,filepath)
415 <inport name="script" type="string"/>
416 <outport name="type" type="string"/>
417 <outport name="stored" type="bool"/>
420 <inline name="SimpleExecuteDirectAlgorithm">
421 <script><code><![CDATA[
423 logging.debug("EXECUTE Entering in SimpleExecuteDirectAlgorithm")
424 from daYacsIntegration.daStudy import *
425 ADD = Study.getResults()
428 <inport name="Study" type="pyobj"/>
429 <outport name="Study" type="pyobj"/>
432 <inline name="SimpleUserAnalysis">
433 <script><code><![CDATA[
434 #-*-coding:iso-8859-1-*-
436 logging.debug("TERMINATE Entering in SimpleUserAnalysis")
437 ADD = Study.getResults()
441 <inport name="Study" type="pyobj"/>
444 <inline name="FakeOptimizerLoopNode">
445 <script><code><![CDATA[
447 logging.debug("EXECUTE Entering in FakeOptimizerLoopNode")
450 <inport name="computation" type="SALOME_TYPES/ParametricInput"/>
451 <outport name="result" type="SALOME_TYPES/ParametricOutput"/>
454 <inline name="CreateDictFromString">
455 <script><code><![CDATA[
456 import logging, sys, os
457 logging.debug("CREATE Entering in CreateDictFromString")
458 dico = eval(dict_in_string)
460 <inport name="dict_in_string" type="string"/>
463 <inline name="CreateDictFromScript">
464 <script><code><![CDATA[
465 import logging, sys, os
466 logging.debug("CREATE Entering in CreateDictFromScript")
468 # Get file path and filename
470 if sys.path.count(studydir)==0 or (sys.path.count(studydir)>0 and sys.path.index(studydir)>0):
471 sys.path.insert(0,studydir)
474 filepath = os.path.dirname(script)
475 filename = os.path.basename(script)
476 module_name = os.path.splitext(filename)[0]
477 if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index(filepath)>0):
478 sys.path.insert(0,filepath)
481 <inport name="script" type="string"/>
484 <inline name="UserDataInitFromScript">
485 <script><code><![CDATA[
486 import logging, sys, os
487 logging.debug("CREATE Entering in UserDataInitFromScript")
489 # Get file path and filename
491 if sys.path.count(studydir)==0 or (sys.path.count(studydir)>0 and sys.path.index(studydir)>0):
492 sys.path.insert(0,studydir)
495 filepath = os.path.dirname(script)
496 filename = os.path.basename(script)
497 module_name = os.path.splitext(filename)[0]
498 if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index(filepath)>0):
499 sys.path.insert(0,filepath)
502 <inport name="script" type="string"/>
503 <outport name="init_data" type="pyobj"/>
506 <inline name="ReadForSwitchNode">
507 <script><code><![CDATA[
509 logging.debug("CREATE Entering in ReadForSwitchNode")
510 logging.debug(" with input data : "+str(data["specificParameters"]))
512 for param in data["specificParameters"]:
513 if param["name"] == "switch_value":
514 switch_value = int(param["value"])
515 logging.debug(" switching to value : "+str(switch_value))
517 <inport name="data" type="SALOME_TYPES/ParametricInput"/>
518 <outport name="data" type="SALOME_TYPES/ParametricInput"/>
519 <outport name="switch_value" type="int"/>
522 <inline name="ExtractDataNode">
523 <script><code><![CDATA[
525 logging.debug("TERMINATE Entering in ExtractDataNode")
527 from daCore.AssimilationStudy import AssimilationStudy
530 for param in data["specificParameters"]:
531 if param["name"] == "var":
532 var = cPickle.loads(param["value"])
533 if param["name"] == "info":
534 info = param["value"]
536 <inport name="data" type="SALOME_TYPES/ParametricInput"/>
537 <outport name="var" type="pyobj"/>
538 <outport name="info" type="pyobj"/>
541 <inline name="ObservationNodeString">
542 <script><code><![CDATA[]]></code></script>
543 <inport name="var" type="pyobj"/>
544 <inport name="info" type="pyobj"/>
547 <inline name="ObservationNodeFile">
548 <script><code><![CDATA[execfile(script)]]></code></script>
549 <inport name="var" type="pyobj"/>
550 <inport name="info" type="pyobj"/>
551 <inport name="script" type="string"/>
554 <inline name="EndObservationNode">
555 <script><code><![CDATA[
556 # Create a fake output object.
557 # An observer is always successful.
559 output["outputValues"] = [[[[]]]]
560 output["specificOutputInfos"] = []
561 output["returnCode"] = 0
562 output["errorMessage"] = ""
564 <outport name="output" type="SALOME_TYPES/ParametricOutput"/>
567 <inline name="SetObserversNode">
568 <script><code><![CDATA[
569 #print "Setting observers"
571 <outport name="has_observers" type="bool"/>
572 <outport name="observers" type="pyobj"/>