From: André Ribes Date: Fri, 1 Apr 2011 11:22:41 +0000 (+0200) Subject: test017 Ok X-Git-Tag: V6_4_0rc3~54 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=035dcbfbd83992b7efda708111a177fc755a9823;p=modules%2Fadao.git test017 Ok Maintenant il faut le cas Aster qui décrit plusieurs variables --- diff --git a/resources/ADAOSchemaCatalog.xml b/resources/ADAOSchemaCatalog.xml index 64742bc..e6883b3 100644 --- a/resources/ADAOSchemaCatalog.xml +++ b/resources/ADAOSchemaCatalog.xml @@ -222,7 +222,7 @@ print "Entering in FakeOptimizerLoopNode" result = None ]]> - + diff --git a/src/daSalome/daYacsIntegration/daOptimizerLoop.py b/src/daSalome/daYacsIntegration/daOptimizerLoop.py index dfa5a4f..7487d9d 100644 --- a/src/daSalome/daYacsIntegration/daOptimizerLoop.py +++ b/src/daSalome/daYacsIntegration/daOptimizerLoop.py @@ -67,6 +67,20 @@ class OptimizerHooks: return sample + def get_data_from_any(self, any_data): + error = any_data["returnCode"].getIntValue() + if error != 0: + self.optim_algo.setError(any_data["errorMessage"].getStringValue()) + + data = [] + outputValues = any_data["outputValues"] + for param in outputValues[0]: + for i in range(param.size()): + data.append(param[i].getDoubleValue()) + + matrix = numpy.matrix(data).T + return matrix + def Direct(self, X, sync = 1): print "Call Direct OptimizerHooks" if sync == 1: @@ -92,15 +106,13 @@ class OptimizerHooks: sample_id = self.optim_algo.pool.getCurrentId() if sample_id == local_counter: # 4: Data is ready - matrix_from_pool = self.optim_algo.pool.getOutSample(local_counter).getStringValue() + any_data = self.optim_algo.pool.getOutSample(local_counter) + Y = self.get_data_from_any(any_data) # 5: Release lock # Have to be done before but need a new implementation # of the optimizer loop self.counter_lock.release() - - # 6: return results - Y = pickle.loads(matrix_from_pool) return Y else: print "sync false is not yet implemented" @@ -129,15 +141,13 @@ class OptimizerHooks: sample_id = self.optim_algo.pool.getCurrentId() if sample_id == local_counter: # 4: Data is ready - matrix_from_pool = self.optim_algo.pool.getOutSample(local_counter).getStringValue() + any_data = self.optim_algo.pool.getOutSample(local_counter) + Y = self.get_data_from_any(any_data) # 5: Release lock # Have to be done before but need a new implementation # of the optimizer loop self.counter_lock.release() - - # 6: return results - Y = pickle.loads(matrix_from_pool) return Y else: print "sync false is not yet implemented" @@ -168,15 +178,13 @@ class OptimizerHooks: sample_id = self.optim_algo.pool.getCurrentId() if sample_id == local_counter: # 4: Data is ready - matrix_from_pool = self.optim_algo.pool.getOutSample(local_counter).getStringValue() + any_data = self.optim_algo.pool.getOutSample(local_counter) + Z = self.get_data_from_any(any_data) # 5: Release lock # Have to be done before but need a new implementation # of the optimizer loop self.counter_lock.release() - - # 6: return results - Z = pickle.loads(matrix_from_pool) return Z else: print "sync false is not yet implemented" @@ -190,8 +198,9 @@ 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("SALOME_TYPES/ParametricInput") - self.tout = self.runtime.getTypeCode("pyobj") + self.tin = self.runtime.getTypeCode("SALOME_TYPES/ParametricInput") + self.tout = self.runtime.getTypeCode("SALOME_TYPES/ParametricOutput") + self.pyobject = self.runtime.getTypeCode("pyobj") self.optim_hooks = OptimizerHooks(self) @@ -254,7 +263,7 @@ class AssimilationAlgorithm_asynch(SALOMERuntime.OptimizerAlgASync): def getTCForOut(self): return self.tout def getTCForAlgoInit(self): - return self.tout + return self.pyobject def getTCForAlgoResult(self): - return self.tout + return self.pyobject diff --git a/src/daSalome/daYacsSchemaCreator/methods.py b/src/daSalome/daYacsSchemaCreator/methods.py index d5fc4a2..bc58afc 100644 --- a/src/daSalome/daYacsSchemaCreator/methods.py +++ b/src/daSalome/daYacsSchemaCreator/methods.py @@ -50,9 +50,11 @@ def create_yacs_proc(study_config): proc = runtime.createProc("proc") proc.setTypeCode("pyobj", runtime.getTypeCode("pyobj")) proc.setTypeCode("SALOME_TYPES/ParametricInput", catalogAd._typeMap["SALOME_TYPES/ParametricInput"]) + proc.setTypeCode("SALOME_TYPES/ParametricOutput", catalogAd._typeMap["SALOME_TYPES/ParametricOutput"]) t_pyobj = proc.getTypeCode("pyobj") t_string = proc.getTypeCode("string") - t_param_input = proc.getTypeCode("SALOME_TYPES/ParametricInput") + t_param_input = proc.getTypeCode("SALOME_TYPES/ParametricInput") + t_param_output = proc.getTypeCode("SALOME_TYPES/ParametricOutput") repertory = False base_repertory = "" if "Repertory" in study_config.keys(): @@ -228,7 +230,7 @@ def create_yacs_proc(study_config): sys.exit(1) opt_script_node.setScript(script_str.read()) opt_script_node.edAddInputPort("computation", t_param_input) - opt_script_node.edAddOutputPort("result", t_pyobj) + opt_script_node.edAddOutputPort("result", t_param_output) # Add it computation_bloc = runtime.createBloc("computation_bloc") diff --git a/src/tests/daSalome/test017_3DVAR_function_script.py b/src/tests/daSalome/test017_3DVAR_function_script.py index 09f2e4c..3581d9e 100644 --- a/src/tests/daSalome/test017_3DVAR_function_script.py +++ b/src/tests/daSalome/test017_3DVAR_function_script.py @@ -18,12 +18,27 @@ def AdjointH( (X, Y) ): return H.T * Y if method == "Direct": - result = FunctionH(numpy.matrix(computation["inputValues"][0][0]).T) + data = FunctionH(numpy.matrix(computation["inputValues"][0][0]).T) if method == "Tangent": - result = FunctionH(numpy.matrix(computation["inputValues"][0][0]).T) + data = FunctionH(numpy.matrix(computation["inputValues"][0][0]).T) if method == "Adjoint": - result = AdjointH((numpy.matrix(computation["inputValues"][0][0]).T, numpy.matrix(computation["inputValues"][0][1]).T)) + data = AdjointH((numpy.matrix(computation["inputValues"][0][0]).T, numpy.matrix(computation["inputValues"][0][1]).T)) + +outputValues = [[[]]] +it = data.flat +for val in it: + outputValues[0][0].append(val) + +print outputValues + +result = {} +result["outputValues"] = outputValues +result["specificOutputInfos"] = [] +result["returnCode"] = 0 +result["errorMessage"] = "" + +print result print "Computation end"