From 184b7b802624224d6efb4d3b1dfcaaa61ed180e4 Mon Sep 17 00:00:00 2001 From: Jean-Philippe ARGAUD Date: Sun, 23 Sep 2012 21:25:01 +0200 Subject: [PATCH] Extending input possibilities of operators --- bin/AdaoCatalogGenerator.py | 18 +- src/daEficas/generator_adao.py | 30 ++ .../daYacsSchemaCreator/help_methods.py | 24 ++ .../daYacsSchemaCreator/infos_daComposant.py | 8 +- src/daSalome/daYacsSchemaCreator/methods.py | 263 ++++++++++++++++++ 5 files changed, 334 insertions(+), 9 deletions(-) diff --git a/bin/AdaoCatalogGenerator.py b/bin/AdaoCatalogGenerator.py index c7764ed..5e9e23e 100644 --- a/bin/AdaoCatalogGenerator.py +++ b/bin/AdaoCatalogGenerator.py @@ -48,15 +48,23 @@ def F_${data_name}(statut) : return FACT(statut = statut, FROM = SIMP(statut = "o", typ = "TXM", into=(${data_into}), defaut=${data_default}), SCRIPT_DATA = BLOC ( condition = " FROM in ( 'Script', ) ", - SCRIPT_FILE = SIMP(statut = "o", typ = "FichierNoAbs", validators=(OnlyStr())), + SCRIPT_FILE = SIMP(statut = "o", typ = "FichierNoAbs", validators=(OnlyStr()), fr="En attente d'un nom de fichier script, avec ou sans le chemin complet pour le trouver, contenant la définition d'une variable interne de même nom que le concept parent", ang="Waiting for a script file name, with or without the full path to find it, containing the definition of an internal variable of the same name as the parent concept"), ), STRING_DATA = BLOC ( condition = " FROM in ( 'String', ) ", - STRING = SIMP(statut = "o", typ = "TXM"), + STRING = SIMP(statut = "o", typ = "TXM", fr="En attente d'une chaine de caractères entre guillements, qui soit valide pour construire un vecteur : une suite de nombres, utilisant un espace ou une virgule pour séparer deux éléments et un point-virgule pour séparer deux lignes", ang="Waiting for a string in quotes, valid to build a vector: a floats serie, using a space or comma to separate two elements in a line, a semi-colon to separate rows"), + ), + SCRIPTWITHFUNCTIONS_DATA = BLOC ( condition = " FROM in ( 'ScriptWithFunctions', ) ", + + SCRIPTWITHFUNCTIONS_FILE = SIMP(statut = "o", typ = "FichierNoAbs", validators=(OnlyStr()), fr="En attente d'un nom de fichier script, avec ou sans le chemin complet pour le trouver, contenant en variables internes trois fonctions de calcul nommées DirectOperator, TangentOperator et AdjointOperator", ang="Waiting for a script file name, with or without the full path to find it, containing as internal variables three computation functions named DirectOperator, TangentOperator and AdjointOperator"), + ), + SCRIPTWITHSWITCH_DATA = BLOC ( condition = " FROM in ( 'ScriptWithSwitch', ) ", + + SCRIPTWITHSWITCH_FILE = SIMP(statut = "o", typ = "FichierNoAbs", validators=(OnlyStr()), fr="En attente d'un nom de fichier script, avec ou sans le chemin complet pour le trouver, contenant un switch pour les calculs direct, tangent et adjoint", ang="Waiting for a script file name, with or without the full path to find it, containing a switch for direct, tangent and adjoint computations"), ), FUNCTIONDICT_DATA = BLOC ( condition = " FROM in ( 'FunctionDict', ) ", - FUNCTIONDICT_FILE = SIMP(statut = "o", typ = "FichierNoAbs", validators=(OnlyStr())), + FUNCTIONDICT_FILE = SIMP(statut = "o", typ = "FichierNoAbs", validators=(OnlyStr()), fr="OBSOLETE : conservé pour compatibilité avec la version 6.5, sera supprimé dans le futur", ang="OBSOLETE: keeped for compatibility with the 6.5 version, will be removed in the future"), ), ) """ @@ -239,12 +247,12 @@ for assim_data_input_name in infos.AssimDataDict.keys(): decl_choices = "" decl_opts = "" if infos.AssimDataDefaultDict[assim_data_input_name] in infos.StoredAssimData: - storage = " Stored = SIMP(statut=\"o\", typ = \"I\", into=(0, 1), defaut=0)," + storage = " Stored = SIMP(statut=\"o\", typ = \"I\", into=(0, 1), defaut=0, fr=\"Choix de stockage interne ou non du concept parent\", ang=\"Choice of the storage or not of the parent concept\")," for choice in infos.AssimDataDict[assim_data_input_name]: choices += "\"" + choice + "\", " decl_choices += assim_data_choice.substitute(choice_name = choice) if choice in infos.StoredAssimData: - storage = " Stored = SIMP(statut=\"o\", typ = \"I\", into=(0, 1), defaut=0)," + storage = " Stored = SIMP(statut=\"o\", typ = \"I\", into=(0, 1), defaut=0, fr=\"Choix de stockage interne ou non du concept parent\", ang=\"Choice of the storage or not of the parent concept\")," default_choice = "\"" + infos.AssimDataDefaultDict[assim_data_input_name] + "\"" mem_file.write(assim_data_method.substitute(assim_name = assim_name, diff --git a/src/daEficas/generator_adao.py b/src/daEficas/generator_adao.py index 7f59d0a..e0eb7e6 100644 --- a/src/daEficas/generator_adao.py +++ b/src/daEficas/generator_adao.py @@ -154,6 +154,10 @@ class AdaoGenerator(PythonGenerator): data = self.dictMCVal[search_type + "STRING_DATA__STRING"] elif from_type == "Script": data = self.dictMCVal[search_type + "SCRIPT_DATA__SCRIPT_FILE"] + elif from_type == "ScriptWithSwitch": + 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 == "FunctionDict": data = self.dictMCVal[search_type + "FUNCTIONDICT_DATA__FUNCTIONDICT_FILE"] else: @@ -168,6 +172,32 @@ class AdaoGenerator(PythonGenerator): self.text_da += data_name + "_config['Stored'] = '" + str(self.dictMCVal[search_text+"Stored"]) + "'\n" self.text_da += "study_config['" + data_name + "'] = " + data_name + "_config\n" + if from_type == "ScriptWithSwitch": + self.text_da += data_name + "_ScriptWithSwitch = {}\n" + self.text_da += data_name + "_ScriptWithSwitch['Function'] = ['Direct', 'Tangent', 'Adjoint']\n" + self.text_da += data_name + "_ScriptWithSwitch['Script'] = {}\n" + self.text_da += data_name + "_ScriptWithSwitch['Script']['Direct'] = '" + data + "'\n" + self.text_da += data_name + "_ScriptWithSwitch['Script']['Tangent'] = '" + data + "'\n" + self.text_da += data_name + "_ScriptWithSwitch['Script']['Adjoint'] = '" + data + "'\n" + self.text_da += data_name + "_config = {}\n" + self.text_da += data_name + "_config['Type'] = 'Function'\n" + self.text_da += data_name + "_config['From'] = 'ScriptWithSwitch'\n" + self.text_da += data_name + "_config['Data'] = " + data_name + "_ScriptWithSwitch\n" + self.text_da += "study_config['" + data_name + "'] = " + data_name + "_config\n" + + if from_type == "ScriptWithFunctions": + self.text_da += data_name + "_ScriptWithFunctions = {}\n" + self.text_da += data_name + "_ScriptWithFunctions['Function'] = ['Direct', 'Tangent', 'Adjoint']\n" + self.text_da += data_name + "_ScriptWithFunctions['Script'] = {}\n" + self.text_da += data_name + "_ScriptWithFunctions['Script']['Direct'] = '" + data + "'\n" + self.text_da += data_name + "_ScriptWithFunctions['Script']['Tangent'] = '" + data + "'\n" + self.text_da += data_name + "_ScriptWithFunctions['Script']['Adjoint'] = '" + data + "'\n" + self.text_da += data_name + "_config = {}\n" + self.text_da += data_name + "_config['Type'] = 'Function'\n" + self.text_da += data_name + "_config['From'] = 'ScriptWithFunctions'\n" + 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 == "FunctionDict": self.text_da += data_name + "_FunctionDict = {}\n" self.text_da += data_name + "_FunctionDict['Function'] = ['Direct', 'Tangent', 'Adjoint']\n" diff --git a/src/daSalome/daYacsSchemaCreator/help_methods.py b/src/daSalome/daYacsSchemaCreator/help_methods.py index c7c3385..90e195d 100644 --- a/src/daSalome/daYacsSchemaCreator/help_methods.py +++ b/src/daSalome/daYacsSchemaCreator/help_methods.py @@ -246,3 +246,27 @@ def check_data(data_name, data_config, repertory_check=False, repertory=""): logging.fatal("A script file cannot be found") logging.fatal("File is %s" % check_file_name) sys.exit(1) + elif from_type == "ScriptWithSwitch": + ScriptWithSwitch = data_config["Data"] + for FunctionName in ScriptWithSwitch["Function"]: + check_file_name = "" + if repertory_check: + check_file_name = os.path.join(repertory, os.path.basename(ScriptWithSwitch["Script"][FunctionName])) + else: + check_file_name = ScriptWithSwitch["Script"][FunctionName] + if not os.path.exists(check_file_name): + logging.fatal("A script file cannot be found") + logging.fatal("File is %s" % check_file_name) + sys.exit(1) + elif from_type == "ScriptWithFunctions": + ScriptWithFunctions = data_config["Data"] + for FunctionName in ScriptWithFunctions["Function"]: + check_file_name = "" + if repertory_check: + check_file_name = os.path.join(repertory, os.path.basename(ScriptWithFunctions["Script"][FunctionName])) + else: + check_file_name = ScriptWithFunctions["Script"][FunctionName] + if not os.path.exists(check_file_name): + logging.fatal("A script file cannot be found") + logging.fatal("File is %s" % check_file_name) + sys.exit(1) diff --git a/src/daSalome/daYacsSchemaCreator/infos_daComposant.py b/src/daSalome/daYacsSchemaCreator/infos_daComposant.py index 33067f6..600a285 100644 --- a/src/daSalome/daYacsSchemaCreator/infos_daComposant.py +++ b/src/daSalome/daYacsSchemaCreator/infos_daComposant.py @@ -50,7 +50,7 @@ FromNumpyList = {} FromNumpyList["Vector"] = ["String", "Script"] FromNumpyList["VectorSerie"] = ["String", "Script"] FromNumpyList["Matrix"] = ["String", "Script"] -FromNumpyList["Function"] = ["FunctionDict"] +FromNumpyList["Function"] = ["ScriptWithFunctions", "ScriptWithSwitch", "FunctionDict"] FromNumpyList["Dict"] = ["Script"] # -- Infos from daAlgorithms -- @@ -134,21 +134,21 @@ AlgoType["QuantileRegression"] = "Optim" # catalogue Eficas # Basic data types -BasicDataInputs = ["String", "Script", "FunctionDict"] +BasicDataInputs = ["String", "Script", "ScriptWithFunctions", "ScriptWithSwitch", "FunctionDict"] # Data input dict DataTypeDict = {} DataTypeDict["Vector"] = ["String", "Script"] DataTypeDict["VectorSerie"] = ["String", "Script"] DataTypeDict["Matrix"] = ["String", "Script"] -DataTypeDict["Function"] = ["FunctionDict"] +DataTypeDict["Function"] = ["ScriptWithFunctions", "ScriptWithSwitch", "FunctionDict"] DataTypeDict["Dict"] = ["Script"] DataTypeDefaultDict = {} DataTypeDefaultDict["Vector"] = "Script" DataTypeDefaultDict["VectorSerie"] = "Script" DataTypeDefaultDict["Matrix"] = "Script" -DataTypeDefaultDict["Function"] = "FunctionDict" +DataTypeDefaultDict["Function"] = "ScriptWithFunctions" DataTypeDefaultDict["Dict"] = "Script" # Assimilation data input diff --git a/src/daSalome/daYacsSchemaCreator/methods.py b/src/daSalome/daYacsSchemaCreator/methods.py index 0bef2df..688f9a6 100644 --- a/src/daSalome/daYacsSchemaCreator/methods.py +++ b/src/daSalome/daYacsSchemaCreator/methods.py @@ -336,6 +336,46 @@ def create_yacs_proc(study_config): else: CAS_node.getInputPort(port_name).edInitPy(FunctionDict["Script"][FunctionName]) + if data_config["Type"] == "Function" and data_config["From"] == "ScriptWithSwitch" and key == "ObservationOperator": + ScriptWithSwitch = data_config["Data"] + for FunctionName in ScriptWithSwitch["Function"]: + port_name = "ObservationOperator" + FunctionName + CAS_node.edAddInputPort(port_name, t_string) + if repertory: + CAS_node.getInputPort(port_name).edInitPy(os.path.join(base_repertory, os.path.basename(ScriptWithSwitch["Script"][FunctionName]))) + else: + CAS_node.getInputPort(port_name).edInitPy(ScriptWithSwitch["Script"][FunctionName]) + + if data_config["Type"] == "Function" and data_config["From"] == "ScriptWithSwitch" and key == "EvolutionModel": + ScriptWithSwitch = data_config["Data"] + for FunctionName in ScriptWithSwitch["Function"]: + port_name = "EvolutionModel" + FunctionName + CAS_node.edAddInputPort(port_name, t_string) + if repertory: + CAS_node.getInputPort(port_name).edInitPy(os.path.join(base_repertory, os.path.basename(ScriptWithSwitch["Script"][FunctionName]))) + else: + CAS_node.getInputPort(port_name).edInitPy(ScriptWithSwitch["Script"][FunctionName]) + + if data_config["Type"] == "Function" and data_config["From"] == "ScriptWithFunctions" and key == "ObservationOperator": + ScriptWithFunctions = data_config["Data"] + for FunctionName in ScriptWithFunctions["Function"]: + port_name = "ObservationOperator" + FunctionName + CAS_node.edAddInputPort(port_name, t_string) + if repertory: + CAS_node.getInputPort(port_name).edInitPy(os.path.join(base_repertory, os.path.basename(ScriptWithFunctions["Script"][FunctionName]))) + else: + CAS_node.getInputPort(port_name).edInitPy(ScriptWithFunctions["Script"][FunctionName]) + + if data_config["Type"] == "Function" and data_config["From"] == "ScriptWithFunctions" and key == "EvolutionModel": + ScriptWithFunctions = data_config["Data"] + for FunctionName in ScriptWithFunctions["Function"]: + port_name = "EvolutionModel" + FunctionName + CAS_node.edAddInputPort(port_name, t_string) + if repertory: + CAS_node.getInputPort(port_name).edInitPy(os.path.join(base_repertory, os.path.basename(ScriptWithFunctions["Script"][FunctionName]))) + else: + CAS_node.getInputPort(port_name).edInitPy(ScriptWithFunctions["Script"][FunctionName]) + # Step 3: create compute bloc compute_bloc = runtime.createBloc("compute_bloc") ADAO_Case.edAddChild(compute_bloc) @@ -382,6 +422,118 @@ def create_yacs_proc(study_config): opt_script_nodeOO.setScript(node_script) opt_script_nodeOO.edAddInputPort("computation", t_param_input) opt_script_nodeOO.edAddOutputPort("result", t_param_output) + elif data_config["Type"] == "Function" and data_config["From"] == "ScriptWithSwitch": + # Get script + ScriptWithSwitch = data_config["Data"] + script_filename = "" + for FunctionName in ScriptWithSwitch["Function"]: + # We currently support only one file + script_filename = ScriptWithSwitch["Script"][FunctionName] + break + + # We create a new pyscript node + opt_script_nodeOO = runtime.createScriptNode("", "FunctionNodeOO") + if repertory: + script_filename = os.path.join(base_repertory, os.path.basename(script_filename)) + try: + script_str= open(script_filename, 'r') + except: + logging.fatal("Exception in opening function script file : " + script_filename) + traceback.print_exc() + sys.exit(1) + node_script = "#-*-coding:iso-8859-1-*-\n" + node_script += "import sys, os \n" + if base_repertory != "": + node_script += "filepath = \"" + base_repertory + "\"\n" + else: + node_script += "filepath = \"" + os.path.dirname(script_filename) + "\"\n" + node_script += "if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index(filepath)>0):\n" + node_script += " sys.path.insert(0,filepath)\n" + node_script += script_str.read() + opt_script_nodeOO.setScript(node_script) + opt_script_nodeOO.edAddInputPort("computation", t_param_input) + opt_script_nodeOO.edAddOutputPort("result", t_param_output) + elif data_config["Type"] == "Function" and data_config["From"] == "ScriptWithFunctions": + # Get script + ScriptWithFunctions = data_config["Data"] + script_filename = "" + for FunctionName in ScriptWithFunctions["Function"]: + # We currently support only one file + script_filename = ScriptWithFunctions["Script"][FunctionName] + break + + # We create a new pyscript node + opt_script_nodeOO = runtime.createScriptNode("", "FunctionNodeOO") + if repertory: + script_filename = os.path.join(base_repertory, os.path.basename(script_filename)) + try: + script_str= open(script_filename, 'r') + except: + logging.fatal("Exception in opening function script file : " + script_filename) + traceback.print_exc() + sys.exit(1) + node_script = "#-*-coding:iso-8859-1-*-\n" + node_script += "import sys, os, numpy, logging\n" + if base_repertory != "": + node_script += "filepath = \"" + base_repertory + "\"\n" + else: + node_script += "filepath = \"" + os.path.dirname(script_filename) + "\"\n" + node_script += "if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index(filepath)>0):\n" + node_script += " sys.path.insert(0,filepath)\n" + node_script += """# ==============================================\n""" + node_script += script_str.read() + node_script += """# ==============================================\n""" + node_script += """for param in computation["specificParameters"]:\n""" + node_script += """ if param["name"] == "method": method = param["value"]\n""" + node_script += """ else: method = ""\n""" + node_script += """logging.info("ComputationFunctionNode: Found method is \'%s\'"%method)\n""" + node_script += """#\n""" + node_script += """#\n""" + node_script += """if method == "Direct":\n""" + node_script += """ try:\n""" + node_script += """ DirectOperator\n""" + node_script += """ except NameError:\n""" + node_script += """ raise ValueError("ComputationFunctionNode: DirectOperator not found in the imported user script file")\n""" + node_script += """ logging.info("ComputationFunctionNode: Direct computation")\n""" + node_script += """ Xcurrent = computation["inputValues"][0][0][0]\n""" + node_script += """ data = DirectOperator(numpy.matrix( Xcurrent ).T)\n""" + node_script += """#\n""" + node_script += """if method == "Tangent":\n""" + node_script += """ try:\n""" + node_script += """ TangentOperator\n""" + node_script += """ except NameError:\n""" + node_script += """ raise ValueError("ComputationFunctionNode: TangentOperator not found in the imported user script file")\n""" + node_script += """ logging.info("ComputationFunctionNode: Tangent computation")\n""" + node_script += """ Xcurrent = computation["inputValues"][0][0][0]\n""" + node_script += """ dXcurrent = computation["inputValues"][0][0][1]\n""" + node_script += """ data = TangentOperator((numpy.matrix( Xcurrent ).T, numpy.matrix( dXcurrent ).T))\n""" + node_script += """#\n""" + node_script += """if method == "Adjoint":\n""" + node_script += """ try:\n""" + node_script += """ AdjointOperator\n""" + node_script += """ except NameError:\n""" + node_script += """ raise ValueError("ComputationFunctionNode: AdjointOperator not found in the imported user script file")\n""" + node_script += """ logging.info("ComputationFunctionNode: Adjoint computation")\n""" + node_script += """ Xcurrent = computation["inputValues"][0][0][0]\n""" + node_script += """ Ycurrent = computation["inputValues"][0][0][1]\n""" + node_script += """ data = AdjointOperator((numpy.matrix( Xcurrent ).T, numpy.matrix( Ycurrent ).T))\n""" + node_script += """#\n""" + node_script += """logging.info("ComputationFunctionNode: Formatting the output")\n""" + node_script += """it = data.flat\n""" + node_script += """outputValues = [[[[]]]]\n""" + node_script += """for val in it:\n""" + node_script += """ outputValues[0][0][0].append(val)\n""" + node_script += """#\n""" + node_script += """result = {}\n""" + node_script += """result["outputValues"] = outputValues\n""" + node_script += """result["specificOutputInfos"] = []\n""" + node_script += """result["returnCode"] = 0\n""" + node_script += """result["errorMessage"] = ""\n""" + node_script += """# ==============================================\n""" + # + opt_script_nodeOO.setScript(node_script) + opt_script_nodeOO.edAddInputPort("computation", t_param_input) + opt_script_nodeOO.edAddOutputPort("result", t_param_output) else: factory_opt_script_node = catalogAd.getNodeFromNodeMap("FakeOptimizerLoopNode") opt_script_nodeOO = factory_opt_script_node.cloneNode("FakeFunctionNode") @@ -421,6 +573,117 @@ def create_yacs_proc(study_config): opt_script_nodeEM.setScript(node_script) opt_script_nodeEM.edAddInputPort("computation", t_param_input) opt_script_nodeEM.edAddOutputPort("result", t_param_output) + elif data_config["Type"] == "Function" and data_config["From"] == "ScriptWithSwitch": + # Get script + ScriptWithSwitch = data_config["Data"] + script_filename = "" + for FunctionName in ScriptWithSwitch["Function"]: + # We currently support only one file + script_filename = ScriptWithSwitch["Script"][FunctionName] + break + + # We create a new pyscript node + opt_script_nodeEM = runtime.createScriptNode("", "FunctionNodeEM") + if repertory: + script_filename = os.path.join(base_repertory, os.path.basename(script_filename)) + try: + script_str= open(script_filename, 'r') + except: + logging.fatal("Exception in opening function script file : " + script_filename) + traceback.print_exc() + sys.exit(1) + node_script = "#-*-coding:iso-8859-1-*-\n" + node_script += "import sys, os \n" + if base_repertory != "": + node_script += "filepath = \"" + base_repertory + "\"\n" + else: + node_script += "filepath = \"" + os.path.dirname(script_filename) + "\"\n" + node_script += "if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index(filepath)>0):\n" + node_script += " sys.path.insert(0,filepath)\n" + node_script += script_str.read() + opt_script_nodeEM.setScript(node_script) + opt_script_nodeEM.edAddInputPort("computation", t_param_input) + opt_script_nodeEM.edAddOutputPort("result", t_param_output) + elif data_config["Type"] == "Function" and data_config["From"] == "ScriptWithFunctions": + # Get script + ScriptWithFunctions = data_config["Data"] + script_filename = "" + for FunctionName in ScriptWithFunctions["Function"]: + # We currently support only one file + script_filename = ScriptWithFunctions["Script"][FunctionName] + break + + # We create a new pyscript node + opt_script_nodeEM = runtime.createScriptNode("", "FunctionNodeEM") + if repertory: + script_filename = os.path.join(base_repertory, os.path.basename(script_filename)) + try: + script_str= open(script_filename, 'r') + except: + logging.fatal("Exception in opening function script file : " + script_filename) + traceback.print_exc() + sys.exit(1) + node_script = "#-*-coding:iso-8859-1-*-\n" + node_script += "import sys, os, numpy, logging\n" + if base_repertory != "": + node_script += "filepath = \"" + base_repertory + "\"\n" + else: + node_script += "filepath = \"" + os.path.dirname(script_filename) + "\"\n" + node_script += "if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index(filepath)>0):\n" + node_script += " sys.path.insert(0,filepath)\n" + node_script += script_str.read() + node_script += """# ==============================================\n""" + node_script += """for param in computation["specificParameters"]:\n""" + node_script += """ if param["name"] == "method": method = param["value"]\n""" + node_script += """ else: method = ""\n""" + node_script += """logging.info("ComputationFunctionNode: Found method is \'%s\'"%method)\n""" + node_script += """#\n""" + node_script += """#\n""" + node_script += """if method == "Direct":\n""" + node_script += """ try:\n""" + node_script += """ DirectOperator\n""" + node_script += """ except NameError:\n""" + node_script += """ raise ValueError("ComputationFunctionNode: mandatory DirectOperator not found in the imported user script file")\n""" + node_script += """ logging.info("ComputationFunctionNode: Direct computation")\n""" + node_script += """ Xcurrent = computation["inputValues"][0][0][0]\n""" + node_script += """ data = DirectOperator(numpy.matrix( Xcurrent ).T)\n""" + node_script += """#\n""" + node_script += """if method == "Tangent":\n""" + node_script += """ try:\n""" + node_script += """ TangentOperator\n""" + node_script += """ except NameError:\n""" + node_script += """ raise ValueError("ComputationFunctionNode: mandatory TangentOperator not found in the imported user script file")\n""" + node_script += """ logging.info("ComputationFunctionNode: Tangent computation")\n""" + node_script += """ Xcurrent = computation["inputValues"][0][0][0]\n""" + node_script += """ dXcurrent = computation["inputValues"][0][0][1]\n""" + node_script += """ data = TangentOperator((numpy.matrix( Xcurrent ).T, numpy.matrix( dXcurrent ).T))\n""" + node_script += """#\n""" + node_script += """if method == "Adjoint":\n""" + node_script += """ try:\n""" + node_script += """ AdjointOperator\n""" + node_script += """ except NameError:\n""" + node_script += """ raise ValueError("ComputationFunctionNode: mandatory AdjointOperator not found in the imported user script file")\n""" + node_script += """ logging.info("ComputationFunctionNode: Adjoint computation")\n""" + node_script += """ Xcurrent = computation["inputValues"][0][0][0]\n""" + node_script += """ Ycurrent = computation["inputValues"][0][0][1]\n""" + node_script += """ data = AdjointOperator((numpy.matrix( Xcurrent ).T, numpy.matrix( Ycurrent ).T))\n""" + node_script += """#\n""" + node_script += """logging.info("ComputationFunctionNode: Formatting the output")\n""" + node_script += """it = data.flat\n""" + node_script += """outputValues = [[[[]]]]\n""" + node_script += """for val in it:\n""" + node_script += """ outputValues[0][0][0].append(val)\n""" + node_script += """#\n""" + node_script += """result = {}\n""" + node_script += """result["outputValues"] = outputValues\n""" + node_script += """result["specificOutputInfos"] = []\n""" + node_script += """result["returnCode"] = 0\n""" + node_script += """result["errorMessage"] = ""\n""" + node_script += """# ==============================================\n""" + # + opt_script_nodeEM.setScript(node_script) + opt_script_nodeEM.edAddInputPort("computation", t_param_input) + opt_script_nodeEM.edAddOutputPort("result", t_param_output) else: factory_opt_script_node = catalogAd.getNodeFromNodeMap("FakeOptimizerLoopNode") opt_script_nodeEM = factory_opt_script_node.cloneNode("FakeFunctionNode") -- 2.39.2