X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FdaComposant%2FdaCore%2FAidsm.py;h=3aa0c20e835bb64958b4f7425609d10f8971fa9b;hb=61f19963a2e2ed620bdf577c5a01808586dd938d;hp=a981db1b3330e1a1e0e4af1020af85a952e71c4e;hpb=b65156518aa4eea50d8dec1320b5eca3b48ca239;p=modules%2Fadao.git diff --git a/src/daComposant/daCore/Aidsm.py b/src/daComposant/daCore/Aidsm.py index a981db1..3aa0c20 100644 --- a/src/daComposant/daCore/Aidsm.py +++ b/src/daComposant/daCore/Aidsm.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # -# Copyright (C) 2008-2021 EDF R&D +# Copyright (C) 2008-2022 EDF R&D # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -21,13 +21,14 @@ # Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D """ - Normalized interface for ADAO scripting (generic API) + Normalized interface for ADAO scripting (generic API). """ __author__ = "Jean-Philippe ARGAUD" __all__ = ["Aidsm"] import os import sys +import inspect # from daCore.BasicObjects import State, Covariance, FullOperator, Operator from daCore.BasicObjects import AlgorithmAndParameters, DataObserver @@ -42,7 +43,8 @@ import logging class Aidsm(object): """ ADAO Internal Data Structure Model """ def __init__(self, name = "", addViewers=None): - self.__name = str(name) + self.__name = str(name) + self.__objname = None self.__directory = None self.__case = CaseLogger(self.__name, "case", addViewers) # @@ -76,6 +78,10 @@ class Aidsm(object): self.__adaoObject[ename] = None for ename in ("ObservationOperator", "EvolutionModel", "ControlModel"): self.__adaoObject[ename] = {} + for ename in ("BackgroundError", "ObservationError"): + self.__adaoObject[ename] = Covariance(ename, asEyeByScalar = 1.) + for ename in ("EvolutionError",): + self.__adaoObject[ename] = Covariance(ename, asEyeByScalar = 1.e-16) for ename in ("Observer", "UserPostAnalysis"): self.__adaoObject[ename] = [] self.__StoredInputs[ename] = [] # Vide par defaut @@ -93,7 +99,6 @@ class Aidsm(object): Concept = None, # Premier argument Algorithm = None, AppliedInXb = None, - AvoidRC = True, Checked = False, ColMajor = False, ColNames = None, @@ -107,6 +112,7 @@ class Aidsm(object): ObjectMatrix = None, OneFunction = None, Parameters = None, + PerformanceProfile = None, ScalarSparseMatrix = None, Scheduler = None, Script = None, @@ -150,20 +156,20 @@ class Aidsm(object): self.setObservationOperator( Matrix, OneFunction, ThreeFunctions, AppliedInXb, Parameters, Script, ExtraArguments, - Stored, AvoidRC, InputFunctionAsMulti, Checked ) + Stored, PerformanceProfile, InputFunctionAsMulti, Checked ) elif Concept in ("EvolutionModel", "ControlModel"): commande = getattr(self,"set"+Concept) commande( Matrix, OneFunction, ThreeFunctions, Parameters, Script, Scheduler, ExtraArguments, - Stored, AvoidRC, InputFunctionAsMulti, Checked ) + Stored, PerformanceProfile, InputFunctionAsMulti, Checked ) else: raise ValueError("the variable named '%s' is not allowed."%str(Concept)) except Exception as e: - if isinstance(e, SyntaxError): msg = "at %s: %s"%(e.offset, e.text) + if isinstance(e, SyntaxError): msg = " at %s: %s"%(e.offset, e.text) else: msg = "" raise ValueError(("during settings, the following error occurs:\n"+\ - "\n%s %s\n\nSee also the potential messages, "+\ + "\n%s%s\n\nSee also the potential messages, "+\ "which can show the origin of the above error, "+\ "in the launching terminal.")%(str(e),msg)) @@ -362,7 +368,7 @@ class Aidsm(object): Script = None, ExtraArguments = None, Stored = False, - AvoidRC = True, + PerformanceProfile = None, InputFunctionAsMulti = False, Checked = False): "Definition d'un concept de calcul" @@ -377,7 +383,7 @@ class Aidsm(object): asDict = Parameters, appliedInX = AppliedInXb, extraArguments = ExtraArguments, - avoidRC = AvoidRC, + performancePrf = PerformanceProfile, inputAsMF = InputFunctionAsMulti, scheduledBy = None, toBeChecked = Checked, @@ -395,7 +401,7 @@ class Aidsm(object): Scheduler = None, ExtraArguments = None, Stored = False, - AvoidRC = True, + PerformanceProfile = None, InputFunctionAsMulti = False, Checked = False): "Definition d'un concept de calcul" @@ -410,7 +416,7 @@ class Aidsm(object): asDict = Parameters, appliedInX = None, extraArguments = ExtraArguments, - avoidRC = AvoidRC, + performancePrf = PerformanceProfile, inputAsMF = InputFunctionAsMulti, scheduledBy = Scheduler, toBeChecked = Checked, @@ -428,7 +434,7 @@ class Aidsm(object): Scheduler = None, ExtraArguments = None, Stored = False, - AvoidRC = True, + PerformanceProfile = None, InputFunctionAsMulti = False, Checked = False): "Definition d'un concept de calcul" @@ -443,7 +449,7 @@ class Aidsm(object): asDict = Parameters, appliedInX = None, extraArguments = ExtraArguments, - avoidRC = AvoidRC, + performancePrf = PerformanceProfile, inputAsMF = InputFunctionAsMulti, scheduledBy = Scheduler, toBeChecked = Checked, @@ -620,6 +626,7 @@ class Aidsm(object): asString = String, asScript = self.__with_directory(Script), ))) + return 0 # ----------------------------------------------------------- @@ -759,6 +766,11 @@ class Aidsm(object): if FileName is not None: self.dump( FileName, "TUI") self.__adaoObject["AlgorithmParameters"].executePythonScheme( self.__adaoObject ) + if "UserPostAnalysis" in self.__adaoObject and len(self.__adaoObject["UserPostAnalysis"])>0: + self.__objname = self.__retrieve_objname() + for __UpaOne in self.__adaoObject["UserPostAnalysis"]: + __UpaOne = eval(str(__UpaOne)) + exec(__UpaOne, {}, {'self':self, 'ADD':self, 'case':self, 'adaopy':self, self.__objname:self}) return 0 def __executeYACSScheme(self, FileName=None): @@ -781,7 +793,7 @@ class Aidsm(object): from numpy import array, matrix for __command in __commands: if (__command.find("set")>-1 and __command.find("set_")<0) or 'UserPostAnalysis' in __command: - exec("self."+__command) + exec("self."+__command, {}, locals()) else: self.__PostAnalysis.append(__command) return self @@ -812,10 +824,28 @@ class Aidsm(object): __fullpath = __filename return __fullpath + def __retrieve_objname(self): + "Ne pas utiliser dans le __init__, la variable appelante n'existe pas encore" + __names = [] + for level in reversed(inspect.stack()): + __names += [name for name, value in level.frame.f_locals.items() if value is self] + __names += [name for name, value in globals().items() if value is self] + while 'self' in __names: __names.remove('self') # Devrait toujours être trouvé, donc pas d'erreur + if len(__names) > 0: + self.__objname = __names[0] + else: + self.__objname = "ADD" + return self.__objname + def __dir__(self): "Clarifie la visibilité des méthodes" return ['set', 'get', 'execute', 'dump', 'load', '__doc__', '__init__', '__module__'] + def __str__(self): + "Représentation pour impression (mais pas repr)" + msg = self.dump(None, "SimpleReportInPlainTxt") + return msg + def prepare_to_pickle(self): "Retire les variables non pickelisables, avec recopie efficace" if self.__adaoObject['AlgorithmParameters'] is not None: