From: André Ribes Date: Wed, 30 Mar 2011 15:19:04 +0000 (+0200) Subject: Parametric Input en cours X-Git-Tag: V6_4_0rc3~57 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=73327174aa2eaccc8c91bbfb63373e2f51390e00;p=modules%2Fadao.git Parametric Input en cours --- diff --git a/resources/ADAOSchemaCatalog.xml b/resources/ADAOSchemaCatalog.xml index 823c011..64742bc 100644 --- a/resources/ADAOSchemaCatalog.xml +++ b/resources/ADAOSchemaCatalog.xml @@ -5,6 +5,32 @@ pyobj + + + + + + + + + + + + + + + + + + + + + + + + + + - + diff --git a/src/daSalome/daYacsIntegration/daOptimizerLoop.py b/src/daSalome/daYacsIntegration/daOptimizerLoop.py index 1ea9a60..c36e666 100644 --- a/src/daSalome/daYacsIntegration/daOptimizerLoop.py +++ b/src/daSalome/daYacsIntegration/daOptimizerLoop.py @@ -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 diff --git a/src/daSalome/daYacsSchemaCreator/methods.py b/src/daSalome/daYacsSchemaCreator/methods.py index 0aa752c..d5fc4a2 100644 --- a/src/daSalome/daYacsSchemaCreator/methods.py +++ b/src/daSalome/daYacsSchemaCreator/methods.py @@ -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 diff --git a/src/tests/daSalome/test017_3DVAR_function_script.py b/src/tests/daSalome/test017_3DVAR_function_script.py index 6272b5d..4a8a6b0 100644 --- a/src/tests/daSalome/test017_3DVAR_function_script.py +++ b/src/tests/daSalome/test017_3DVAR_function_script.py @@ -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"