From: Jean-Philippe ARGAUD Date: Tue, 16 Oct 2018 20:07:16 +0000 (+0200) Subject: Correction of Python 3 compatibility with YACS types X-Git-Tag: V9_2_0b_ok_ADAO X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=be415eaa6bc8d642ed98f3f483f0dfe70df64d4d;p=modules%2Fadao.git Correction of Python 3 compatibility with YACS types --- diff --git a/resources/ADAOSchemaCatalog.xml b/resources/ADAOSchemaCatalog.xml index 07792d2..9cab17f 100644 --- a/resources/ADAOSchemaCatalog.xml +++ b/resources/ADAOSchemaCatalog.xml @@ -33,7 +33,7 @@ - + @@ -238,6 +238,7 @@ if (matrix_in_string.find("array")>-1) or (matrix_in_string.find("matrix")>-1): exec("matrix="+matrix_in_string) matrix = numpy.matrix(matrix) else: + matrix_in_string=matrix_in_string.replace("'","").replace('"','') matrix = numpy.matrix(matrix_in_string) type = "Matrix" logging.debug("CREATE YI Matrix is %s"%matrix) @@ -258,6 +259,7 @@ if (matrix_in_string.find("array")>-1) or (matrix_in_string.find("matrix")>-1): exec("matrix="+matrix_in_string) matrix = numpy.matrix(matrix) else: + matrix_in_string=matrix_in_string.replace("'","").replace('"','') matrix = numpy.matrix(matrix_in_string) type = "ScalarSparseMatrix" logging.debug("CREATE YI ScalarSparseMatrix is %s"%matrix) @@ -278,6 +280,7 @@ if (matrix_in_string.find("array")>-1) or (matrix_in_string.find("matrix")>-1): exec("matrix="+matrix_in_string) matrix = numpy.matrix(matrix) else: + matrix_in_string=matrix_in_string.replace("'","").replace('"','') matrix = numpy.matrix(matrix_in_string) type = "DiagonalSparseMatrix" logging.debug("CREATE YI DiagonalSparseMatrix is %s"%matrix) @@ -370,6 +373,7 @@ if (vector_in_string.find("array")>-1) or (vector_in_string.find("matrix")>-1): exec("vector="+vector_in_string) vector = numpy.matrix(vector) else: + vector_in_string=vector_in_string.replace("'","").replace('"','') vector = numpy.matrix(vector_in_string) type = "Vector" logging.debug("Vector is %s"%vector) @@ -458,9 +462,12 @@ ADD.analyze() @@ -530,10 +537,10 @@ if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index - diff --git a/src/daSalome/daYacsIntegration/daOptimizerLoop.py b/src/daSalome/daYacsIntegration/daOptimizerLoop.py index 14e5a22..0a05918 100644 --- a/src/daSalome/daYacsIntegration/daOptimizerLoop.py +++ b/src/daSalome/daYacsIntegration/daOptimizerLoop.py @@ -31,12 +31,12 @@ except: import numpy import threading import sys +import traceback # Pour disposer des classes dans l'espace de nommage lors du pickle from daCore.AssimilationStudy import AssimilationStudy from daYacsIntegration import daStudy - class OptimizerHooks: def __init__(self, optim_algo, switch_value=-1): @@ -60,18 +60,27 @@ class OptimizerHooks: 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) + if sys.version_info.major < 3: + method_name.setEltAtRank("value", method) + else: + method_name.setEltAtRank("value", pickle.dumps(method)) specificParameters.pushBack(method_name) # print self.optim_algo.has_observer if self.optim_algo.has_observer: obs_switch = pilot.StructAny_New(self.optim_algo.runtime.getTypeCode('SALOME_TYPES/Parameter')) obs_switch.setEltAtRank("name", "switch_value") - obs_switch.setEltAtRank("value", "1") + if sys.version_info.major < 3: + obs_switch.setEltAtRank("value", "1") + else: + obs_switch.setEltAtRank("value", pickle.dumps("1")) specificParameters.pushBack(obs_switch) if self.optim_algo.has_evolution_model: obs_switch = pilot.StructAny_New(self.optim_algo.runtime.getTypeCode('SALOME_TYPES/Parameter')) obs_switch.setEltAtRank("name", "switch_value") - obs_switch.setEltAtRank("value", self.switch_value) + if sys.version_info.major < 3: + obs_switch.setEltAtRank("value", self.switch_value) + else: + obs_switch.setEltAtRank("value", pickle.dumps(self.switch_value)) specificParameters.pushBack(obs_switch) sample.setEltAtRank("specificParameters", specificParameters) @@ -290,8 +299,11 @@ class AssimilationAlgorithm_asynch(SALOMERuntime.OptimizerAlgASync): #print "Algorithme initialize" # get the daStudy - #print "[Debug] Input is ", input - str_da_study = input.getStringValue() + # print "[Debug] Input is ", input + if sys.version_info.major < 3: + str_da_study = input.getStringValue() + else: + str_da_study = input.getBytes() try: self.da_study = pickle.loads(str_da_study) except ValueError as e: @@ -388,7 +400,10 @@ class AssimilationAlgorithm_asynch(SALOMERuntime.OptimizerAlgASync): # Switch Value obs_switch = pilot.StructAny_New(self.runtime.getTypeCode('SALOME_TYPES/Parameter')) obs_switch.setEltAtRank("name", "switch_value") - obs_switch.setEltAtRank("value", self.da_study.observers_dict[info]["number"]) + if sys.version_info.major < 3: + obs_switch.setEltAtRank("value", self.da_study.observers_dict[info]["number"]) + else: + obs_switch.setEltAtRank("value", pickle.dumps(self.da_study.observers_dict[info]["number"])) specificParameters.pushBack(obs_switch) # Var @@ -398,19 +413,21 @@ class AssimilationAlgorithm_asynch(SALOMERuntime.OptimizerAlgASync): # Remove Data Observer, so you can ... var.removeDataObserver(self.obs) # Pickle then ... - var_str = pickle.dumps(var) + var_struct.setEltAtRank("value", pickle.dumps(var)) + specificParameters.pushBack(var_struct) # Add Again Data Observer if self.da_study.observers_dict[info]["scheduler"] != "": self.ADD.setObserver(Variable = info, ObjectFunction = self.obs, Scheduler = self.da_study.observers_dict[info]["scheduler"], Info = info) else: self.ADD.setObserver(Variable = info, ObjectFunction = self.obs, Info = info) - var_struct.setEltAtRank("value", var_str) - specificParameters.pushBack(var_struct) # Info info_struct = pilot.StructAny_New(self.runtime.getTypeCode('SALOME_TYPES/Parameter')) info_struct.setEltAtRank("name", "info") - info_struct.setEltAtRank("value", self.da_study.observers_dict[info]["info"]) + if sys.version_info.major < 3: + info_struct.setEltAtRank("value", self.da_study.observers_dict[info]["info"]) + else: + info_struct.setEltAtRank("value", pickle.dumps(self.da_study.observers_dict[info]["info"])) specificParameters.pushBack(info_struct) sample.setEltAtRank("specificParameters", specificParameters) @@ -421,7 +438,6 @@ class AssimilationAlgorithm_asynch(SALOMERuntime.OptimizerAlgASync): self.pool.pushInSample(local_counter, sample) # Wait - import sys, traceback try: while True: self.signalMasterAndWait()