Salome HOME
Parametric Input en cours
authorAndré Ribes <andre.ribes@edf.fr>
Wed, 30 Mar 2011 15:19:04 +0000 (17:19 +0200)
committerAndré Ribes <andre.ribes@edf.fr>
Wed, 30 Mar 2011 15:19:04 +0000 (17:19 +0200)
resources/ADAOSchemaCatalog.xml
src/daSalome/daYacsIntegration/daOptimizerLoop.py
src/daSalome/daYacsSchemaCreator/methods.py
src/tests/daSalome/test017_3DVAR_function_script.py

index 823c011dddf10e22faa8abf7c51769791ccbe4e6..64742bcf0a600cb45badb4b4a252c421d58b368b 100644 (file)
@@ -5,6 +5,32 @@
     <base>pyobj</base>
   </objref>
 
+  <!-- Types for parametric computations -->
+  <!-- TODO On devrait pouvoir le lire depuis le KERNEL !!!-->
+  <type name="long" kind="int"/>
+  <struct name="SALOME_TYPES/Parameter">
+    <member type="string" name="name"></member>
+    <member type="string" name="value"></member>
+  </struct>
+  <sequence content="SALOME_TYPES/Parameter" name="SALOME_TYPES/ParameterList"></sequence>
+  <sequence content="double" name="Value1D"></sequence>
+  <sequence content="Value1D" name="SALOME_TYPES/Value"></sequence>
+  <sequence content="string" name="SALOME_TYPES/VarList"></sequence>
+  <sequence content="SALOME_TYPES/Value" name="SALOME_TYPES/ValueList"></sequence>
+  <struct name="SALOME_TYPES/ParametricInput">
+    <member type="SALOME_TYPES/VarList" name="inputVarList"></member>
+    <member type="SALOME_TYPES/VarList" name="outputVarList"></member>
+    <member type="SALOME_TYPES/ValueList" name="inputValues"></member>
+    <member type="SALOME_TYPES/ParameterList" name="specificParameters"></member>
+  </struct>
+  <struct name="SALOME_TYPES/ParametricOutput">
+    <member type="SALOME_TYPES/ValueList" name="outputValues"></member>
+    <member type="SALOME_TYPES/ParameterList" name="specificOutputInfos"></member>
+    <member type="long" name="returnCode"></member>
+    <member type="string" name="errorMessage"></member>
+  </struct>
+
+
   <inline name="CreateAssimilationStudy">
     <script><code>
 
@@ -195,7 +221,7 @@ ADD = Study.getAssimilationStudy()
 print "Entering in FakeOptimizerLoopNode"
 result = None
 ]]></code></script>
-    <inport name="computation" type="pyobj"/>
+    <inport name="computation" type="SALOME_TYPES/ParametricInput"/>
     <outport name="result" type="pyobj"/>
   </inline>
 
index 1ea9a60e0f73e7c4a4ecc19f8b55196a9e6e1831..c36e66611bda1dcc03a50f40caf78b69fa2a8bf5 100644 (file)
@@ -1,6 +1,7 @@
 #-*- coding: utf-8 -*-
 
 import SALOMERuntime
+import pilot
 import pickle
 import numpy
 import threading
@@ -17,6 +18,46 @@ class OptimizerHooks:
     self.sample_counter = 0
     self.counter_lock = threading.Lock()
 
+  def create_sample(self, data, method):
+    sample = pilot.StructAny_New(self.optim_algo.runtime.getTypeCode('SALOME_TYPES/ParametricInput'))
+
+    # TODO Input, Output VarList
+    inputVarList  = pilot.SequenceAny_New(self.optim_algo.runtime.getTypeCode("string"))
+    outputVarList = pilot.SequenceAny_New(self.optim_algo.runtime.getTypeCode("string"))
+    inputVarList.pushBack("adao_default")
+    outputVarList.pushBack("adao_default")
+    sample.setEltAtRank("inputVarList", inputVarList)
+    sample.setEltAtRank("outputVarList", outputVarList)
+
+    # Les parametres specifiques à ADAO
+    specificParameters = pilot.SequenceAny_New(self.optim_algo.runtime.getTypeCode("SALOME_TYPES/Parameter"))
+    method_name = pilot.StructAny_New(self.optim_algo.runtime.getTypeCode('SALOME_TYPES/Parameter'))
+    method_name.setEltAtRank("name", "method")
+    method_name.setEltAtRank("value", method)
+    specificParameters.pushBack(method_name)
+    sample.setEltAtRank("specificParameters", specificParameters)
+
+    # Les données
+    # TODO à faire
+    parameter_1D = pilot.SequenceAny_New(self.optim_algo.runtime.getTypeCode("double"))
+    #print data
+    #print data.ndim
+    #print data.shape
+    #print data[:,0]
+    #print data.flatten()
+    #print data.flatten().shape
+    it = data.flat
+    for val in it:
+      print val
+      parameter_1D.pushBack(val)
+    parameter_2D = pilot.SequenceAny_New(parameter_1D.getType())
+    parameter_2D.pushBack(parameter_1D)
+    parameters_3D = pilot.SequenceAny_New(parameter_2D.getType())
+    parameters_3D.pushBack(parameter_2D)
+    sample.setEltAtRank("inputValues", parameters_3D)
+
+    return sample
+
   def Direct(self, X, sync = 1):
     print "Call Direct OptimizerHooks"
     if sync == 1:
@@ -26,11 +67,8 @@ class OptimizerHooks:
       local_counter = self.sample_counter
 
       # 2: Put sample in the job pool
-      computation = {}
-      computation["method"] = "Direct"
-      computation["data"] = X
-      computation = pickle.dumps(computation)
-      self.optim_algo.pool.pushInSample(local_counter, computation)
+      sample = self.create_sample(X, "Direct")
+      self.optim_algo.pool.pushInSample(local_counter, sample)
 
       # 3: Wait
       while 1:
@@ -149,7 +187,7 @@ class AssimilationAlgorithm_asynch(SALOMERuntime.OptimizerAlgASync):
     self.runtime = SALOMERuntime.getSALOMERuntime()
 
     # Definission des types d'entres et de sorties pour le code de calcul
-    self.tin  = self.runtime.getTypeCode("pyobj")
+    self.tin  = self.runtime.getTypeCode("SALOME_TYPES/ParametricInput")
     self.tout = self.runtime.getTypeCode("pyobj")
 
     self.optim_hooks = OptimizerHooks(self)
@@ -213,7 +251,7 @@ class AssimilationAlgorithm_asynch(SALOMERuntime.OptimizerAlgASync):
   def getTCForOut(self):
     return self.tout
   def getTCForAlgoInit(self):
-    return self.tin
+    return self.tout
   def getTCForAlgoResult(self):
     return self.tout
 
index 0aa752c16bd36df751ae6d3fa44690f898952029..d5fc4a2d055e9f1f4e27d1d1039786574811874b 100644 (file)
@@ -40,6 +40,7 @@ def create_yacs_proc(study_config):
   runtime = pilot.getRuntime()
   try:
     catalogAd = runtime.loadCatalog("proc", os.environ["ADAO_ROOT_DIR"] + "/share/salome/resources/adao/ADAOSchemaCatalog.xml")
+    runtime.addCatalog(catalogAd)
   except:
     logging.fatal("Exception in loading DataAssim YACS catalog")
     traceback.print_exc()
@@ -48,9 +49,10 @@ def create_yacs_proc(study_config):
   # Starting creating proc
   proc = runtime.createProc("proc")
   proc.setTypeCode("pyobj", runtime.getTypeCode("pyobj"))
+  proc.setTypeCode("SALOME_TYPES/ParametricInput", catalogAd._typeMap["SALOME_TYPES/ParametricInput"])
   t_pyobj  = proc.getTypeCode("pyobj")
   t_string = proc.getTypeCode("string")
-
+  t_param_input = proc.getTypeCode("SALOME_TYPES/ParametricInput")
   repertory = False
   base_repertory = ""
   if "Repertory" in study_config.keys():
@@ -225,7 +227,7 @@ def create_yacs_proc(study_config):
         traceback.print_exc()
         sys.exit(1)
       opt_script_node.setScript(script_str.read())
-      opt_script_node.edAddInputPort("computation", t_pyobj)
+      opt_script_node.edAddInputPort("computation", t_param_input)
       opt_script_node.edAddOutputPort("result", t_pyobj)
 
       # Add it
index 6272b5d7003b8e908adadc9710bb525daf7fd0f9..4a8a6b04adfe82efd86b339e384a47c5bb8ee002 100644 (file)
@@ -1,10 +1,14 @@
 import numpy
 import pickle
 
-print computation["method"]
+print computation
+method = ""
+for param in computation["specificParameters"]:
+  if param["name"] == "method":
+    method = param["value"]
+print "Method found is", method
 
 dimension = 300
-
 H  = numpy.matrix(numpy.core.identity(dimension))
 
 def FunctionH( X ):
@@ -13,13 +17,13 @@ def FunctionH( X ):
 def AdjointH( (X, Y) ):
     return H.T * Y
 
-if computation["method"] == "Direct":
+if method == "Direct":
   result = FunctionH(computation["data"])
 
-if computation["method"] == "Tangent":
+if method == "Tangent":
   result = FunctionH(computation["data"])
 
-if computation["method"] == "Adjoint":
+if method == "Adjoint":
   result = AdjointH(computation["data"])
 
 print "Computation end"