From 803e92088f1c58e78636a0204c1bd2ccea24d6bc Mon Sep 17 00:00:00 2001 From: Jean-Philippe ARGAUD Date: Wed, 3 Oct 2018 21:10:30 +0200 Subject: [PATCH] Compatibility updates and documentation corrections --- doc/en/snippets/Minimizer_DE.rst | 2 -- doc/fr/snippets/Minimizer_DE.rst | 2 -- resources/ADAOSchemaCatalog.xml | 1 + .../daAlgorithms/DifferentialEvolution.py | 4 +-- src/daComposant/daCore/Aidsm.py | 29 +++++++++++++++- src/daComposant/daCore/BasicObjects.py | 33 ++++++++++++++++++- src/daComposant/daCore/Interfaces.py | 15 ++++++--- 7 files changed, 74 insertions(+), 12 deletions(-) diff --git a/doc/en/snippets/Minimizer_DE.rst b/doc/en/snippets/Minimizer_DE.rst index 69a46d7..1947080 100644 --- a/doc/en/snippets/Minimizer_DE.rst +++ b/doc/en/snippets/Minimizer_DE.rst @@ -8,11 +8,9 @@ Minimizer "BEST1EXP", "RAND1EXP", "RANDTOBEST1EXP", - "CURRENTTOBEST1EXP", "BEST2EXP", "RAND2EXP", "RANDTOBEST1BIN", - "CURRENTTOBEST1BIN", "BEST2BIN", "RAND2BIN", "RAND1BIN". diff --git a/doc/fr/snippets/Minimizer_DE.rst b/doc/fr/snippets/Minimizer_DE.rst index 616ca5d..4c96c14 100644 --- a/doc/fr/snippets/Minimizer_DE.rst +++ b/doc/fr/snippets/Minimizer_DE.rst @@ -9,11 +9,9 @@ Minimizer "BEST1EXP", "RAND1EXP", "RANDTOBEST1EXP", - "CURRENTTOBEST1EXP", "BEST2EXP", "RAND2EXP", "RANDTOBEST1BIN", - "CURRENTTOBEST1BIN", "BEST2BIN", "RAND2BIN", "RAND1BIN". diff --git a/resources/ADAOSchemaCatalog.xml b/resources/ADAOSchemaCatalog.xml index b1a32ab..4569aa1 100644 --- a/resources/ADAOSchemaCatalog.xml +++ b/resources/ADAOSchemaCatalog.xml @@ -67,6 +67,7 @@ print("Algorithm is set to...:", Algorithm) try: # Create Assimilation study + import adao from daYacsIntegration.daStudy import * assim_study = daStudy(Name, Algorithm, Debug) diff --git a/src/daComposant/daAlgorithms/DifferentialEvolution.py b/src/daComposant/daAlgorithms/DifferentialEvolution.py index 381d413..74cd606 100644 --- a/src/daComposant/daAlgorithms/DifferentialEvolution.py +++ b/src/daComposant/daAlgorithms/DifferentialEvolution.py @@ -38,11 +38,11 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): "BEST1EXP", "RAND1EXP", "RANDTOBEST1EXP", - "CURRENTTOBEST1EXP", + # "CURRENTTOBEST1EXP", "BEST2EXP", "RAND2EXP", "RANDTOBEST1BIN", - "CURRENTTOBEST1BIN", + # "CURRENTTOBEST1BIN", "BEST2BIN", "RAND2BIN", "RAND1BIN", diff --git a/src/daComposant/daCore/Aidsm.py b/src/daComposant/daCore/Aidsm.py index dcd14f5..953ef8d 100644 --- a/src/daComposant/daCore/Aidsm.py +++ b/src/daComposant/daCore/Aidsm.py @@ -90,6 +90,9 @@ class Aidsm(object): AppliedInXb = None, AvoidRC = True, Checked = False, + ColMajor = False, + ColNames = None, + DataFile = None, DiagonalSparseMatrix = None, Info = None, Matrix = None, @@ -113,7 +116,7 @@ class Aidsm(object): try: if Concept in ("Background", "CheckingPoint", "ControlInput", "Observation"): commande = getattr(self,"set"+Concept) - commande(Vector, VectorSerie, Script, Stored, Scheduler, 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, @@ -158,6 +161,9 @@ class Aidsm(object): Vector = None, VectorSerie = None, Script = None, + DataFile = None, + ColNames = None, + ColMajor = False, Stored = False, Scheduler = None, Checked = False): @@ -169,6 +175,9 @@ class Aidsm(object): asVector = Vector, asPersistentVector = VectorSerie, asScript = self.__with_directory(Script), + asDataFile = DataFile, + colNames = ColNames, + colMajor = ColMajor, scheduledBy = Scheduler, toBeChecked = Checked, ) @@ -180,6 +189,9 @@ class Aidsm(object): Vector = None, VectorSerie = None, Script = None, + DataFile = None, + ColNames = None, + ColMajor = False, Stored = False, Scheduler = None, Checked = False): @@ -191,6 +203,9 @@ class Aidsm(object): asVector = Vector, asPersistentVector = VectorSerie, asScript = self.__with_directory(Script), + asDataFile = DataFile, + colNames = ColNames, + colMajor = ColMajor, scheduledBy = Scheduler, toBeChecked = Checked, ) @@ -202,6 +217,9 @@ class Aidsm(object): Vector = None, VectorSerie = None, Script = None, + DataFile = None, + ColNames = None, + ColMajor = False, Stored = False, Scheduler = None, Checked = False): @@ -213,6 +231,9 @@ class Aidsm(object): asVector = Vector, asPersistentVector = VectorSerie, asScript = self.__with_directory(Script), + asDataFile = DataFile, + colNames = ColNames, + colMajor = ColMajor, scheduledBy = Scheduler, toBeChecked = Checked, ) @@ -224,6 +245,9 @@ class Aidsm(object): Vector = None, VectorSerie = None, Script = None, + DataFile = None, + ColNames = None, + ColMajor = False, Stored = False, Scheduler = None, Checked = False): @@ -235,6 +259,9 @@ class Aidsm(object): asVector = Vector, asPersistentVector = VectorSerie, asScript = self.__with_directory(Script), + asDataFile = DataFile, + colNames = ColNames, + colMajor = ColMajor, scheduledBy = Scheduler, toBeChecked = Checked, ) diff --git a/src/daComposant/daCore/BasicObjects.py b/src/daComposant/daCore/BasicObjects.py index 7de386e..f45eda8 100644 --- a/src/daComposant/daCore/BasicObjects.py +++ b/src/daComposant/daCore/BasicObjects.py @@ -35,7 +35,7 @@ from daCore import Persistence from daCore import PlatformInfo from daCore import Interfaces from daCore import Templates -from daCore.Interfaces import ImportFromScript +from daCore.Interfaces import ImportFromScript, ImportFromFile # ============================================================================== class CacheManager(object): @@ -1216,6 +1216,9 @@ class State(object): asVector = None, asPersistentVector = None, asScript = None, + asDataFile = None, + colNames = None, + colMajor = False, scheduledBy = None, toBeChecked = False, ): @@ -1230,6 +1233,14 @@ class State(object): nommée "name", la variable est de type "asVector" (par défaut) ou "asPersistentVector" selon que l'une de ces variables est placée à "True". + - asDataFile : si un ou plusieurs fichiers valides sont donnés + contenant des valeurs en colonnes, elles-mêmes nommées "colNames" + (s'il n'y a pas de nom de colonne indiquée, on cherche une colonne + nommée "name"), on récupère les colonnes et on les range ligne après + ligne (colMajor=False) ou colonne après colonne (colMajor=True). La + variable résultante est de type "asVector" (par défaut) ou + "asPersistentVector" selon que l'une de ces variables est placée à + "True". """ self.__name = str(name) self.__check = bool(toBeChecked) @@ -1245,6 +1256,26 @@ class State(object): __Series = ImportFromScript(asScript).getvalue( self.__name ) else: __Vector = ImportFromScript(asScript).getvalue( self.__name ) + elif asDataFile is not None: + __Vector, __Series = None, None + if asPersistentVector: + if colNames is not None: + __Series = ImportFromFile(asDataFile).getvalue( colNames )[1] + else: + __Series = ImportFromFile(asDataFile).getvalue( [self.__name,] )[1] + if bool(colMajor) and not ImportFromFile(asDataFile).getformat() == "application/numpy.npz": + __Series = numpy.transpose(__Series) + elif not bool(colMajor) and ImportFromFile(asDataFile).getformat() == "application/numpy.npz": + __Series = numpy.transpose(__Series) + else: + if colNames is not None: + __Vector = ImportFromFile(asDataFile).getvalue( colNames )[1] + else: + __Vector = ImportFromFile(asDataFile).getvalue( [self.__name,] )[1] + if bool(colMajor): + __Vector = numpy.ravel(__Vector, order = "F") + else: + __Vector = numpy.ravel(__Vector, order = "C") else: __Vector, __Series = asVector, asPersistentVector # diff --git a/src/daComposant/daCore/Interfaces.py b/src/daComposant/daCore/Interfaces.py index 7737fa0..01a3001 100644 --- a/src/daComposant/daCore/Interfaces.py +++ b/src/daComposant/daCore/Interfaces.py @@ -118,9 +118,10 @@ class _TUIViewer(GenericCaseViewer): for k in __keys: __v = __local[k] if __v is None: continue - if k == "Checked" and not __v: continue - if k == "Stored" and not __v: continue - if k == "AvoidRC" and __v: continue + if k == "Checked" and not __v: continue + if k == "Stored" and not __v: continue + if k == "ColMajor" and not __v: continue + if k == "AvoidRC" and __v: continue if k == "noDetails": continue if isinstance(__v,Persistence.Persistence): __v = __v.values() if callable(__v): __text = self._missing%__v.__name__+__text @@ -391,7 +392,7 @@ class _SCDViewer(GenericCaseViewer): __text += "%s_config['From'] = '%s'\n"%(__command,__f) __text += "%s_config['Data'] = %s\n"%(__command,__v) __text = __text.replace("''","'") - elif __k in ('Stored', 'Checked'): + elif __k in ('Stored', 'Checked', 'ColMajor'): if bool(__v): __text += "%s_config['%s'] = '%s'\n"%(__command,__k,int(bool(__v))) elif __k in ('AvoidRC', 'noDetails'): @@ -666,12 +667,14 @@ class ImportFromFile(object): self.__header, self._varsline, self._skiprows = self.__getentete() # if self._format == "text/csv" or Format.upper() == "CSV": + self._format = "text/csv" self.__filestring = "".join(self.__header) if self.__filestring.count(",") > 1: self._delimiter = "," elif self.__filestring.count(";") > 1: self._delimiter = ";" elif self._format == "text/tab-separated-values" or Format.upper() == "TSV": + self._format = "text/tab-separated-values" self._delimiter = "\t" else: self._delimiter = None @@ -776,6 +779,7 @@ class ImportFromFile(object): __index = numpy.loadtxt(self._filename, dtype = bytes, usecols = (__useindex,), delimiter = self._delimiter, skiprows=self._skiprows) else: raise ValueError("Unkown file format \"%s\""%self._format) + if __columns is None: __columns = () # def toString(value): try: @@ -792,6 +796,9 @@ class ImportFromFile(object): with open(self._filename,'r') as fid: return fid.read() + def getformat(self): + return self._format + # ============================================================================== class ImportScalarLinesFromFile(ImportFromFile): """ -- 2.39.2