BlocMonteCarlo1 = BLOC ( condition = "Methode == 'MonteCarlo'",
CritereArret = FACT ( statut = "o", max = 1,
regles = (AU_MOINS_UN('SimulationsNumber','MaximumElapsedTime'),),
+ # TODO : regles = (AU_MOINS_UN('Accuracy', 'SimulationsNumber','MaximumElapsedTime'),),
Accuracy = SIMP ( statut = "o", typ = "R", #TODO: statut = "f"
val_min = 0.0, val_max = 1.0, sug = 0.01, #TODO: val_min > 0
- fr = "Coefficient de variation maximum à atteindre",
+ fr = "Coefficient de variation maximum à atteindre pour la moyenne",
ang = "Accuracy - the maximum coefficient of variation (CV) for the mean",),
SimulationsNumber = SIMP ( statut = "o", typ = "I",
val_min = 1, defaut =10000,
), # FIN FACT EvaluationParameter
AdvancedParameter = FACT ( statut = "f", max = 1, #TODO: BlockSize < SimulationsNumber
ComputeConfidenceIntervalAt = SIMP ( statut = "o", typ = "R",
- val_min = 0, val_max = 0.9999,
+ val_min = 0, val_max = 0.9999, defaut = 0.95,
#TODO: avec statut = "f" && defaut = 0.95,
fr = "Demande le calcul de l'interval de confiance au niveau donné",
ang = "Require the computation of the confidence interval at a given level",),
- Seed = SIMP ( statut = "o", typ = "R", val_min = 0, defaut = 0,
+ Seed = SIMP ( statut = "o", typ = "I", val_min = 0, defaut = 0,
fr = "La graine d'initialisation du générateur aléatoire",
ang = "The seed of the random generator ",),
), # FIN FACT AdvancedParameter
from .generator_python import PythonGenerator
from .textePersalys import headerScriptPersalys, fonctionPersalys, etudeScript, codePersalys
from .textePersalys import mainPersalys, inputHeaderPersalys, outputHeaderPersalys
-from .textePersalys import centralTendencyTaylor, resultTaylor, optionalResultTaylor
-from .textePersalys import centralTendencyMC, resultMC, optionalResultMC
+from .textePersalys import centralTendencyTaylor, resultTaylor
+from .textePersalys import optionalResultTaylor, optionalPrintResultTaylor
+from .textePersalys import centralTendencyMC, resultMC
+from .textePersalys import critereArretMC, advancedParameterMC
+from .textePersalys import optionalResultMC, optionalPrintResultMC
from .textePersalys import yacsJobParameters
def entryPoint():
def gener(self,jdc,format='beautifie'):
- self.indent = ' '
+ self.indent1 = ' '
print (jdc.code)
if jdc.nature != 'JDC' :
self.fichierUQComm = self.fichierSansSuffixe+'_UQ.comm'
self.fichierUQBalise = self.fichierSansSuffixe+'_UQBalise.comm'
self.fichierUQExe = self.fichierSansSuffixe+'_UQ.py'
+ self.fichierUQModule = os.path.basename(self.fichierUQExe)[:-3]
else:
return (0, 'le fichier jeux de données |'+fichier+'| doit être suffixé par .comm')
if etapeIncertitude == [] : return(0, 'il faut au moins un mot-clef ExpressionIncertitude')
if len(etapeIncertitude) !=1 : return(0, 'il faut au plus un mot-clef ExpressionIncertitude')
etapeIncertitude = etapeIncertitude[0]
+
incertitudeInput = etapeIncertitude.getChildOrChildInBloc('Input')
self.lesVariablesInput = incertitudeInput[0].getChildOrChildInBloc('VariableProbabiliste')
self.mcIncertains = []
sectionPropagation = etapeIncertitude.getChildOrChildInBloc('Propagation')[0]
self.Methode = sectionPropagation.getChildOrChildInBloc('Methode').valeur
self.Result = sectionPropagation.getChildOrChildInBloc('Result')[0]
-
+ self.critereArret = sectionPropagation.getChildOrChildInBloc('CritereArret')[0]
+ # self.SimulationsNumber = self.critereArret.getChildOrChildInBloc('SimulationsNumber')[0]
+ # self.MaximumElapsedTime = self.critereArret.getChildOrChildInBloc('MaximumElapsedTime')[0]
+ # self.Accuracy = self.critereArret.getChildOrChildInBloc('Accuracy')[0]
+ sectionEvaluationParameter = sectionPropagation.getChildOrChildInBloc('EvaluationParameter')[0]
+ self.Blocksize = sectionEvaluationParameter.getChildOrChildInBloc('BlockSize').valeur
+ self.advancedParameter = sectionPropagation.getChildOrChildInBloc('AdvancedParameter')
+ if self.advancedParameter != None:
+ self.advancedParameter = self.advancedParameter[0]
+ # self.ComputeConfidenceIntervalAt = self.advancedParameter.getChildOrChildInBloc('ComputeConfidenceIntervalAt')[0]
+ # self.Seed = self.advancedParameter.getChildOrChildInBloc('Seed')[0]
+
self.lesVariablesOutput = sectionOutput.getChildOrChildInBloc('VariableDeSortie')
self.variablesOutput = {}
self.chaineDesVariablesOutput=''
self.chaineDesVariablesOutput+=nomVar+ ', '
Fonctions = mc.getChildOrChildInBloc('FonctionDAggregation').valeur
self.variablesOutput [nomVar]=Fonctions
- self.txtOutputVariableInitList += self.indent + nomVar + " = persalys.Output('"+ nomVar + "', '"+nomVar + "')\n"
+ self.txtOutputVariableInitList += self.indent1 + nomVar + " = persalys.Output('"+ nomVar + "', '"+nomVar + "')\n"
print (self.variablesOutput)
self.chaineDesVariablesOutput=self.chaineDesVariablesOutput[0:-2]
chaineDesVariablesInput = self.chaineDesVariablesInput,
chaineSelfDesVariablesInput = getStrSelfVar(self.nomsDesVariablesInput),
chaineInitDesVariablesInput = getStrInitClass(self.nomsDesVariablesInput),
- commFileUQBaliseStr = self.fichierUQBalise,
+ commFileUQBalise = self.fichierUQBalise,
commFileUQComm = self.fichierUQComm,
- nproc = self.NbOfProcs,
+ nproc = self.NbOfProcs,
replaceDataList = getStrReplaceVar(self.nomsDesVariablesInput)
)
txtFonctionPersalys = fonctionPersalys.format(
- currentFile = self.fichierUQExe[:-3],
+ currentFile = self.fichierUQModule,
chaineDesVariablesInput = self.chaineDesVariablesInput,
chaineDesVariablesOutput = self.chaineDesVariablesOutput
)
fonctionPersalys =txtFonctionPersalys
)
-
+ ## Propagation des inceritudes : Choix de la méthode et de ses paramètres
if (self.Methode == 'Taylor' ):
txtCentralTendencyPersalys = centralTendencyTaylor
optionalResult = optionalResultTaylor
- txtResultTemp = resultTaylor
+ optionalPrintResult = optionalPrintResultTaylor
+ txtResultCT = resultTaylor
elif (self.Methode == 'MonteCarlo' ):
- txtCentralTendencyPersalys = centralTendencyMC
+ critereArret = ""
+ for mc in self.critereArret.mcListe:
+ critereArret+= self.indent1 + critereArretMC[mc.nom].format(**{mc.nom : mc.valeur}) + '\n'
+
+ txtAdvancedParameterMC = ""
+ advancedParameter = ""
+ if self.advancedParameter != None:
+ for mc in self.advancedParameter.mcListe:
+ advancedParameter+= self.indent1+advancedParameterMC[mc.nom].format(**{mc.nom : mc.valeur}) + '\n'
+
+ txtCentralTendencyPersalys = centralTendencyMC.format(
+ critereArretMC = critereArret,
+ advancedParameterMC = advancedParameter,
+ BlockSize = self.Blocksize
+ )
optionalResult = optionalResultMC
- txtResultTemp = resultMC
+ optionalPrintResult = optionalPrintResultMC
+ txtResultCT = resultMC
+ else :
+ return(0, "Impossible de gérer la méthode :",self.Methode)
+
result=""
for mc in self.Result.mcListe:
# print('mc : ',mc)
# print('mc.nature : ',mc.nature)
# print('mc.valeur : ',mc.valeur)
- if mc.nature == 'MCSIMP' and mc.valeur == 'yes' :
- result+= self.indent+optionalResult[mc.nom] + '\n'
+ if mc.nom == 'EmpiricalQuantile' and mc.valeur == 'yes' :
+ empiricalQuantile_Order = self.Result.getChildOrChildInBloc("EmpiricalQuantile_Order")
+ result+= self.indent1+optionalResult[mc.nom].format(
+ **{empiricalQuantile_Order.nom : empiricalQuantile_Order.valeur}
+ ) + '\n'
+ result+= self.indent1+optionalPrintResult["EmpiricalQuantile_Order"] + '\n'
+ result+= self.indent1+optionalPrintResult[mc.nom] + '\n'
+ elif mc.nature == 'MCSIMP' and mc.valeur == 'yes' :
+ result+= self.indent1+optionalResult[mc.nom] + '\n'
+ result+= self.indent1+optionalPrintResult[mc.nom] + '\n'
+
+
# print('result:',result)
- # print('txtResultTemp:',txtResultTemp)
- txtResult= txtResultTemp.format( optionalResult=result )
+ # print('txtResultCT:',txtResultCT)
+ txtResult= txtResultCT.format( optionalResult=result )
#TODO ;: Tester si Cluster== Gaia, ajouter les champs suivants
# resourceName = 'gaia'
# workDirectory = '/scratch/'+login+'/workingdir/persalys_light' #TODO: path.join
# resultDirectory = '/tmp/result_0'
wckey = 'P11N0:SALOME'
-
+
inFiles =[]
inFiles.append(os.path.join(wrapperDir,'incertainty_tools.py'))
pyFile = self.fichierUQExe
self.txtScriptPersalys += mainPersalys.format(
nomEtude=nomEtude,
- inputVariableInitList = self.creeTexteInputVariables(self.indent),
+ inputVariableInitList = self.creeTexteInputVariables(self.indent1),
outputVariableInitList = self.txtOutputVariableInitList,
#outputVariableInitList = '#Not yet implemented',
- inputHeaderPersalys = inputHeaderPersalys.format(indent=self.indent),
+ inputHeaderPersalys = inputHeaderPersalys.format(indent=self.indent1),
chaineDesVariablesInput = self.chaineDesVariablesInput,
- outputHeaderPersalys = outputHeaderPersalys.format(indent=self.indent),
+ outputHeaderPersalys = outputHeaderPersalys.format(indent=self.indent1),
chaineDesVariablesOutput = self.chaineDesVariablesOutput,
yacsJobParameters = txtYacsJobParameters,
centralTendencyPersalys = txtCentralTendencyPersalys,
resultPersalys = txtResult
)
-
- # self.txtScriptPersalys += inputHeaderPersalys.format(indent,indent)
- # self.txtScriptPersalys +=self.creeTexteInputVariables(indent)
- # self.txtScriptPersalys += outputHeaderPersalys.format(indent,indent)
-
+
os.mkdir(self.workdir)
#section spécifique au code de calcul
- comm_file_uq_balise = '{commFileUQBaliseStr}'
+ comm_file_uq_balise = '{commFileUQBalise}'
self.nproc = {nproc}
self.comm_file_uq_balise = os.path.join(self.workdir, comm_file_uq_balise)
# inputs = [a, b]
# outputs = [d]
-
+## Tendance Centrale Taylor
centralTendencyTaylor ="""
centralTendency = persalys.TaylorExpansionMomentsAnalysis('centralTendencyTaylor', yacsPhysicalModel)
"""
'MeanSecondOrder' : 'meanSecondOrder = result.getMeanSecondOrder()',
'Variance' : 'variance = result.getVariance()'
}
-# print('result : ',result)
-# print('meanFirstOrder',meanFirstOrder)
-# print('standardDeviationFirstOrder',standardDeviationFirstOrder)
+optionalPrintResultTaylor={
+ 'MeanFirstOrder' : 'print("MeanFirstOrder : ",meanFirstOrder)',
+ 'StandardDeviationFirstOrder' : 'print("StandardDeviationFirstOrder :",standardDeviationFirstOrder)',
+ 'MeanSecondOrder' : 'print("MeanSecondOrder :",meanSecondOrder)',
+ 'Variance' : 'print("Variance :",variance)',
+}
+## Tendance Centrale MC
centralTendencyMC ="""
centralTendency = persalys.MonteCarloAnalysis('centralTendencyMC', yacsPhysicalModel)
- centralTendency.setMaximumCoefficientOfVariation({CoefficientOfVariation})
- centralTendency.setMaximumElapsedTime({MaximumElapsedTime})
- centralTendency.setMaximumCalls({MaximumCalls})
+{critereArretMC}
+{advancedParameterMC}
centralTendency.setBlockSize({BlockSize})
- centralTendency.setSeed({Seed})
"""
+critereArretMC = {
+ 'SimulationsNumber' : 'centralTendency.setMaximumCalls({SimulationsNumber})',
+ 'MaximumElapsedTime' : 'centralTendency.setMaximumElapsedTime({MaximumElapsedTime})',
+ 'Accuracy' : 'centralTendency.setMaximumCoefficientOfVariation({Accuracy})'
+}
+
+advancedParameterMC = {
+ 'Seed' : 'centralTendency.setSeed({Seed})',
+ 'ComputeConfidenceIntervalAt' : 'centralTendency.setLevelConfidenceInterval({ComputeConfidenceIntervalAt})'
+}
+
#TODO: Demander à Liana cf:eficas
resultMC="""
result = centralTendency.getResult()
optionalResultMC={
'EmpiricalMean' : 'empiricalMean = result.getMean()', #TOCHECK
'Variance' : 'variance = result.getVariance()',
- 'EmpiricalStandardDeviation' : '#Not Implemented',
- 'EmpiricalQuantile' : '#Not Implemented',
- 'EmpiricalQuantile_Order' : '#Not Implemented'
+ 'EmpiricalStandardDeviation' : 'empiricalStandardDeviation = result.getStandardDeviation()', #TOCHECK
+ 'EmpiricalQuantile' : """
+ designOfExperiment=result.getDesignOfExperiment()
+ outputSample=designOfExperiment.getOutputSample()
+ empiricalQuantile_Order = {EmpiricalQuantile_Order}
+ empiricalQuantile=outputSample.computeQuantile(empiricalQuantile_Order)
+ """
+}
+
+optionalPrintResultMC={
+ 'EmpiricalMean' : 'print("EmpiricalMean : ", empiricalMean)',
+ 'Variance' : 'print("Variance : ", variance)',
+ 'EmpiricalStandardDeviation' : 'print("EmpiricalStandardDeviation : ",empiricalStandardDeviation)',
+ 'EmpiricalQuantile' : 'print("EmpiricalQuantile : ",empiricalQuantile)',
+ 'EmpiricalQuantile_Order' : 'print("EmpiricalQuantile_Order : ",empiricalQuantile_Order)'
}
+
+# designOfExperiment=result.getDesignOfExperiment()
+# outputSample=designOfExperiment.getOutputSample()
+# computeQuantile=outputSample.computeQuantile(empiricalQuantile_Order)
+# ##isample=designOfExperiment.getSample()
+# ##computeQuantile=sample.computeQuantile(0.95)
+# ##nputSample=designOfExperiment.getInputSample()
+# ##computeQuantile=inputSample.computeQuantile(0.95)
+
yacsJobParameters="""
yacsPhysicalModel.jobParameters().salome_parameters.job_name = '{nomEtude}'
yacsPhysicalModel.jobParameters().salome_parameters.work_directory = '{workDirectory}'