X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FdaEficas%2Fgenerator_adao.py;h=0bd1bfff841ed4f467139f5807401715d49de02d;hb=b4ec54a708ac4f11e9c710edd09219849ebf3242;hp=924d4b9d478ea2cbbb4ad72d938280881b449991;hpb=8a7695b2ad9c2f37f6ddb9e6687dd2930d30586d;p=modules%2Fadao.git diff --git a/src/daEficas/generator_adao.py b/src/daEficas/generator_adao.py index 924d4b9..0bd1bff 100644 --- a/src/daEficas/generator_adao.py +++ b/src/daEficas/generator_adao.py @@ -1,5 +1,8 @@ # -*- coding: utf-8 -*- -# Copyright (C) 2010-2012 EDF R&D +# +# Copyright (C) 2008-2017 EDF R&D +# +# This file is part of SALOME ADAO module # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -52,7 +55,7 @@ class AdaoGenerator(PythonGenerator): ch.setFormatter(formatter) self.logger.addHandler(ch) - def gener(self,obj,format='brut',config=None): + def gener(self,obj,format='brut',config=None,appli=None): self.logger.debug("method gener called") self.text_comm = PythonGenerator.gener(self, obj, format, config) for key, value in self.dictMCVal.iteritems(): @@ -63,15 +66,15 @@ class AdaoGenerator(PythonGenerator): self.generate_da() self.text_da_status = True except: - self.logger.info("Case is not correct, python command file for YACS schema generation cannot be created") + self.logger.debug("EFICAS case is not valid, python command file for YACS schema generation cannot be created") self.logger.debug(self.text_da) self.dictMCVal = {} - traceback.print_exc() + # traceback.print_exc() return self.text_comm def writeDefault(self, fn): if self.text_da_status: - print "write adao python command file" + self.logger.debug("write adao python command file") filename = fn[:fn.rfind(".")] + '.py' f = open( str(filename), 'wb') f.write( self.text_da ) @@ -91,7 +94,7 @@ class AdaoGenerator(PythonGenerator): def generate_da(self): - if "__CHECKING_STUDY__Study_name" in self.dictMCVal.keys(): + if "__CHECKING_STUDY__StudyName" in self.dictMCVal.keys(): self.type_of_study = "CHECKING_STUDY" else: self.type_of_study = "ASSIMILATION_STUDY" @@ -101,12 +104,20 @@ class AdaoGenerator(PythonGenerator): # Extraction de Study_type self.text_da += "study_config['StudyType'] = '" + self.type_of_study + "'\n" - # Extraction de Study_name - self.text_da += "study_config['Name'] = '" + self.dictMCVal["__"+self.type_of_study+"__Study_name"] + "'\n" + # Extraction de StudyName + self.text_da += "study_config['Name'] = '" + self.dictMCVal["__"+self.type_of_study+"__StudyName"] + "'\n" # Extraction de Debug - self.text_da += "study_config['Debug'] = '" + str(self.dictMCVal["__"+self.type_of_study+"__Debug"]) + "'\n" - # Extraction de Algorithm - self.text_da += "study_config['Algorithm'] = '" + self.dictMCVal["__"+self.type_of_study+"__Algorithm"] + "'\n" + if "__"+self.type_of_study+"__Debug" in self.dictMCVal.keys(): + self.text_da += "study_config['Debug'] = '" + str(self.dictMCVal["__"+self.type_of_study+"__Debug"]) + "'\n" + else: + self.text_da += "study_config['Debug'] = '0'\n" + + # Extraction de Algorithm et de ses parametres + if "__"+self.type_of_study+"__AlgorithmParameters__Algorithm" in self.dictMCVal.keys(): + self.text_da += "study_config['Algorithm'] = '" + self.dictMCVal["__"+self.type_of_study+"__AlgorithmParameters__Algorithm"] + "'\n" + self.add_AlgorithmParameters() + elif "__"+self.type_of_study+"__Algorithm" in self.dictMCVal.keys(): + self.text_da += "study_config['Algorithm'] = '" + self.dictMCVal["__"+self.type_of_study+"__Algorithm"] + "'\n" if "__"+self.type_of_study+"__Background__INPUT_TYPE" in self.dictMCVal.keys(): self.add_data("Background") @@ -124,16 +135,15 @@ class AdaoGenerator(PythonGenerator): self.add_data("EvolutionModel") if "__"+self.type_of_study+"__EvolutionError__INPUT_TYPE" in self.dictMCVal.keys(): self.add_data("EvolutionError") + if "__"+self.type_of_study+"__ControlInput__INPUT_TYPE" in self.dictMCVal.keys(): + self.add_data("ControlInput") self.add_variables() # Parametres optionnels - # Extraction du Study_repertory - if "__"+self.type_of_study+"__Study_repertory" in self.dictMCVal.keys(): - self.text_da += "study_config['Repertory'] = '" + self.dictMCVal["__"+self.type_of_study+"__Study_repertory"] + "'\n" - # Extraction de AlgorithmParameters - if "__"+self.type_of_study+"__AlgorithmParameters__INPUT_TYPE" in self.dictMCVal.keys(): - self.add_algorithm_parameters() + # Extraction du StudyRepertory + if "__"+self.type_of_study+"__StudyRepertory" in self.dictMCVal.keys(): + self.text_da += "study_config['Repertory'] = '" + self.dictMCVal["__"+self.type_of_study+"__StudyRepertory"] + "'\n" # Extraction de UserPostAnalysis if "__"+self.type_of_study+"__UserPostAnalysis__FROM" in self.dictMCVal.keys(): self.add_UserPostAnalysis() @@ -158,6 +168,8 @@ class AdaoGenerator(PythonGenerator): data = self.dictMCVal[search_type + "SCRIPTWITHSWITCH_DATA__SCRIPTWITHSWITCH_FILE"] elif from_type == "ScriptWithFunctions": data = self.dictMCVal[search_type + "SCRIPTWITHFUNCTIONS_DATA__SCRIPTWITHFUNCTIONS_FILE"] + elif from_type == "ScriptWithOneFunction": + data = self.dictMCVal[search_type + "SCRIPTWITHONEFUNCTION_DATA__SCRIPTWITHONEFUNCTION_FILE"] elif from_type == "FunctionDict": data = self.dictMCVal[search_type + "FUNCTIONDICT_DATA__FUNCTIONDICT_FILE"] else: @@ -198,6 +210,25 @@ class AdaoGenerator(PythonGenerator): self.text_da += data_name + "_config['Data'] = " + data_name + "_ScriptWithFunctions\n" self.text_da += "study_config['" + data_name + "'] = " + data_name + "_config\n" + if from_type == "ScriptWithOneFunction": + self.text_da += data_name + "_ScriptWithOneFunction = {}\n" + self.text_da += data_name + "_ScriptWithOneFunction['Function'] = ['Direct', 'Tangent', 'Adjoint']\n" + self.text_da += data_name + "_ScriptWithOneFunction['Script'] = {}\n" + self.text_da += data_name + "_ScriptWithOneFunction['Script']['Direct'] = '" + data + "'\n" + self.text_da += data_name + "_ScriptWithOneFunction['Script']['Tangent'] = '" + data + "'\n" + self.text_da += data_name + "_ScriptWithOneFunction['Script']['Adjoint'] = '" + data + "'\n" + self.text_da += data_name + "_ScriptWithOneFunction['DifferentialIncrement'] = " + str(float(self.dictMCVal[search_type + "SCRIPTWITHONEFUNCTION_DATA__DifferentialIncrement"])) + "\n" + self.text_da += data_name + "_ScriptWithOneFunction['CenteredFiniteDifference'] = " + str(self.dictMCVal[search_type + "SCRIPTWITHONEFUNCTION_DATA__CenteredFiniteDifference"]) + "\n" + if search_type + "SCRIPTWITHONEFUNCTION_DATA__EnableMultiProcessing" in self.dictMCVal.keys(): + self.text_da += data_name + "_ScriptWithOneFunction['EnableMultiProcessing'] = " + str(self.dictMCVal[search_type + "SCRIPTWITHONEFUNCTION_DATA__EnableMultiProcessing"]) + "\n" + if search_type + "SCRIPTWITHONEFUNCTION_DATA__NumberOfProcesses" in self.dictMCVal.keys(): + self.text_da += data_name + "_ScriptWithOneFunction['NumberOfProcesses'] = " + str(self.dictMCVal[search_type + "SCRIPTWITHONEFUNCTION_DATA__NumberOfProcesses"]) + "\n" + self.text_da += data_name + "_config = {}\n" + self.text_da += data_name + "_config['Type'] = 'Function'\n" + self.text_da += data_name + "_config['From'] = 'ScriptWithOneFunction'\n" + self.text_da += data_name + "_config['Data'] = " + data_name + "_ScriptWithOneFunction\n" + self.text_da += "study_config['" + data_name + "'] = " + data_name + "_config\n" + if from_type == "FunctionDict": self.text_da += data_name + "_FunctionDict = {}\n" self.text_da += data_name + "_FunctionDict['Function'] = ['Direct', 'Tangent', 'Adjoint']\n" @@ -211,19 +242,6 @@ class AdaoGenerator(PythonGenerator): self.text_da += data_name + "_config['Data'] = " + data_name + "_FunctionDict\n" self.text_da += "study_config['" + data_name + "'] = " + data_name + "_config\n" - def add_algorithm_parameters(self): - - data_name = "AlgorithmParameters" - data_type = "Dict" - from_type = "Script" - data = self.dictMCVal["__"+self.type_of_study+"__AlgorithmParameters__Dict__data__SCRIPT_DATA__SCRIPT_FILE"] - - self.text_da += data_name + "_config = {} \n" - self.text_da += data_name + "_config['Type'] = '" + data_type + "'\n" - self.text_da += data_name + "_config['From'] = '" + from_type + "'\n" - self.text_da += data_name + "_config['Data'] = '" + data + "'\n" - self.text_da += "study_config['" + data_name + "'] = " + data_name + "_config\n" - def add_init(self): init_file_data = self.dictMCVal["__"+self.type_of_study+"__UserDataInit__INIT_FILE"] @@ -258,9 +276,66 @@ class AdaoGenerator(PythonGenerator): self.text_da += "Analysis_config['From'] = 'Script'\n" self.text_da += "Analysis_config['Data'] = '" + data + "'\n" self.text_da += "study_config['UserPostAnalysis'] = Analysis_config\n" + elif from_type == "Template": + tmpl = self.dictMCVal["__"+self.type_of_study+"__UserPostAnalysis__TEMPLATE_DATA__Template"] + data = self.dictMCVal["__"+self.type_of_study+"__UserPostAnalysis__TEMPLATE_DATA__%s__ValueTemplate"%tmpl] + self.text_da += "Analysis_config = {}\n" + self.text_da += "Analysis_config['From'] = 'String'\n" + self.text_da += "Analysis_config['Data'] = \"\"\"" + data + "\"\"\"\n" + self.text_da += "study_config['UserPostAnalysis'] = Analysis_config\n" else: raise Exception('From Type unknown', from_type) + def add_AlgorithmParameters(self): + + if not self.dictMCVal.has_key("__"+self.type_of_study+"__AlgorithmParameters__Parameters"): return + + data_name = "AlgorithmParameters" + data_type = "Dict" + para_type = self.dictMCVal["__"+self.type_of_study+"__AlgorithmParameters__Parameters"] + if para_type == "Defaults": + from_type = para_type + elif para_type == "Dict": + from_type = self.dictMCVal["__"+self.type_of_study+"__AlgorithmParameters__Dict__data__FROM"] + + if from_type == "Script": + data = self.dictMCVal["__"+self.type_of_study+"__AlgorithmParameters__Dict__data__SCRIPT_DATA__SCRIPT_FILE"] + self.text_da += data_name + "_config = {} \n" + self.text_da += data_name + "_config['Type'] = '" + data_type + "'\n" + self.text_da += data_name + "_config['From'] = '" + from_type + "'\n" + self.text_da += data_name + "_config['Data'] = '" + data + "'\n" + self.text_da += "study_config['" + data_name + "'] = " + data_name + "_config\n" + elif from_type == "String": + data = self.dictMCVal["__"+self.type_of_study+"__AlgorithmParameters__Dict__data__STRING_DATA__STRING"] + self.text_da += data_name + "_config = {} \n" + self.text_da += data_name + "_config['Type'] = '" + data_type + "'\n" + self.text_da += data_name + "_config['From'] = '" + from_type + "'\n" + self.text_da += data_name + "_config['Data'] = '" + data + "'\n" + self.text_da += "study_config['" + data_name + "'] = " + data_name + "_config\n" + elif from_type == "Defaults": + base = "__"+self.type_of_study+"__AlgorithmParameters__Parameters" + keys = [k for k in self.dictMCVal.keys() if base in k] + keys.remove(base) + keys = [k.replace(base,'') for k in keys] + data = '{' + for k in keys: + key = k.split('__')[-1] + val = self.dictMCVal[base+k] + # print key," = ",val," ",type(val) + if isinstance(val, str) and key == "SetSeed": + data += '"%s":%s,'%(key,int(val)) + elif isinstance(val, str) and not (val.count('[')>=2 or val.count('(')>=2): + data += '"%s":"%s",'%(key,val) + else: + data += '"%s":%s,'%(key,val) + data = data.replace("'",'"') + data += '}' + self.text_da += data_name + "_config = {} \n" + self.text_da += data_name + "_config['Type'] = '" + data_type + "'\n" + self.text_da += data_name + "_config['From'] = 'String'\n" + self.text_da += data_name + "_config['Data'] = '" + data + "'\n" + self.text_da += "study_config['" + data_name + "'] = " + data_name + "_config\n" + def add_variables(self): # Input variables @@ -330,6 +405,9 @@ class AdaoGenerator(PythonGenerator): self.text_da += "observers[\"" + observer + "\"][\"nodetype\"] = \"" + observers[observer]["nodetype"] + "\"\n" if observers[observer]["nodetype"] == "String": self.text_da += "observers[\"" + observer + "\"][\"String\"] = \"\"\"" + observers[observer]["script"] + "\"\"\"\n" + elif observers[observer]["nodetype"] == "Template": + self.text_da += "observers[\"" + observer + "\"][\"String\"] = \"\"\"" + observers[observer]["script"] + "\"\"\"\n" + self.text_da += "observers[\"" + observer + "\"][\"Template\"] = \"\"\"" + observers[observer]["template"] + "\"\"\"\n" else: self.text_da += "observers[\"" + observer + "\"][\"Script\"] = \"" + observers[observer]["file"] + "\"\n" if "scheduler" in observers[observer].keys(): @@ -352,6 +430,11 @@ class AdaoGenerator(PythonGenerator): # NodeType script/file if observers[observer]["nodetype"] == "String": observers[observer]["script"] = self.dictMCVal[observer_eficas_name + "PythonScript__Value"] + elif observers[observer]["nodetype"] == "Template": + observers[observer]["nodetype"] = "String" + observer_template_key = observer_eficas_name + "ObserverTemplate__" + observers[observer]["template"] = self.dictMCVal[observer_template_key + "Template"] + observers[observer]["script"] = self.dictMCVal[observer_template_key + observers[observer]["template"] + "__ValueTemplate"] else: observers[observer]["file"] = self.dictMCVal[observer_eficas_name + "UserFile__Value"]