# -*- coding: utf-8 -*-
#
-# Copyright (C) 2008-2017 EDF R&D
+# Copyright (C) 2008-2021 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
#
from daCore.BasicObjects import State, Covariance, FullOperator, Operator
from daCore.BasicObjects import AlgorithmAndParameters, DataObserver
-from daCore.BasicObjects import DiagnosticAndParameters, CaseLogger
+from daCore.BasicObjects import RegulationAndParameters, CaseLogger
+from daCore.BasicObjects import UserScript, ExternalParameters
from daCore import PlatformInfo
#
from daCore import ExtendedLogging ; ExtendedLogging.ExtendedLogging() # A importer en premier
""" ADAO Internal Data Structure Model """
def __init__(self, name = "", addViewers=None):
self.__name = str(name)
+ self.__directory = None
self.__case = CaseLogger(self.__name, "case", addViewers)
#
self.__adaoObject = {}
self.__StoredInputs = {}
+ self.__PostAnalysis = []
#
- self.__Concepts = [
+ self.__Concepts = [ # Liste exhaustive
"AlgorithmParameters",
"Background",
+ "BackgroundError",
"CheckingPoint",
"ControlInput",
- "Observation",
- "Controls",
- "BackgroundError",
- "ObservationError",
- "EvolutionError",
- "ObservationOperator",
- "EvolutionModel",
"ControlModel",
"Debug",
+ "Directory",
+ "EvolutionError",
+ "EvolutionModel",
+ "Name",
"NoDebug",
+ "Observation",
+ "ObservationError",
+ "ObservationOperator",
"Observer",
+ "RegulationParameters",
+ "SupplementaryParameters",
+ "UserPostAnalysis",
]
#
for ename in self.__Concepts:
self.__adaoObject[ename] = None
for ename in ("ObservationOperator", "EvolutionModel", "ControlModel"):
self.__adaoObject[ename] = {}
- for ename in ("Diagnostic", "Observer"):
+ for ename in ("Observer", "UserPostAnalysis"):
self.__adaoObject[ename] = []
- self.__StoredInputs[ename] = []
+ self.__StoredInputs[ename] = [] # Vide par defaut
+ self.__StoredInputs["Name"] = self.__name
+ self.__StoredInputs["Directory"] = self.__directory
#
# Récupère le chemin du répertoire parent et l'ajoute au path
# (Cela complète l'action de la classe PathManagement dans PlatformInfo,
Algorithm = None,
AppliedInXb = None,
AvoidRC = True,
- BaseType = None,
Checked = False,
- Diagnostic = None,
+ ColMajor = False,
+ ColNames = None,
+ DataFile = None,
DiagonalSparseMatrix = None,
- Identifier = None,
+ ExtraArguments = None,
Info = None,
+ InputFunctionAsMulti = False,
Matrix = None,
ObjectFunction = None,
ObjectMatrix = None,
String = None,
Template = None,
ThreeFunctions = None,
- Unit = None,
Variable = None,
Vector = None,
VectorSerie = None,
"Interface unique de definition de variables d'entrees par argument"
self.__case.register("set",dir(),locals(),None,True)
try:
- if Concept in ("Background", "CheckingPoint", "ControlInput", "Observation", "Controls"):
+ if Concept in ("Background", "CheckingPoint", "ControlInput", "Observation"):
commande = getattr(self,"set"+Concept)
- commande(Vector, VectorSerie, Script, Scheduler, Stored, Checked )
+ commande(Vector, VectorSerie, Script, DataFile, ColNames, ColMajor, Stored, Scheduler, Checked )
elif Concept in ("BackgroundError", "ObservationError", "EvolutionError"):
commande = getattr(self,"set"+Concept)
commande(Matrix, ScalarSparseMatrix, DiagonalSparseMatrix,
- ObjectMatrix, Script, Stored, Checked )
+ Script, Stored, ObjectMatrix, Checked )
elif Concept == "AlgorithmParameters":
self.setAlgorithmParameters( Algorithm, Parameters, Script )
+ elif Concept == "RegulationParameters":
+ self.setRegulationParameters( Algorithm, Parameters, Script )
+ elif Concept == "Name":
+ self.setName(String)
+ elif Concept == "Directory":
+ self.setDirectory(String)
elif Concept == "Debug":
self.setDebug()
elif Concept == "NoDebug":
self.setNoDebug()
elif Concept == "Observer":
- self.setObserver( Variable, Template, String, Script, ObjectFunction, Scheduler, Info )
- elif Concept == "Diagnostic":
- self.setDiagnostic( Diagnostic, Identifier, Parameters, Script, Unit, BaseType )
+ self.setObserver( Variable, Template, String, Script, Info, ObjectFunction, Scheduler )
+ elif Concept == "UserPostAnalysis":
+ self.setUserPostAnalysis( Template, String, Script )
+ elif Concept == "SupplementaryParameters":
+ self.setSupplementaryParameters( Parameters, Script )
elif Concept == "ObservationOperator":
self.setObservationOperator(
Matrix, OneFunction, ThreeFunctions, AppliedInXb,
- Parameters, Script, AvoidRC, Stored, Checked )
+ Parameters, Script, ExtraArguments,
+ Stored, AvoidRC, InputFunctionAsMulti, Checked )
elif Concept in ("EvolutionModel", "ControlModel"):
commande = getattr(self,"set"+Concept)
commande(
Matrix, OneFunction, ThreeFunctions,
- Parameters, Script, Scheduler, AvoidRC, Stored, Checked )
-
+ Parameters, Script, Scheduler, ExtraArguments,
+ Stored, AvoidRC, 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)
else: msg = ""
- raise ValueError("during settings, the following error occurs:\n"+\
- "\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))
+ raise ValueError(("during settings, the following error occurs:\n"+\
+ "\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))
# -----------------------------------------------------------
Vector = None,
VectorSerie = None,
Script = None,
- Scheduler = None,
+ DataFile = None,
+ ColNames = None,
+ ColMajor = False,
Stored = False,
+ Scheduler = None,
Checked = False):
"Definition d'un concept de calcul"
Concept = "Background"
name = Concept,
asVector = Vector,
asPersistentVector = VectorSerie,
- asScript = Script,
+ asScript = self.__with_directory(Script),
+ asDataFile = DataFile,
+ colNames = ColNames,
+ colMajor = ColMajor,
scheduledBy = Scheduler,
toBeChecked = Checked,
)
Vector = None,
VectorSerie = None,
Script = None,
- Scheduler = None,
+ DataFile = None,
+ ColNames = None,
+ ColMajor = False,
Stored = False,
+ Scheduler = None,
Checked = False):
"Definition d'un concept de calcul"
Concept = "CheckingPoint"
name = Concept,
asVector = Vector,
asPersistentVector = VectorSerie,
- asScript = Script,
+ asScript = self.__with_directory(Script),
+ asDataFile = DataFile,
+ colNames = ColNames,
+ colMajor = ColMajor,
scheduledBy = Scheduler,
toBeChecked = Checked,
)
Vector = None,
VectorSerie = None,
Script = None,
- Scheduler = None,
+ DataFile = None,
+ ColNames = None,
+ ColMajor = False,
Stored = False,
+ Scheduler = None,
Checked = False):
"Definition d'un concept de calcul"
Concept = "ControlInput"
name = Concept,
asVector = Vector,
asPersistentVector = VectorSerie,
- asScript = Script,
+ asScript = self.__with_directory(Script),
+ asDataFile = DataFile,
+ colNames = ColNames,
+ colMajor = ColMajor,
scheduledBy = Scheduler,
toBeChecked = Checked,
)
Vector = None,
VectorSerie = None,
Script = None,
- Scheduler = None,
+ DataFile = None,
+ ColNames = None,
+ ColMajor = False,
Stored = False,
- Checked = False):
- "Definition d'un concept de calcul"
- Concept = "Observation"
- self.__case.register("set"+Concept, dir(), locals())
- self.__adaoObject[Concept] = State(
- name = Concept,
- asVector = Vector,
- asPersistentVector = VectorSerie,
- asScript = Script,
- scheduledBy = Scheduler,
- toBeChecked = Checked,
- )
- if Stored:
- self.__StoredInputs[Concept] = self.__adaoObject[Concept].getO()
- return 0
-
- def setControls(self,
- Vector = (), # Valeur par defaut pour un vecteur vide
- VectorSerie = None,
- Script = None,
Scheduler = None,
- Stored = False,
Checked = False):
"Definition d'un concept de calcul"
- Concept = "Controls"
+ Concept = "Observation"
self.__case.register("set"+Concept, dir(), locals())
self.__adaoObject[Concept] = State(
name = Concept,
asVector = Vector,
asPersistentVector = VectorSerie,
- asScript = Script,
+ asScript = self.__with_directory(Script),
+ asDataFile = DataFile,
+ colNames = ColNames,
+ colMajor = ColMajor,
scheduledBy = Scheduler,
toBeChecked = Checked,
)
Matrix = None,
ScalarSparseMatrix = None,
DiagonalSparseMatrix = None,
- ObjectMatrix = None,
Script = None,
Stored = False,
+ ObjectMatrix = None,
Checked = False):
"Definition d'un concept de calcul"
Concept = "BackgroundError"
asEyeByScalar = ScalarSparseMatrix,
asEyeByVector = DiagonalSparseMatrix,
asCovObject = ObjectMatrix,
- asScript = Script,
+ asScript = self.__with_directory(Script),
toBeChecked = Checked,
)
if Stored:
Matrix = None,
ScalarSparseMatrix = None,
DiagonalSparseMatrix = None,
- ObjectMatrix = None,
Script = None,
Stored = False,
+ ObjectMatrix = None,
Checked = False):
"Definition d'un concept de calcul"
Concept = "ObservationError"
asEyeByScalar = ScalarSparseMatrix,
asEyeByVector = DiagonalSparseMatrix,
asCovObject = ObjectMatrix,
- asScript = Script,
+ asScript = self.__with_directory(Script),
toBeChecked = Checked,
)
if Stored:
Matrix = None,
ScalarSparseMatrix = None,
DiagonalSparseMatrix = None,
- ObjectMatrix = None,
Script = None,
Stored = False,
+ ObjectMatrix = None,
Checked = False):
"Definition d'un concept de calcul"
Concept = "EvolutionError"
asEyeByScalar = ScalarSparseMatrix,
asEyeByVector = DiagonalSparseMatrix,
asCovObject = ObjectMatrix,
- asScript = Script,
+ asScript = self.__with_directory(Script),
toBeChecked = Checked,
)
if Stored:
return 0
def setObservationOperator(self,
- Matrix = None,
- OneFunction = None,
- ThreeFunctions = None,
- AppliedInXb = None,
- Parameters = None,
- Script = None,
- AvoidRC = True,
- Stored = False,
- Checked = False):
+ Matrix = None,
+ OneFunction = None,
+ ThreeFunctions = None,
+ AppliedInXb = None,
+ Parameters = None,
+ Script = None,
+ ExtraArguments = None,
+ Stored = False,
+ AvoidRC = True,
+ InputFunctionAsMulti = False,
+ Checked = False):
"Definition d'un concept de calcul"
Concept = "ObservationOperator"
self.__case.register("set"+Concept, dir(), locals())
asMatrix = Matrix,
asOneFunction = OneFunction,
asThreeFunctions = ThreeFunctions,
- asScript = Script,
+ asScript = self.__with_directory(Script),
asDict = Parameters,
appliedInX = AppliedInXb,
+ extraArguments = ExtraArguments,
avoidRC = AvoidRC,
+ inputAsMF = InputFunctionAsMulti,
scheduledBy = None,
toBeChecked = Checked,
)
return 0
def setEvolutionModel(self,
- Matrix = None,
- OneFunction = None,
- ThreeFunctions = None,
- Parameters = None,
- Script = None,
- Scheduler = None,
- AvoidRC = True,
- Stored = False,
- Checked = False):
+ Matrix = None,
+ OneFunction = None,
+ ThreeFunctions = None,
+ Parameters = None,
+ Script = None,
+ Scheduler = None,
+ ExtraArguments = None,
+ Stored = False,
+ AvoidRC = True,
+ InputFunctionAsMulti = False,
+ Checked = False):
"Definition d'un concept de calcul"
Concept = "EvolutionModel"
self.__case.register("set"+Concept, dir(), locals())
asMatrix = Matrix,
asOneFunction = OneFunction,
asThreeFunctions = ThreeFunctions,
- asScript = Script,
+ asScript = self.__with_directory(Script),
asDict = Parameters,
appliedInX = None,
+ extraArguments = ExtraArguments,
avoidRC = AvoidRC,
+ inputAsMF = InputFunctionAsMulti,
scheduledBy = Scheduler,
toBeChecked = Checked,
)
return 0
def setControlModel(self,
- Matrix = None,
- OneFunction = None,
- ThreeFunctions = None,
- Parameters = None,
- Script = None,
- Scheduler = None,
- AvoidRC = True,
- Stored = False,
- Checked = False):
+ Matrix = None,
+ OneFunction = None,
+ ThreeFunctions = None,
+ Parameters = None,
+ Script = None,
+ Scheduler = None,
+ ExtraArguments = None,
+ Stored = False,
+ AvoidRC = True,
+ InputFunctionAsMulti = False,
+ Checked = False):
"Definition d'un concept de calcul"
Concept = "ControlModel"
self.__case.register("set"+Concept, dir(), locals())
asMatrix = Matrix,
asOneFunction = OneFunction,
asThreeFunctions = ThreeFunctions,
- asScript = Script,
+ asScript = self.__with_directory(Script),
asDict = Parameters,
appliedInX = None,
+ extraArguments = ExtraArguments,
avoidRC = AvoidRC,
+ inputAsMF = InputFunctionAsMulti,
scheduledBy = Scheduler,
toBeChecked = Checked,
)
self.__StoredInputs[Concept] = self.__adaoObject[Concept].getO()
return 0
- def setDebug(self, level = 10):
+ def setName(self, String=None):
+ "Definition d'un concept de calcul"
+ self.__case.register("setName",dir(),locals())
+ if String is not None:
+ self.__name = str(String)
+ else:
+ self.__name = None
+ self.__StoredInputs["Name"] = self.__name
+
+ def setDirectory(self, String=None):
+ "Definition d'un concept de calcul"
+ self.__case.register("setDirectory",dir(),locals())
+ if os.path.isdir(os.path.abspath(str(String))):
+ self.__directory = os.path.abspath(str(String))
+ else:
+ self.__directory = None
+ self.__StoredInputs["Directory"] = self.__directory
+
+ def setDebug(self, __level = 10):
"NOTSET=0 < DEBUG=10 < INFO=20 < WARNING=30 < ERROR=40 < CRITICAL=50"
self.__case.register("setDebug",dir(),locals())
log = logging.getLogger()
- log.setLevel( level )
- self.__StoredInputs["Debug"] = level
+ log.setLevel( __level )
+ self.__StoredInputs["Debug"] = __level
self.__StoredInputs["NoDebug"] = False
return 0
name = Concept,
asAlgorithm = Algorithm,
asDict = Parameters,
- asScript = Script,
+ asScript = self.__with_directory(Script),
)
return 0
Parameters = None,
Script = None):
"Mise a jour d'un concept de calcul"
- if "AlgorithmParameters" not in self.__adaoObject:
- raise ValueError("No algorithm registred, ask for one before updating parameters")
- self.__adaoObject["AlgorithmParameters"].updateParameters(
+ Concept = "AlgorithmParameters"
+ if Concept not in self.__adaoObject or self.__adaoObject[Concept] is None:
+ raise ValueError("\n\nNo algorithm registred, set one before updating parameters or executing\n")
+ self.__adaoObject[Concept].updateParameters(
asDict = Parameters,
- asScript = Script,
+ asScript = self.__with_directory(Script),
+ )
+ # RaJ du register
+ return 0
+
+ def setRegulationParameters(self,
+ Algorithm = None,
+ Parameters = None,
+ Script = None):
+ "Definition d'un concept de calcul"
+ Concept = "RegulationParameters"
+ self.__case.register("set"+Concept, dir(), locals())
+ self.__adaoObject[Concept] = RegulationAndParameters(
+ name = Concept,
+ asAlgorithm = Algorithm,
+ asDict = Parameters,
+ asScript = self.__with_directory(Script),
+ )
+ return 0
+
+ def setSupplementaryParameters(self,
+ Parameters = None,
+ Script = None):
+ "Definition d'un concept de calcul"
+ Concept = "SupplementaryParameters"
+ self.__case.register("set"+Concept, dir(), locals())
+ self.__adaoObject[Concept] = ExternalParameters(
+ name = Concept,
+ asDict = Parameters,
+ asScript = self.__with_directory(Script),
+ )
+ return 0
+
+ def updateSupplementaryParameters(self,
+ Parameters = None,
+ Script = None):
+ "Mise a jour d'un concept de calcul"
+ Concept = "SupplementaryParameters"
+ if Concept not in self.__adaoObject or self.__adaoObject[Concept] is None:
+ self.__adaoObject[Concept] = ExternalParameters(name = Concept)
+ self.__adaoObject[Concept].updateParameters(
+ asDict = Parameters,
+ asScript = self.__with_directory(Script),
)
return 0
Template = None,
String = None,
Script = None,
+ Info = None,
ObjectFunction = None,
- Scheduler = None,
- Info = None):
+ Scheduler = None):
"Definition d'un concept de calcul"
Concept = "Observer"
self.__case.register("set"+Concept, dir(), locals())
onVariable = Variable,
asTemplate = Template,
asString = String,
- asScript = Script,
+ asScript = self.__with_directory(Script),
asObsObject = ObjectFunction,
withInfo = Info,
scheduledBy = Scheduler,
else:
return self.__adaoObject["AlgorithmParameters"].removeObserver( ename, ObjectFunction )
- # -----------------------------------------------------------
-
- def setDiagnostic(self,
- Diagnostic = None,
- Identifier = None,
- Parameters = None,
- Script = None,
- Unit = None,
- BaseType = None):
+ def setUserPostAnalysis(self,
+ Template = None,
+ String = None,
+ Script = None):
"Definition d'un concept de calcul"
- Concept = "Diagnostic"
+ Concept = "UserPostAnalysis"
self.__case.register("set"+Concept, dir(), locals())
- self.__adaoObject[Concept].append( DiagnosticAndParameters(
- name = Concept,
- asDiagnostic = Diagnostic,
- asIdentifier = Identifier,
- asDict = Parameters,
- asScript = Script,
- asUnit = Unit,
- asBaseType = BaseType,
- asExistingDiags = self.__StoredInputs[Concept],
- ))
- self.__StoredInputs[Concept].append(str(Identifier))
- return 0
+ self.__adaoObject[Concept].append( repr(UserScript(
+ name = Concept,
+ asTemplate = Template,
+ asString = String,
+ asScript = self.__with_directory(Script),
+ )))
+
+ # -----------------------------------------------------------
def get(self, Concept=None, noDetails=True ):
"Recuperation d'une sortie du calcul"
elif Concept == "AlgorithmRequiredParameters" and self.__adaoObject["AlgorithmParameters"] is not None:
return self.__adaoObject["AlgorithmParameters"].getAlgorithmRequiredParameters(noDetails)
#
- elif Concept in self.__StoredInputs["Diagnostic"]:
- indice = self.__StoredInputs["Diagnostic"].index(Concept)
- return self.__adaoObject["Diagnostic"][indice].get()
+ elif Concept == "AlgorithmRequiredInputs" and self.__adaoObject["AlgorithmParameters"] is not None:
+ return self.__adaoObject["AlgorithmParameters"].getAlgorithmInputArguments()
+ #
+ elif Concept == "AlgorithmAttributes" and self.__adaoObject["AlgorithmParameters"] is not None:
+ return self.__adaoObject["AlgorithmParameters"].getAlgorithmAttributes()
+ #
+ elif self.__adaoObject["SupplementaryParameters"] is not None and Concept == "SupplementaryParameters":
+ return self.__adaoObject["SupplementaryParameters"].get()
+ #
+ elif self.__adaoObject["SupplementaryParameters"] is not None and Concept in self.__adaoObject["SupplementaryParameters"]:
+ return self.__adaoObject["SupplementaryParameters"].get( Concept )
#
else:
- raise ValueError("The requested key \"%s\" does not exists as an input, a diagnostic or a stored variable."%Concept)
+ raise ValueError("The requested key \"%s\" does not exists as an input or a stored variable."%Concept)
else:
allvariables = {}
allvariables.update( {"AlgorithmParameters":self.__adaoObject["AlgorithmParameters"].get()} )
- allvariables.update( self.__adaoObject["AlgorithmParameters"].get() )
+ if self.__adaoObject["SupplementaryParameters"] is not None:
+ allvariables.update( {"SupplementaryParameters":self.__adaoObject["SupplementaryParameters"].get()} )
+ # allvariables.update( self.__adaoObject["AlgorithmParameters"].get() )
allvariables.update( self.__StoredInputs )
- allvariables.pop('Diagnostic', None)
allvariables.pop('Observer', None)
+ allvariables.pop('UserPostAnalysis', None)
return allvariables
# -----------------------------------------------------------
variables = []
if len(list(self.__adaoObject["AlgorithmParameters"].keys())) > 0:
variables.extend(list(self.__adaoObject["AlgorithmParameters"].keys()))
+ if self.__adaoObject["SupplementaryParameters"] is not None and \
+ len(list(self.__adaoObject["SupplementaryParameters"].keys())) > 0:
+ variables.extend(list(self.__adaoObject["SupplementaryParameters"].keys()))
if len(list(self.__StoredInputs.keys())) > 0:
variables.extend( list(self.__StoredInputs.keys()) )
- variables.remove('Diagnostic')
variables.remove('Observer')
+ variables.remove('UserPostAnalysis')
variables.sort()
return variables
"""
files = []
for directory in sys.path:
- if os.path.isdir(os.path.join(directory,"daAlgorithms")):
- for fname in os.listdir(os.path.join(directory,"daAlgorithms")):
- root, ext = os.path.splitext(fname)
- if ext == '.py' and root != '__init__':
- files.append(root)
- files.sort()
- return files
-
- def get_available_diagnostics(self):
- """
- Renvoie la liste des diagnostics potentiellement utilisables, identifiés
- par les chaînes de caractères.
- """
- files = []
- for directory in sys.path:
- if os.path.isdir(os.path.join(directory,"daDiagnostics")):
- for fname in os.listdir(os.path.join(directory,"daDiagnostics")):
- root, ext = os.path.splitext(fname)
- if ext == '.py' and root != '__init__':
- files.append(root)
+ trypath = os.path.join(directory,"daAlgorithms")
+ if os.path.isdir(trypath):
+ for fname in os.listdir(trypath):
+ if os.path.isfile(os.path.join(trypath,fname)):
+ root, ext = os.path.splitext(fname)
+ if ext != ".py": continue
+ with open(os.path.join(trypath,fname)) as fc:
+ iselal = bool("class ElementaryAlgorithm" in fc.read())
+ if iselal and ext == '.py' and root != '__init__':
+ files.append(root)
files.sort()
return files
- # -----------------------------------------------------------
-
def get_algorithms_main_path(self):
"""
Renvoie le chemin pour le répertoire principal contenant les algorithmes
- dans un sous-répertoire "daAlgorithms"
"""
return self.__parent
"""
Ajoute au chemin de recherche des algorithmes un répertoire dans lequel
se trouve un sous-répertoire "daAlgorithms"
-
- Remarque : si le chemin a déjà été ajouté pour les diagnostics, il n'est
- pas indispensable de le rajouter ici.
"""
if not os.path.isdir(Path):
raise ValueError("The given "+Path+" argument must exist as a directory")
sys.path = PlatformInfo.uniq( sys.path ) # Conserve en unique exemplaire chaque chemin
return 0
- def get_diagnostics_main_path(self):
- """
- Renvoie le chemin pour le répertoire principal contenant les diagnostics
- dans un sous-répertoire "daDiagnostics"
- """
- return self.__parent
-
- def add_diagnostics_path(self, Path=None):
- """
- Ajoute au chemin de recherche des algorithmes un répertoire dans lequel
- se trouve un sous-répertoire "daDiagnostics"
-
- Remarque : si le chemin a déjà été ajouté pour les algorithmes, il n'est
- pas indispensable de le rajouter ici.
- """
- if not os.path.isdir(Path):
- raise ValueError("The given "+Path+" argument must exist as a directory")
- if not os.path.isdir(os.path.join(Path,"daDiagnostics")):
- raise ValueError("The given \""+Path+"\" argument must contain a subdirectory named \"daDiagnostics\"")
- if not os.path.isfile(os.path.join(Path,"daDiagnostics","__init__.py")):
- raise ValueError("The given \""+Path+"/daDiagnostics\" path must contain a file named \"__init__.py\"")
- sys.path.insert(0, os.path.abspath(Path))
- sys.path = PlatformInfo.uniq( sys.path ) # Conserve en unique exemplaire chaque chemin
- return 0
-
# -----------------------------------------------------------
- def execute(self, Executor=None, SaveCaseInFile=None):
+ def execute(self, Executor=None, SaveCaseInFile=None, nextStep=False):
"Lancement du calcul"
self.__case.register("execute",dir(),locals(),None,True)
- Operator.CM.clearCache()
+ self.updateAlgorithmParameters(Parameters={"nextStep":bool(nextStep)})
+ if not nextStep: Operator.CM.clearCache()
try:
if Executor == "YACS": self.__executeYACSScheme( SaveCaseInFile )
else: self.__executePythonScheme( SaveCaseInFile )
except Exception as e:
if isinstance(e, SyntaxError): msg = "at %s: %s"%(e.offset, e.text)
else: msg = ""
- raise ValueError("during execution, the following error occurs:\n"+\
+ raise ValueError(("during execution, the following error occurs:\n"+\
"\n%s %s\n\nSee also the potential messages, "+\
"which can show the origin of the above error, "+\
- "in the launching terminal.\n"%(str(e),msg))
+ "in the launching terminal.\n")%(str(e),msg))
return 0
def __executePythonScheme(self, FileName=None):
def __executeYACSScheme(self, FileName=None):
"Lancement du calcul"
self.__case.register("executeYACSScheme", dir(), locals())
- if FileName is not None:
- self.dump( FileName, "DIC")
+ self.dump( FileName, "YACS")
self.__adaoObject["AlgorithmParameters"].executeYACSScheme( FileName )
return 0
def dump(self, FileName=None, Formater="TUI"):
"Restitution normalisée des commandes"
- return self.__case.dump(FileName, Formater)
+ __Upa = "\n".join(self.__PostAnalysis)
+ return self.__case.dump(FileName, Formater, __Upa)
- def load(self, FileName=None, Formater="TUI"):
+ def load(self, FileName=None, Content=None, Object=None, Formater="TUI"):
"Chargement normalisé des commandes"
- __commands = self.__case.load(FileName, Formater)
+ __commands = self.__case.load(FileName, Content, Object, Formater)
from numpy import array, matrix
for __command in __commands:
- exec("self."+__command)
- return 0
+ if (__command.find("set")>-1 and __command.find("set_")<0) or 'UserPostAnalysis' in __command:
+ exec("self."+__command)
+ else:
+ self.__PostAnalysis.append(__command)
+ return self
+
+ def convert(self,
+ FileNameFrom=None, ContentFrom=None, ObjectFrom=None, FormaterFrom="TUI",
+ FileNameTo=None, FormaterTo="TUI",
+ ):
+ "Conversion normalisée des commandes"
+ return self.load(
+ FileName=FileNameFrom, Content=ContentFrom, Object=ObjectFrom, Formater=FormaterFrom
+ ).dump(
+ FileName=FileNameTo, Formater=FormaterTo
+ )
def clear(self):
"Effacement du contenu du cas en cours"
# -----------------------------------------------------------
+ def __with_directory(self, __filename=None):
+ if os.path.exists(str(__filename)):
+ __fullpath = __filename
+ elif os.path.exists(os.path.join(str(self.__directory), str(__filename))):
+ __fullpath = os.path.join(self.__directory, str(__filename))
+ else:
+ __fullpath = __filename
+ return __fullpath
+
def __dir__(self):
"Clarifie la visibilité des méthodes"
- return ['set', 'get', 'execute', '__doc__', '__init__', '__module__']
+ return ['set', 'get', 'execute', 'dump', 'load', '__doc__', '__init__', '__module__']
def prepare_to_pickle(self):
"Retire les variables non pickelisables, avec recopie efficace"
for k in self.__adaoObject['AlgorithmParameters'].keys():
if k == "Algorithm": continue
if k in self.__StoredInputs:
- raise ValueError("the key \"%s\s to be transfered for pickling will overwrite an existing one.")
+ raise ValueError("The key \"%s\" to be transfered for pickling will overwrite an existing one."%(k,))
if self.__adaoObject['AlgorithmParameters'].hasObserver( k ):
self.__adaoObject['AlgorithmParameters'].removeObserver( k, "", True )
self.__StoredInputs[k] = self.__adaoObject['AlgorithmParameters'].pop(k, None)
- del self.__adaoObject # Because it breaks pickle in Python 2. Not required for Python 3
- del self.__case # Because it breaks pickle in Python 2. Not required for Python 3
- return 0
+ if sys.version_info[0] == 2:
+ del self.__adaoObject # Because it breaks pickle in Python 2. Not required for Python 3
+ del self.__case # Because it breaks pickle in Python 2. Not required for Python 3
+ if sys.version_info.major < 3:
+ return 0
+ else:
+ return self.__StoredInputs
# ==============================================================================
if __name__ == "__main__":
- print('\n AUTODIAGNOSTIC \n')
+ print('\n AUTODIAGNOSTIC\n')