From 962f145fbc4814280fdff9ab3b41647290ac546d Mon Sep 17 00:00:00 2001 From: Jean-Philippe ARGAUD Date: Wed, 29 Sep 2021 21:13:29 +0200 Subject: [PATCH] Minor internal clarification and performance improvements --- bin/AdaoCatalogGenerator.py | 2 +- .../daAlgorithms/LinearLeastSquares.py | 24 ++++++++++-------- .../daAlgorithms/NonLinearLeastSquares.py | 25 +++++++++++-------- src/daComposant/daCore/Interfaces.py | 2 ++ .../daGUI/daGuiImpl/adaoGuiManager.py | 18 ++++++------- 5 files changed, 40 insertions(+), 31 deletions(-) diff --git a/bin/AdaoCatalogGenerator.py b/bin/AdaoCatalogGenerator.py index 9b1037d..5a183d4 100644 --- a/bin/AdaoCatalogGenerator.py +++ b/bin/AdaoCatalogGenerator.py @@ -546,7 +546,7 @@ for algo in all_names: elif pt is float: algo_parameters += """ %s = SIMP(statut="f", typ="R"%s%s, min=1, max=1, defaut=%s, fr="%s"),\n"""%(pn,vi,vs,float(pd),pm) elif pt is bool: - algo_parameters += """ %s = SIMP(statut="f", typ="I", min=1, max=1, defaut=%s, fr="%s"),\n"""%(pn,int(pd),pm) + algo_parameters += """ %s = SIMP(statut="f", typ="I", into=(0, 1), min=1, max=1, defaut=%s, fr="%s"),\n"""%(pn,int(pd),pm) elif pt is str and "listval" in par_dict[pn]: algo_parameters += """ %s = SIMP(statut="f", typ="TXM", min=1, max=1, defaut="%s", into=%s, fr="%s"),\n"""%(pn,pd,par_dict[pn]["listval"],pm) elif pt is tuple and "listval" in par_dict[pn]: diff --git a/src/daComposant/daAlgorithms/LinearLeastSquares.py b/src/daComposant/daAlgorithms/LinearLeastSquares.py index 8e34142..2da26a4 100644 --- a/src/daComposant/daAlgorithms/LinearLeastSquares.py +++ b/src/daComposant/daAlgorithms/LinearLeastSquares.py @@ -56,7 +56,8 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): ] ) self.requireInputArguments( - mandatory= ("Y", "HO", "R"), + mandatory= ("Y", "HO"), + optional = ("R"), ) self.setAttributes(tags=( "Optimization", @@ -72,13 +73,16 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): Ha = HO["Adjoint"].asMatrix(Xb) Ha = Ha.reshape(-1,Y.size) # ADAO & check shape # - RI = R.getI() + if R is None: + RI = 1. + else: + RI = R.getI() # # Calcul de la matrice de gain et de l'analyse # -------------------------------------------- K = (Ha * RI * Hm).I * Ha * RI Xa = K * Y - self.StoredVariables["Analysis"].store( Xa.A1 ) + self.StoredVariables["Analysis"].store( Xa ) # # Calcul de la fonction coût # -------------------------- @@ -109,19 +113,19 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): # Calculs et/ou stockages supplémentaires # --------------------------------------- if self._parameters["StoreInternalVariables"] or self._toStore("CurrentState"): - self.StoredVariables["CurrentState"].store( numpy.ravel(Xa) ) + self.StoredVariables["CurrentState"].store( Xa ) if self._toStore("CurrentOptimum"): - self.StoredVariables["CurrentOptimum"].store( numpy.ravel(Xa) ) + self.StoredVariables["CurrentOptimum"].store( Xa ) if self._toStore("OMA"): - self.StoredVariables["OMA"].store( numpy.ravel(oma) ) + self.StoredVariables["OMA"].store( oma ) if self._toStore("SimulatedObservationAtBackground"): - self.StoredVariables["SimulatedObservationAtBackground"].store( numpy.ravel(HXb) ) + self.StoredVariables["SimulatedObservationAtBackground"].store( HXb ) if self._toStore("SimulatedObservationAtCurrentState"): - self.StoredVariables["SimulatedObservationAtCurrentState"].store( numpy.ravel(HXa) ) + self.StoredVariables["SimulatedObservationAtCurrentState"].store( HXa ) if self._toStore("SimulatedObservationAtCurrentOptimum"): - self.StoredVariables["SimulatedObservationAtCurrentOptimum"].store( numpy.ravel(HXa) ) + self.StoredVariables["SimulatedObservationAtCurrentOptimum"].store( HXa ) if self._toStore("SimulatedObservationAtOptimum"): - self.StoredVariables["SimulatedObservationAtOptimum"].store( numpy.ravel(HXa) ) + self.StoredVariables["SimulatedObservationAtOptimum"].store( HXa ) # self._post_run(HO) return 0 diff --git a/src/daComposant/daAlgorithms/NonLinearLeastSquares.py b/src/daComposant/daAlgorithms/NonLinearLeastSquares.py index aad66fc..d0afe68 100644 --- a/src/daComposant/daAlgorithms/NonLinearLeastSquares.py +++ b/src/daComposant/daAlgorithms/NonLinearLeastSquares.py @@ -107,7 +107,8 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): message = "État initial imposé (par défaut, c'est l'ébauche si None)", ) self.requireInputArguments( - mandatory= ("Xb", "Y", "HO", "R"), + mandatory= ("Xb", "Y", "HO"), + optional = ("R"), ) self.setAttributes(tags=( "Optimization", @@ -135,11 +136,13 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): if max(Y.shape) != max(HXb.shape): raise ValueError("The shapes %s of observations Y and %s of observed calculation H(X) are different, they have to be identical."%(Y.shape,HXb.shape)) # - # Précalcul des inversions de B et R - # ---------------------------------- - RI = R.getI() - if self._parameters["Minimizer"] == "LM": - RdemiI = R.choleskyI() + if R is None: + RI = 1. + RdemiI = 1. + else: + RI = R.getI() + if self._parameters["Minimizer"] == "LM": + RdemiI = R.choleskyI() # # Définition de la fonction-coût # ------------------------------ @@ -321,7 +324,7 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): # ---------------------- Xa = numpy.asmatrix(numpy.ravel( Minimum )).T # - self.StoredVariables["Analysis"].store( Xa.A1 ) + self.StoredVariables["Analysis"].store( Xa ) # if self._toStore("OMA") or \ self._toStore("SimulatedObservationAtOptimum"): @@ -339,17 +342,17 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): self._toStore("OMB"): d = Y - HXb if self._toStore("Innovation"): - self.StoredVariables["Innovation"].store( numpy.ravel(d) ) + self.StoredVariables["Innovation"].store( d ) if self._toStore("BMA"): self.StoredVariables["BMA"].store( numpy.ravel(Xb) - numpy.ravel(Xa) ) if self._toStore("OMA"): self.StoredVariables["OMA"].store( numpy.ravel(Y) - numpy.ravel(HXa) ) if self._toStore("OMB"): - self.StoredVariables["OMB"].store( numpy.ravel(d) ) + self.StoredVariables["OMB"].store( d ) if self._toStore("SimulatedObservationAtBackground"): - self.StoredVariables["SimulatedObservationAtBackground"].store( numpy.ravel(HXb) ) + self.StoredVariables["SimulatedObservationAtBackground"].store( HXb ) if self._toStore("SimulatedObservationAtOptimum"): - self.StoredVariables["SimulatedObservationAtOptimum"].store( numpy.ravel(HXa) ) + self.StoredVariables["SimulatedObservationAtOptimum"].store( HXa ) # self._post_run(HO) return 0 diff --git a/src/daComposant/daCore/Interfaces.py b/src/daComposant/daCore/Interfaces.py index 725a9c0..f567763 100644 --- a/src/daComposant/daCore/Interfaces.py +++ b/src/daComposant/daCore/Interfaces.py @@ -183,6 +183,8 @@ class _COMViewer(GenericCaseViewer): "Transformation d'enregistrement(s) en commande(s) individuelle(s)" __suppparameters = {} if __multilines is not None: + if 'adaoBuilder' in __multilines: + raise ValueError("Impossible to load given content as an ADAO COMM one (Hint: it's perhaps not a COMM input, but a TUI one).") if "ASSIMILATION_STUDY" in __multilines: __suppparameters.update({'StudyType':"ASSIMILATION_STUDY"}) __multilines = __multilines.replace("ASSIMILATION_STUDY","dict") diff --git a/src/daSalome/daGUI/daGuiImpl/adaoGuiManager.py b/src/daSalome/daGUI/daGuiImpl/adaoGuiManager.py index a7aeb45..8a9e05b 100644 --- a/src/daSalome/daGUI/daGuiImpl/adaoGuiManager.py +++ b/src/daSalome/daGUI/daGuiImpl/adaoGuiManager.py @@ -449,34 +449,34 @@ class AdaoGuiUiComponentBuilder: a = sgPyQt.createAction( UI_ELT_IDS.NEW_ADAOCASE_ID, "New case", "New case", "Create a new ADAO case", "eficas_new.png" ) sgPyQt.createMenu(a, mid) sgPyQt.createTool(a, tid) - a = sgPyQt.createAction( UI_ELT_IDS.OPEN_ADAOCASE_ID, "Open case", "Open case", "Open an ADAO case", "eficas_open.png" ) + a = sgPyQt.createAction( UI_ELT_IDS.OPEN_ADAOCASE_ID, "Open a case", "Open a case", "Open an ADAO case", "eficas_open.png" ) sgPyQt.createMenu(a, mid) sgPyQt.createTool(a, tid) - a = sgPyQt.createAction( UI_ELT_IDS.SAVE_ADAOCASE_ID, "Save case", "Save case", "Save an ADAO case", "eficas_save.png" ) + a = sgPyQt.createAction( UI_ELT_IDS.SAVE_ADAOCASE_ID, "Save the case", "Save the case", "Save the ADAO case", "eficas_save.png" ) sgPyQt.createMenu(a, mid) sgPyQt.createTool(a, tid) - a = sgPyQt.createAction( UI_ELT_IDS.SAVE_AS_ADAOCASE_ID, "Save as case", "Save as case", "Save an ADAO case as", "eficas_saveas.png" ) + a = sgPyQt.createAction( UI_ELT_IDS.SAVE_AS_ADAOCASE_ID, "Save the case as", "Save the case as", "Save the ADAO case as", "eficas_saveas.png" ) sgPyQt.createMenu(a, mid) sgPyQt.createTool(a, tid) - a = sgPyQt.createAction( UI_ELT_IDS.VALIDATE_ADAOCASE_ID, "Validate case", "Validate case", "Validate an ADAO case", "eficas_valid.png" ) + a = sgPyQt.createAction( UI_ELT_IDS.VALIDATE_ADAOCASE_ID, "Validate the case", "Validate the case", "Validate the ADAO case", "eficas_valid.png" ) sgPyQt.createMenu(a, mid) sgPyQt.createTool(a, tid) a = sgPyQt.createAction( UI_ELT_IDS.SHOWTREE_ADAOCASE_ID, "Show tree", "Show tree", "Show the commands tree", "eficas_tree.png" ) sgPyQt.createMenu(a, mid) sgPyQt.createTool(a, tid) - a = sgPyQt.createAction( UI_ELT_IDS.TUI_EXPORT_ID, "Export to TUI", "Export to TUI", "Generate an ADAO TUI version of this case", "eficas_totui.png" ) + a = sgPyQt.createAction( UI_ELT_IDS.TUI_EXPORT_ID, "Export the case to TUI", "Export the case to TUI", "Generate the ADAO TUI version of this case", "eficas_totui.png" ) sgPyQt.createMenu(a, mid) sgPyQt.createTool(a, tid) - a = sgPyQt.createAction( UI_ELT_IDS.CLOSE_ADAOCASE_ID, "Close case", "Close case", "Close an ADAO case", "eficas_close.png" ) + a = sgPyQt.createAction( UI_ELT_IDS.CLOSE_ADAOCASE_ID, "Close the case", "Close the case", "Close the ADAO case", "eficas_close.png" ) sgPyQt.createMenu(a, mid) sgPyQt.createTool(a, tid) - a = sgPyQt.createAction( UI_ELT_IDS.YACS_EXPORT_ID, "Export to YACS", "Export to YACS", "Generate a YACS graph executing this case", "eficas_yacs.png" ) + a = sgPyQt.createAction( UI_ELT_IDS.YACS_EXPORT_ID, "Export the case to YACS", "Export the case to YACS", "Generate the YACS graph to execute this case", "eficas_yacs.png" ) sgPyQt.createMenu(a, mid) sgPyQt.createTool(a, tid) # the following action are used in context popup - a = sgPyQt.createAction( UI_ELT_IDS.CLOSE_ADAOCASE_ID, "Close case", "Close case", "Close the selected case", "" ) - a = sgPyQt.createAction( UI_ELT_IDS.YACS_EXPORT_ID, "Export to YACS", "Export to YACS", "Generate a YACS graph executing this case", "" ) + a = sgPyQt.createAction( UI_ELT_IDS.CLOSE_ADAOCASE_ID, "Close the case", "Close the case", "Close the ADAO case", "" ) + a = sgPyQt.createAction( UI_ELT_IDS.YACS_EXPORT_ID, "Export the case to YACS", "Export the case to YACS", "Generate the YACS graph to execute this case", "" ) def createPopupMenuOnItem(self,popup,item): # salomeSudyId, item): if adaoStudyEditor.isValidAdaoCaseItem(item): # Attention : appel ancien avec un coquille (StudyId) : (salomeSudyId, item): -- 2.39.2