From: Jean-Philippe ARGAUD Date: Wed, 15 Mar 2017 21:25:37 +0000 (+0100) Subject: Python 3 compatibility improvement X-Git-Tag: V8_3_0rc1~17 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c4d26891b4d5909257317d959d19ce7068030171;p=modules%2Fadao.git Python 3 compatibility improvement --- diff --git a/src/daComposant/daAlgorithms/3DVAR.py b/src/daComposant/daAlgorithms/3DVAR.py index d9a1187..7ddc1bb 100644 --- a/src/daComposant/daAlgorithms/3DVAR.py +++ b/src/daComposant/daAlgorithms/3DVAR.py @@ -364,4 +364,4 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): # ============================================================================== if __name__ == "__main__": - print '\n AUTODIAGNOSTIC \n' + print('\n AUTODIAGNOSTIC \n') diff --git a/src/daComposant/daAlgorithms/4DVAR.py b/src/daComposant/daAlgorithms/4DVAR.py index 9c49f91..344ee6c 100644 --- a/src/daComposant/daAlgorithms/4DVAR.py +++ b/src/daComposant/daAlgorithms/4DVAR.py @@ -324,4 +324,4 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): # ============================================================================== if __name__ == "__main__": - print '\n AUTODIAGNOSTIC \n' + print('\n AUTODIAGNOSTIC \n') diff --git a/src/daComposant/daAlgorithms/AdjointTest.py b/src/daComposant/daAlgorithms/AdjointTest.py index bda7162..92ae2f3 100644 --- a/src/daComposant/daAlgorithms/AdjointTest.py +++ b/src/daComposant/daAlgorithms/AdjointTest.py @@ -163,13 +163,12 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): # # Sorties eventuelles # ------------------- - print - print "Results of adjoint check by \"%s\" formula:"%self._parameters["ResiduFormula"] - print msgs + print("\nResults of adjoint check by \"%s\" formula:"%self._parameters["ResiduFormula"]) + print(msgs) # self._post_run(HO) return 0 # ============================================================================== if __name__ == "__main__": - print '\n AUTODIAGNOSTIC \n' + print('\n AUTODIAGNOSTIC \n') diff --git a/src/daComposant/daAlgorithms/Blue.py b/src/daComposant/daAlgorithms/Blue.py index 2e9b1af..00c429d 100644 --- a/src/daComposant/daAlgorithms/Blue.py +++ b/src/daComposant/daAlgorithms/Blue.py @@ -207,4 +207,4 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): # ============================================================================== if __name__ == "__main__": - print '\n AUTODIAGNOSTIC \n' + print('\n AUTODIAGNOSTIC \n') diff --git a/src/daComposant/daAlgorithms/DerivativeFreeOptimization.py b/src/daComposant/daAlgorithms/DerivativeFreeOptimization.py index 44f9364..221d4ef 100644 --- a/src/daComposant/daAlgorithms/DerivativeFreeOptimization.py +++ b/src/daComposant/daAlgorithms/DerivativeFreeOptimization.py @@ -217,8 +217,8 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): lb = lub[:,0] ub = lub[:,1] if self._parameters["optdisp"]: - print "%s: upper bounds %s"%(opt.get_algorithm_name(),ub) - print "%s: lower bounds %s"%(opt.get_algorithm_name(),lb) + print("%s: upper bounds %s"%(opt.get_algorithm_name(),ub)) + print("%s: lower bounds %s"%(opt.get_algorithm_name(),lb)) opt.set_upper_bounds(ub) opt.set_lower_bounds(lb) opt.set_ftol_rel(self._parameters["CostDecrementTolerance"]) @@ -226,9 +226,9 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): opt.set_maxeval(self._parameters["MaximumNumberOfFunctionEvaluations"]) Minimum = opt.optimize( Xini ) if self._parameters["optdisp"]: - print "%s: optimal state: %s"%(opt.get_algorithm_name(),Minimum) - print "%s: minimum of J: %s"%(opt.get_algorithm_name(),opt.last_optimum_value()) - print "%s: return code: %i"%(opt.get_algorithm_name(),opt.last_optimize_result()) + print("%s: optimal state: %s"%(opt.get_algorithm_name(),Minimum)) + print("%s: minimum of J: %s"%(opt.get_algorithm_name(),opt.last_optimum_value())) + print("%s: return code: %i"%(opt.get_algorithm_name(),opt.last_optimize_result())) elif self._parameters["Minimizer"] == "SIMPLEX" and not PlatformInfo.has_nlopt: Minimum, J_optimal, niter, nfeval, rc = scipy.optimize.fmin( func = CostFunction, @@ -253,8 +253,8 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): lb = lub[:,0] ub = lub[:,1] if self._parameters["optdisp"]: - print "%s: upper bounds %s"%(opt.get_algorithm_name(),ub) - print "%s: lower bounds %s"%(opt.get_algorithm_name(),lb) + print("%s: upper bounds %s"%(opt.get_algorithm_name(),ub)) + print("%s: lower bounds %s"%(opt.get_algorithm_name(),lb)) opt.set_upper_bounds(ub) opt.set_lower_bounds(lb) opt.set_ftol_rel(self._parameters["CostDecrementTolerance"]) @@ -262,9 +262,9 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): opt.set_maxeval(self._parameters["MaximumNumberOfFunctionEvaluations"]) Minimum = opt.optimize( Xini ) if self._parameters["optdisp"]: - print "%s: optimal state: %s"%(opt.get_algorithm_name(),Minimum) - print "%s: minimum of J: %s"%(opt.get_algorithm_name(),opt.last_optimum_value()) - print "%s: return code: %i"%(opt.get_algorithm_name(),opt.last_optimize_result()) + print("%s: optimal state: %s"%(opt.get_algorithm_name(),Minimum)) + print("%s: minimum of J: %s"%(opt.get_algorithm_name(),opt.last_optimum_value())) + print("%s: return code: %i"%(opt.get_algorithm_name(),opt.last_optimize_result())) elif self._parameters["Minimizer"] == "BOBYQA" and PlatformInfo.has_nlopt: import nlopt opt = nlopt.opt(nlopt.LN_BOBYQA, Xini.size) @@ -277,8 +277,8 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): lb = lub[:,0] ub = lub[:,1] if self._parameters["optdisp"]: - print "%s: upper bounds %s"%(opt.get_algorithm_name(),ub) - print "%s: lower bounds %s"%(opt.get_algorithm_name(),lb) + print("%s: upper bounds %s"%(opt.get_algorithm_name(),ub)) + print("%s: lower bounds %s"%(opt.get_algorithm_name(),lb)) opt.set_upper_bounds(ub) opt.set_lower_bounds(lb) opt.set_ftol_rel(self._parameters["CostDecrementTolerance"]) @@ -286,9 +286,9 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): opt.set_maxeval(self._parameters["MaximumNumberOfFunctionEvaluations"]) Minimum = opt.optimize( Xini ) if self._parameters["optdisp"]: - print "%s: optimal state: %s"%(opt.get_algorithm_name(),Minimum) - print "%s: minimum of J: %s"%(opt.get_algorithm_name(),opt.last_optimum_value()) - print "%s: return code: %i"%(opt.get_algorithm_name(),opt.last_optimize_result()) + print("%s: optimal state: %s"%(opt.get_algorithm_name(),Minimum)) + print("%s: minimum of J: %s"%(opt.get_algorithm_name(),opt.last_optimum_value())) + print("%s: return code: %i"%(opt.get_algorithm_name(),opt.last_optimize_result())) elif self._parameters["Minimizer"] == "NEWUOA" and PlatformInfo.has_nlopt: import nlopt opt = nlopt.opt(nlopt.LN_NEWUOA, Xini.size) @@ -301,8 +301,8 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): lb = lub[:,0] ub = lub[:,1] if self._parameters["optdisp"]: - print "%s: upper bounds %s"%(opt.get_algorithm_name(),ub) - print "%s: lower bounds %s"%(opt.get_algorithm_name(),lb) + print("%s: upper bounds %s"%(opt.get_algorithm_name(),ub)) + print("%s: lower bounds %s"%(opt.get_algorithm_name(),lb)) opt.set_upper_bounds(ub) opt.set_lower_bounds(lb) opt.set_ftol_rel(self._parameters["CostDecrementTolerance"]) @@ -310,9 +310,9 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): opt.set_maxeval(self._parameters["MaximumNumberOfFunctionEvaluations"]) Minimum = opt.optimize( Xini ) if self._parameters["optdisp"]: - print "%s: optimal state: %s"%(opt.get_algorithm_name(),Minimum) - print "%s: minimum of J: %s"%(opt.get_algorithm_name(),opt.last_optimum_value()) - print "%s: return code: %i"%(opt.get_algorithm_name(),opt.last_optimize_result()) + print("%s: optimal state: %s"%(opt.get_algorithm_name(),Minimum)) + print("%s: minimum of J: %s"%(opt.get_algorithm_name(),opt.last_optimum_value())) + print("%s: return code: %i"%(opt.get_algorithm_name(),opt.last_optimize_result())) elif self._parameters["Minimizer"] == "SUBPLEX" and PlatformInfo.has_nlopt: import nlopt opt = nlopt.opt(nlopt.LN_SBPLX, Xini.size) @@ -325,8 +325,8 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): lb = lub[:,0] ub = lub[:,1] if self._parameters["optdisp"]: - print "%s: upper bounds %s"%(opt.get_algorithm_name(),ub) - print "%s: lower bounds %s"%(opt.get_algorithm_name(),lb) + print("%s: upper bounds %s"%(opt.get_algorithm_name(),ub)) + print("%s: lower bounds %s"%(opt.get_algorithm_name(),lb)) opt.set_upper_bounds(ub) opt.set_lower_bounds(lb) opt.set_ftol_rel(self._parameters["CostDecrementTolerance"]) @@ -334,9 +334,9 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): opt.set_maxeval(self._parameters["MaximumNumberOfFunctionEvaluations"]) Minimum = opt.optimize( Xini ) if self._parameters["optdisp"]: - print "%s: optimal state: %s"%(opt.get_algorithm_name(),Minimum) - print "%s: minimum of J: %s"%(opt.get_algorithm_name(),opt.last_optimum_value()) - print "%s: return code: %i"%(opt.get_algorithm_name(),opt.last_optimize_result()) + print("%s: optimal state: %s"%(opt.get_algorithm_name(),Minimum)) + print("%s: minimum of J: %s"%(opt.get_algorithm_name(),opt.last_optimum_value())) + print("%s: return code: %i"%(opt.get_algorithm_name(),opt.last_optimize_result())) else: raise ValueError("Error in Minimizer name: %s"%self._parameters["Minimizer"]) # @@ -377,4 +377,4 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): # ============================================================================== if __name__ == "__main__": - print '\n AUTODIAGNOSTIC \n' + print('\n AUTODIAGNOSTIC \n') diff --git a/src/daComposant/daAlgorithms/EnsembleBlue.py b/src/daComposant/daAlgorithms/EnsembleBlue.py index f07c53c..6cc0cf2 100644 --- a/src/daComposant/daAlgorithms/EnsembleBlue.py +++ b/src/daComposant/daAlgorithms/EnsembleBlue.py @@ -110,4 +110,4 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): # ============================================================================== if __name__ == "__main__": - print '\n AUTODIAGNOSTIC \n' + print('\n AUTODIAGNOSTIC \n') diff --git a/src/daComposant/daAlgorithms/ExtendedBlue.py b/src/daComposant/daAlgorithms/ExtendedBlue.py index eb6ff58..8f77514 100644 --- a/src/daComposant/daAlgorithms/ExtendedBlue.py +++ b/src/daComposant/daAlgorithms/ExtendedBlue.py @@ -208,4 +208,4 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): # ============================================================================== if __name__ == "__main__": - print '\n AUTODIAGNOSTIC \n' + print('\n AUTODIAGNOSTIC \n') diff --git a/src/daComposant/daAlgorithms/ExtendedKalmanFilter.py b/src/daComposant/daAlgorithms/ExtendedKalmanFilter.py index b38239e..f15f183 100644 --- a/src/daComposant/daAlgorithms/ExtendedKalmanFilter.py +++ b/src/daComposant/daAlgorithms/ExtendedKalmanFilter.py @@ -201,4 +201,4 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): # ============================================================================== if __name__ == "__main__": - print '\n AUTODIAGNOSTIC \n' + print('\n AUTODIAGNOSTIC \n') diff --git a/src/daComposant/daAlgorithms/FunctionTest.py b/src/daComposant/daAlgorithms/FunctionTest.py index 4d194a2..8b4cd5b 100644 --- a/src/daComposant/daAlgorithms/FunctionTest.py +++ b/src/daComposant/daAlgorithms/FunctionTest.py @@ -172,4 +172,4 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): # ============================================================================== if __name__ == "__main__": - print '\n AUTODIAGNOSTIC \n' + print('\n AUTODIAGNOSTIC \n') diff --git a/src/daComposant/daAlgorithms/GradientTest.py b/src/daComposant/daAlgorithms/GradientTest.py index 842604b..66eacba 100644 --- a/src/daComposant/daAlgorithms/GradientTest.py +++ b/src/daComposant/daAlgorithms/GradientTest.py @@ -276,9 +276,8 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): msgs += "\n" # # ---------- - print - print "Results of gradient check by \"%s\" formula:"%self._parameters["ResiduFormula"] - print msgs + print("\nResults of gradient check by \"%s\" formula:"%self._parameters["ResiduFormula"]) + print(msgs) # if self._parameters["PlotAndSave"]: f = open(str(self._parameters["ResultFile"])+".txt",'a') @@ -375,4 +374,4 @@ def dessiner( # ============================================================================== if __name__ == "__main__": - print '\n AUTODIAGNOSTIC \n' + print('\n AUTODIAGNOSTIC \n') diff --git a/src/daComposant/daAlgorithms/KalmanFilter.py b/src/daComposant/daAlgorithms/KalmanFilter.py index caca1e7..6684c8b 100644 --- a/src/daComposant/daAlgorithms/KalmanFilter.py +++ b/src/daComposant/daAlgorithms/KalmanFilter.py @@ -177,4 +177,4 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): # ============================================================================== if __name__ == "__main__": - print '\n AUTODIAGNOSTIC \n' + print('\n AUTODIAGNOSTIC \n') diff --git a/src/daComposant/daAlgorithms/LinearLeastSquares.py b/src/daComposant/daAlgorithms/LinearLeastSquares.py index 491ea0a..fe21b64 100644 --- a/src/daComposant/daAlgorithms/LinearLeastSquares.py +++ b/src/daComposant/daAlgorithms/LinearLeastSquares.py @@ -91,4 +91,4 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): # ============================================================================== if __name__ == "__main__": - print '\n AUTODIAGNOSTIC \n' + print('\n AUTODIAGNOSTIC \n') diff --git a/src/daComposant/daAlgorithms/LinearityTest.py b/src/daComposant/daAlgorithms/LinearityTest.py index c09fcf6..8f79f48 100644 --- a/src/daComposant/daAlgorithms/LinearityTest.py +++ b/src/daComposant/daAlgorithms/LinearityTest.py @@ -334,13 +334,12 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): # # Sorties eventuelles # ------------------- - print - print "Results of linearity check by \"%s\" formula:"%self._parameters["ResiduFormula"] - print msgs + print("\nResults of linearity check by \"%s\" formula:"%self._parameters["ResiduFormula"]) + print(msgs) # self._post_run(HO) return 0 # ============================================================================== if __name__ == "__main__": - print '\n AUTODIAGNOSTIC \n' + print('\n AUTODIAGNOSTIC \n') diff --git a/src/daComposant/daAlgorithms/NonLinearLeastSquares.py b/src/daComposant/daAlgorithms/NonLinearLeastSquares.py index b568207..ca3f98b 100644 --- a/src/daComposant/daAlgorithms/NonLinearLeastSquares.py +++ b/src/daComposant/daAlgorithms/NonLinearLeastSquares.py @@ -286,4 +286,4 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): # ============================================================================== if __name__ == "__main__": - print '\n AUTODIAGNOSTIC \n' + print('\n AUTODIAGNOSTIC \n') diff --git a/src/daComposant/daAlgorithms/ObserverTest.py b/src/daComposant/daAlgorithms/ObserverTest.py index 07b20df..e08fd68 100644 --- a/src/daComposant/daAlgorithms/ObserverTest.py +++ b/src/daComposant/daAlgorithms/ObserverTest.py @@ -31,9 +31,9 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): def run(self, Xb=None, Y=None, U=None, HO=None, EM=None, CM=None, R=None, B=None, Q=None, Parameters=None): self._pre_run(Parameters) - print "Results of observer check on all potential variables or commands," - print " only activated on selected ones by explicit association." - print + print("Results of observer check on all potential variables or commands,") + print(" only activated on selected ones by explicit association.") + print("") # __Xa = 1.+numpy.arange(3.) __Xb = numpy.zeros(3) @@ -71,10 +71,10 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): self.StoredVariables["SimulatedObservationAtOptimum"].store( __YY ) self.StoredVariables["SimulatedObservationAtCurrentOptimum"].store( __YY ) # - print + print("") self._post_run() return 0 # ============================================================================== if __name__ == "__main__": - print '\n AUTODIAGNOSTIC \n' + print('\n AUTODIAGNOSTIC \n') diff --git a/src/daComposant/daAlgorithms/ParticleSwarmOptimization.py b/src/daComposant/daAlgorithms/ParticleSwarmOptimization.py index 68dba9f..7b7edd0 100644 --- a/src/daComposant/daAlgorithms/ParticleSwarmOptimization.py +++ b/src/daComposant/daAlgorithms/ParticleSwarmOptimization.py @@ -272,4 +272,4 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): # ============================================================================== if __name__ == "__main__": - print '\n AUTODIAGNOSTIC \n' + print('\n AUTODIAGNOSTIC \n') diff --git a/src/daComposant/daAlgorithms/QuantileRegression.py b/src/daComposant/daAlgorithms/QuantileRegression.py index 671bfa5..d6c50c1 100644 --- a/src/daComposant/daAlgorithms/QuantileRegression.py +++ b/src/daComposant/daAlgorithms/QuantileRegression.py @@ -174,4 +174,4 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): # ============================================================================== if __name__ == "__main__": - print '\n AUTODIAGNOSTIC \n' + print('\n AUTODIAGNOSTIC \n') diff --git a/src/daComposant/daAlgorithms/SamplingTest.py b/src/daComposant/daAlgorithms/SamplingTest.py index cb71257..77d08af 100644 --- a/src/daComposant/daAlgorithms/SamplingTest.py +++ b/src/daComposant/daAlgorithms/SamplingTest.py @@ -191,4 +191,4 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): # ============================================================================== if __name__ == "__main__": - print '\n AUTODIAGNOSTIC \n' + print('\n AUTODIAGNOSTIC \n') diff --git a/src/daComposant/daAlgorithms/TabuSearch.py b/src/daComposant/daAlgorithms/TabuSearch.py index 9efa49b..161fd4a 100644 --- a/src/daComposant/daAlgorithms/TabuSearch.py +++ b/src/daComposant/daAlgorithms/TabuSearch.py @@ -265,4 +265,4 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): # ============================================================================== if __name__ == "__main__": - print '\n AUTODIAGNOSTIC \n' + print('\n AUTODIAGNOSTIC \n') diff --git a/src/daComposant/daAlgorithms/TangentTest.py b/src/daComposant/daAlgorithms/TangentTest.py index 1ed6440..3612f55 100644 --- a/src/daComposant/daAlgorithms/TangentTest.py +++ b/src/daComposant/daAlgorithms/TangentTest.py @@ -191,13 +191,12 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): # # Sorties eventuelles # ------------------- - print - print "Results of tangent check by \"%s\" formula:"%self._parameters["ResiduFormula"] - print msgs + print("\nResults of tangent check by \"%s\" formula:"%self._parameters["ResiduFormula"]) + print(msgs) # self._post_run(HO) return 0 # ============================================================================== if __name__ == "__main__": - print '\n AUTODIAGNOSTIC \n' + print('\n AUTODIAGNOSTIC \n') diff --git a/src/daComposant/daAlgorithms/UnscentedKalmanFilter.py b/src/daComposant/daAlgorithms/UnscentedKalmanFilter.py index 3f1245c..fdb6b4f 100644 --- a/src/daComposant/daAlgorithms/UnscentedKalmanFilter.py +++ b/src/daComposant/daAlgorithms/UnscentedKalmanFilter.py @@ -295,4 +295,4 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): # ============================================================================== if __name__ == "__main__": - print '\n AUTODIAGNOSTIC \n' + print('\n AUTODIAGNOSTIC \n')