From 28c9083dd6f057c9262711078e7ab3dce852d632 Mon Sep 17 00:00:00 2001 From: Eric Fayolle Date: Wed, 15 Jun 2022 14:33:42 +0200 Subject: [PATCH] =?utf8?q?Permi=C3=A8re=20version=20fonctionelle=20eficas+?= =?utf8?q?incertitudes/Persalys=20test=C3=A9e=20sur=20gaia?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- generator/generator_UQ.py | 21 +++++---- generator/incertainty_tools.py | 5 +- generator/textePersalys.py | 84 +++++++++++++++++++++++++--------- 3 files changed, 78 insertions(+), 32 deletions(-) diff --git a/generator/generator_UQ.py b/generator/generator_UQ.py index a1b97259..c36d1a50 100644 --- a/generator/generator_UQ.py +++ b/generator/generator_UQ.py @@ -182,7 +182,7 @@ class UQGenerator(PythonGenerator): # on cherche le bloc qui contient ce qui est necessaire a la loi # on est confiant !!!! sur l adequation du catalogue et des attributs des lois persalys # reflechir a cela - texte="{}{} = persalys.input('{}', ot.{}(".format(indent,nomVariableInput,nomVariableInput,loiDistribution) + texte="{}{} = persalys.Input('{}', ot.{}(".format(indent,nomVariableInput,nomVariableInput,loiDistribution) chaineArgs='' leBlocDesArgs=None for mc in v.mcListe : @@ -206,10 +206,11 @@ class UQGenerator(PythonGenerator): def getStrVarList(l): return reduce(lambda x,y:x+', '+y, l) def getStrInitClass(l): - return getStrVarList( map(lambda x:'self.{}={};'.format(x,x),l) ) + return getStrVarList( map(lambda x:'self.{} = {};'.format(x,x),l) ) def getStrReplaceVar(l): return getStrVarList( map(lambda x:"'@{}@': repr(self.{})".format(x,x), l) ) - + def getStrSelfVar(l): + return getStrVarList( map(lambda x:'self.{}'.format(x),l) ) wrapperDir = os.path.abspath(os.path.dirname(__file__)) wrapperName = "eficas_wrapper" @@ -221,17 +222,19 @@ class UQGenerator(PythonGenerator): wrapperName=wrapperName ) self.txtScriptPersalys += etudeScript.format( - chaineDesVariablesInput =self.chaineDesVariablesInput, - chaineInitDesVariablesInput=getStrInitClass(self.nomsDesVariablesInput), - commFileStr = self.fichierUQBalise, + chaineDesVariablesInput = self.chaineDesVariablesInput, + chaineSelfDesVariablesInput = getStrSelfVar(self.nomsDesVariablesInput), + chaineInitDesVariablesInput = getStrInitClass(self.nomsDesVariablesInput), + commFileUQBaliseStr = self.fichierUQBalise, + commFileUQComm = self.fichierUQComm, nproc = self.NbOfProcs, replaceDataList = getStrReplaceVar(self.nomsDesVariablesInput) ) txtFonctionPersalys = fonctionPersalys.format( currentFile = self.fichierUQExe[:-3], - chaineDesVariablesInput =self.chaineDesVariablesInput, - chaineDesVariablesOutput =self.chaineDesVariablesOutput + chaineDesVariablesInput = self.chaineDesVariablesInput, + chaineDesVariablesOutput = self.chaineDesVariablesOutput ) self.txtScriptPersalys += codePersalys.format( fonctionPersalys =txtFonctionPersalys @@ -270,6 +273,8 @@ class UQGenerator(PythonGenerator): inFiles.append(os.path.join(os.getcwd(),pyFile)) pyFile = self.fichierUQBalise inFiles.append(os.path.join(os.getcwd(),pyFile)) + scriptFile = "ib_test.sh" + inFiles.append(os.path.join(os.getcwd(),scriptFile)) txtYacsJobParameters=yacsJobParameters.format( nomEtude = self.JobName, workDirectory = self.WorkDirectory, diff --git a/generator/incertainty_tools.py b/generator/incertainty_tools.py index 261f647a..739f5cd0 100644 --- a/generator/incertainty_tools.py +++ b/generator/incertainty_tools.py @@ -31,7 +31,7 @@ def temp_dirname(): import tempfile return tempfile.mkdtemp(dir=os.getcwd()) -def replace_data(filename, key_values): +def replace_data(filename, key_values, filename_out=""): """ Modify an input file using replace function. Example: @@ -43,7 +43,8 @@ def replace_data(filename, key_values): filedata = f.read() for key,value in key_values.items(): filedata = filedata.replace(key,value) - with open(filename,'w') as f: + if len(filename_out) == 0 : filename_out=filename + with open(filename_out,'w') as f: f.write(filedata) def format_data(filename, key_values): diff --git a/generator/textePersalys.py b/generator/textePersalys.py index 0418e9ca..ff34143c 100644 --- a/generator/textePersalys.py +++ b/generator/textePersalys.py @@ -17,11 +17,9 @@ import sys import os # Chargement du module OpenTURNS #TODO : Parametrer OpenTurns/Uranie -import openturns +import openturns as ot import persalys -# Chargement de incertainty_tools -from incertainty_tools import value_repr_name, replace_data, format_data # from {wrapperDir} import {wrapperName} """ @@ -42,51 +40,90 @@ from incertainty_tools import value_repr_name, replace_data, format_data # etudeScript etudeScript = """ class Study: + import os + print('dir() 0 : ', dir()) + import subprocess + print('dir() 0b : ', dir()) +# from incertainty_tools import value_repr_name, replace_data, format_data + def __init__(self, {chaineDesVariablesInput}): - {chaineInitDesVariablesInput} + print('--------------------------------------- 0 ---------------------------------------') + {chaineInitDesVariablesInput} + + def do_sh(self, command, execdir=os.getcwd()): + print('dir() 1 : ', dir()) + print('execdir 1 : ', execdir) + import subprocess + print('dir() 2 : ', dir()) + sh = subprocess.Popen(command, shell=True, cwd=execdir, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT) + out, err = sh.communicate() + return out, err, sh.poll() #TODO : Définir un décorateur pour sélectionner la fonction voulue def define_workdirectory(self): - self.workdir = valueReprName( [{chaineDesVariablesInput}]) + from incertainty_tools import value_repr_name + print('--------------------------------------- 1 ---------------------------------------') + self.workdir = value_repr_name([{chaineSelfDesVariablesInput}]) def case_exists(self): + print('--------------------------------------- 2 ---------------------------------------') ok = True if os.path.isdir(self.workdir): - try: - ok = False #TODO - except: - ok = False + try: + ok = False #TODO + except: + ok = False else: - ok = False + ok = False return ok def prepare_case(self): + from incertainty_tools import replace_data + print('--------------------------------------- 3 ---------------------------------------') import shutil if not os.path.isdir(self.workdir): os.mkdir(self.workdir) #section spécifique au code de calcul - comm_file = {commFileStr} + comm_file_uq_balise = '{commFileUQBaliseStr}' self.nproc = {nproc} - self.comm_file=os.path.join(self.workdir, comm_file) + self.comm_file_uq_balise = os.path.join(self.workdir, comm_file_uq_balise) + shutil.copy(comm_file_uq_balise, self.comm_file_uq_balise) + + self.comm_file_uq_comm = os.path.join(self.workdir, '{commFileUQComm}') + replace_data(self.comm_file_uq_balise, {{ {replaceDataList} }} , self.comm_file_uq_comm) - shutil.copy(comm_file, self.comm_file) - replace_data(self.comm_file, {{ {replaceDataList} }}) pass def get_results(self): + print('--------------------------------------- 4 ---------------------------------------') # return self.extract_probe(2,2), self.extract_balance(2, 2) - return None, None + return 1.0 + + def run_case(self): + print('--------------------------------------- 5 ---------------------------------------') + #os.chdir(self.workdir) + o,e,c = self.do_sh(command="ib_test.sh", execdir=self.workdir) + if o != None : print('o.decode() : ',o.decode()) + if e != None : print('e.decode() : ',e.decode()) + print(c) + """ +# /home/C65845/VIMMP/Banc_integration.newer_odysee/environment/bin/python3 /home/C65845/VIMMP/Banc_integration.newer_odysee/environment/bin/ib-run --cocagne-neutro-solver SPN --cocagne-thermo-solver THERMOMI/TRMIC -- /home/C65845/VIMMP/Banc_integration.newer_odysee/integration_bench/tests/control_rod_ejection_small_core_cathare3_cocagne.comm /home/C65845/VIMMP/Banc_integration.newer_odysee/integration_bench/tests/control_rod_ejection_small_core_cathare3_cocagne_spn_thermomi-trmic_serial + + # ------------------------ # fonctionPersalys # ------------------------ fonctionPersalys = """ def _exec({chaineDesVariablesInput}): + print('--------------------------------------- 00 ---------------------------------------') from {currentFile} import Study @@ -154,7 +191,7 @@ if __name__ == '__main__': {nomEtude}.add(yacsPhysicalModel) {centralTendencyPersalys} - Study.add(centralTendency) + {nomEtude}.add(centralTendency) centralTendency.run() @@ -178,11 +215,14 @@ resultTaylor=""" {optionalResult} """ optionalResultTaylor={ - 'MeanFirstOrder' : 'meanFirstOrder=result.getMeanFirstOrder()', - 'StandardDeviationFirstOrder' : 'standardDeviationFirstOrder=result.getStandardDeviation()', - 'MeanSecondOrder' : 'meanSecondOrder=result.getMeanSecondOrder()', - 'Variance' : 'variance=result.getVariance()' + 'MeanFirstOrder' : 'meanFirstOrder = result.getMeanFirstOrder()', + 'StandardDeviationFirstOrder' : 'standardDeviationFirstOrder = result.getStandardDeviation()', + 'MeanSecondOrder' : 'meanSecondOrder = result.getMeanSecondOrder()', + 'Variance' : 'variance = result.getVariance()' } +# print('result : ',result) +# print('meanFirstOrder',meanFirstOrder) +# print('standardDeviationFirstOrder',standardDeviationFirstOrder) centralTendencyMC =""" centralTendency = persalys.MonteCarloAnalysis('centralTendencyMC', yacsPhysicalModel) @@ -211,10 +251,10 @@ yacsJobParameters=""" yacsPhysicalModel.jobParameters().salome_parameters.work_directory = '{workDirectory}' yacsPhysicalModel.jobParameters().salome_parameters.result_directory = '{resultDirectory}' yacsPhysicalModel.jobParameters().salome_parameters.resource_required.name = '{resourceName}' - yacsPhysicalModel.jobParameters().salome_parameters.resource_required.nb_proc = '{nprocs}' + yacsPhysicalModel.jobParameters().salome_parameters.resource_required.nb_proc = {nprocs} yacsPhysicalModel.jobParameters().salome_parameters.wckey = '{wckey}' yacsPhysicalModel.jobParameters().salome_parameters.in_files = {inFiles} # Chemins des fichiers locaux à copier dans work_directory - yacsPhysicalModel.jobParameters().nb_branches = '{nprocs}' # nombre de jobs parallèles + yacsPhysicalModel.jobParameters().nb_branches = {nprocs} # nombre de jobs parallèles """ yacsJobParametersRef=""" -- 2.39.2