case.set( 'Observation', Vector=array([0.5, 1.5, 2.5]) )
case.set( 'ObservationError', DiagonalSparseMatrix='1 1 1' )
-As a remark, vector or matrix inputs can be given as objects of type ``str``,
-``list`` or ``tuple`` of Python, or of type ``array`` or ``matrix`` of Numpy.
+As a remark, vector or matrix inputs can be given as objects of type ``str``,
+``list`` or ``tuple`` of Python, or of type ``array`` or ``matrix`` of Numpy.
For these last two cases, one has only to import Numpy module before.
After that, one has to define the operators :math:`H` of observation and
simple present case of a linear operator, we use the following syntax for an
operator from :math:`\mathbf{R}^3` into itself::
- case.ObservationOperator(Matrix = "1 0 0;0 2 0;0 0 3")
+ case.set( 'ObservationOperator', Matrix = "1 0 0;0 2 0;0 0 3")
In the most frequent case of a non-linear operator of :math:`\mathbf{R}^n` into
:math:`\mathbf{R}^p`, it has to be previously available as a Python function,
**setObservationOperator** (*Matrix, OneFunction, ThreeFunctions, AppliedInXb, Parameters, Script, Stored*)
This command allows to set the evolution operator :math:`H`, which
transforms the input parameters :math:`\mathbf{x}` in results
- :math:`\mathbf{y}` that are compared to observations :math:`\mathbf{y}^o`.
+ :math:`\mathbf{y}` that are compared to observations :math:`\mathbf{y}^o`.
Its value is defined as an object of type function or of type "*Matrix*".
For the function case, various functional forms may be used, as described in
the :ref:`section_ref_operator_requirements`, and entered by "*OneFunction*"
.. index:: single: setObserver
**setObserver** (*Variable, Template, String, Script, Info*)
- This command allows to set an *observer* on the current or final
- calculation variable. Reference should be made to the description of the
- ':ref:`ref_observers_requirements` for their list and content, and to the
- :ref:`section_reference` to know what are the observable quantities. One
- defines as "*String*" the *observer* body, using a string including if
- necessary line breaks. It is recommended to use the patterns available by
- the argument "*Template*". In the case of a definition as "*Script*", the
- file must contain only the body of the function, as described in the
- :ref:`ref_observers_requirements`. The "*Info*" variable contains an
+ This command allows to set an *observer* on the current or final
+ calculation variable. Reference should be made to the description of the
+ ':ref:`ref_observers_requirements` for their list and content, and to the
+ :ref:`section_reference` to know what are the observable quantities. One
+ defines as "*String*" the *observer* body, using a string including if
+ necessary line breaks. It is recommended to use the patterns available by
+ the argument "*Template*". In the case of a definition as "*Script*", the
+ file must contain only the body of the function, as described in the
+ :ref:`ref_observers_requirements`. The "*Info*" variable contains an
information string or can be void.
Perform the calculation
+++++++++++++++++++++++
-.. index:: single: executePythonScheme
-
-**executePythonScheme** ()
- This command launches the complete calculation in the environment of the
- current Python interpreter, without interaction with YACS [YACS]_. The
- standard output and standard error are those of the Python interpreter. If
- necessary, the internal parallelism, of the algorithms in ADAO and of the
- simulation code used, is available.
-
.. index:: single: execute
-
-**execute** ()
- This command is a user shorthand for "*executePythonScheme*".
+.. index:: single: Executor
+.. index:: single: SaveCaseInFile
+
+**execute** (*Executor, SaveCaseInFile*)
+ This command launches the complete calculation in the execution environment
+ chosen by the keyword *Executor*. This environment can be the current
+ Python interpreter, without interaction with YACS (using the value
+ "*Python*"), or the one of YACS (using the value "*YACS*"). If a file is
+ given in the keyword *SaveCaseInFile*, it will be used to save the
+ associated version of commands file for the given execution environment.
+ During the execution, the usual outputs (standard and error) are the one of
+ the chosen environment. If necessary (and if possible), the ADAO algorithms
+ internal parallelism, the parallelism of YACS, and the internal parallelism
+ of the simulation code(s) used, are available.
Get the calculation results separately
++++++++++++++++++++++++++++++++++++++
Dans le cas présent le plus simple d'opérateur linéaire, on utilise la syntaxe
suivante pour un opérateur de :math:`\mathbf{R}^3` sur lui-même::
- case.ObservationOperator(Matrix = "1 0 0;0 2 0;0 0 3")
+ case.set( 'ObservationOperator', Matrix = "1 0 0;0 2 0;0 0 3")
Dans le cas beaucoup plus courant d'un opérateur non-linéaire de
:math:`\mathbf{R}^n` dans :math:`\mathbf{R}^p`, il doit être préalablement
Effectuer le calcul
+++++++++++++++++++
-.. index:: single: executePythonScheme
-
-**executePythonScheme** ()
- Cette commande lance le calcul complet dans l'environnement de
- l'interpréteur Python courant, sans interaction avec YACS [YACS]_. Les
- sorties standard et d'erreur sont celles de l'interpréteur Python. On
- dispose si nécessaire du parallélisme interne des algorithmes dans ADAO et
- du parallélisme interne du ou des codes de simulation utilisé.
-
-.. .. index:: single: generateYACSscheme
-..
-.. **executeYACSScheme** (*File*)
-.. Cete commande génère le schéma YACS [YACS]_ du cas de calcul dans le fichier
-.. requis "*File*", et en lance l'exécution dans l'interpréteur YACS, comme on
-.. peut le réaliser en utilisant l'éditeur standard de cas ADAO. Les sorties
-.. standard et d'erreur sont celles de l'interpréteur YACS. On dispose si
-.. nécessaire du parallélisme de noeuds et blocs dans YACS, du parallélisme
-.. interne des algorithmes dans ADAO et du parallélisme interne du ou des codes
-.. de simulation utilisé.
-
.. index:: single: execute
-
-**execute** ()
- Cette commande est un raccourci utilisateur pour "*executePythonScheme*".
+.. index:: single: Executor
+.. index:: single: SaveCaseInFile
+
+**execute** (*Executor, SaveCaseInFile*)
+ Cette commande lance le calcul complet dans l'environnement d'exécution
+ choisi par le mot-clé *Executor*. Cet environnement peut être celui de
+ l'interpréteur Python, sans interaction avec YACS (demandé par la valeur
+ "*Python*"), ou celui de YACS (demandé par la valeur "*YACS*"). Si un
+ fichier est indiqué dans le mot-clé *SaveCaseInFile*, il sera utilisé
+ pour enregistrer la version associée du fichier de commande pour
+ l'environnement d'exécution requis. Lors de l'exécution, les sorties
+ courantes (standard et d'erreur) sont celles de l'environnement choisi.
+ On dispose si nécessaire (ou si possible) du parallélisme interne des
+ algorithmes dans ADAO, du parallélisme de YACS, et du parallélisme interne
+ du ou des codes de simulation utilisés.
Obtenir séparément les résultats de calcul
++++++++++++++++++++++++++++++++++++++++++
from daCore.BasicObjects import DiagnosticAndParameters, ImportFromScript
from daCore.BasicObjects import CaseLogger, GenericCaseViewer
from daCore.Templates import ObserverTemplates
+from daCore import Persistence
from daCore import PlatformInfo
# ==============================================================================
__local.pop(__k)
for __k,__v in __local.items():
if __k == "Concept": continue
- if __k in ['ScalarSparseMatrix','DiagonalSparseMatrix','Matrix'] and 'Script' in __local: continue
+ if __k in ['ScalarSparseMatrix','DiagonalSparseMatrix','Matrix','OneFunction','ThreeFunctions'] and 'Script' in __local: continue
if __k == 'Algorithm':
__text += "study_config['Algorithm'] = %s\n"%(repr(__v))
elif __k == 'Script':
__k = 'Vector'
+ __f = 'Script'
+ __v = "'"+repr(__v)+"'"
for __lk in ['ScalarSparseMatrix','DiagonalSparseMatrix','Matrix']:
if __lk in __local and __local[__lk]: __k = __lk
if __command == "AlgorithmParameters": __k = "Dict"
+ if 'OneFunction' in __local and __local['OneFunction']:
+ __text += "%s_ScriptWithOneFunction = {}\n"%(__command,)
+ __text += "%s_ScriptWithOneFunction['Function'] = ['Direct', 'Tangent', 'Adjoint']\n"%(__command,)
+ __text += "%s_ScriptWithOneFunction['Script'] = {}\n"%(__command,)
+ __text += "%s_ScriptWithOneFunction['Script']['Direct'] = %s\n"%(__command,__v)
+ __text += "%s_ScriptWithOneFunction['Script']['Tangent'] = %s\n"%(__command,__v)
+ __text += "%s_ScriptWithOneFunction['Script']['Adjoint'] = %s\n"%(__command,__v)
+ __text += "%s_ScriptWithOneFunction['DifferentialIncrement'] = 1e-06\n"%(__command,)
+ __text += "%s_ScriptWithOneFunction['CenteredFiniteDifference'] = 0\n"%(__command,)
+ __k = 'Function'
+ __f = 'ScriptWithOneFunction'
+ __v = '%s_ScriptWithOneFunction'%(__command,)
+ if 'ThreeFunctions' in __local and __local['ThreeFunctions']:
+ __text += "%s_ScriptWithFunctions = {}\n"%(__command,)
+ __text += "%s_ScriptWithFunctions['Function'] = ['Direct', 'Tangent', 'Adjoint']\n"%(__command,)
+ __text += "%s_ScriptWithFunctions['Script'] = {}\n"%(__command,)
+ __text += "%s_ScriptWithFunctions['Script']['Direct'] = %s\n"%(__command,__v)
+ __text += "%s_ScriptWithFunctions['Script']['Tangent'] = %s\n"%(__command,__v)
+ __text += "%s_ScriptWithFunctions['Script']['Adjoint'] = %s\n"%(__command,__v)
+ __k = 'Function'
+ __f = 'ScriptWithFunctions'
+ __v = '%s_ScriptWithFunctions'%(__command,)
__text += "%s_config['Type'] = '%s'\n"%(__command,__k)
- __text += "%s_config['From'] = '%s'\n"%(__command,'Script')
- __text += "%s_config['Data'] = '%s'\n"%(__command,repr(__v))
+ __text += "%s_config['From'] = '%s'\n"%(__command,__f)
+ __text += "%s_config['Data'] = %s\n"%(__command,__v)
__text = __text.replace("''","'")
elif __k in ('Stored', 'Checked'):
if bool(__v):
__text += "%s_config['%s'] = '%s'\n"%(__command,__k,int(bool(__v)))
else:
if __k is 'Parameters': __k = "Dict"
+ if isinstance(__v,Persistence.Persistence): __v = __v.values()
+ if callable(__v): __text = self._missing%__v.__name__+__text
+ if isinstance(__v,dict):
+ for val in __v.values():
+ if callable(val): __text = self._missing%val.__name__+__text
__text += "%s_config['Type'] = '%s'\n"%(__command,__k)
__text += "%s_config['From'] = '%s'\n"%(__command,'String')
__text += "%s_config['Data'] = \"\"\"%s\"\"\"\n"%(__command,repr(__v))
class XMLViewer(GenericCaseViewer):
"""
- Etablissement des commandes de creation d'un cas DIC
+ Etablissement des commandes de creation d'un cas XML
"""
def __init__(self, __name="", __objname="case", __content=None):
"Initialisation et enregistrement de l'entete"
# ==============================================================================
class Aidsm(object):
""" ADAO Internal Data Structure Model """
- def __init__(self, name = "", viewers={"DIC":DICViewer, "XML":XMLViewer}):
+ def __init__(self, name = "", addViewers={"DIC":DICViewer}):
self.__name = str(name)
- self.__case = CaseLogger(self.__name, "case", viewers)
+ self.__case = CaseLogger(self.__name, "case", addViewers)
#
self.__adaoObject = {}
self.__StoredInputs = {}
#
for ename in self.__Concepts:
self.__adaoObject[ename] = None
- for ename in ("ObservationOperator", "EvolutionModel", "ControlModel", "Observer"):
+ for ename in ("ObservationOperator", "EvolutionModel", "ControlModel"):
self.__adaoObject[ename] = {}
for ename in ("Diagnostic", "Observer"):
self.__adaoObject[ename] = []
# -----------------------------------------------------------
- def execute(self, Executor=None, FileName=None):
+ def execute(self, Executor=None, SaveCaseInFile=None):
"Lancement du calcul"
self.__case.register("execute",dir(),locals(),None,True)
Operator.CM.clearCache()
#~ try:
- if Executor == "YACS": self.__executeYACSScheme( FileName )
- else: self.__executePythonScheme( FileName )
+ 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 = ""
if self.__adaoObject['AlgorithmParameters'].hasObserver( k ):
self.__adaoObject['AlgorithmParameters'].removeObserver( k, "", True )
self.__StoredInputs[k] = self.__adaoObject['AlgorithmParameters'].pop(k, None)
- del self.__adaoObject # Break pickle in Python 2
- del self.__case # Break pickle in Python 2
+ del self.__adaoObject # Because it breaks pickle in Python 2
+ del self.__case # Because it breaks pickle in Python 2
return 0
# ==============================================================================
"""
Conservation des commandes de creation d'un cas
"""
- def __init__(self, __name="", __objname="case", __viewers={}, __loaders={}):
+ def __init__(self, __name="", __objname="case", __addViewers={}, __addLoaders={}):
self.__name = str(__name)
self.__objname = str(__objname)
self.__logSerie = []
self.__switchoff = False
self.__viewers = self.__loaders = {"TUI":_TUIViewer}
- self.__viewers.update(__viewers)
- self.__loaders.update(__loaders)
+ self.__viewers.update(__addViewers)
+ self.__loaders.update(__addLoaders)
def register(self, __command=None, __keys=None, __local=None, __pre=None, __switchoff=False):
"Enregistrement d'une commande individuelle"