# -*- 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
# 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
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)
#
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
Concept = None, # Premier argument
Algorithm = None,
AppliedInXb = None,
- AvoidRC = True,
Checked = False,
ColMajor = False,
ColNames = None,
ObjectMatrix = None,
OneFunction = None,
Parameters = None,
+ PerformanceProfile = None,
ScalarSparseMatrix = None,
Scheduler = None,
Script = None,
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))
Script = None,
ExtraArguments = None,
Stored = False,
- AvoidRC = True,
+ PerformanceProfile = None,
InputFunctionAsMulti = False,
Checked = False):
"Definition d'un concept de calcul"
asDict = Parameters,
appliedInX = AppliedInXb,
extraArguments = ExtraArguments,
- avoidRC = AvoidRC,
+ performancePrf = PerformanceProfile,
inputAsMF = InputFunctionAsMulti,
scheduledBy = None,
toBeChecked = Checked,
Scheduler = None,
ExtraArguments = None,
Stored = False,
- AvoidRC = True,
+ PerformanceProfile = None,
InputFunctionAsMulti = False,
Checked = False):
"Definition d'un concept de calcul"
asDict = Parameters,
appliedInX = None,
extraArguments = ExtraArguments,
- avoidRC = AvoidRC,
+ performancePrf = PerformanceProfile,
inputAsMF = InputFunctionAsMulti,
scheduledBy = Scheduler,
toBeChecked = Checked,
Scheduler = None,
ExtraArguments = None,
Stored = False,
- AvoidRC = True,
+ PerformanceProfile = None,
InputFunctionAsMulti = False,
Checked = False):
"Definition d'un concept de calcul"
asDict = Parameters,
appliedInX = None,
extraArguments = ExtraArguments,
- avoidRC = AvoidRC,
+ performancePrf = PerformanceProfile,
inputAsMF = InputFunctionAsMulti,
scheduledBy = Scheduler,
toBeChecked = Checked,
asString = String,
asScript = self.__with_directory(Script),
)))
+ return 0
# -----------------------------------------------------------
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):
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
__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: