English Français

Documentation / Manuel utilisateur en Python : PDF version

XIV.5. Macros Launcher

XIV.5. Macros Launcher

XIV.5.1. Macro "launchFunctionDataBase.py"

XIV.5.1.1. Objective

Evaluating an analytic function towards a design-of-experiments given in an ASCII file.

This analytic function is written in C++ using the protocol of Uranie in file "UserFunctions.C" (the file can be found in the folder ${URANIESYS}/share/uranie/macros/). This function is named "flowrateModel" and it requires 8 inputs (, , , , , , , ) and returns a scalar ("ymod"). The analytic expression of the function is given in (Section IV.1.2.1).

The design-of-experiments is the same as in precedent macro (Section XIV.3.4).

XIV.5.1.2. Macro Uranie

 """
Example of database function launching
"""
from rootlogon import ROOT, DataServer, Launcher

# Create a DataServer.TDataServer
tds = DataServer.TDataServer()
# Load the data set in the DataServer
tds.fileDataRead("flowrateUniformDesign.dat")

# Load the function in the UserFunction macros file
ROOT.gROOT.LoadMacro("UserFunctions.C")

# Create a TLauncherFunction from a TDataServer and an analytical function
# Rename the outpout attribute "ymod"
tlf = Launcher.TLauncherFunction(tds, "flowrateModel", "", "ymod")
# Evaluate the function on all the points in the Design Of Experiments (DoE)
tlf.run()

# Graph
Canvas = ROOT.TCanvas("c1", "Graph for the Macro loadASCIIFile",
                      5, 64, 1270, 667)
pad = ROOT.TPad("pad", "pad", 0, 0.03, 1, 1)
pad.Draw()
pad.Divide(2, 4)
pad.cd(1)
tds.draw("ymod:rw")
pad.cd(2)
tds.draw("ymod:r")
pad.cd(3)
tds.draw("ymod:tu")
pad.cd(4)
tds.draw("ymod:tl")
pad.cd(5)
tds.draw("ymod:hu")
pad.cd(6)
tds.draw("ymod:hl")
pad.cd(7)
tds.draw("ymod:l")
pad.cd(8)
tds.draw("ymod:kw")

XIV.5.1.3. Graph

Figure XIV.18. Graph of the macro "launchFunctionDataBase.py"

Graph of the macro "launchFunctionDataBase.py"

XIV.5.2. Macro "launchFunctionSampling.py"

XIV.5.2.1. Objective

Evaluating an analytic function in a stochastic design-of-experiments made with the LHS method.

This analytic function is written in C++ using the protocol of Uranie in file "UserFunctions.C" (the file can be found in the folder ${URANIESYS}/share/uranie/macros/). This function is named "flowrateModel" and it requires 8 inputs (, , , , , , , ) and returns a scalar ("ymod"). The analytic expression of the function is given in (Section IV.1.2.1).

The design-of-experiments is made using the LHS method requesting 1000 samples.

XIV.5.2.2. Macro Uranie

 """
Example of function launching
"""
from rootlogon import ROOT, DataServer, Launcher, Sampler

nS = 1000
# Create a DataServer.TDataServer
tds = DataServer.TDataServer("tdsFlowrate", "TDS for flowrate")
# Add the eight attributes of the study with uniform law
tds.addAttribute(DataServer.TUniformDistribution("rw", 0.05, 0.15))
tds.addAttribute(DataServer.TUniformDistribution("r", 100.0, 50000.0))
tds.addAttribute(DataServer.TUniformDistribution("tu", 63070.0, 115600.0))
tds.addAttribute(DataServer.TUniformDistribution("tl", 63.1, 116.0))
tds.addAttribute(DataServer.TUniformDistribution("hu", 990.0, 1110.0))
tds.addAttribute(DataServer.TUniformDistribution("hl", 700.0, 820.0))
tds.addAttribute(DataServer.TUniformDistribution("l", 1120.0, 1680.0))
tds.addAttribute(DataServer.TUniformDistribution("kw", 9855.0, 12045.0))

# Generate the sampling from the DataServer.TDataServer
sampling = Sampler.TSampling(tds, "lhs", nS)
sampling.generateSample()

# Load the function in the UserFunction macros file
ROOT.gROOT.LoadMacro("UserFunctions.C")

# Create a TLauncherFunction from a TDataServer and an analytical function
# Rename the outpout attribute "ymod"
tlf = Launcher.TLauncherFunction(tds, "flowrateModel", "", "ymod")
# Evaluate the function on all the design of experiments
tlf.run()


# Graph
Canvas = ROOT.TCanvas("c1", "Graph loadASCIIFile", 5, 64, 1270, 667)
pad = ROOT.TPad("pad", "pad", 0, 0.03, 1, 1)
pad.Draw()
pad.Divide(2, 4)
pad.cd(1)
tds.drawProfile("ymod:rw", "", "same")
pad.cd(2)
tds.drawProfile("ymod:r", "", "same")
pad.cd(3)
tds.drawProfile("ymod:tu", "", "same")
pad.cd(4)
tds.drawProfile("ymod:tl", "", "same")
pad.cd(5)
tds.drawProfile("ymod:hu", "", "same")
pad.cd(6)
tds.drawProfile("ymod:hl", "", "same")
pad.cd(7)
tds.drawProfile("ymod:l", "", "same")
pad.cd(8)
tds.drawProfile("ymod:kw", "", "same")

XIV.5.2.3. Graph

Figure XIV.19. Graph of the macro "launchFunctionSampling.py"

Graph of the macro "launchFunctionSampling.py"

XIV.5.3. Macro "launchFunctionSamplingGraphs.py"

XIV.5.3.1. Objective

The objective of this macro is to evaluate the flowrateModel function on a design-of-experiments, then to perform visualisations with different options. The sampling is made out of 1000 patterns using the LHS method. The flowrateModel function is used as a function and uses parameters obeying uniform laws on specific intervals defined in Section IV.1.2.1.

XIV.5.3.2. Macro Uranie

"""
Example of function launching with graphical examples
"""
from rootlogon import ROOT, DataServer, Launcher, Sampler

nS = 1000
# Create a DataServer.TDataServer
tds = DataServer.TDataServer("tdsFlowrate", "TDS for flowrate")
# Add the eight attributes of the study with uniform law
tds.addAttribute(DataServer.TUniformDistribution("rw", 0.05, 0.15))
tds.addAttribute(DataServer.TUniformDistribution("r", 100.0, 50000.0))
tds.addAttribute(DataServer.TUniformDistribution("tu", 63070.0, 115600.0))
tds.addAttribute(DataServer.TUniformDistribution("tl", 63.1, 116.0))
tds.addAttribute(DataServer.TUniformDistribution("hu", 990.0, 1110.0))
tds.addAttribute(DataServer.TUniformDistribution("hl", 700.0, 820.0))
tds.addAttribute(DataServer.TUniformDistribution("l", 1120.0, 1680.0))
tds.addAttribute(DataServer.TUniformDistribution("kw", 9855.0, 12045.0))

# Generate the sampling from the DataServer.TDataServer
sampling = Sampler.TSampling(tds, "lhs", nS)
sampling.generateSample()

# Load the function in the UserFunction macros file
ROOT.gROOT.LoadMacro("UserFunctions.C")

# Create a TLauncherFunction from a TDataServer and an analytical function
# Rename the outpout attribute "ymod"
tlf = Launcher.TLauncherFunction(tds, "flowrateModel", "", "ymod")
# Evaluate the function on all the design of experiments
tlf.run()

# Graph
Canvas = ROOT.TCanvas("c1", "Graph launchFunctionSampling", 5, 90, 935, 614)
pad = ROOT.TPad("pad", "pad", 0, 0.03, 1, 1)
pad.Draw()
pad.Divide(2, 4)
pad.cd(1)
tds.drawTufte("rw:r", "", "same")
pad.cd(2)
tds.drawCDF("rw")
pad.cd(3)
tds.draw("ymod")
pad.cd(4)
tds.drawCDF("ymod", "", "ccdf")
pad.cd(5)
tds.draw("ymod:rw:hu")
pad.cd(6)
tds.drawProfile("ymod:r", "", "same")
pad.cd(7)
tds.drawProfile("ymod:rw", "", "same")
pad.cd(8)
tds.draw("ymod:rw", "", "colz")

The attributes linked to the TDataServer obey uniform laws:

tds.addAttribute(DataServer.TUniformDistribution("rw", 0.05, 0.15));
tds.addAttribute(DataServer.TUniformDistribution("r", 100.0, 50000.0));
tds.addAttribute(DataServer.TUniformDistribution("tu", 63070.0, 115600.0));
tds.addAttribute(DataServer.TUniformDistribution("tl", 63.1, 116.0));
tds.addAttribute(DataServer.TUniformDistribution("hu", 990.0, 1110.0));
tds.addAttribute(DataServer.TUniformDistribution("hl", 700.0, 820.0));
tds.addAttribute(DataServer.TUniformDistribution("l", 1120.0, 1680.0));
tds.addAttribute(DataServer.TUniformDistribution("kw", 9855.0, 12045.0));

The sampling is built with a LHS method on 1000 patterns:

sampling=Sampler.TSampling(tds, "lhs", nS);  
sampling.generateSample();

The flowrateModel function is evaluated on the design-of-experiments:

tlf=Launcher.TLauncherFunction(tds, "flowrateModel","","ymod");
# Evaluate the function on all the design of experiments
tlf.run();

Different visualisations are then performed on attributes:

tds.drawTufte("rw:r","","same");
tds.drawCDF("rw");
tds.draw("ymod");
tds.drawCDF("ymod","","ccdf");
tds.draw("ymod:rw:hu");
tds.drawProfile("ymod:r","","same");
tds.drawProfile("ymod:rw","","same");
tds.draw("ymod:rw","","colz");

XIV.5.3.3. Graph

Figure XIV.20. Graph of the macro "launchFunctionSamplingGraphs.py"

Graph of the macro "launchFunctionSamplingGraphs.py"

XIV.5.4.  Macro "launchCodeFlowrateKeyDataBase.py"

XIV.5.4.1. Objective

The objective of the macro is to evaluate the flowrate external code on a design-of-experiments where the input file 'flowrate_input_with_keys.in' is a "key=value" type and the output file "_output_flowrate_withRow_.dat" is a "values in rows" type. This flowrate code is described in Section IV.1.2.3.1.1.

The database is contained in the file flowrateUniformDesign.dat containing 32 patterns.

#NAME: flowrateborehole
#TITLE: Uniform design of flow rate borehole problem proposed by Ho and Xu(2000)
#COLUMN_NAMES: rw| r| tu| tl| hu| hl| l| kw | ystar
#COLUMN_TITLES: r_{#omega}| r | T_{u} | T_{l} | H_{u} | H_{l} | L | K_{#omega} | y^{*}
#COLUMN_UNITS: m | m | m^{2}/yr | m^{2}/yr | m | m | m | m/yr | m^{3}/yr

0.0500 33366.67  63070.0 116.00 1110.00 768.57 1200.0 11732.14  26.18
0.0500   100.00  80580.0  80.73 1092.86 802.86 1600.0 10167.86  14.46
0.0567   100.00  98090.0  80.73 1058.57 717.14 1680.0 11106.43  22.75
0.0567 33366.67  98090.0  98.37 1110.00 734.29 1280.0 10480.71  30.98
0.0633   100.00 115600.0  80.73 1075.71 751.43 1600.0 11106.43  28.33
0.0633 16733.33  80580.0  80.73 1058.57 785.71 1680.0 12045.00  24.60
0.0700 33366.67  63070.0  98.37 1092.86 768.57 1200.0 11732.14  48.65
0.0700 16733.33 115600.0 116.00  990.00 700.00 1360.0 10793.57  35.36
0.0767   100.0  115600.0  80.73 1075.71 751.43 1520.0 10793.57  42.44
0.0767 16733.33  80580.0  80.73 1075.71 802.86 1120.0  9855.00  44.16
0.0833 50000.00  98090.0  63.10 1041.43 717.14 1600.0 10793.57  47.49
0.0833 50000.00 115600.0  63.10 1007.14 768.57 1440.0 11419.29  41.04
0.0900 16733.33  63070.0 116.00 1075.71 751.43 1120.0 11419.29  83.77
0.0900 33366.67 115600.0 116.00 1007.14 717.14 1360.0 11106.43  60.05
0.0967 50000.00  80580.0  63.10 1024.29 820.00 1360.0  9855.00  43.15
0.0967 16733.33  80580.0  98.37 1058.57 700.00 1120.0 10480.71  97.98
0.1033 50000.00  80580.0  63.10 1024.29 700.00 1520.0 10480.71  74.44
0.1033 16733.33  80580.0  98.37 1058.57 820.00 1120.0 10167.86  72.23
0.1100 50000.00  98090.0  63.10 1024.29 717.14 1520.0 10793.57  82.18
0.1100   100.00  63070.0  98.37 1041.43 802.86 1600.0 12045.00  68.06
0.1167 33366.67  63070.0 116.00  990.00 785.71 1280.0 12045.00  81.63
0.1167   100.00  98090.0  98.37 1092.86 802.86 1680.0  9855.00  72.5
0.1233 16733.33 115600.0  80.73 1092.86 734.29 1200.0 11419.29 161.35
0.1233 16733.33  63070.0  63.10 1041.43 785.71 1680.0 12045.00  86.73
0.1300 33366.67  80580.0 116.00 1110.00 768.57 1280.0 11732.14 164.78
0.1300   100.00  98090.0  98.37 1110.00 820.00 1280.0 10167.86 121.76
0.1367 50000.00  98090.0  63.10 1007.14 820.00 1440.0 10167.86  76.51
0.1367 33366.67  98090.0 116.00 1024.29 700.00 1200.0 10480.71 164.75
0.1433 50000.00  63070.0 116.00  990.00 785.71 1440.0  9855.00  89.54
0.1433 50000.00 115600.0  63.10 1007.14 734.29 1440.0 11732.14 141.09
0.1500 33366.67  63070.0  98.37  990.00 751.43 1360.0 11419.29 139.94 
0.1500   100.00 115600.0  80.73 1041.43 734.29 1520.0 11106.43 157.59

The input file flowrate_input_with_keys.in is "key=value" format:

#
# 
# INPUT FILE with KEYS for the "FLOWREATE" code
# \date   2008-04-22 12:53:35
#


date = 123456 ;


#########################
##
##  exclude points
##
chu = 1050;
chl = 770;
cr  = 1100;
##
#########################

#########################
##
##  parameters : 8
##
Rw = 0.0500 ;
R = 33366.67 ;
Tu = 63070.0 ;
Tl = 116.00 ;
Hu = 1110.00 ;
Hl = 768.57;
L = 1200.0 ;
Kw = 11732.14 ;
##
#########################


#########################
##
## to simulate CPU time
##
## normal         1 :
## min     10000000 : 1.160u 0.000s 0:01.16 100.0%
## max    100000000 : 11.600u 0.010s 0:11.61 100.0%
##
nLoop = 1;
##
#########################

end = 6;

This file defines the eight variables , , , , , , , needed to perform the execution of the command flowrate -k.

The output file, _output_flowrate_withRow_.dat when created, is a "values in rows with an header" type. It looks like:

#COLUMN_NAMES: yhat | d
		  
6.757218e+01  4.092561e+03

yhat and d have to be defined as output variables in the macro.

XIV.5.4.2. Macro Uranie

"""
Example of flowrate code launching with key database
"""
from rootlogon import ROOT, DataServer, Launcher

# Create a DataServer.TDataServer
tds = DataServer.TDataServer()
# Load the data base in the DataServer
tds.fileDataRead("flowrateUniformDesign.dat")

# The reference input file
sIn = "flowrate_input_with_keys.in"

# Set the reference input file and the key for each input attributes
tds.getAttribute("rw").setFileKey(sIn, "Rw")
tds.getAttribute("r").setFileKey(sIn, "R")
tds.getAttribute("tu").setFileKey(sIn, "Tu")
tds.getAttribute("tl").setFileKey(sIn, "Tl")
tds.getAttribute("hu").setFileKey(sIn, "Hu")
tds.getAttribute("hl").setFileKey(sIn, "Hl")
tds.getAttribute("l").setFileKey(sIn, "L")
tds.getAttribute("kw").setFileKey(sIn, "Kw")

# The output file of the code
fout = Launcher.TOutputFileRow("_output_flowrate_withRow_.dat")
# The attribute in the output file
fout.addAttribute(DataServer.TAttribute("yhat"))

# Instanciation de mon code
mycode = Launcher.TCode(tds, "flowrate -s -k")
# on ajoute le fichier de sortie du code
mycode.addOutputFile(fout)

# Lancement du code
laun = Launcher.TLauncher(tds, mycode)
laun.setSave()
laun.setClean()
# laun.setWorkingDirectory(ROOT.gSystem.pwd() + "/tmpLaunUranie/flowrate")
laun.setVarDraw("yhat:rw", "", "")
laun.run()


# Graph
Canvas = ROOT.TCanvas("c1", "Graph launchCodeFlowrateKeyDataBase",
                      5, 64, 1270, 667)
pad = ROOT.TPad("pad", "pad", 0, 0.03, 1, 1)
pad.Draw()
pad.Divide(2, 4)

pad.cd(1)
tds.draw("yhat:rw")
pad.cd(2)
tds.draw("yhat:r")
pad.cd(3)
tds.draw("yhat:tu")
pad.cd(4)
tds.draw("yhat:tl")
pad.cd(5)
tds.draw("yhat:hu")
pad.cd(6)
tds.draw("yhat:hl")
pad.cd(7)
tds.draw("yhat:l")
pad.cd(8)
tds.draw("yhat:kw")

The database is loaded from a data file flowrateUniformDesign.dat:

tds.fileDataRead("flowrateUniformDesign.dat");

Then, properties are set for each input variable. For example for the first variable, it is created as a TAttribute named "rw": this TAttribute is then linked to the input file with:

tds.getAttribute("rw").setFileKey(sIn, "Rw");

which will be understood by Uranie as the fact the rw variable has to be read in the input file with "key=value" format with the key Rw.

We use the output file with "values in rows" type _output_flowrate_withRow_.dat which will be instantiated as a TOutputFileRow.

fout=Launcher.TOutputFileRow("_output_flowrate_withRow_.dat");

The variables yhat and d can be linked to this TOutputFileRow output file. But here, only yhat will be considered by Uranie as variable of interest.

fout.addAttribute(DataServer.TAttribute("yhat"));

We set the code as being the flowrate execution with "-k" option.

mycode=Launcher.TCode(tds, "flowrate -s -k");

which indicates that flowrate code has to find the input file with "key=value" type.

Then the launcher is initialised with a TDataServer and the code is executed:

lanceur=Launcher.TLauncher(tds, mycode);

The launcher will execute the flowrate -k command for each of the 32 patterns with the run method:

lanceur.run();

XIV.5.4.3. Graph

Figure XIV.21.  Graph of the macro "launchCodeFlowrateKeyDataBase.py"

Graph of the macro "launchCodeFlowrateKeyDataBase.py"

XIV.5.5. Macro "launchCodeFlowrateKeySampling.py"

XIV.5.5.1. Objective

The objective of the macro is to evaluate the flowrate external code on a design-of-experiments with the input file "flowrate_input_with_keys.in" with "key=value" type and the output file "_output_flowrate_withRow_.dat" with "values in rows" type. This flowrate code is described in Section IV.1.2.3.1.1.

The used input file flowrate_input_with_keys.in is with "key=value" type:

#
# 
# INPUT FILE with KEYS for the "FLOWREATE" code
# \date   2008-04-22 12:53:35
#


date = 123456 ;


#########################
##
##  exclude points
##
chu = 1050;
chl = 770;
cr  = 1100;
##
#########################

#########################
##
##  parameters : 8
##
Rw = 0.0500 ;
R = 33366.67 ;
Tu = 63070.0 ;
Tl = 116.00 ;
Hu = 1110.00 ;
Hl = 768.57;
L = 1200.0 ;
Kw = 11732.14 ;
##
#########################


#########################
##
## to simulate CPU time
##
## normal         1 :
## min     10000000 : 1.160u 0.000s 0:01.16 100.0%
## max    100000000 : 11.600u 0.010s 0:11.61 100.0%
##
nLoop = 1;
##
#########################

end = 6;

This file defines the eight variables , , , , , , , needed to perform the execution of the command flowrate -k.

The output file, _output_flowrate_withRow_.dat is with "values in rows" type. It looks like:

#COLUMN_NAMES: yhat | d
		  
6.757218e+01  4.092561e+03

yhat and d have to be defined as output variables in the macro.

XIV.5.5.2. Macro Uranie

"""
Example of code launching with key sampling
"""
from rootlogon import ROOT, DataServer, Launcher, Sampler

nS = 100
# Define the DataServer
tds = DataServer.TDataServer("tdsFlowrate", "DoE for Flowrate")

# Add the study attributes ( min, max and nominal values)
tds.addAttribute(DataServer.TUniformDistribution("rw", 0.05, 0.15))
tds.addAttribute(DataServer.TUniformDistribution("r", 100.0, 50000.0))
tds.addAttribute(DataServer.TUniformDistribution("tu", 63070.0, 115600.0))
tds.addAttribute(DataServer.TUniformDistribution("tl", 63.1, 116.0))
tds.addAttribute(DataServer.TUniformDistribution("hu", 990.0, 1110.0))
tds.addAttribute(DataServer.TUniformDistribution("hl", 700.0, 820.0))
tds.addAttribute(DataServer.TUniformDistribution("l", 1120.0, 1680.0))
tds.addAttribute(DataServer.TUniformDistribution("kw", 9855.0, 12045.0))

# The reference input file
sIn = "flowrate_input_with_keys.in"

# Set the reference input file and the key for each input attributes
tds.getAttribute("rw").setFileKey(sIn, "Rw")
tds.getAttribute("r").setFileKey(sIn, "R")
tds.getAttribute("tu").setFileKey(sIn, "Tu")
tds.getAttribute("tl").setFileKey(sIn, "Tl")
tds.getAttribute("hu").setFileKey(sIn, "Hu")
tds.getAttribute("hl").setFileKey(sIn, "Hl")
tds.getAttribute("l").setFileKey(sIn, "L")
tds.getAttribute("kw").setFileKey(sIn, "Kw")

# Generate the Design of Experiments
sampling = Sampler.TSampling(tds, "lhs", nS)
sampling.generateSample()

# The output file of the code
fout = Launcher.TOutputFileRow("_output_flowrate_withRow_.dat")
# The attribute in the output file
fout.addAttribute(DataServer.TAttribute("yhat"))

# Instanciation de mon code
mycode = Launcher.TCode(tds, "flowrate -s -k")
# on ajoute le fichier de sortie du code
mycode.addOutputFile(fout)

# Lancement du code
laun = Launcher.TLauncher(tds, mycode)
laun.setSave()
laun.setClean()
# laun.setWorkingDirectory(ROOT.gSystem.pwd() + "/tmpLaunUranie/flowrate")
laun.setVarDraw("yhat:rw", "", "")

laun.run()

tds.exportData("_flowrate_sampler_launcher_.dat")

# Visualisation
Canvas = ROOT.TCanvas("c1", "Graph launchCodeFlowrateFlag",
                      5, 64, 1270, 667)
pad = ROOT.TPad("pad", "pad", 0, 0.03, 1, 1)
pad.Draw()
ROOT.gStyle.SetPalette(1)
pad.Divide(2, 2)
pad.cd(1)
tds.draw("yhat:rw")

pad.cd(3)
tds.draw("yhat")
pad.cd(2)
tds.draw("yhat:rw", "", "colz")

pad.cd(4)
# The parallel plot
tds.draw("rw:r:tu:tl:hu:hl:l:kw:yhat", "", "para")
para = ROOT.gPad.GetListOfPrimitives().FindObject("ParaCoord")

# The output attribute
axis = para.GetVarList().FindObject("yhat")
axis.AddRange(ROOT.TParallelCoordRange(axis, 15.0, 80.0))
para.AddSelection("blue")
para.GetCurrentSelection().SetLineColor(ROOT.kBlue)

The laws of distribution are set for each input variable. For example for the Rw variable, the macro creates an uniform distribution between 0.05 and 0.15 associated to a TAttribute named "rw":

tds.addAttribute(DataServer.TUniformDistribution("rw", 0.05, 0.15));

Then, the TAttribute is linked to the input file with:

tds.getAttribute("rw").setFileKey(sIn, "Rw");

which will be understood by Uranie as the fact the rw variable has to be read in the input file with "key=value" format with the key Rw.

A design-of-experiments is then built with 100 samplings using the LHS method:

sampling=Sampler.TSampling(tds, "lhs", nS);   
sampling.generateSample();

We want the output file to be with values in rows. So the output file _output_flowrate_withRow_.dat is set as a TOutputFileRow:

fout=Launcher.TOutputFileRow("_output_flowrate_withRow_.dat");

The variable yhat and d could be linked to this TOutputFileRow output file. But here, only yhat will be considered as variable of interest by Uranie:

fout.addAttribute(DataServer.TAttribute("yhat"));

We set the code as being the flowrate execution with "-k" option:

mycode=Launcher.TCode(tds, "flowrate -s -k");

in xhich the "-k" option indicates that flowrate has to find input files with "key=value" format.

Then the launcher is initialised with a TDataServer and the code is executed:

lanceur=Launcher.TLauncher(tds, mycode);

The launcher will execute the flowrate -k command for each of the 100 patterns with the run method:

lanceur.run();

XIV.5.5.3. Graph

Figure XIV.22.  Graph of the macro "launchCodeFlowrateKeySampling.py"

Graph of the macro "launchCodeFlowrateKeySampling.py"

XIV.5.6. Macro "launchCodeFlowrateXMLSampling.py"

XIV.5.6.1. Objective

The objective of the macro is to evaluate the flowrate external code on a design-of-experiments with the input file "flowrate_input_with_xml.in" with XML format and the output file "_output_flowrate_withXML_.dat" also with XML format. This flowrate code is described in Section IV.1.2.3.1.1.

The used input file flowrate_input_with_xml.in is with XML type:

<?xml version="1.0"?>
<problem>
  <description name="flowrate" title="UseCase flowrate with XML input file" version="1.0" date="2011-07-22 12:55:17">
    <tool name="uranie" version="0.3"/>
  </description>

  <steady_state name="sch">
    <wall_friction rw="0.0500" r="33366.67"/>
    <tinit>0.0</tinit>
    <tmax>1000000</tmax>
    <dt_step_nb_max>1500</dt_step_nb_max>
    <parameter>
      <tonode>mesher</tonode><toport>dt_hu</toport>
      <value><double>1110.00</double></value>
    </parameter>
    <parameter>
      <tonode>mesher</tonode><toport>dt_hl</toport>
      <value><double>768.57</double></value>
    </parameter>
    <parameter>
      <tonode>mesher</tonode><toport>dt_hd</toport>
      <value><int>12345</int></value>
    </parameter>
    <facsec>1000000.</facsec>
    <kW value="11732.14"/>
    <informations>
      <parameter name="Tu">
        <Uniform_Field>1</Uniform_Field>
        <value><double>63070.0</double></value>
      </parameter>
      <parameter name="Tl">
        <Uniform_Field>1</Uniform_Field>
        <value><double>116.00</double></value>
      </parameter>
      <parameter name="L" precision="1200.0"/>
    </informations>

    <convergence>
      <criterion>relative_max_du_dt</criterion>
      <precision>1.e-6</precision>
    </convergence>

    <stop_criterium ch_abscissa_hu="1050" ch_ordinate_hl="770" c_radius="1100" nLoop="1"/>

    <solver name="Newton3">
      <max_iter_matrix>1</max_iter_matrix>
      <max_iter_implicit>1</max_iter_implicit>
      <date>5654321</date>
      <implicit_convergence_threshold>1.e-6</implicit_convergence_threshold>
      <implicit_assembly>10</implicit_assembly>
      <linear_solver name="BiCGS">
        <preconditioner>ILU</preconditioner>
        <implicit_solve_threshold>1.e-5</implicit_solve_threshold>
      </linear_solver>
    </solver>

  </steady_state>
</problem>

This file defines the eight variables , , , , , , , needed to perform the execution of the command flowrate -x.

The output file, _output_flowrate_withXML_.dat is with XML type. It looks like:

<?xml version="1.0"?>
<steady_state name="flowrate">
  <parameter>
    <tonode>mesher</tonode>
    <toport>dt_hl</toport>
    <value>
      <double>2.618019e+01</double>
    </value>
  </parameter>
  <distance value="3.602045e+03"/>
</steady_state>

yhat and d have to be defined as output variables in the macro.

XIV.5.6.2. Macro Uranie

"""
Example of flowrate code launching with XML input files
"""
from rootlogon import ROOT, DataServer, Launcher, Sampler

nS = 100
# Define the DataServer
tds = DataServer.TDataServer("tdsFlowrate", "DoE for Flowrate")

# Add the study attributes ( min, max and nominal values)
tds.addAttribute(DataServer.TUniformDistribution("rw", 0.05, 0.15))
tds.addAttribute(DataServer.TUniformDistribution("r", 100.0, 50000.0))
tds.addAttribute(DataServer.TUniformDistribution("tu", 63070.0, 115600.0))
tds.addAttribute(DataServer.TUniformDistribution("tl", 63.1, 116.0))
tds.addAttribute(DataServer.TUniformDistribution("hu", 990.0, 1110.0))
tds.addAttribute(DataServer.TUniformDistribution("hl", 700.0, 820.0))
tds.addAttribute(DataServer.TUniformDistribution("l", 1120.0, 1680.0))
tds.addAttribute(DataServer.TUniformDistribution("kw", 9855.0, 12045.0))

# The reference input file
sIn = "flowrate_input_with_xml.in"
AttIn = DataServer.TAttributeFileKey.kXMLAttribute
FieIn = DataServer.TAttributeFileKey.kXMLField
XmlKey = "parameter[tonode='mesher' and toport='dt_%s']/value/double"
tds.getAttribute("rw").setFileKey(sIn, "wall_friction/@rw", "%e", AttIn)
tds.getAttribute("r").setFileKey(sIn, "wall_friction/@r", "%e", AttIn)
tds.getAttribute("tu").setFileKey(sIn, "parameter[@name='Tu']/value/double",
                                  "%e", FieIn)
tds.getAttribute("tl").setFileKey(sIn, "parameter[@name='Tl']/value/double",
                                  "%e", FieIn)
tds.getAttribute("hu").setFileKey(sIn, XmlKey % ("hu"), "%e", FieIn)
tds.getAttribute("hl").setFileKey(sIn, XmlKey % ("hl"), "%e", FieIn)
tds.getAttribute("l").setFileKey(sIn, "parameter[@name='L']/@precision",
                                 "%e", AttIn)
tds.getAttribute("kw").setFileKey(sIn, "kW/@value", "%e", AttIn)

# Generate the Design of Experiments
sampling = Sampler.TSampling(tds, "lhs", nS)
sampling.generateSample()

# The output file of the code
fout = Launcher.TOutputFileXML("_output_flowrate_withXML_.dat")
# The attribute in the output file
fout.addAttribute(DataServer.TAttribute("yhat"),
                  "/steady_state[@name='flowrate']/parameter/value/double",
                  FieIn)

# Instanciation de mon code
mycode = Launcher.TCode(tds, "flowrate -s -x")
# on ajoute le fichier de sortie du code
mycode.addOutputFile(fout)

# Lancement du code
lanceur = Launcher.TLauncher(tds, mycode)
lanceur.setSave()
lanceur.setClean()
lanceur.setVarDraw("yhat:rw", "", "")

lanceur.run()

tds.exportData("_flowrate_sampler_launcher_.dat")

# Visualisation
Canvas = ROOT.TCanvas("c1", "Graph for the Macro launchCodeFlowrateOATMinMax",
                      5, 64, 1270, 667)
pad = ROOT.TPad("pad", "pad", 0, 0.03, 1, 1)
pad.Draw()
ROOT.gStyle.SetPalette(1)
pad.Divide(2, 2)
pad.cd(1)
tds.draw("yhat:rw")

pad.cd(3)
tds.draw("yhat")
pad.cd(2)
tds.draw("yhat:rw", "", "colz")

pad.cd(4)
# The parallel plot
tds.draw("rw:r:tu:tl:hu:hl:l:kw:yhat", "", "para")
para = ROOT.gPad.GetListOfPrimitives().FindObject("ParaCoord")

# The output attribute
axis = para.GetVarList().FindObject("yhat")
axis.AddRange(ROOT.TParallelCoordRange(axis, 15.0, 80.0))
para.AddSelection("blue")
para.GetCurrentSelection().SetLineColor(ROOT.kBlue)

The laws of distribution are set for each input variable. For example for the Rw variable, the macro creates an uniform distribution between bounds 0.05 and 0.15 associated to a TAttribute named "rw":

tds.addAttribute(DataServer.TUniformDistribution("rw", 0.05, 0.15));

Then, the TAttribute is linked to the input file with:

tds.getAttribute("rw").setFileKey(sIn, "wall_friction/@rw", "%e", DataServer.TAttributeFileKey.kXMLAttribute);

which will be understood by Uranie as the fact the rw variable has to be read in the input file with XML format as an XML attribute (kXMLAttribute) with the path frottement_paroi/@rw. In the same way, others TAttributes are added, some with XML fields:

tds.getAttribute("tu").setFileKey(sIn, "parameter[@name='Tu']/value/double", "%e", DataServer.TAttributeFileKey.kXMLField);

A design-of-experiments is then built with 100 samplings using the LHS method.

sampling=Sampler.TSampling(tds, "lhs", nS);  
sampling.generateSample();

We want the output file to be with XML format. So the output file _output_flowrate_withXML_.dat is set as a TOutputFileXML.

fout=Launcher.TOutputFileXML("_output_flowrate_withXML_.dat");

The variable yhat and d could be linked to this TOutputFileRow output file. But here, only yhat will be considered as variable of interest by Uranie, by passing Uranie the new attribute, its XML path and type:

fout.addAttribute(DataServer.TAttribute("yhat"), "/steady_state[@name='flowrate']/parameter/value/double", DataServer.TAttributeFileKey.kXMLField);

We set the code as being the flowrate execution with "-x" option to deal with XML inputs.

mycode=Launcher.TCode(tds, "flowrate -s -x");

which indicates that flowrate has to find input files with XML format.

Then the launcher is initialised with a TDataServer and the code is executed:

lanceur=Launcher.TLauncher(tds, mycode);

The launcher will execute the flowrate -k command for each of the 100 patterns with the run method:

lanceur.run();

XIV.5.6.3. Graph

Figure XIV.23.  Graph of the macro "launchCodeFlowrateXMLSampling.py"

Graph of the macro "launchCodeFlowrateXMLSampling.py"

XIV.5.7. Macro "launchCodeFlowrateKeySamplingKey.py"

XIV.5.7.1. Objective

The objective of the macro is to evaluate the flowrate external code on a design-of-experiments where input file "flowrate_input_with_keys.in" is with type "key=value" and the output file "_output_flowrate_withKey_.dat" is also of the "key=value" type. This code is described in Section IV.1.2.3.1.1.

The used input file flowrate_input_with_keys.in has "key=value" format:

#
# 
# INPUT FILE with KEYS for the "FLOWREATE" code
# \date   2008-04-22 12:53:35
#


date = 123456 ;


#########################
##
##  exclude points
##
chu = 1050;
chl = 770;
cr  = 1100;
##
#########################

#########################
##
##  parameters : 8
##
Rw = 0.0500 ;
R = 33366.67 ;
Tu = 63070.0 ;
Tl = 116.00 ;
Hu = 1110.00 ;
Hl = 768.57;
L = 1200.0 ;
Kw = 11732.14 ;
##
#########################


#########################
##
## to simulate CPU time
##
## normal         1 :
## min     10000000 : 1.160u 0.000s 0:01.16 100.0%
## max    100000000 : 11.600u 0.010s 0:11.61 100.0%
##
nLoop = 1;
##
#########################

end = 6;

It defines the eight variables , , , , , , , and performs the execution of the command flowrate -k.

The output file _output_flowrate_withKey_.dat is with "key=value" type. It looks like:

yhat = 6.757218e+01;
d = 4.092561e+03;

yhat and d are defined as output variables in the macro.

XIV.5.7.2. Macro Uranie

"""
Example of flowrate code launching with key input / output files
"""
from rootlogon import ROOT, DataServer, Launcher, Sampler

nS = 100
# Define the DataServer
tds = DataServer.TDataServer("tdsFlowrate", "DoE for Flowrate")

# Add the study attributes (min, max and nominal values)
tds.addAttribute(DataServer.TUniformDistribution("rw", 0.05, 0.15))
tds.addAttribute(DataServer.TUniformDistribution("r", 100.0, 50000.0))
tds.addAttribute(DataServer.TUniformDistribution("tu", 63070.0, 115600.0))
tds.addAttribute(DataServer.TUniformDistribution("tl", 63.1, 116.0))
tds.addAttribute(DataServer.TUniformDistribution("hu", 990.0, 1110.0))
tds.addAttribute(DataServer.TUniformDistribution("hl", 700.0, 820.0))
tds.addAttribute(DataServer.TUniformDistribution("l", 1120.0, 1680.0))
tds.addAttribute(DataServer.TUniformDistribution("kw", 9855.0, 12045.0))

# The reference input file
sIn = "flowrate_input_with_keys.in"

# Set the reference input file and the key for each input attributes
tds.getAttribute("rw").setFileKey(sIn, "Rw")
tds.getAttribute("r").setFileKey(sIn, "R")
tds.getAttribute("tu").setFileKey(sIn, "Tu")
tds.getAttribute("tl").setFileKey(sIn, "Tl")
tds.getAttribute("hu").setFileKey(sIn, "Hu")
tds.getAttribute("hl").setFileKey(sIn, "Hl")
tds.getAttribute("l").setFileKey(sIn, "L")
tds.getAttribute("kw").setFileKey(sIn, "Kw")

# Generate the Design of Experiments
sampling = Sampler.TSampling(tds, "lhs", nS)
sampling.generateSample()

# The output file of the code
fout = Launcher.TOutputFileKey("_output_flowrate_withKey_.dat")
# The attribute in the output file
fout.addAttribute(DataServer.TAttribute("yhat"))
fout.addAttribute(DataServer.TAttribute("d"))

# Instanciation de mon code
mycode = Launcher.TCode(tds, "flowrate -s -k")
# on ajoute le fichier de sortie du code
mycode.addOutputFile(fout)

# Lancement du code
laun = Launcher.TLauncher(tds, mycode)
laun.setSave()
laun.setClean()
# laun.setWorkingDirectory(ROOT.gSystem.pxd() + "/tmpLaunUranie/flowrate")
laun.setVarDraw("yhat:rw", "", "")

laun.run()

# tds.exportData("_flowrate_sampler_launcher_.dat")
tds.startViewer()

# Visualisation
Canvas = ROOT.TCanvas("c1", "Graph launchCodeFlowrateOATMinMax",
                      5, 64, 1270, 667)
pad = ROOT.TPad("pad", "pad", 0, 0.03, 1, 1)
pad.Draw()
ROOT.gStyle.SetPalette(1)
pad.Divide(2, 2)
pad.cd(1)
tds.draw("yhat:rw")

pad.cd(3)
tds.draw("yhat")
pad.cd(2)
tds.draw("yhat:rw", "", "colz")

pad.cd(4)
# The parallel plot
tds.draw("rw:r:tu:tl:hu:hl:l:kw:yhat", "", "para")
para = ROOT.gPad.GetListOfPrimitives().FindObject("ParaCoord")

# The output attribute
axis = para.GetVarList().FindObject("yhat")
axis.AddRange(ROOT.TParallelCoordRange(axis, 15.0, 20.0))
para.AddSelection("blue")
para.GetCurrentSelection().SetLineColor(ROOT.kBlue)

axis.AddRange(ROOT.TParallelCoordRange(axis, 155.0, 160.0))
para.AddSelection("blue")

The laws of distributions are set for each input variable. For example for the rw variable, the macro creates an uniform distribution between bounds 0.05 and 0.15 associated to a TAttribute named "rw" (note that the set value in flowrate_input_with_keys.in for Rw, 0.05, is between bounds. It is important to check this property when creating the distribution):

tds.addAttribute( DataServer.TUniformDistribution("rw", 0.05, 0.15));

Then, the TAttribute is linked to the input file with:

tds.getAttribute("rw").setFileKey("flowrate_input_with_keys.in", "Rw");

which will be understood by Uranie as the fact the rw variable has to be read in an input file with "key=value" format with the key Rw.

A design-of-experiments is then built with 100 samplings using the LHS method.

sampling = Sampler.TSampling(tds, "lhs", 100);
sampling.generateSample();

The output file with "key=value" type of format _output_flowrate_withKey_.dat is instantiated as a TOutputFileKey.

fout = Launcher.TOutputFileKey("_output_flowrate_withKey_.dat");

The two output variables yhat and d are then linked to this TOutputFileKey output file.

fout.addAttribute(DataServer.TAttribute("d"));
fout.addAttribute(DataServer.TAttribute("yhat"));

We set the code as being the flowrate execution with "-k"option:

mycode = Launcher.TCode(tds, "flowrate -k");

in which the "-k" option indicates that flowrate code has to find "key=value" input files.

The launcher is initialised:

tlch = Launcher.TLauncher(tds, mycode);

The launcher will execute the flowrate -k command for each of the 100 patterns and launched with the run method:

tlch.run();

XIV.5.7.3. Graph

Figure XIV.24. Graph of the macro "launchCodeFlowrateKeySamplingKey.py"

Graph of the macro "launchCodeFlowrateKeySamplingKey.py"

XIV.5.8.  Macro "launchCodeFlowrateKeyRecreateSampling.py"

XIV.5.8.1. Objective

The objective of the macro is to evaluate the flowrate external code on a design-of-experiments where the input file "flowrate_input_with_keys.in" which is produced by Uranie on the fly is with type "key=value" and the output file "_output_flowrate_withKey_.dat" with type "key=value". This flowrate code is described in Section IV.1.2.3.1.1.

The used input file flowrate_input_with_keys.in has "key=value" format and will be produced on the fly by the code:

Rw = 1.480238e-01 ;
R = 3.644187e+03 ;
Tu = 7.840305e+04 ;
Tl = 8.467102e+01 ;
Hu = 1.008708e+03 ;
Hl = 7.667991e+02 ;
L = 1.174857e+03 ;
Kw = 1.097634e+04 ;

This file defines the eight variables , , , , , , , needed to perform the execution of the command flowrate -k.

The output file _output_flowrate_withRow_.dat is with "values in rows" type. It looks like:

#COLUMN_NAMES: yhat | d
		  
6.757218e+01  4.092561e+03

yhat and d are defined as output variables in the macro. But here, only yhat is considered as variable of interest by Uranie.

XIV.5.8.2. Macro Uranie

"""
Example of flowrate code launching with recreated key input file
"""
from rootlogon import ROOT, DataServer, Launcher, Sampler

nS = 100
# Define the DataServer
tds = DataServer.TDataServer("tdsFlowrate", "DoE for Flowrate")

# Add the study attributes ( min, max and nominal values)
tds.addAttribute(DataServer.TUniformDistribution("rw", 0.05, 0.15))
tds.addAttribute(DataServer.TUniformDistribution("r", 100.0, 50000.0))
tds.addAttribute(DataServer.TUniformDistribution("tu", 63070.0, 115600.0))
tds.addAttribute(DataServer.TUniformDistribution("tl", 63.1, 116.0))
tds.addAttribute(DataServer.TUniformDistribution("hu", 990.0, 1110.0))
tds.addAttribute(DataServer.TUniformDistribution("hl", 700.0, 820.0))
tds.addAttribute(DataServer.TUniformDistribution("l", 1120.0, 1680.0))
tds.addAttribute(DataServer.TUniformDistribution("kw", 9855.0, 12045.0))

# The reference input file
sIn = "flowrate_input_with_keys.in"

# Set the reference input file and the key for each input attributes
InType = DataServer.TAttributeFileKey.kNewKey
tds.getAttribute("rw").setFileKey(sIn, "Rw", "", InType)
tds.getAttribute("r").setFileKey(sIn, "R", "", InType)
tds.getAttribute("tu").setFileKey(sIn, "Tu", "", InType)
tds.getAttribute("tl").setFileKey(sIn, "Tl", "", InType)
tds.getAttribute("hu").setFileKey(sIn, "Hu", "", InType)
tds.getAttribute("hl").setFileKey(sIn, "Hl", "", InType)
tds.getAttribute("l").setFileKey(sIn, "L", "", InType)
tds.getAttribute("kw").setFileKey(sIn, "Kw", "", InType)

# Generate the Design of Experiments
sampling = Sampler.TSampling(tds, "lhs", nS)
sampling.generateSample()

# The output file of the code
fout = Launcher.TOutputFileKey("_output_flowrate_withKey_.dat")
# The attribute in the output file
fout.addAttribute(DataServer.TAttribute("yhat"))

# Instanciation de mon code
mycode = Launcher.TCode(tds, "flowrate -s -k")
# on ajoute le fichier de sortie du code
mycode.addOutputFile(fout)

# Lancement du code
laun = Launcher.TLauncher(tds, mycode)
laun.setSave()
laun.setClean()
# laun.setWorkingDirectory(ROOT.gSystem.pwd() + "/tmpLaunUranie/flowrate")
laun.setVarDraw("yhat:rw", "", "")

laun.run()

tds.exportData("_flowrate_sampler_launcher_.dat")

# Visualisation
Canvas = ROOT.TCanvas("c1", "Graph launchCodeFlowrateKeyRecreateSampling",
                      5, 64, 1270, 667)
pad = ROOT.TPad("pad", "pad", 0, 0.03, 1, 1)
pad.Draw()
ROOT.gStyle.SetPalette(1)
pad.Divide(2, 2)
pad.cd(1)
tds.draw("yhat:rw")

pad.cd(3)
tds.draw("yhat")
pad.cd(2)
tds.draw("yhat:rw", "", "colz")

pad.cd(4)
# The parallel plot
tds.draw("rw:r:tu:tl:hu:hl:l:kw:yhat", "", "para")
para = ROOT.gPad.GetListOfPrimitives().FindObject("ParaCoord")

# The output attribute
axis = para.GetVarList().FindObject("yhat")
axis.AddRange(ROOT.TParallelCoordRange(axis, 15.0, 80.0))
para.AddSelection("blue")
para.GetCurrentSelection().SetLineColor(ROOT.kBlue)

In the first part of this macro, properties are set for each input variable. For example for the Rw variable, the macro creates an uniform distribution between bounds 0.05 and 0.15 associated to a TAttribute named "rw":

tds.addAttribute(DataServer.TUniformDistribution("rw", 0.05, 0.15));

Then, the TAttribute is linked to the input file with:

tds.getAttribute("rw").setFileKey("flowrate_input_keys.in", "Rw","",DataServer.TAttributeFileKey.kNewKey);

which will be understood by Uranie as the fact the rw variable has to be read in the input file with "key=value" format with the key Rw. The property DataServer.TAttributeFileKey.kNewKey means that the input file is of "key=value" type and has to be created on the fly for each sampling locations.

A design-of-experiments is then built with 100 samplings using the LHS method.

sampling = Sampler.TSampling(tds, "lhs", 100);
sampling.generateSample();

The output file with "values in rows" type _output_flowrate_withRow_.dat is instantiated set as a TOutputFileRow.

fout = Launcher.TOutputFileRow("_output_flowrate_withRow_.dat");

The variable yhat and d could be linked to this TOutputFileRow output file. But here, only yhat will be considered by Uranie as variable of interest.

fout.addAttribute("yhat");

We set the code as being the flowrate execution with "-k" option.

mycode = Launcher.TCode(tds, "flowrate -k");

which indicates that flowrate code has to find "key=value" input files.

Then the launcher is initialised with a TDataServer and the code is executed:

tlch = Launcher.TLauncher(tds, mycode);

The launcher will execute the flowrate -k command for each of the 100 patterns with the run method:

tlch.run();

XIV.5.8.3. Graph

Figure XIV.25.  Graph of the macro "launchCodeFlowrateKeyRecreateSampling.py"

Graph of the macro "launchCodeFlowrateKeyRecreateSampling.py"

XIV.5.9.  Macro "launchCodeFlowrateKeyRecreateSamplingOutputDataServer.py"

XIV.5.9.1. Objective

The objective of the macro is to evaluate the flowrate external code on a design-of-experiments where the input file "flowrate_input_with_keys.in" which will be produced by Uranie on the fly is with type "key=value" and the output file "_output_flowrate_withRow_.dat" is with type "DataServer". This flowrate code is described in Section IV.1.2.3.1.1.

The input file flowrate_input_with_keys.in has "key=value" format and will be produced on the fly by the code:

#
# 
# INPUT FILE with KEYS for the "FLOWREATE" code
# \date   2008-04-22 12:53:35
#


date = 123456 ;


#########################
##
##  exclude points
##
chu = 1050;
chl = 770;
cr  = 1100;
##
#########################

#########################
##
##  parameters : 8
##
Rw = 0.0500 ;
R = 33366.67 ;
Tu = 63070.0 ;
Tl = 116.00 ;
Hu = 1110.00 ;
Hl = 768.57;
L = 1200.0 ;
Kw = 11732.14 ;
##
#########################


#########################
##
## to simulate CPU time
##
## normal         1 :
## min     10000000 : 1.160u 0.000s 0:01.16 100.0%
## max    100000000 : 11.600u 0.010s 0:11.61 100.0%
##
nLoop = 1;
##
#########################

end = 6;

This file defines the eight variables , , , , , , , needed to perform the execution of the command flowrate -k.

The output file _output_flowrate_withRow_.dat is with "DataServer" type. It looks like:

#COLUMN_NAMES: yhat | d
		  
6.757218e+01  4.092561e+03

yhat and d are defined as output variables in the macro. But here, only yhat is considered as variable of interest by Uranie.

XIV.5.9.2. Macro Uranie

"""
Example of code launching with output dataserver
"""
from rootlogon import ROOT, DataServer, Launcher, Sampler

nS = 100
# Define the DataServer
tds = DataServer.TDataServer("tdsFlowrate", "DoE for Flowrate")

# Add the study attributes ( min, max and nominal values)
tds.addAttribute(DataServer.TUniformDistribution("rw", 0.05, 0.15))
tds.addAttribute(DataServer.TUniformDistribution("r", 100.0, 50000.0))
tds.addAttribute(DataServer.TUniformDistribution("tu", 63070.0, 115600.0))
tds.addAttribute(DataServer.TUniformDistribution("tl", 63.1, 116.0))
tds.addAttribute(DataServer.TUniformDistribution("hu", 990.0, 1110.0))
tds.addAttribute(DataServer.TUniformDistribution("hl", 700.0, 820.0))
tds.addAttribute(DataServer.TUniformDistribution("l", 1120.0, 1680.0))
tds.addAttribute(DataServer.TUniformDistribution("kw", 9855.0, 12045.0))

# The reference input file
sIn = "flowrate_input_with_keys.in"

# Set the reference input file and the key for each input attributes
InType = DataServer.TAttributeFileKey.kNewKey
tds.getAttribute("rw").setFileKey(sIn, "Rw", "", InType)
tds.getAttribute("r").setFileKey(sIn, "R", "", InType)
tds.getAttribute("tu").setFileKey(sIn, "Tu", "", InType)
tds.getAttribute("tl").setFileKey(sIn, "Tl", "", InType)
tds.getAttribute("hu").setFileKey(sIn, "Hu", "", InType)
tds.getAttribute("hl").setFileKey(sIn, "Hl", "", InType)
tds.getAttribute("l").setFileKey(sIn, "L", "", InType)
tds.getAttribute("kw").setFileKey(sIn, "Kw", "", InType)

# Generate the design of experiments
sampling = Sampler.TSampling(tds, "lhs", nS)
sampling.generateSample()

# The output file of the code
fout = Launcher.TOutputFileDataServer("_output_flowrate_withRow_.dat")
# The attribute in the output file
fout.addAttribute("yhat")  # fout.addAttribute(DataServer.TAttribute("y"))

# Create a Launcher.TCode object from a TDS and the command line
mycode = Launcher.TCode(tds, "flowrate -s -k")
# Add the output file
mycode.addOutputFile(fout)

# Create a launcher of code
laun = Launcher.TLauncher(tds, mycode)
laun.setSave()
laun.setClean()
# laun.setWorkingDirectory(ROOT.gSystem.pwd() + "/tmpLaunUranie/flowrate")

laun.setVarDraw("yhat:rw", "", "")

laun.run()

tds.exportData("_flowrate_sampler_launcher_.dat")
# Visualisation
Canvas = ROOT.TCanvas("c1",
                      "launchCodeFlowrateKeyRecreateSamplingOutputDataServer",
                      565, 62, 560, 619)
pad = ROOT.TPad("pad", "pad", 0, 0.03, 1, 1)
pad.Draw()
ROOT.gStyle.SetPalette(1)
pad.Divide(1, 3)

# Scatterplot y versus rw
pad.cd(1)
tds.draw("yhat:rw")

# Histogramm of the output attribute
pad.cd(2)
tds.draw("yhat")

# The parallel plot
pad.cd(3)
tds.draw("rw:r:tu:tl:hu:hl:l:kw:yhat", "", "para")
para = ROOT.gPad.GetListOfPrimitives().FindObject("ParaCoord")

# The output attribute
axis = para.GetVarList().FindObject("yhat")
axis.AddRange(ROOT.TParallelCoordRange(axis, 15.0, 20.0))
para.AddSelection("blue")
para.GetCurrentSelection().SetLineColor(ROOT.kBlue)

axis.AddRange(ROOT.TParallelCoordRange(axis, 155.0, 160.0))
para.AddSelection("blue")

The laws of distributions are set for each input variable. For example for the rw variable, the macro creates an uniform distribution between bounds 0.05 and 0.15 associated to a TAttribute named "rw":

tds.addAttribute(DataServer.TUniformDistribution("rw", 0.05, 0.15));

Then, the TAttribute is linked to the input file with:

tds.getAttribute("rw").setFileKey("flowrate_input_with_rows.in", "Rw","",DataServer.TAttributeFileKey.kNewKey);

which will be understood by Uranie as the fact the rw variable has to be read in an input file with "key=value" format. The property DataServer.TAttributeFileKey.kNewKey means the input file has to be created on the fly for each sampling created.

A design-of-experiments is then built with 100 samplings using the LHS method.

sampling = Sampler.TSampling(tds, "lhs", 100);
sampling.generateSample();

The output file with "DataServer" type _output_flowrate_withRow_.dat is instantiated as a TOutputFileDataServer. This TOutputFileDataServer file is of the same format that a TDataServer can load.

fout = Launcher.TOutputFileDataServer("_output_flowrate_withRow_.dat");

The variable yhat and d are then linked to this TOutputFileDataServer output file. But here, only yhat will be considered by Uranie as a variable of interest.

fout.addAttribute("yhat");

We set the code as being the flowrate execution with "-k" option.

mycode = Launcher.TCode(tds, "flowrate -k");

which indicates that flowrate code has to find "key=value" input files.

Then the launcher is initialised with a TDataServer and the code is executed:

lanceur = Launcher.TLauncher(tds, mycode);

The launcher will execute the flowrate -k command for each of the 100 patterns with the run method.

lanceur.run();

XIV.5.9.3. Graph

Figure XIV.26.  Graph of the macro "launchCodeFlowrateKeyRecreateSamplingOutputDataServer.py"

Graph of the macro "launchCodeFlowrateKeyRecreateSamplingOutputDataServer.py"

XIV.5.10. Macro "launchCodeFlowrateRowRecreateSamplingOutputDataServer.py"

XIV.5.10.1. Objective

The objective of the macro is to evaluate the flowrate external code on a design-of-experiments where the input file "flowrate_input_with_values_rows.in" will be produced on the fly by Uranie is with "values in rows" type and the output file "_output_flowrate_withRow_.dat" with "DataServer" type. This flowrate code is described in Section IV.1.2.3.1.1.

The input file flowrate_input_with_values_rows.in is with "values in rows" format and will be produced on the fly by the code:

0.0500 33366.67 63070.0 116.00 1110.00 768.57 1200.0 11732.14

This file defines the eight variables , , , , , , , needed to perform the execution of the command flowrate -r.

The output file _output_flowrate_withRow_.dat is of "DataServer" type. It looks like:

#COLUMN_NAMES: yhat | d
		  
6.757218e+01  4.092561e+03

yhat and d are defined as output variables in the macro.

XIV.5.10.2. Macro Uranie

"""
Example of flowrate code launching with dataserver output
"""
from rootlogon import ROOT, DataServer, Launcher, Sampler

nS = 100
# Define the DataServer
tds = DataServer.TDataServer("tdsFlowrate", "DoE for Flowrate")

# Add the study attributes ( min, max and nominal values)
tds.addAttribute(DataServer.TUniformDistribution("rw", 0.05, 0.15))
tds.addAttribute(DataServer.TUniformDistribution("r", 100.0, 50000.0))
tds.addAttribute(DataServer.TUniformDistribution("tu", 63070.0, 115600.0))
tds.addAttribute(DataServer.TUniformDistribution("tl", 63.1, 116.0))
tds.addAttribute(DataServer.TUniformDistribution("hu", 990.0, 1110.0))
tds.addAttribute(DataServer.TUniformDistribution("hl", 700.0, 820.0))
tds.addAttribute(DataServer.TUniformDistribution("l", 1120.0, 1680.0))
tds.addAttribute(DataServer.TUniformDistribution("kw", 9855.0, 12045.0))

# The input file
sFileName = "flowrate_input_with_values_rows.in"

# Set input file with "key = value" format CREATED ON FLY one row per attribute
InType = DataServer.TAttributeFileKey.kNewRow
tds.getAttribute("rw").setFileKey(sFileName, "Rw", "", InType)
tds.getAttribute("r").setFileKey(sFileName, "R", "", InType)
tds.getAttribute("tu").setFileKey(sFileName, "Tu", "", InType)
tds.getAttribute("tl").setFileKey(sFileName, "Tl", "", InType)
tds.getAttribute("hu").setFileKey(sFileName, "Hu", "", InType)
tds.getAttribute("hl").setFileKey(sFileName, "Hl", "", InType)
tds.getAttribute("l").setFileKey(sFileName, "L", "", InType)
tds.getAttribute("kw").setFileKey(sFileName, "Kw", "", InType)

# Generate a Design of experiments (DoE) from the TDataServer
sampling = Sampler.TSampling(tds, "lhs", nS)
sampling.generateSample()

# The output file is based on dataserver format (#COLUMN_NAMES: yhat | d)
fout = Launcher.TOutputFileDataServer("_output_flowrate_withRow_.dat")
# The attributes in the output file
fout.addAttribute("d")  # fout.addAttribute(DataServer.TAttribute("d"))
fout.addAttribute("yhat")  # fout.addAttribute(DataServer.TAttribute("yhat"))

# Create a TCode object with the TDS and the command to execute
mycode = Launcher.TCode(tds, "flowrate -s -r")
# Add the output file
mycode.addOutputFile(fout)

# Launcher of the code on the Design of experiments (DoE) in the TDS
tlch = Launcher.TLauncher(tds, mycode)
tlch.setSave()
tlch.setClean()
# tlch.setWorkingDirectory(ROOT.gSystem.pwd() + "/tmpLanceurUranie/flowrate")
tlch.setVarDraw("yhat:rw", "", "")

# Evaluate the DoE
tlch.run()

# tds.exportData("_flowrate_sampler_launcher_.dat")

# Visualisation
Canvas = ROOT.TCanvas("c1",
                      "launchCodeFlowrateRowRecreateSamplingOutputDataServer",
                      565, 62, 560, 619)
pad = ROOT.TPad("pad", "pad", 0, 0.03, 1, 1)
pad.Draw()
ROOT.gStyle.SetPalette(1)
pad.Divide(1, 3)
pad.cd(1)
tds.draw("yhat:rw")

pad.cd(2)
# Histogramm of the output attribute
tds.draw("yhat")

pad.cd(3)
# The parallel plot
tds.draw("rw:r:tu:tl:hu:hl:l:kw:yhat", "", "para")
para = ROOT.gPad.GetListOfPrimitives().FindObject("ParaCoord")

# The output attribute
axis = para.GetVarList().FindObject("yhat")
axis.AddRange(ROOT.TParallelCoordRange(axis, 15.0, 20.0))
para.AddSelection("blue")
para.GetCurrentSelection().SetLineColor(ROOT.kBlue)

axis.AddRange(ROOT.TParallelCoordRange(axis, 155.0, 160.0))
para.AddSelection("blue")

The laws of distribution are set for each input variable. For example for the rw variable, the macro creates an uniform distribution between bounds 0.05 and 0.15 associated to a TAttribute named "rw":

tds.addAttribute(DataServer.TUniformDistribution("rw", 0.05, 0.15));

Then, the TAttribute is linked to the input file with:

tds.getAttribute("rw").setFileKey("flowrate_input_with_rows.in", "Rw","",DataServer.TAttributeFileKey.kNewRow);

which will be understood by Uranie as the fact the rw variable has to be read in an input file with "values in rows" format. The property DataServer.TAttributeFileKey.kNewRow means the input file has to be created for each sampling created.

A design-of-experiments is then built with 100 samplings using the LHS method.

sampling = Sampler.TSampling(tds, "lhs", 100);
sampling.generateSample();

The output file with "DataServer" type _output_flowrate_withRow_.dat is instantiated as a TOutputFileDataServer. This TOutputFileDataServer file is of the same format that a TDataServer can load.

fout = Launcher.TOutputFileDataServer("_output_flowrate_withRow_.dat");

The variable yhat and d are then linked to this TOutputFileDataServer output file.

fout.addAttribute("d");
fout.addAttribute("yhat");

We set the code as being the flowrate execution with "-r" option:

mycode = Launcher.TCode(tds, "flowrate -r");

in which the "-r" option indicates that flowrate code has to find "values in rows" input files.

Then the launcher is initialised with a TDataServer and the code is executed:

tlch = Launcher.TLauncher(tds, mycode);

The launcher will execute the flowrate -r command for each of the 100 patterns with the run method.

tlch.run();

XIV.5.10.3. Graph

Figure XIV.27.  Graph of the macro "launchCodeFlowrateRowRecreateSamplingOutputDataServer.py"

Graph of the macro "launchCodeFlowrateRowRecreateSamplingOutputDataServer.py"

XIV.5.11. Macro "launchCodeFlowrateFlagSampling.py"

XIV.5.11.1. Objective

The objective of the macro is to evaluate the flowrate external code on the design-of-experiments where the input file "flowrate_input_with_flags.in" has flags" replaced with usable values and the output file "_output_flowrate_withRow_.dat" with "values in rows" type. This code flowrate is described in Section IV.1.2.3.1.1.

The creation of an input file containing some "flags" is motivated by the will to make evolve variables in an input file with no particular structure:

# 
# INPUT FILE with FLAG for the "FLOWREATE" code
# \date   2008-04-22 12:55:17
#

new Implicit_Steady_State sch {
    frottement_paroi { 0.071623 19712.541454 }       // values of Rw and R
    tinit               0.0
    tmax                1000000.
    nb_pas_dt_max       1500
    dt_min              1051.972855                  // value of Hu
    dt_max              805.249178                   // value of Hl
    facsec              1000000.
    kW                  11401.611060                 // value of Kw
    information_Tu      Champ_Uniforme 1        85927.853162    // value of Tu
    information_Tl      Champ_Uniforme 1        85.803614       // value of Tl
    information_L {
        precision  1162.689830                       // value of L
    }	
    convergence {
        criterion relative_max_du_dt
        precision  1.e-6
    }

    stop_criterium {
        ch_abcsissa_hu 1050
        ch_ordinate_hl 770
        c_radius 1100
    }

    Solveur Newton3 {
        max_iter_matrice        1
        max_iter_implicite      1
        date                    5654321
        seuil_convg_implicite   1.e-6
        assemblage_implicite    10
        solveur_lineaire        BiCGS
            preconditionneur    ILU
            seuil_resol_implicite 1.e-5
    }
}

These values are then replaced by "flags" bounded with special characters.

The input file flowrate_input_with_flags.in that contains "flags" is built this way:

# 
# INPUT FILE with FLAG for the "FLOWREATE" code
# \date   2008-04-22 12:55:17
#

new Implicit_Steady_State sch {
    frottement_paroi { @Rw@ @R@ }
    tinit               0.0
    tmax                1000000.
    nb_pas_dt_max       1500
    dt_min              @Hu@
    dt_max              @Hl@
    facsec              1000000.
    kW                  @Kw@
    information_Tu      Champ_Uniforme 1        @Tu@
    information_Tl      Champ_Uniforme 1        @Tl@
    information_L {
        precision  @L@
    }	
    convergence {
        criterion relative_max_du_dt
        precision  @Rw@
    }

    stop_criterium {
        ch_abcsissa_hu 1050
        ch_ordinate_hl 770
        c_radius 1100
    }

    Solveur Newton3 {
        max_iter_matrice        1
        max_iter_implicite      1
        date                    5654321
        seuil_convg_implicite   1.e-6
        assemblage_implicite    10
        solveur_lineaire        BiCGS
            preconditionneur    ILU
            seuil_resol_implicite 1.e-5
    }
}

This file defines the eight variables , , , , , , , needed to perform the execution of the command flowrate -f.

The output file _output_flowrate_withRow_.dat is of "values in rows" type. It looks like:

#COLUMN_NAMES: yhat | d
		  
6.757218e+01  4.092561e+03

yhat and d are defined as output variables in the macro. But here, only yhat is considered as variable of interest by Uranie.

XIV.5.11.2. Macro Uranie

"""
Example of flowrate code launching with flag type
"""
from rootlogon import ROOT, DataServer, Launcher, Sampler

nS = 400
# Define the DataServer
tds = DataServer.TDataServer("tdsFlowrate", "DoE for Flowrate")

# Add the study attributes ( min, max and nominal values)
tds.addAttribute(DataServer.TUniformDistribution("rw", 0.05, 0.15))
tds.addAttribute(DataServer.TUniformDistribution("r", 100.0, 50000.0))
tds.addAttribute(DataServer.TUniformDistribution("tu", 63070.0, 115600.0))
tds.addAttribute(DataServer.TUniformDistribution("tl", 63.1, 116.0))
tds.addAttribute(DataServer.TUniformDistribution("hu", 990.0, 1110.0))
tds.addAttribute(DataServer.TUniformDistribution("hl", 700.0, 820.0))
tds.addAttribute(DataServer.TUniformDistribution("l", 1120.0, 1680.0))
tds.addAttribute(DataServer.TUniformDistribution("kw", 9855.0, 12045.0))

# The reference input file
sIn = "flowrate_input_with_flags.in"

# Set the reference input file and the key for each input attributes
tds.getAttribute("rw").setFileFlag(sIn, "@Rw@")
tds.getAttribute("r").setFileFlag(sIn, "@R@")
tds.getAttribute("tu").setFileFlag(sIn, "@Tu@")
tds.getAttribute("tl").setFileFlag(sIn, "@Tl@")
tds.getAttribute("hu").setFileFlag(sIn, "@Hu@")
tds.getAttribute("hl").setFileFlag(sIn, "@Hl@")
tds.getAttribute("l").setFileFlag(sIn, "@L@")
tds.getAttribute("kw").setFileFlag(sIn, "@Kw@")

# Generate the Design of Experiments
sampling = Sampler.TSampling(tds, "lhs", nS)
sampling.generateSample()

# The output file of the code
fout = Launcher.TOutputFileRow("_output_flowrate_withRow_.dat")
# The attribute in the output file
fout.addAttribute(DataServer.TAttribute("yhat"))

# Instanciation de mon code
mycode = Launcher.TCode(tds, "flowrate -s -f")
# on ajoute le fichier de sortie du code
mycode.addOutputFile(fout)

# Lancement du code
laun = Launcher.TLauncher(tds, mycode)
laun.setSave()
# laun.setClean()
# laun.setWorkingDirectory(ROOT.gSystem.pwd() + "/tmpLaunUranie/flowrate"))
laun.setVarDraw("yhat:rw", "", "")

laun.run()

tds.exportData("_flowrate_sampler_launcher_.dat")

# Visualisation
Canvas = ROOT.TCanvas("c1", "Graph launchCodeFlowrateFlag",
                      5, 64, 1270, 667)
pad = ROOT.TPad("pad", "pad", 0, 0.03, 1, 1)
pad.Draw()
ROOT.gStyle.SetPalette(1)
pad.Divide(2, 2)
pad.cd(1)
tds.draw("yhat:rw")

pad.cd(3)
tds.draw("yhat")
pad.cd(2)
tds.draw("yhat:rw", "", "colz")

pad.cd(4)
# The parallel plot
tds.draw("rw:r:tu:tl:hu:hl:l:kw:yhat", "", "para")
para = ROOT.gPad.GetListOfPrimitives().FindObject("ParaCoord")

# The output attribute
axis = para.GetVarList().FindObject("yhat")
axis.AddRange(ROOT.TParallelCoordRange(axis, 100.0, 160.0))
para.AddSelection("blue")
para.GetCurrentSelection().SetLineColor(ROOT.kBlue)

The laws of distribution are set for each input variable. For example for the rw variable, the macro creates an uniform distribution between bounds 0.05 and 0.15 associated to a TAttribute named "rw":

tds.addAttribute(DataServer.TUniformDistribution("rw", 0.05, 0.15));

Then, the TAttribute is linked to the input file with:

tds.getAttribute("rw").setFileFlag("flowrate_input_with_flags.in", "@Rw@");

which will be understood by Uranie as the fact the rw variable has to be read in an input file with "flags".

A design-of-experiments is then built with 100 samplings using the LHS method.

sampling = Sampler.TSampling(tds, "lhs", 100);
sampling.generateSample();

The output file with "values in rows" type _output_flowrate_withRow_.dat is instantiated as a TOutputFileRow.

fout = Launcher.TOutputFileRow("_output_flowrate_withRow_.dat");

The variable yhat and d are then linked to this TOutputFileRow output file. But here, only yhat will be considered as variable of interest by Uranie.

fout.addAttribute("yhat");

We set the code as being the flowrate execution with "-f" option.

mycode = Launcher.TCode(tds, "flowrate -f");

which indicates that flowrate code has to find input files with "flags". Then the launcher is initialised with a TDataServer and the code is executed:

tlch = Launcher.TLauncher(tds, mycode);

The launcher will execute the flowrate -f command for each of the 100 patterns with the run method:

tlch.run();

XIV.5.11.3. Graph

Figure XIV.28.  Graph of the macro "launchCodeFlowrateFlagSampling.py"

Graph of the macro "launchCodeFlowrateFlagSampling.py"

XIV.5.12. Macro "launchCodeFlowrateFlagSamplingKey.py"

XIV.5.12.1. Objective

The objective of the macro is to evaluate the flowrate external code on a design-of-experiments where the input file "flowrate_input_with_flags.in" has "flags" and the output file "_output_flowrate_withKey_.dat" is with type "key=value". This code is described in Section IV.1.2.3.1.1.

The creation of an input file containing some "flags" is motivated by the will to make evolve variables in an input file with no particular structure:

# 
# INPUT FILE with FLAG for the "FLOWREATE" code
# \date   2008-04-22 12:55:17
#

new Implicit_Steady_State sch {
    frottement_paroi { 0.071623 19712.541454 }       // values of Rw and R
    tinit               0.0
    tmax                1000000.
    nb_pas_dt_max       1500
    dt_min              1051.972855                  // value of Hu
    dt_max              805.249178                   // value of Hl
    facsec              1000000.
    kW                  11401.611060                 // value of Kw
    information_Tu      Champ_Uniforme 1        85927.853162    // value of Tu
    information_Tl      Champ_Uniforme 1        85.803614       // value of Tl
    information_L {
        precision  1162.689830                       // value of L
    }	
    convergence {
        criterion relative_max_du_dt
        precision  1.e-6
    }

    stop_criterium {
        ch_abcsissa_hu 1050
        ch_ordinate_hl 770
        c_radius 1100
    }

    Solveur Newton3 {
        max_iter_matrice        1
        max_iter_implicite      1
        date                    5654321
        seuil_convg_implicite   1.e-6
        assemblage_implicite    10
        solveur_lineaire        BiCGS
            preconditionneur    ILU
            seuil_resol_implicite 1.e-5
    }
}

These values are then replaced by "flags" bounded with special characters.

The input file flowrate_input_with_flags.in containing "flags" is built this way:

# 
# INPUT FILE with FLAG for the "FLOWREATE" code
# \date   2008-04-22 12:55:17
#

new Implicit_Steady_State sch {
    frottement_paroi { @Rw@ @R@ }
    tinit               0.0
    tmax                1000000.
    nb_pas_dt_max       1500
    dt_min              @Hu@
    dt_max              @Hl@
    facsec              1000000.
    kW                  @Kw@
    information_Tu      Champ_Uniforme 1        @Tu@
    information_Tl      Champ_Uniforme 1        @Tl@
    information_L {
        precision  @L@
    }	
    convergence {
        criterion relative_max_du_dt
        precision  @Rw@
    }

    stop_criterium {
        ch_abcsissa_hu 1050
        ch_ordinate_hl 770
        c_radius 1100
    }

    Solveur Newton3 {
        max_iter_matrice        1
        max_iter_implicite      1
        date                    5654321
        seuil_convg_implicite   1.e-6
        assemblage_implicite    10
        solveur_lineaire        BiCGS
            preconditionneur    ILU
            seuil_resol_implicite 1.e-5
    }
}

It defines the eight variables , , , , , , , and performs the execution of the command flowrate -f.

The output file _output_flowrate_withKey_.dat is with "key=value" type. It looks like:

yhat = 6.757218e+01;
d = 4.092561e+03;

yhat and d are defined as output variables in the macro.

XIV.5.12.2. Macro Uranie

"""
Example of flowrate code launching with flag and key sampling
"""
from rootlogon import ROOT, DataServer, Launcher, Sampler

nS = 100
# Define the DataServer
tds = DataServer.TDataServer("tdsFlowrate", "DoE for Flowrate")

# Add the study attributes ( min, max and nominal values)
tds.addAttribute(DataServer.TUniformDistribution("rw", 0.05, 0.15))
tds.addAttribute(DataServer.TUniformDistribution("r", 100.0, 50000.0))
tds.addAttribute(DataServer.TUniformDistribution("tu", 63070.0, 115600.0))
tds.addAttribute(DataServer.TUniformDistribution("tl", 63.1, 116.0))
tds.addAttribute(DataServer.TUniformDistribution("hu", 990.0, 1110.0))
tds.addAttribute(DataServer.TUniformDistribution("hl", 700.0, 820.0))
tds.addAttribute(DataServer.TUniformDistribution("l", 1120.0, 1680.0))
tds.addAttribute(DataServer.TUniformDistribution("kw", 9855.0, 12045.0))

# The reference input file
sIn = "flowrate_input_with_flags.in"

# Set the reference input file and the key for each input attributes
InType = DataServer.TAttributeFileKey.kFlag
tds.getAttribute("rw").setFileKey(sIn, "@Rw@", "%f", InType)
tds.getAttribute("r").setFileKey(sIn, "@R@", "%f", InType)
tds.getAttribute("tu").setFileKey(sIn, "@Tu@", "%f", InType)
tds.getAttribute("tl").setFileKey(sIn, "@Tl@", "%f", InType)
tds.getAttribute("hu").setFileKey(sIn, "@Hu@", "%f", InType)
tds.getAttribute("hl").setFileKey(sIn, "@Hl@", "%f", InType)
tds.getAttribute("l").setFileKey(sIn, "@L@", "%f", InType)
tds.getAttribute("kw").setFileKey(sIn, "@Kw@", "%f", InType)

# Generate the Design of Experiments
sampling = Sampler.TSampling(tds, "lhs", nS)
sampling.generateSample()

# The output file of the code
fout = Launcher.TOutputFileKey("_output_flowrate_withKey_.dat")
# The attribute in the output file
fout.addAttribute(DataServer.TAttribute("yhat"))
fout.addAttribute(DataServer.TAttribute("d"))

# Instanciation de mon code
mycode = Launcher.TCode(tds, "flowrate -s -f ")
# on ajoute le fichier de sortie du code
mycode.addOutputFile(fout)

# Lancement du code
lanceur = Launcher.TLauncher(tds, mycode)
lanceur.setSave()
lanceur.setClean()
# lanceur.setWorkingDirectory(ROOT.gSystem.pwd() + "/tmpLanceurUranie/flwrate")
lanceur.setVarDraw("yhat:rw", "", "")

lanceur.run()

tds.exportData("_flowrate_sampler_launcher_oat_.dat")

# Visualisation
Canvas = ROOT.TCanvas("c1", "Graph for the Macro launchCodeFlowrateFlag",
                      5, 64, 1270, 667)
pad = ROOT.TPad("pad", "pad", 0, 0.03, 1, 1)
pad.Draw()
ROOT.gStyle.SetPalette(1)
pad.Divide(2, 2)
pad.cd(1)
tds.draw("yhat:rw")

pad.cd(3)
tds.draw("yhat")
pad.cd(2)
tds.draw("yhat:rw", "", "colz")

pad.cd(4)
# The parallel plot
tds.draw("rw:r:tu:tl:hu:hl:l:kw:yhat", "", "para")
para = ROOT.gPad.GetListOfPrimitives().FindObject("ParaCoord")

# The output attribute
axis = para.GetVarList().FindObject("yhat")
axis.AddRange(ROOT.TParallelCoordRange(axis, 15.0, 20.0))
para.AddSelection("blue")
para.GetCurrentSelection().SetLineColor(ROOT.kBlue)

axis.AddRange(ROOT.TParallelCoordRange(axis, 155.0, 160.0))
para.AddSelection("blue")

The distribution laws are set for each input variable. For example for the rw variable, the macro creates an uniform distribution between bounds 0.05 and 0.15 associated to a TAttribute named "rw":

tds.addAttribute(DataServer.TUniformDistribution("rw", 0.05, 0.15));

Then, the TAttribute is linked to the input file with:

tds.getAttribute("rw").setFileFlag(sFileName, "@Rw@");

which is the same thing as writing:

tds.getAttribute("rw").setFileKey("flowrate_input_with_flags.in", @Rw@,"%e",DataServer.TAttributeFileKey.kFlag);

which will be understood by Uranie as the fact the rw variable has to be read in an input file with flag format. The code will then, for each generated sampling, replace the flag @Rw@ in the input file by the corresponding value.

A design-of-experiments is then built with 100 samplings using the LHS method:

sampling = Sampler.TSampling(tds, "lhs", 100);
sampling.generateSample();

The output file with "key=value" format _output_flowrate_withKey_.dat is instantiated as a TOutputFileKey.

fout = Launcher.TOutputFileKey("_output_flowrate_withKey_.dat");

The two output variables yhat and d are then linked to this TOutputFileKey output file:

fout.addAttribute(DataServer.TAttribute("d"));
fout.addAttribute(DataServer.TAttribute("yhat"));

We set the code as being the flowrate execution with "-f" option:

mycode = Launcher.TCode(tds, "flowrate -f");

in which the "-f" option indicates that flowrate code has to find input files with "flags".

Then the launcher is initialised with a TDataServer and the code is executed:

tlch = Launcher.TLauncher(tds, mycode);
tlch.run();

The launcher will execute the flowrate -f command for each of the 100 patterns with the run method.

XIV.5.12.3. Graph

Figure XIV.29. Graph of the macro "launchCodeFlowrateFlagSamplingKey.py"

Graph of the macro "launchCodeFlowrateFlagSamplingKey.py"

XIV.5.13.  Macro "launchCodeFlowrateKeyFlagSampling.py"

XIV.5.13.1. Objective

The objective of the macro is to evaluate the flowrate external code on a design-of-experiments where the values of attributes will be replaced in two input files, the first, "flowrate_input_with_keys.in" with "key=value" type, the second, "flowrate_input_with_flags.in" with "flags" and the output file "_output_flowrate_withRow_.dat" with "values in rows" type. This flowrate code is described in Section IV.1.2.3.1.1.

The first input file flowrate_input_with_keys.in is "key=value" format:

#
# 
# INPUT FILE with KEYS for the "FLOWREATE" code
# \date   2008-04-22 12:53:35
#


date = 123456 ;


#########################
##
##  exclude points
##
chu = 1050;
chl = 770;
cr  = 1100;
##
#########################

#########################
##
##  parameters : 8
##
Rw = 0.0500 ;
R = 33366.67 ;
Tu = 63070.0 ;
Tl = 116.00 ;
Hu = 1110.00 ;
Hl = 768.57;
L = 1200.0 ;
Kw = 11732.14 ;
##
#########################


#########################
##
## to simulate CPU time
##
## normal         1 :
## min     10000000 : 1.160u 0.000s 0:01.16 100.0%
## max    100000000 : 11.600u 0.010s 0:11.61 100.0%
##
nLoop = 1;
##
#########################

end = 6;

The creation of an input file containing some "flags" is motivated by the will to make evolve variables in an input file with no particular structure:

# 
# INPUT FILE with FLAG for the "FLOWREATE" code
# \date   2008-04-22 12:55:17
#

new Implicit_Steady_State sch {
    frottement_paroi { 0.071623 19712.541454 }       // values of Rw and R
    tinit               0.0
    tmax                1000000.
    nb_pas_dt_max       1500
    dt_min              1051.972855                  // value of Hu
    dt_max              805.249178                   // value of Hl
    facsec              1000000.
    kW                  11401.611060                 // value of Kw
    information_Tu      Champ_Uniforme 1        85927.853162    // value of Tu
    information_Tl      Champ_Uniforme 1        85.803614       // value of Tl
    information_L {
        precision  1162.689830                       // value of L
    }	
    convergence {
        criterion relative_max_du_dt
        precision  1.e-6
    }

    stop_criterium {
        ch_abcsissa_hu 1050
        ch_ordinate_hl 770
        c_radius 1100
    }

    Solveur Newton3 {
        max_iter_matrice        1
        max_iter_implicite      1
        date                    5654321
        seuil_convg_implicite   1.e-6
        assemblage_implicite    10
        solveur_lineaire        BiCGS
            preconditionneur    ILU
            seuil_resol_implicite 1.e-5
    }
}

These values are then replaced by "flags" bounded with special characters.

The second input file flowrate_input_with_flags.in containing "flags" is built this way:

# 
# INPUT FILE with FLAG for the "FLOWREATE" code
# \date   2008-04-22 12:55:17
#

new Implicit_Steady_State sch {
    frottement_paroi { @Rw@ @R@ }
    tinit               0.0
    tmax                1000000.
    nb_pas_dt_max       1500
    dt_min              @Hu@
    dt_max              @Hl@
    facsec              1000000.
    kW                  @Kw@
    information_Tu      Champ_Uniforme 1        @Tu@
    information_Tl      Champ_Uniforme 1        @Tl@
    information_L {
        precision  @L@
    }	
    convergence {
        criterion relative_max_du_dt
        precision  @Rw@
    }

    stop_criterium {
        ch_abcsissa_hu 1050
        ch_ordinate_hl 770
        c_radius 1100
    }

    Solveur Newton3 {
        max_iter_matrice        1
        max_iter_implicite      1
        date                    5654321
        seuil_convg_implicite   1.e-6
        assemblage_implicite    10
        solveur_lineaire        BiCGS
            preconditionneur    ILU
            seuil_resol_implicite 1.e-5
    }
}

These files define the eight variables , , , , , , , needed to perform the execution of the command flowrate -k and the command flowrate -f.

The output file _output_flowrate_withRow_.dat is of "values in rows" type. It looks like:

#COLUMN_NAMES: yhat | d
		  
6.757218e+01  4.092561e+03

yhat and d are defined as output variables in the macro.

XIV.5.13.2. Macro Uranie

"""
Example of flowrate code launching with key and flag
"""
from rootlogon import ROOT, DataServer, Launcher, Sampler

nS = 100
# Define the DataServer
tds = DataServer.TDataServer("tdsFlowrate", "DoE for Flowrate")

# Add the study attributes ( min, max and nominal values)
tds.addAttribute(DataServer.TUniformDistribution("rw", 0.05, 0.15))
tds.addAttribute(DataServer.TUniformDistribution("r", 100.0, 50000.0))
tds.addAttribute(DataServer.TUniformDistribution("tu", 63070.0, 115600.0))
tds.addAttribute(DataServer.TUniformDistribution("tl", 63.1, 116.0))
tds.addAttribute(DataServer.TUniformDistribution("hu", 990.0, 1110.0))
tds.addAttribute(DataServer.TUniformDistribution("hl", 700.0, 820.0))
tds.addAttribute(DataServer.TUniformDistribution("l", 1120.0, 1680.0))
tds.addAttribute(DataServer.TUniformDistribution("kw", 9855.0, 12045.0))

# The reference input file with key
sInKey = "flowrate_input_with_keys.in"

# Set the reference input file and the key for each input attributes
tds.getAttribute("rw").setFileKey(sInKey, "Rw")
tds.getAttribute("r").setFileKey(sInKey, "R")
tds.getAttribute("tu").setFileKey(sInKey, "Tu")
tds.getAttribute("tl").setFileKey(sInKey, "Tl")
tds.getAttribute("hu").setFileKey(sInKey, "Hu")
tds.getAttribute("hl").setFileKey(sInKey, "Hl")
tds.getAttribute("l").setFileKey(sInKey, "L")
tds.getAttribute("kw").setFileKey(sInKey, "Kw")

# The reference input file with flag
sInFlag = "flowrate_input_with_flags.in"
tds.getAttribute("rw").setFileFlag(sInFlag, "@Rw@")
tds.getAttribute("r").setFileFlag(sInFlag, "@R@")
tds.getAttribute("tu").setFileFlag(sInFlag, "@Tu@")
tds.getAttribute("tl").setFileFlag(sInFlag, "@Tl@")
tds.getAttribute("hu").setFileFlag(sInFlag, "@Hu@")
tds.getAttribute("hl").setFileFlag(sInFlag, "@Hl@")
tds.getAttribute("l").setFileFlag(sInFlag, "@L@")
tds.getAttribute("kw").setFileFlag(sInFlag, "@Kw@")

# Generate the Design of Experiments
sampling = Sampler.TSampling(tds, "lhs", nS)
sampling.generateSample()

# The output file of the code
fout = Launcher.TOutputFileRow("_output_flowrate_withRow_.dat")
# The attribute in the output file
fout.addAttribute(DataServer.TAttribute("yhat"))

# Instanciation de mon code
mycode = Launcher.TCode(tds, "flowrate -s -k")
# on ajoute le fichier de sortie du code
mycode.addOutputFile(fout)

# Lancement du code
laun = Launcher.TLauncher(tds, mycode)
laun.setSave()
laun.setClean()
# laun.setWorkingDirectory(ROOT.gSystem.pwd() + "/tmpLaunUranie/flowrate")
laun.setVarDraw("yhat:rw", "", "")

laun.run()

# tds.scan("*")
tds.exportData("_flowrate_sampler_launcher_.dat")

# Visualisation
Canvas = ROOT.TCanvas("c1", "Graph launchCodeFlowrateFlag",
                      5, 64, 1270, 667)
pad = ROOT.TPad("pad", "pad", 0, 0.03, 1, 1)
pad.Draw()
ROOT.gStyle.SetPalette(1)
pad.Divide(2, 2)
pad.cd(1)
tds.draw("yhat:rw")

pad.cd(3)
tds.draw("yhat")
pad.cd(2)
tds.draw("yhat:rw", "", "colz")

pad.cd(4)
# The parallel plot
tds.draw("rw:r:tu:tl:hu:hl:l:kw:yhat", "", "para")
para = ROOT.gPad.GetListOfPrimitives().FindObject("ParaCoord")

# The output attribute
axis = para.GetVarList().FindObject("yhat")
axis.AddRange(ROOT.TParallelCoordRange(axis, 15.0, 80.0))
para.AddSelection("blue")
para.GetCurrentSelection().SetLineColor(ROOT.kBlue)

The laws of distribution are set for each input variable. For example for the rw variable, the macro creates an uniform distribution between bounds 0.05 and 0.15 associated to a TAttribute named "rw":

tds.addAttribute(DataServer.TUniformDistribution("rw", 0.05, 0.15));

Then, the TAttribute is linked to the first input file with:

tds.getAttribute("rw").setFileKey("flowrate_input_with_keys.in", "Rw");

which will be understood by Uranie as the fact the rw variable has to be read in an input file with "key=value" format. If the user wants to get values of variables in an input file with "flags", he can redefine the link towards the "flag" file directly:

tds.getAttribute("rw").setFileFlag("flowrate_input_with_flags.in", "@Rw@");

So the code will look for input files with "flags".

A design-of-experiments is then built with 100 samplings using the LHS method:

sampling = Sampler.TSampling(tds, "lhs", 100);
sampling.generateSample();

The output file with "values in rows" type _output_flowrate_withRow_.dat is instantiated as a TOutputFileRow.

fout = Launcher.TOutputFileRow("_output_flowrate_withRow_.dat");

The variables yhat and d could then be linked to this TOutputFileRow output file. But here, only yhat will be considered as a variable of interest by Uranie.

fout.addAttribute("yhat");

We set the code as being the flowrate execution with "-f" option but user can also use the "-k" option.

mycode = Launcher.TCode(tds, "flowrate -f");

which indicates that flowrate code has to find input files with "flags". With option "-k", flowrate has to find file with "key=value" format.

Then the launcher is initialised with a TDataServer and the code is executed:

tlch = Launcher.TLauncher(tds, mycode);

The launcher will execute the flowrate -f command for each of the 100 patterns with the run method:

tlch.run();

XIV.5.13.3. Graph

Figure XIV.30.  Graph of the macro "launchCodeFlowrateKeyFlagSampling.py"

Graph of the macro "launchCodeFlowrateKeyFlagSampling.py"

XIV.5.14. Macro "launchCodeFlowrateKeywithFlagSampling.py"

XIV.5.14.1. Objective

The objective of the macro is to evaluate the flowrate external code on a design-of-experiments where the input file "flowrate_input_with_keys.in" is with "key=value" type and defines the variables usable by the code ; a second input file "flowrate_input_with_flags.in" will moved by Uranie in the working directory but it will not be modified. The output file "_output_flowrate_withRow_.dat" is with "values in rows" type. This code is described in Section IV.1.2.3.1.1.

The first input file flowrate_input_with_keys.in has "key=value" format:

#
# 
# INPUT FILE with KEYS for the "FLOWREATE" code
# \date   2008-04-22 12:53:35
#


date = 123456 ;


#########################
##
##  exclude points
##
chu = 1050;
chl = 770;
cr  = 1100;
##
#########################

#########################
##
##  parameters : 8
##
Rw = 0.0500 ;
R = 33366.67 ;
Tu = 63070.0 ;
Tl = 116.00 ;
Hu = 1110.00 ;
Hl = 768.57;
L = 1200.0 ;
Kw = 11732.14 ;
##
#########################


#########################
##
## to simulate CPU time
##
## normal         1 :
## min     10000000 : 1.160u 0.000s 0:01.16 100.0%
## max    100000000 : 11.600u 0.010s 0:11.61 100.0%
##
nLoop = 1;
##
#########################

end = 6;

If we suppose that one wants to add an input file with "flag" format flowrate_input_with_flags.in.

# 
# INPUT FILE with FLAG for the "FLOWREATE" code
# \date   2008-04-22 12:55:17
#

new Implicit_Steady_State sch {
    frottement_paroi { @Rw@ @R@ }
    tinit               0.0
    tmax                1000000.
    nb_pas_dt_max       1500
    dt_min              @Hu@
    dt_max              @Hl@
    facsec              1000000.
    kW                  @Kw@
    information_Tu      Champ_Uniforme 1        @Tu@
    information_Tl      Champ_Uniforme 1        @Tl@
    information_L {
        precision  @L@
    }	
    convergence {
        criterion relative_max_du_dt
        precision  @Rw@
    }

    stop_criterium {
        ch_abcsissa_hu 1050
        ch_ordinate_hl 770
        c_radius 1100
    }

    Solveur Newton3 {
        max_iter_matrice        1
        max_iter_implicite      1
        date                    5654321
        seuil_convg_implicite   1.e-6
        assemblage_implicite    10
        solveur_lineaire        BiCGS
            preconditionneur    ILU
            seuil_resol_implicite 1.e-5
    }
}

The input file flowrate_input_with_keys.in defines the eight variables , , , , , , , needed to perform the execution of the command flowrate -k.

The output file _output_flowrate_withRow_.dat is with "values in rows" type. It looks like:

#COLUMN_NAMES: yhat | d
		  
6.757218e+01  4.092561e+03

yhat and d have to be defined as output variables in the macro. But in this one, only yhat will be considered.

XIV.5.14.2. Macro Uranie

"""
Example of flowratecode launching with flag inputs
"""
from rootlogon import ROOT, DataServer, Launcher, Sampler

nS = 100
# Define the DataServer
tds = DataServer.TDataServer("tdsFlowrate", "DoE for Flowrate")

# Add the study attributes ( min, max and nominal values)
tds.addAttribute(DataServer.TUniformDistribution("rw", 0.05, 0.15))
tds.addAttribute(DataServer.TUniformDistribution("r", 100.0, 50000.0))
tds.addAttribute(DataServer.TUniformDistribution("tu", 63070.0, 115600.0))
tds.addAttribute(DataServer.TUniformDistribution("tl", 63.1, 116.0))
tds.addAttribute(DataServer.TUniformDistribution("hu", 990.0, 1110.0))
tds.addAttribute(DataServer.TUniformDistribution("hl", 700.0, 820.0))
tds.addAttribute(DataServer.TUniformDistribution("l", 1120.0, 1680.0))
tds.addAttribute(DataServer.TUniformDistribution("kw", 9855.0, 12045.0))

# The reference input file with key
sInKey = "flowrate_input_with_keys.in"

# Set the reference input file and the key for each input attributes
tds.getAttribute("rw").setFileKey(sInKey, "Rw")
tds.getAttribute("r").setFileKey(sInKey, "R")
tds.getAttribute("tu").setFileKey(sInKey, "Tu")
tds.getAttribute("tl").setFileKey(sInKey, "Tl")
tds.getAttribute("hu").setFileKey(sInKey, "Hu")
tds.getAttribute("hl").setFileKey(sInKey, "Hl")
tds.getAttribute("l").setFileKey(sInKey, "L")
tds.getAttribute("kw").setFileKey(sInKey, "Kw")

# Generate the Design of Experiments
sampling = Sampler.TSampling(tds, "lhs", nS)
sampling.generateSample()

# The output file of the code
fout = Launcher.TOutputFileRow("_output_flowrate_withRow_.dat")
# The attribute in the output file
fout.addAttribute(DataServer.TAttribute("yhat"))

# Instanciation de mon code
mycode = Launcher.TCode(tds, "flowrate -s -k")
# on ajoute le fichier de sortie du code
mycode.setReferenceDirectory(ROOT.gSystem.pwd())
mycode.addInputFile("flowrate_input_with_flags.in")

mycode.addOutputFile(fout)

# Lancement du code
laun = Launcher.TLauncher(tds, mycode)
# laun.setWorkingDirectory(ROOT.gSystem.pwd() + "/tmpLaunUranie/flowrate")
laun.setVarDraw("yhat:rw", "", "")

laun.run()

# Visualisation
Canvas = ROOT.TCanvas("c1", "Graph launchCodeFlowrateOATMinMax",
                      5, 64, 1270, 667)
ROOT.gStyle.SetPalette(1)
tds.draw("yhat:rw")

tds.startViewer()

The laws of distribution are set for each input variable. For example for the rw variable, the macro creates an uniform distribution between bounds 0.05 and 0.15 associated to a TAttribute named "rw":

tds.addAttribute(DataServer.TUniformDistribution("rw", 0.05, 0.15));

Then, the TAttribute is linked to the input file with:

tds.getAttribute("rw").setFileKey("flowrate_input_with_keys.in", "Rw");

which will be understood by Uranie as the fact the rw variable has to be read in an input file with "key=value" format.

A design-of-experiments is then built with 100 samplings using the LHS method.

sampling = Sampler.TSampling(tds, "lhs", 100);
sampling.generateSample();

The output file with "values in rows" type _output_flowrate_withKey_.dat is set as a TOutputFileRow.

fout = Launcher.TOutputFileRow("_output_flowrate_withRow_.dat");

The variable yhat is then linked to this TOutputFileRow output file.

fout.addAttribute(DataServer.TAttribute("yhat"));

We set the code as being the flowrate execution with "-k" option:

mycode = Launcher.TCode(tds, "flowrate -k");

in which the "-k" option indicates that flowrate code has to find "key=value" input files.

We suppose the user wants to add another input file to the code. He specifies where is the new input file:

mycode.setReferenceDirectory( gSystem.pwd() );

and then he adds the new input file (here it's an input file with "flag" format ) which will be copied each time in the working directory.

mycode.addInputFile("flowrate_input_with_flags.in");

Then the launcher is initialised with a TDataServer and the code is executed and launched with the run method

lanceur = Launcher.TLauncher(tds, mycode);
lanceur.run();

XIV.5.14.3. Graph

Figure XIV.31. Graph of the macro "launchCodeFlowrateKeywithFlagSampling.py"

Graph of the macro "launchCodeFlowrateKeywithFlagSampling.py"

XIV.5.15. Macro "launchCodeFlowrateKeyFailure.py"

XIV.5.15.1. Objective

The objective of the macro is to evaluate the external code flowrate with failures on a design-of-experiments where input file "flowrate_input_with_keys.in" is with "key=value" type and the output file "_output_flowrate_withRow_.dat" with type "values in rows". This flowrate code is described in Section IV.1.2.3.1.1.

The input file flowrate_input_with_keys.in is with "key=value":

#
# 
# INPUT FILE with KEYS for the "FLOWREATE" code
# \date   2008-04-22 12:53:35
#


date = 123456 ;


#########################
##
##  exclude points
##
chu = 1050;
chl = 770;
cr  = 1100;
##
#########################

#########################
##
##  parameters : 8
##
Rw = 0.0500 ;
R = 33366.67 ;
Tu = 63070.0 ;
Tl = 116.00 ;
Hu = 1110.00 ;
Hl = 768.57;
L = 1200.0 ;
Kw = 11732.14 ;
##
#########################


#########################
##
## to simulate CPU time
##
## normal         1 :
## min     10000000 : 1.160u 0.000s 0:01.16 100.0%
## max    100000000 : 11.600u 0.010s 0:11.61 100.0%
##
nLoop = 1;
##
#########################

end = 6;

This file defines the eight variables , , , , , , , and also the three additional variables chu, chl and cr needed to perform the execution of the command flowrate -kf.

The output file _output_flowrate_withRow_.dat is of "values in rows" type. It looks like:

#COLUMN_NAMES: yhat | d
		  
6.757218e+01  4.092561e+03

yhat and d are defined as output variables in the macro.

XIV.5.15.2. Macro Uranie

"""
Example of flowrate code launching in key file and failure mode
"""
from rootlogon import ROOT, DataServer, Launcher, Sampler

nS = 400
# Define the DataServer
tds = DataServer.TDataServer("tdsflowrate", "DataBase flowrate")
tds.addAttribute(DataServer.TUniformDistribution("rw", 0.05, 0.15))
tds.addAttribute(DataServer.TUniformDistribution("r", 100.0, 50000.0))
tds.addAttribute(DataServer.TUniformDistribution("tu", 63070.0, 115600.0))
tds.addAttribute(DataServer.TUniformDistribution("tl", 63.1, 116.0))
tds.addAttribute(DataServer.TUniformDistribution("hu", 990.0, 1110.0))
tds.addAttribute(DataServer.TUniformDistribution("hl", 700.0, 820.0))
tds.addAttribute(DataServer.TUniformDistribution("l", 1120.0, 1680.0))
tds.addAttribute(DataServer.TUniformDistribution("kw", 9855.0, 12045.0))

# The reference input file
sIn = ROOT.gSystem.pwd() + "/"
sIn += "flowrate_input_with_keys.in"
tds.getAttribute("rw").setFileKey(sIn, "Rw")
tds.getAttribute("r").setFileKey(sIn, "R")
tds.getAttribute("tu").setFileKey(sIn, "Tu")
tds.getAttribute("tl").setFileKey(sIn, "Tl")
tds.getAttribute("hu").setFileKey(sIn, "Hu")
tds.getAttribute("hl").setFileKey(sIn, "Hl")
tds.getAttribute("l").setFileKey(sIn, "L")
tds.getAttribute("kw").setFileKey(sIn, "Kw")

# Generate the sample
sampling = Sampler.TSampling(tds, "lhs", nS)
sampling.generateSample()

# The output file of the code
fout = Launcher.TOutputFileRow("_output_flowrate_withRow_.dat")
# The attribute in the output file
tyhat = DataServer.TAttribute("yhat")
tyhat.setDefaultValue(-200.0)
fout.addAttribute(tyhat)

# Create a Launcher.TCode object
mycode = Launcher.TCode(tds, "flowrate -s -kf")
# Add the output file where to find the output attributes
# mycode.addInputFile(Launcher.TInputFile(sIn))
mycode.addOutputFile(fout)

# Create a TLauncher object from a TDataServer and a TCode objects
laun = Launcher.TLauncher(tds, mycode)
laun.setSave()
# laun.setClean()
laun.setVarDraw("hu:hl", "yhat>0", "")
# laun.setWorkingDirectory(ROOT.gSystem.pwd() + "/tmpLaunUranie/flowrate")

laun.run()

# Visualisation
Canvas = ROOT.TCanvas("c1", "Graph launchCodeFlowratestop", 5, 64, 1270, 667)
tds.draw("hu:hl", "yhat>0")

tds.exportData("_flowrate_sampler_launcher_.dat")

The laws of distribution are set for each input variable. For example for the rw variable, the macro creates an uniform distribution between bounds 0.05 and 0.15 associated to a TAttribute named "rw":

tds.addAttribute(DataServer.TUniformDistribution("rw", 0.05, 0.15));

Then, the TAttribute is linked to the input file with:

tds.getAttribute("rw").setFileKey("flowrate_input_with_keys.in", "Rw");

which will be understood by Uranie as the fact the rw variable has to be read in an input file with "key=value" format.

A design-of-experiments is then built with 400 samplings using the LHS method.

sampling = Sampler.TSampling(tds, "lhs", 400);
sampling.generateSample();

The output file with "values in rows" _output_flowrate_withRow_.dat is instantiated as a TOutputFileRow.

fout = Launcher.TOutputFileRow("_output_flowrate_withRow_.dat");

The variable yhat and d are then linked to this TOutputFileRow output file. But here, only yhat will be considered as variable of interest by Uranie.

fout.addAttribute("yhat");

We set the code as being the flowrate execution with "-kf" option.

mycode = Launcher.TCode(tds, "flowrate -v -kf");

which indicates that flowrate code has to find input files with "key=value" format. Furthermore, the additional variables chu, chl and cr allow to check if flowrate is in failure or not. If it is in failure, the output file will not be produced.

Then the launcher is initialised with a TDataServer and the code is executed.

lanceur = Launcher.TLauncher(tds, mycode);

The launcher will execute the flowrate -kf command for each of the 400 patterns with the run method.

lanceur.run();

XIV.5.15.3. Graph

Figure XIV.32.  Graph of the macro "launchCodeFlowrateKeyFailure.py"

Graph of the macro "launchCodeFlowrateKeyFailure.py"

XIV.5.15.4. Console

The macro simulates 100 failures of flowrate.

--- Uranie v0.0/0 --- Developed with ROOT (6.32.02)
                      Copyright (C) 2013-2024 CEA/DES 
                      Contact: support-uranie@cea.fr 
                      Date: Tue Jan 09, 2024

 <URANIE::INFO> 
 <URANIE::INFO> TLauncher "0x8b14fe0" TCode "codetdsflowrate" with TDataServer "tdsflowrate"
 <URANIE::INFO>  ** Save : Yes
 <URANIE::INFO>  ** WorkingDirectory[${RUNNINGDIR}/URANIE]
 <URANIE::INFO>  ** Proc : 1
 <URANIE::INFO> 
 <URANIE::INFO> time elapsed 1.94 sec
 <URANIE::INFO>      Failure : 92/400 --- 23%

XIV.5.16. Macro "launchCodeFlowrateFlagFailure.py"

XIV.5.16.1. Objective

The objective of the macro is to evaluate the external code flowrate with failures on a design-of-experiments where input file "flowrate_input_with_flags.in" has"flags" and the output file "_output_flowrate_withRow_.dat" with type "values in rows". This flowrate code is described in Section IV.1.2.3.1.1.

The creation of an input file containing some "flags" is motivated by the will to make evolve variables in an input file with no particular structure:

# 
# INPUT FILE with FLAG for the "FLOWREATE" code
# \date   2008-04-22 12:55:17
#

new Implicit_Steady_State sch {
    frottement_paroi { 0.071623 19712.541454 }       // values of Rw and R
    tinit               0.0
    tmax                1000000.
    nb_pas_dt_max       1500
    dt_min              1051.972855                  // value of Hu
    dt_max              805.249178                   // value of Hl
    facsec              1000000.
    kW                  11401.611060                 // value of Kw
    information_Tu      Champ_Uniforme 1        85927.853162    // value of Tu
    information_Tl      Champ_Uniforme 1        85.803614       // value of Tl
    information_L {
        precision  1162.689830                       // value of L
    }	
    convergence {
        criterion relative_max_du_dt
        precision  1.e-6
    }

    stop_criterium {
        ch_abcsissa_hu 1050
        ch_ordinate_hl 770
        c_radius 1100
    }

    Solveur Newton3 {
        max_iter_matrice        1
        max_iter_implicite      1
        date                    5654321
        seuil_convg_implicite   1.e-6
        assemblage_implicite    10
        solveur_lineaire        BiCGS
            preconditionneur    ILU
            seuil_resol_implicite 1.e-5
    }
}

These values are then replaced by "flags" bounded with special characters.

The input file flowrate_input_with_flags.in containing "flags" is built this way:

# 
# INPUT FILE with FLAG for the "FLOWREATE" code
# \date   2008-04-22 12:55:17
#

new Implicit_Steady_State sch {
    frottement_paroi { @Rw@ @R@ }
    tinit               0.0
    tmax                1000000.
    nb_pas_dt_max       1500
    dt_min              @Hu@
    dt_max              @Hl@
    facsec              1000000.
    kW                  @Kw@
    information_Tu      Champ_Uniforme 1        @Tu@
    information_Tl      Champ_Uniforme 1        @Tl@
    information_L {
        precision  @L@
    }	
    convergence {
        criterion relative_max_du_dt
        precision  @Rw@
    }

    stop_criterium {
        ch_abcsissa_hu 1050
        ch_ordinate_hl 770
        c_radius 1100
    }

    Solveur Newton3 {
        max_iter_matrice        1
        max_iter_implicite      1
        date                    5654321
        seuil_convg_implicite   1.e-6
        assemblage_implicite    10
        solveur_lineaire        BiCGS
            preconditionneur    ILU
            seuil_resol_implicite 1.e-5
    }
}

This file defines the eight variables , , , , , , , and also the three additional variables chu, chl and cr needed to perform the execution of the command flowrate -kf.

The output file _output_flowrate_withRow_.dat is of "values in rows" type. It looks like:

#COLUMN_NAMES: yhat | d
		  
6.757218e+01  4.092561e+03

yhat and d are defined as output variables in the macro.

XIV.5.16.2. Macro Uranie

"""
Example of flowrate code launching with flag file in failure mode
"""
from rootlogon import ROOT, DataServer, Launcher, Sampler

nS = 400
# Define the DataServer
tds = DataServer.TDataServer("tdsflowrate", "DataBase flowrate")
# Add the eight attributes of the study with uniform law
tds.addAttribute(DataServer.TUniformDistribution("rw", 0.05, 0.15))
tds.addAttribute(DataServer.TUniformDistribution("r", 100.0, 50000.0))
tds.addAttribute(DataServer.TUniformDistribution("tu", 63070.0, 115600.0))
tds.addAttribute(DataServer.TUniformDistribution("tl", 63.1, 116.0))
tds.addAttribute(DataServer.TUniformDistribution("hu", 990.0, 1110.0))
tds.addAttribute(DataServer.TUniformDistribution("hl", 700.0, 820.0))
tds.addAttribute(DataServer.TUniformDistribution("l", 1120.0, 1680.0))
tds.addAttribute(DataServer.TUniformDistribution("kw", 9855.0, 12045.0))

# The input file
sFileName = "flowrate_input_with_flags.in"

# Set the input file with flag format and the flag for each input attributes
tds.getAttribute("rw").setFileFlag(sFileName, "@Rw@")
tds.getAttribute("r").setFileFlag(sFileName, "@R@")
tds.getAttribute("tu").setFileFlag(sFileName, "@Tu@")
tds.getAttribute("tl").setFileFlag(sFileName, "@Tl@")
tds.getAttribute("hu").setFileFlag(sFileName, "@Hu@")
tds.getAttribute("hl").setFileFlag(sFileName, "@Hl@")
tds.getAttribute("l").setFileFlag(sFileName, "@L@")
tds.getAttribute("kw").setFileFlag(sFileName, "@Kw@")

# Generate the sample
sampling = Sampler.TSampling(tds, "lhs", nS)
sampling.generateSample()

# The output file of the code where values are stored in row
fout = Launcher.TOutputFileRow("_output_flowrate_withRow_.dat")
# The attribute in the output file
tyhat = DataServer.TAttribute("yhat")
tyhat.setDefaultValue(-200.0)
fout.addAttribute(tyhat)

# Create a Launcher.TCode object
mycode = Launcher.TCode(tds, "flowrate -s -ff")
# Add the output file where to find the output attributes
mycode.addOutputFile(fout)

# Create a TLauncher object from a TDataServer and a TCode objects
tlch = Launcher.TLauncher(tds, mycode)
tlch.setSave()
# tlch.setClean()
tlch.setVarDraw("hu:hl", "yhat>0", "")
Pwd = ROOT.gSystem.Getenv("PWD")
# tlch.setWorkingDirectory(Pwd + "/tmpLanceurUranie/flowrate"))

tlch.run()

# Visualisation
Canvas = ROOT.TCanvas("c1", "Graph launchCodeFlowrateFlagFailure",
                      5, 64, 1270, 667)
tds.draw("hu:hl", "yhat>0", "")

tds.exportData("_flowrate_sampler_launcher_.dat")

The laws of distribution are set for each input variable. For example for the rw variable, the macro creates an uniform distribution between bounds 0.05 and 0.15 associated to a TAttribute named "rw":

tds.addAttribute(DataServer.TUniformDistribution("rw", 0.05, 0.15));

Then, the TAttribute is linked to the input file with:

tds.getAttribute("rw").setFileFlag("flowrate_input_with_flags.in","@Rw@");

which will be understood by Uranie as the fact the rw variable has to be read in an input file with "flags".

A design-of-experiments is then built with 400 samplings using the LHS method.

sampling = Sampler.TSampling(tds, "lhs", 400);
sampling.generateSample();

The output file with "values in rows" type _output_flowrate_withRow_.dat is instantiated as a TOutputFileRow.

fout = Launcher.TOutputFileRow("_output_flowrate_withRow_.dat");

The variable yhat and d are then linked to this TOutputFileRow output file. But here, only yhat will be considered as a variable of interest by Uranie.

fout.addAttribute("yhat");

We set the code as being the flowrate execution with "-ff" option.

mycode = Launcher.TCode(tds, "flowrate -ff");

which indicates that flowrate code has to find input files with "flags" format. Furthermore, the additional variables chu, chl and cr allow to check if flowrate is in failure or not. If it is in failure, the output file will not be produced.

Then the launcher is initialised with a TDataServer and the code is executed.

tlch = Launcher.TLauncher(tds, mycode);

The launcher will execute the flowrate -ff command for each of the 400 patterns with the run method.

tlch.run();

XIV.5.16.3. Graph

Figure XIV.33.  Graph of the macro "launchCodeFlowrateFlagFailure.py"

Graph of the macro "launchCodeFlowrateFlagFailure.py"

XIV.5.16.4. Console

The macro simulates 100 failures for flowrate.

--- Uranie v0.0/0 --- Developed with ROOT (6.32.02)
                      Copyright (C) 2013-2024 CEA/DES 
                      Contact: support-uranie@cea.fr 
                      Date: Tue Jan 09, 2024

 <URANIE::INFO> 
 <URANIE::INFO> TLauncher "0x80fcec0" TCode "codetdsflowrate" with TDataServer "tdsflowrate"
 <URANIE::INFO>  ** Save : Yes
 <URANIE::INFO>  ** WorkingDirectory[${RUNNINGDIR}/URANIE]
 <URANIE::INFO>  ** Proc : 1
 <URANIE::INFO> 
 <URANIE::INFO> time elapsed 2.01 sec
 <URANIE::INFO>      Failure : 100/400 --- 25%

XIV.5.17. Macro "launchCodeFlowrateKeyOATMinMax.py"

XIV.5.17.1. Objective

The objective of the macro is to evaluate the flowrate external code on a design-of-experiments generated by the function PlanOATMinMax where input file "flowrate_input_with_keys.in" is with "key=value" format and the output file "_output_flowrate_withRow_.dat" is with "values in rows" type. This code is described in Section IV.1.2.1. The function PlanOATMinMax consists in constructing a design around the nominal value for each attribute, except for one attribute whose value is set to one of its boundaries(minimum and then maximum). Doing this for the 8 input attributes and the central design, in which each attribute takes its nominal value leads to a seventeen patterns design.

The input file for this code is flowrate_input_with_keys.in of key = value type. It looks like:

#
# 
# INPUT FILE with KEYS for the "FLOWREATE" code
# \date   2008-04-22 12:53:35
#


date = 123456 ;


#########################
##
##  exclude points
##
chu = 1050;
chl = 770;
cr  = 1100;
##
#########################

#########################
##
##  parameters : 8
##
Rw = 0.0500 ;
R = 33366.67 ;
Tu = 63070.0 ;
Tl = 116.00 ;
Hu = 1110.00 ;
Hl = 768.57;
L = 1200.0 ;
Kw = 11732.14 ;
##
#########################


#########################
##
## to simulate CPU time
##
## normal         1 :
## min     10000000 : 1.160u 0.000s 0:01.16 100.0%
## max    100000000 : 11.600u 0.010s 0:11.61 100.0%
##
nLoop = 1;
##
#########################

end = 6;

These files define the eight variables , , , , , , , needed to perform the execution of the command flowrate -k.

The output file _output_flowrate_withRow_.dat is of "values in rows" type. It looks like:

#COLUMN_NAMES: yhat | d
		  
6.757218e+01  4.092561e+03

yhat and d are defined as output variables in the macro.

XIV.5.17.2. Macro Uranie

"""
Example of flowrate code with OATMinMax with key
"""
import numpy as np
from rootlogon import ROOT, DataServer, Launcher


def plan_oat_min_max(mytds):
    """Generate the OAT min max doe"""

    # Create the data tuple
    mytds.createTuple()

    natt = mytds.getNAttributes()
    # The number of attributes is incremented by one for the iterator
    number_n = natt+1

    # Allocate the data vector to fill the tuple
    value = np.zeros([number_n])

    # Init the iterator. It is always the first value.
    value[0] = 0
    # Init the data vector with the nominal / mean values of attributes
    for i in range(natt):
        value[1+i] = mytds.getAttribute(i).getMean()

    # Fill the nominal/mean values: nominal pattern
    mytds.getTuple().Fill(value)

    # Loop on each attributes
    for i in range(natt):
        # Case of min values
        value[1+i] = mytds.getAttribute(i).getLowerBound()
        value[0] += 1.0
        # Fill min value for xi attribute and nominal values
        mytds.getTuple().Fill(value)
        # Case of the max value
        value[1+i] = mytds.getAttribute(i).getUpperBound()
        value[0] += 1.0
        # Fill max value for xi attribute and nominal values
        mytds.getTuple().Fill(value)
        # Reset the nominal/mean value
        value[1+i] = mytds.getAttribute(i).getMean()


# Define the DataServer
tds = DataServer.TDataServer("tdsOATMinMaxFlowrate", "OATMinMax for Flowrate")

# Add the study attributes ( min, max and nominal values)
tds.addAttribute(DataServer.TAttribute("rw", 0.05, 0.15))
tds.getAttribute("rw").setMean(0.10)

tds.addAttribute(DataServer.TAttribute("r", 100.0, 50000.0))
tds.getAttribute("r").setMean(25050.)

tds.addAttribute(DataServer.TAttribute("tu", 63070.0, 115600.0))
tds.getAttribute("tu").setMean(89335.)

tds.addAttribute(DataServer.TAttribute("tl", 63.1, 116.0))
tds.getAttribute("tl").setMean(89.55)

tds.addAttribute(DataServer.TAttribute("hu", 990.0, 1110.0))
tds.getAttribute("hu").setMean(1050.)

tds.addAttribute(DataServer.TAttribute("hl", 700.0, 820.0))
tds.getAttribute("hl").setMean(760.)

tds.addAttribute(DataServer.TAttribute("l", 1120.0, 1680.0))
tds.getAttribute("l").setMean(1400.)

tds.addAttribute(DataServer.TAttribute("kw", 9855.0, 12045.0))
tds.getAttribute("kw").setMean(10950.)

# The reference input file
sIn = ROOT.gSystem.pwd() + "/"
sIn += "flowrate_input_with_keys.in"

# Set the reference input file and the key for each input attributes
tds.getAttribute("rw").setFileKey(sIn, "Rw")
tds.getAttribute("r").setFileKey(sIn, "R")
tds.getAttribute("tu").setFileKey(sIn, "Tu")
tds.getAttribute("tl").setFileKey(sIn, "Tl")
tds.getAttribute("hu").setFileKey(sIn, "Hu")
tds.getAttribute("hl").setFileKey(sIn, "Hl")
tds.getAttribute("l").setFileKey(sIn, "L")
tds.getAttribute("kw").setFileKey(sIn, "Kw")

# Construit le plan OAT par avec les bornes (Min, Max) and the nominal values
plan_oat_min_max(tds)

# Scan the data ( 17 = 1 + 2*8 patterns)
tds.Scan("*", "", "colsize = 5 col = 3:4:5:6:5:4:3:4")

# Save the Design of experiments in an ASCII file
tds.exportData("_flowrate_sampler_oat_.dat")

# The output file of the code
fout = Launcher.TOutputFileRow("_output_flowrate_withRow_.dat")
# The attribute in the output file
fout.addAttribute(DataServer.TAttribute("yhat"))

# Instanciation de mon code
mycode = Launcher.TCode(tds, "flowrate -s -k")
# mycode.addInputFile(Launcher.TInputFile(sIn))
# on ajoute le fichier de sortie du code
mycode.addOutputFile(fout)

# Lancement du code
laun = Launcher.TLauncher(tds, mycode)
laun.setSave()
laun.setClean()
# laun.setWorkingDirectory(ROOT.gSystem.pwd() + "/tmpLaunUranie/flowrate")
laun.setVarDraw("yhat:rw", "", "")

laun.run()

tds.exportData("_flowrate_sampler_launcher_oat_.dat")

# Visualisation
Canvas = ROOT.TCanvas("c1", "Graph launchCodeFlowrateOATMinMax",
                      5, 64, 1270, 667)
pad = ROOT.TPad("pad", "pad", 0, 0.03, 1, 1)
pad.Draw()
ROOT.gStyle.SetPalette(1)
pad.Divide(2, 2)
pad.cd(1)
tds.draw("yhat:rw")

pad.cd(3)
tds.draw("yhat")
pad.cd(2)
tds.draw("yhat:rw", "", "colz")

pad.cd(4)
# The parallel plot
tds.draw("rw:r:tu:tl:hu:hl:l:kw:yhat", "", "para")
para = ROOT.gPad.GetListOfPrimitives().FindObject("ParaCoord")

# The output attribute
axis = para.GetVarList().FindObject("yhat")
axis.AddRange(ROOT.TParallelCoordRange(axis, 15.0, 20.0))
para.AddSelection("blue")
para.GetCurrentSelection().SetLineColor(ROOT.kBlue)

axis.AddRange(ROOT.TParallelCoordRange(axis, 155.0, 160.0))
para.AddSelection("blue")
para.GetCurrentSelection().SetLineColor(ROOT.kBlue)

PlanOATMinMax function builds the design-of-experiments from a TDataServer: for the first design and for each attribute of the TDataServer, values of attributes are initialised with their means.

for i in range(natt) : value[1+i] = tds.getAttribute(i).getMean();

These data are put in the TDataServer,

tds.getTuple().Fill(value)

this is how the central point is constructed. Two designs are then built for every attribute: one with the value of the attribute initialised to its lower boundary while other attributes are still initialised to their means:

value[1+i] = tds.getAttribute(i).getLowerBound();
tds.getTuple().Fill(value);

and the other where the value of the attribute is initialised to its upper boundary while other attributes are still initialised to their means:

value[1+i] = tds.getAttribute(i).getUpperBound();
tds.getTuple().Fill(value);

In the first part of the function launchCodeFlowrateKeyOATMinMax, properties are set for each input variable. For example for the rw variable, the macro creates a TAttribute named "rw" bounded by 0.05 and 0.15:

tds.addAttribute(DataServer.TAttribute("rw", 0.05, 0.15));

A initial mean value value is then set for this TAttribute, so as to inform the PlanOATMinMax function.

tds.getAttribute("rw").setMean(0.10);

Then, the TAttribute is linked to the first input file with:

tds.getAttribute("rw").setFileKey("flowrate_input_with_keys.in", "Rw");

which will be understood by Uranie as the fact the rw variable has to be read in an input file with "key=value" format.

Then the design-of-experiments is generated by the PlanOATMinMax function.

PlanOATMinMax(tds);

The output file with values in rows _output_flowrate_withRow_.dat is instantiated as a TOutputFileRow.

fout = Launcher.TOutputFileRow("_output_flowrate_withRow_.dat");

The variable yhat and d are then linked to this TOutputFileRow output file. But here, only yhat will be considered by Uranie as a variable of interest.

fout.addAttribute("yhat");

We set the code as being the flowrate execution with "-k" option:

mycode = Launcher.TCode(tds, "flowrate -k");

in which the "-k" option indicates that flowrate code has to find input files with "key=value" format.

Then the launcher is initialised with a TDataServer and the code is executed

tlch = Launcher.TLauncher(tds, mycode);

The launcher will execute the flowrate -k command for each of the seventeen patterns with the run method.

tlch.run();

XIV.5.17.3. Graph

Figure XIV.34. Graph of the macro "launchCodeFlowrateKeyOATMinMax.py"

Graph of the macro "launchCodeFlowrateKeyOATMinMax.py"

XIV.5.17.4. Console

The macro succeeded with no failure, using the following design-of-experiments;

Processing launchCodeFlowrateKeyOATMinMax.py...
************************************************************************************************************************
*    Row   * tdsOATMin *     rw.rw *       r.r *     tu.tu *     tl.tl *     hu.hu *     hl.hl *       l.l *     kw.kw *
************************************************************************************************************************
*        0 *         0 *       0.1 *     25050 *     89335 *     89.55 *      1050 *       760 *      1400 *     10950 *
*        1 *         1 *      0.05 *     25050 *     89335 *     89.55 *      1050 *       760 *      1400 *     10950 *
*        2 *         2 *      0.15 *     25050 *     89335 *     89.55 *      1050 *       760 *      1400 *     10950 *
*        3 *         3 *       0.1 *       100 *     89335 *     89.55 *      1050 *       760 *      1400 *     10950 *
*        4 *         4 *       0.1 *     50000 *     89335 *     89.55 *      1050 *       760 *      1400 *     10950 *
*        5 *         5 *       0.1 *     25050 *     63070 *     89.55 *      1050 *       760 *      1400 *     10950 *
*        6 *         6 *       0.1 *     25050 *    115600 *     89.55 *      1050 *       760 *      1400 *     10950 *
*        7 *         7 *       0.1 *     25050 *     89335 *      63.1 *      1050 *       760 *      1400 *     10950 *
*        8 *         8 *       0.1 *     25050 *     89335 *       116 *      1050 *       760 *      1400 *     10950 *
*        9 *         9 *       0.1 *     25050 *     89335 *     89.55 *       990 *       760 *      1400 *     10950 *
*       10 *        10 *       0.1 *     25050 *     89335 *     89.55 *      1110 *       760 *      1400 *     10950 *
*       11 *        11 *       0.1 *     25050 *     89335 *     89.55 *      1050 *       700 *      1400 *     10950 *
*       12 *        12 *       0.1 *     25050 *     89335 *     89.55 *      1050 *       820 *      1400 *     10950 *
*       13 *        13 *       0.1 *     25050 *     89335 *     89.55 *      1050 *       760 *      1120 *     10950 *
*       14 *        14 *       0.1 *     25050 *     89335 *     89.55 *      1050 *       760 *      1680 *     10950 *
*       15 *        15 *       0.1 *     25050 *     89335 *     89.55 *      1050 *       760 *      1400 *      9855 *
*       16 *        16 *       0.1 *     25050 *     89335 *     89.55 *      1050 *       760 *      1400 *     12045 *
************************************************************************************************************************

XIV.5.18. Macro "launchCodeFlowrateFlagOATMinMax.py"

XIV.5.18.1. Objective

The objective of the macro is to evaluate the flowrate external code on a design-of-experiments generated by the function PlanOATMinMax where input file "flowrate_input_with_flags.in" contains "flags" and the output file "_output_flowrate_withRow_.dat" is with "values in rows" type. This code is described in section (Section IV.1.2.1). The function PlanOATMinMax consists in constructing a design around the nominal value for each attribute, except for one attribute whose value is set to one of its boundaries(minimum and then maximum). Doing this for the 8 input attributes and the central design, in which each attribute takes its nominal value leads to a seventeen patterns design.

The input file for this code is flowrate_input_with_flags.in with "flags" type. It looks like:

# 
# INPUT FILE with FLAG for the "FLOWREATE" code
# \date   2008-04-22 12:55:17
#

new Implicit_Steady_State sch {
    frottement_paroi { @Rw@ @R@ }
    tinit               0.0
    tmax                1000000.
    nb_pas_dt_max       1500
    dt_min              @Hu@
    dt_max              @Hl@
    facsec              1000000.
    kW                  @Kw@
    information_Tu      Champ_Uniforme 1        @Tu@
    information_Tl      Champ_Uniforme 1        @Tl@
    information_L {
        precision  @L@
    }	
    convergence {
        criterion relative_max_du_dt
        precision  @Rw@
    }

    stop_criterium {
        ch_abcsissa_hu 1050
        ch_ordinate_hl 770
        c_radius 1100
    }

    Solveur Newton3 {
        max_iter_matrice        1
        max_iter_implicite      1
        date                    5654321
        seuil_convg_implicite   1.e-6
        assemblage_implicite    10
        solveur_lineaire        BiCGS
            preconditionneur    ILU
            seuil_resol_implicite 1.e-5
    }
}

These files define the eight variables , , , , , , , needed to perform the execution of the command flowrate -f.

The output file, _output_flowrate_withRow_.dat when created, is of "values in rows" type. It looks like:

#COLUMN_NAMES: yhat | d
		  
6.757218e+01  4.092561e+03

yhat and d have to be defined as output variables in the macro.

XIV.5.18.2. Macro Uranie

"""
Example of flowrate code launching with OATMinMax
"""
import numpy as np
from rootlogon import ROOT, DataServer, Launcher


def plan_oat_min_max(mytds):
    """Generate the OAT min max doe"""

    # Create the data tuple
    mytds.createTuple()

    natt = mytds.getNAttributes()
    # The number of attributes is incremented by one for the iterator
    number_n = natt+1

    # Allocate the data vector to fill the tuple
    value = np.zeros([number_n])

    # Init the iterator. It is always the first value.
    value[0] = 0
    # Init the data vector with the nominal/mean values of attributes
    for i in range(natt):
        value[1+i] = mytds.getAttribute(i).getMean()

    # Fill the nominal/mean values: nominal pattern
    mytds.getTuple().Fill(value)

    # Loop on each attributes
    for i in range(natt):
        # Case of min values
        value[1+i] = mytds.getAttribute(i).getLowerBound()
        value[0] += 1.0
        # Fill min value for xi attribute and nominal values for others
        mytds.getTuple().Fill(value)
        # Case of the max value
        value[1+i] = mytds.getAttribute(i).getUpperBound()
        value[0] += 1.0
        # Fill max value for xi attribute and nominal values for others
        mytds.getTuple().Fill(value)
        # Reset the nominal/mean value
        value[1+i] = mytds.getAttribute(i).getMean()


# Define the DataServer
tds = DataServer.TDataServer("tdsOATMinMaxFlowrateFlag",
                             "OATMinMax DoE for Flowrate")

# Add the eight attributes of the study with min, max and nominal values
tds.addAttribute(DataServer.TAttribute("rw", 0.05, 0.15))
tds.getAttribute("rw").setMean(0.10)

tds.addAttribute(DataServer.TAttribute("r", 100.0, 50000.0))
tds.getAttribute("r").setMean(25050.)

tds.addAttribute(DataServer.TAttribute("tu", 63070.0, 115600.0))
tds.getAttribute("tu").setMean(89335.)

tds.addAttribute(DataServer.TAttribute("tl", 63.1, 116.0))
tds.getAttribute("tl").setMean(89.55)

tds.addAttribute(DataServer.TAttribute("hu", 990.0, 1110.0))
tds.getAttribute("hu").setMean(1050.)

tds.addAttribute(DataServer.TAttribute("hl", 700.0, 820.0))
tds.getAttribute("hl").setMean(760.)

tds.addAttribute(DataServer.TAttribute("l", 1120.0, 1680.0))
tds.getAttribute("l").setMean(1400.)

tds.addAttribute(DataServer.TAttribute("kw", 9855.0, 12045.0))
tds.getAttribute("kw").setMean(10950.)

# The input file
sFileName = "flowrate_input_with_flags.in"

# Set the input file with flag format and the flag for each input attributes
tds.getAttribute("rw").setFileFlag(sFileName, "@Rw@")
tds.getAttribute("r").setFileFlag(sFileName, "@R@")
tds.getAttribute("tu").setFileFlag(sFileName, "@Tu@")
tds.getAttribute("tl").setFileFlag(sFileName, "@Tl@")
tds.getAttribute("hu").setFileFlag(sFileName, "@Hu@")
tds.getAttribute("hl").setFileFlag(sFileName, "@Hl@")
tds.getAttribute("l").setFileFlag(sFileName, "@L@")
tds.getAttribute("kw").setFileFlag(sFileName, "@Kw@")

# Build the Design of Experiments (DoE)
plan_oat_min_max(tds)

# Scan the data ( 17 = 1 + 2*8 patterns)
tds.Scan("*", "", "colsize = 5 col = 3:4:5:6:5:4:3:4")

# Save the Design of experiments in an ASCII file
tds.exportData("_flowrate_sampler_oat_.dat")

# The output file of the code
fout = Launcher.TOutputFileRow("_output_flowrate_withRow_.dat")
# The attribute in the output file
fout.addAttribute(DataServer.TAttribute("yhat"))

# Instanciation de mon code
mycode = Launcher.TCode(tds, "flowrate -s -f")
# mycode.setLog()
# on ajoute le fichier de sortie du code
mycode.addOutputFile(fout)

# Lancement du code
tlch = Launcher.TLauncher(tds, mycode)
tlch.setSave()
tlch.setClean()
tlch.setDrawProgressBar(False)
tlch.setVarDraw("yhat:rw", "", "")

tlch.run()

tds.exportData("_flowrate_sampler_launcher_oat_.dat")

# Visualisation
Canvas = ROOT.TCanvas("c1", "Graph launchCodeFlowrateFlagOATMinMax",
                      5, 64, 1270, 667)
pad = ROOT.TPad("pad", "pad", 0, 0.03, 1, 1)
pad.Draw()
ROOT.gStyle.SetPalette(1)
pad.Divide(2, 2)
pad.cd(1)
tds.draw("yhat:rw")

pad.cd(3)
tds.draw("yhat")
pad.cd(2)
tds.draw("yhat:rw", "", "colz")

pad.cd(4)
# The parallel plot
tds.draw("rw:r:tu:tl:hu:hl:l:kw:yhat", "", "para")
para = ROOT.gPad.GetListOfPrimitives().FindObject("ParaCoord")

# The output attribute
axis = para.GetVarList().FindObject("yhat")
axis.AddRange(ROOT.TParallelCoordRange(axis, 15.0, 20.0))
para.AddSelection("blue")
para.GetCurrentSelection().SetLineColor(ROOT.kBlue)

axis.AddRange(ROOT.TParallelCoordRange(axis, 155.0, 160.0))
para.AddSelection("blue")

para.GetCurrentSelection().SetLineColor(ROOT.kBlue)

PlanOATMinMax function builds the design-of-experiments from a TDataServer: for the first design and for each attribute of the TDataServer, values of attributes are initialised with their means.

for i in range(natt) : value[1+i] = tds.getAttribute(i).getMean();

These data are put in the TDataServer,

tds.getTuple().Fill(value)

this is how the central point is constructed. Two designs are then built for every attribute: one with the value of the attribute initialised to its lower boundary while other attributes are still initialised to their means:

value[1+i] = tds.getAttribute(i).getLowerBound();
tds.getTuple().Fill(value);

and the other where the value of the attribute is initialised to its upper boundary while other attributes are still initialised to their means:

value[1+i] = tds.getAttribute(i).getUpperBound();
tds.getTuple().Fill(value);

In the first part of the function launchCodeFlowrateFlagOATMinMax, properties are set for each input variable. For example for the Rw variable, the macro creates a TAttribute named "rw" bounded by 0.05 and 0.15:

tds.addAttribute(DataServer.TAttribute("rw", 0.05, 0.15));

An initial mean value is then set for this TAttribute, so as to inform the PlanOATMinMax function.

tds.getAttribute("rw").setMean(0.10);

Then, the TAttribute is linked to the input file with:

tds.getAttribute("rw").setFileFlag("flowrate_input_with_flags.in", "@Rw@");

which is the same thing as writing:

tds.getAttribute("rw").setFileKey("flowrate_input_with_flags.in", "@Rw@","",DataServer.TAttributeFileKey.kFlag);

which will be understood by Uranie as the fact the rw variable has to be read in an input file with "flags" format.

Then the design-of-experiments is generated by the PlanOATMinMax function.

PlanOATMinMax(tds);

We want the output file to be with values in rows. So the output file _output_flowrate_withRow_.dat is set as a TOutputFileRow.

fout = Launcher.TOutputFileRow("_output_flowrate_withRow_.dat");

The variable yhat and d could then be linked to this TOutputFileRow output file. But here, only yhat will be considered.

fout.addAttribute("yhat");

We set the code as being the flowrate execution with "-f" option:

mycode = Launcher.TCode(tds, "flowrate -f");

in which the "-f" option indicates that flowrate code has to find input files with "flags" format.

The launcher will execute the flowrate -f command for each of the seventeen patterns. One sampling corresponds to one input file created by the launcher.

Then the launcher is initialised and launched with the run method

tlch = Launcher.TLauncher(tds, mycode);
tlch.run();

XIV.5.18.3. Graph

Figure XIV.35. Graph of the macro "launchCodeFlowrateFlagOATMinMax.py"

Graph of the macro "launchCodeFlowrateFlagOATMinMax.py"

XIV.5.18.4. Console

The macro succeeded with no failure, using the following design-of-experiments:

Processing launchCodeFlowrateFlagOATMinMax.py...
************************************************************************************************************************
*    Row   * tdsOATMin *     rw.rw *       r.r *     tu.tu *     tl.tl *     hu.hu *     hl.hl *       l.l *     kw.kw *
************************************************************************************************************************
*        0 *         0 *       0.1 *     25050 *     89335 *     89.55 *      1050 *       760 *      1400 *     10950 *
*        1 *         1 *      0.05 *     25050 *     89335 *     89.55 *      1050 *       760 *      1400 *     10950 *
*        2 *         2 *      0.15 *     25050 *     89335 *     89.55 *      1050 *       760 *      1400 *     10950 *
*        3 *         3 *       0.1 *       100 *     89335 *     89.55 *      1050 *       760 *      1400 *     10950 *
*        4 *         4 *       0.1 *     50000 *     89335 *     89.55 *      1050 *       760 *      1400 *     10950 *
*        5 *         5 *       0.1 *     25050 *     63070 *     89.55 *      1050 *       760 *      1400 *     10950 *
*        6 *         6 *       0.1 *     25050 *    115600 *     89.55 *      1050 *       760 *      1400 *     10950 *
*        7 *         7 *       0.1 *     25050 *     89335 *      63.1 *      1050 *       760 *      1400 *     10950 *
*        8 *         8 *       0.1 *     25050 *     89335 *       116 *      1050 *       760 *      1400 *     10950 *
*        9 *         9 *       0.1 *     25050 *     89335 *     89.55 *       990 *       760 *      1400 *     10950 *
*       10 *        10 *       0.1 *     25050 *     89335 *     89.55 *      1110 *       760 *      1400 *     10950 *
*       11 *        11 *       0.1 *     25050 *     89335 *     89.55 *      1050 *       700 *      1400 *     10950 *
*       12 *        12 *       0.1 *     25050 *     89335 *     89.55 *      1050 *       820 *      1400 *     10950 *
*       13 *        13 *       0.1 *     25050 *     89335 *     89.55 *      1050 *       760 *      1120 *     10950 *
*       14 *        14 *       0.1 *     25050 *     89335 *     89.55 *      1050 *       760 *      1680 *     10950 *
*       15 *        15 *       0.1 *     25050 *     89335 *     89.55 *      1050 *       760 *      1400 *      9855 *
*       16 *        16 *       0.1 *     25050 *     89335 *     89.55 *      1050 *       760 *      1400 *     12045 *
************************************************************************************************************************

XIV.5.19.  Macro "launchCodeLevelEOutputColumn.py"

Warning

The levele command will be install on your machine only if a Fortran compiler has been found

XIV.5.19.1. Objective

The objective of this macro is to launch a code that will produce several numerical values for at least one attribute, when only once computation is performed. To do so, the levele use-case code will be used. It is a code that computes the dose emitted by radioactive sources, as a function of time, given a set of twelve input parameters. It provides three possible output formats, the one under consideration being here the Column one, corresponding to the TOutputFileColumn class. Here is an example of the output:

   20000.00       30000.00       40000.00       50000.00       60000.00       70000.00       80000.00       90000.00       100000.0       200000.0       300000.0       400000.0       500000.0       600000.0       700000.0       800000.0       900000.0       1000000.       2000000.       3000000.       4000000.       5000000.       6000000.       7000000.       8000000.       9000000.    
  0.9223239E-37  0.4206201E-32  0.5129892E-29  0.9733449E-27  0.6020410E-25  0.1766700E-23  0.3050058E-22  0.3543269E-21  0.3028644E-20  0.1192590E-14  0.6677703E-12  0.2881550E-10  0.3190472E-09  0.1532743E-08  0.4212096E-08  0.7793285E-08  0.1077026E-07  0.1192316E-07  0.1117317E-09 -0.9543977E-12  0.1073334E-19  0.2311560E-19  0.3043276E-19  0.3529515E-19  0.4011028E-19  0.4548453E-19
   0.000000       0.000000       0.000000       0.000000       0.000000       0.000000      0.1401298E-44  0.1261169E-42  0.9172900E-41  0.1422271E-29  0.4459172E-24  0.8303329E-21  0.1017911E-18  0.2349300E-17  0.1774175E-16  0.6073529E-16  0.1159985E-15  0.1421619E-15  0.1248398E-19  0.9108749E-24  0.1152050E-39  0.5343305E-39  0.9261532E-39  0.1245747E-38  0.1608835E-38  0.2068842E-38

XIV.5.19.2. Macro Uranie

"""
Example of levelE code launching with column output format
"""
import sys
import numpy as np
from rootlogon import ROOT, DataServer, Launcher, Sampler

# Exit if levele not found
if ROOT.gSystem.Exec("which levele"):
    sys.exit(-1)

# Create DataServer and add input attributes
tds1 = DataServer.TDataServer("tds1", "levelE usecase")
tds1.addAttribute(DataServer.TUniformDistribution("t", 100, 1000))
tds1.addAttribute(DataServer.TLogUniformDistribution("kl", 0.001, 0.01))
tds1.addAttribute(DataServer.TLogUniformDistribution("kc", 0.000001, 0.00001))
tds1.addAttribute(DataServer.TLogUniformDistribution("v1", 0.001, 0.1))
tds1.addAttribute(DataServer.TUniformDistribution("l1", 100, 500))
tds1.addAttribute(DataServer.TUniformDistribution("r1", 1, 5))
tds1.addAttribute(DataServer.TUniformDistribution("rc1", 3, 30))
tds1.addAttribute(DataServer.TLogUniformDistribution("v2", 0.01, 0.1))
tds1.addAttribute(DataServer.TUniformDistribution("l2", 50, 200))
tds1.addAttribute(DataServer.TUniformDistribution("r2", 1, 5))
tds1.addAttribute(DataServer.TUniformDistribution("rc2", 3, 30))
tds1.addAttribute(DataServer.TLogUniformDistribution("w", 100000, 10000000))

# Tell the code where to find attribute value in input file
sJDD = "levelE_input_with_values_rows.in"
InType = DataServer.TAttributeFileKey.kNewRow
tds1.getAttribute("t").setFileKey(sJDD, "", "%e", InType)
tds1.getAttribute("kl").setFileKey(sJDD, "", "%e", InType)
tds1.getAttribute("kc").setFileKey(sJDD, "", "%e", InType)
tds1.getAttribute("v1").setFileKey(sJDD, "", "%e", InType)
tds1.getAttribute("l1").setFileKey(sJDD, "", "%e", InType)
tds1.getAttribute("r1").setFileKey(sJDD, "", "%e", InType)
tds1.getAttribute("rc1").setFileKey(sJDD, "", "%e", InType)
tds1.getAttribute("v2").setFileKey(sJDD, "", "%e", InType)
tds1.getAttribute("l2").setFileKey(sJDD, "", "%e", InType)
tds1.getAttribute("r2").setFileKey(sJDD, "", "%e", InType)
tds1.getAttribute("rc2").setFileKey(sJDD, "", "%e", InType)
tds1.getAttribute("w").setFileKey(sJDD, "", "%e", InType)

# Create DOE
ns = 100
samp = Sampler.TSampling(tds1, "lhs", ns)
samp.generateSample()

# How to read ouput files
_fout = Launcher.TOutputFileColumn("_output_levelE_withColumn_.dat")
_fout.addAttribute(DataServer.TAttribute("tps", DataServer.TAttribute.kVector))
_fout.addAttribute(DataServer.TAttribute("y", DataServer.TAttribute.kVector))
_fout.addAttribute(DataServer.TAttribute("z", DataServer.TAttribute.kVector))

# Creation of TCode
tc1 = Launcher.TCode(tds1, "levele 2> /dev/null")
tc1.addOutputFile(_fout)

# Run the code
tl1 = Launcher.TLauncher(tds1, tc1)
tl1.run()

# Draw the results
Can = ROOT.TCanvas("Can", "Can", 1)
Can.SetGrid()
Can.SetLogx()

mean = np.zeros([26])
stand = np.zeros([26])
tds1.computeStatistic("y")
for i in range(26):
    mean[i] = tds1.getAttribute("y").getMean(i)
    stand[i] = tds1.getAttribute("y").getStd(i)

tps = np.array([20000, 30000, 40000, 50000, 60000, 70000, 80000, 90000, 100000,
                200000, 300000, 400000, 500000, 600000, 700000, 800000, 900000,
                1e+06, 2e+06, 3e+06, 4e+06, 5e+06, 6e+06, 7e+06, 8e+06, 9e+06])
Zeros = np.zeros([26])
gr = ROOT.TGraphErrors(26, tps, mean, Zeros, stand)
gr.Draw("A*")
gr.SetTitle("")
gr.GetXaxis().SetTitle("Time")
gr.GetYaxis().SetTitle("<y>")

The levele external code is located in the bin directory.

When looking at the code and comparing it to an usual launcher job, the organisation is completely transparent. The only noticeable (and compulsory) thing to do is to change the default type of the attribute read at the end of the job. This is done in this line:

_fout.addAttribute(DataServer.TAttribute("y", DataServer.TAttribute.kVector));

where the output attribute is provided, changing its nature to a vector, thanks to the second argument of the TAttribute constructor from the default (kReal) to the desired nature (kVector). Once this is done, this information is broadcast internally to the code that knows how to deal with this type of attribute.

XIV.5.19.3. Graph

The results of the previous macro is shown in Figure XIV.36, that displays the average of the hundred dose curve, over the time.

Figure XIV.36. Graph of the macro "launchCodeLevelEOutputColumn.py"

Graph of the macro "launchCodeLevelEOutputColumn.py"

XIV.5.20.  Macro "launchCodeLevelEOutputRow.py"

Warning

The levele command will be installed on your machine only if a Fortran compiler is found

XIV.5.20.1. Objective

The objective of this macro is to launch a code that will produce several numerical values for at least one attribute, when only once computation is performed. To do so, the levele use-case code will be used. It is a code that compute the dose emitted by radioactive sources, as a function of time, given a set of twelve inputs parameters. It provides three possible output formats, the one under consideration being here the Row one, corresponding to the TOutputFileRow class. Here is an example of the output:

#COLUMN_NAMES: tps | y | z
 
   20000.00      0.9223239E-37   0.000000    
   30000.00      0.4206201E-32   0.000000    
   40000.00      0.5129892E-29   0.000000    
   50000.00      0.9733449E-27   0.000000    
   60000.00      0.6020410E-25   0.000000    
   70000.00      0.1766700E-23   0.000000    
   80000.00      0.3050058E-22  0.1401298E-44
   90000.00      0.3543269E-21  0.1261169E-42
   100000.0      0.3028644E-20  0.9172900E-41
   200000.0      0.1192590E-14  0.1422271E-29
   300000.0      0.6677703E-12  0.4459172E-24
   400000.0      0.2881550E-10  0.8303329E-21
   500000.0      0.3190472E-09  0.1017911E-18
   600000.0      0.1532743E-08  0.2349300E-17
   700000.0      0.4212096E-08  0.1774175E-16
   800000.0      0.7793285E-08  0.6073529E-16
   900000.0      0.1077026E-07  0.1159985E-15
   1000000.      0.1192316E-07  0.1421619E-15
   2000000.      0.1117317E-09  0.1248398E-19
   3000000.     -0.9543977E-12  0.9108749E-24
   4000000.      0.1073334E-19  0.1152050E-39
   5000000.      0.2311560E-19  0.5343305E-39
   6000000.      0.3043276E-19  0.9261532E-39
   7000000.      0.3529515E-19  0.1245747E-38
   8000000.      0.4011028E-19  0.1608835E-38
   9000000.      0.4548453E-19  0.2068842E-38

XIV.5.20.2. Macro Uranie

"""
Example of levelE code launching with row output format
"""
import sys
import numpy as np
from rootlogon import ROOT, DataServer, Launcher, Sampler

# Exit if levele not found
if ROOT.gSystem.Exec("which levele"):
    sys.exit(-1)

# Create DataServer and add input attributes
tds1 = DataServer.TDataServer("tds1", "levelE usecase")
tds1.addAttribute(DataServer.TUniformDistribution("t", 100, 1000))
tds1.addAttribute(DataServer.TLogUniformDistribution("kl", 0.001, 0.01))
tds1.addAttribute(DataServer.TLogUniformDistribution("kc", 0.000001, 0.00001))
tds1.addAttribute(DataServer.TLogUniformDistribution("v1", 0.001, 0.1))
tds1.addAttribute(DataServer.TUniformDistribution("l1", 100, 500))
tds1.addAttribute(DataServer.TUniformDistribution("r1", 1, 5))
tds1.addAttribute(DataServer.TUniformDistribution("rc1", 3, 30))
tds1.addAttribute(DataServer.TLogUniformDistribution("v2", 0.01, 0.1))
tds1.addAttribute(DataServer.TUniformDistribution("l2", 50, 200))
tds1.addAttribute(DataServer.TUniformDistribution("r2", 1, 5))
tds1.addAttribute(DataServer.TUniformDistribution("rc2", 3, 30))
tds1.addAttribute(DataServer.TLogUniformDistribution("w", 100000, 10000000))

# Tell the code where to find attribute value in input file
sJDD = "levelE_input_with_values_rows.in"
InType = DataServer.TAttributeFileKey.kNewRow
tds1.getAttribute("t").setFileKey(sJDD, "", "%e", InType)
tds1.getAttribute("kl").setFileKey(sJDD, "", "%e", InType)
tds1.getAttribute("kc").setFileKey(sJDD, "", "%e", InType)
tds1.getAttribute("v1").setFileKey(sJDD, "", "%e", InType)
tds1.getAttribute("l1").setFileKey(sJDD, "", "%e", InType)
tds1.getAttribute("r1").setFileKey(sJDD, "", "%e", InType)
tds1.getAttribute("rc1").setFileKey(sJDD, "", "%e", InType)
tds1.getAttribute("v2").setFileKey(sJDD, "", "%e", InType)
tds1.getAttribute("l2").setFileKey(sJDD, "", "%e", InType)
tds1.getAttribute("r2").setFileKey(sJDD, "", "%e", InType)
tds1.getAttribute("rc2").setFileKey(sJDD, "", "%e", InType)
tds1.getAttribute("w").setFileKey(sJDD, "", "%e", InType)

# Create DOE
ns = 100
samp = Sampler.TSampling(tds1, "lhs", ns)
samp.generateSample()

# How to read ouput files
_fout = Launcher.TOutputFileRow("_output_levelE_withRow_.dat")
_fout.addAttribute(DataServer.TAttribute("tps", DataServer.TAttribute.kVector))
_fout.addAttribute(DataServer.TAttribute("y", DataServer.TAttribute.kVector))
_fout.addAttribute(DataServer.TAttribute("z", DataServer.TAttribute.kVector))

# Creation of Launcher.TCode
tc1 = Launcher.TCode(tds1, "levele 2> /dev/null")
tc1.addOutputFile(_fout)

# Run the code
tl1 = Launcher.TLauncher(tds1, tc1)
tl1.run()

# Draw the results
Can = ROOT.TCanvas("Can", "Can", 1)
Can.SetGrid()
Can.SetLogx()

mean = np.zeros([26])
stand = np.zeros([26])
tds1.computeStatistic("y")
for i in range(26):
    mean[i] = tds1.getAttribute("y").getMean(i)
    stand[i] = tds1.getAttribute("y").getStd(i)

tps = np.array([20000, 30000, 40000, 50000, 60000, 70000, 80000, 90000, 100000,
                200000, 300000, 400000, 500000, 600000, 700000, 800000, 900000,
                1e+06, 2e+06, 3e+06, 4e+06, 5e+06, 6e+06, 7e+06, 8e+06, 9e+06])
Zeros = np.zeros([26])
gr = ROOT.TGraphErrors(26, tps, mean, Zeros, stand)
gr.Draw("A*")
gr.SetTitle("")
gr.GetXaxis().SetTitle("Time")
gr.GetYaxis().SetTitle("<y>")

The levele external code is located in the bin directory.

When looking at the code and comparing it to an usual launcher job, the organisation is completely transparent. The only noticeable (and compulsory) thing to do is to change the default type of the attribute read at the end of the job. This is done in this line:

_fout.addAttribute(DataServer.TAttribute("y", DataServer.TAttribute.kVector));

where the output attribute is provided, changing its nature to a vector, thanks to the second argument of the TAttribute constructor from the default (kReal) to the desired nature (kVector). Once this is done, this information is broadcast internally to the code that knows how to deal with this type of attribute.

XIV.5.20.3. Graph

The results of the previous macro is shown in Figure XIV.37, that displays the average of the hundred dose curve, over the time.

Figure XIV.37. Graph of the macro "launchCodeLevelEOutputRow.py"

Graph of the macro "launchCodeLevelEOutputRow.py"

XIV.5.21.  Macro "launchCodeLevelEOutputKey.py"

Warning

The levele command will be installed on your machine only if a Fortran compiler is found

XIV.5.21.1. Objective

The objective of this macro is to launch a code that will produce several numerical values for at least one attribute, when only once computation is performed. To do so, the levele use-case code will be used. It is a code that compute the dose emitted by radioactive sources, as a function of time, given a set of twelve inputs parameters. It provides three possible output formats, the one under consideration being here the Key one, corresponding to the TOutputFileKey class. Here is an example of the output:

time =    20000.00    
y =   0.9223239E-37
z =    0.000000    
time =    30000.00    
y =   0.4206201E-32
z =    0.000000    
time =    40000.00    
y =   0.5129892E-29
z =    0.000000    
time =    50000.00    
y =   0.9733449E-27
z =    0.000000    
time =    60000.00    
y =   0.6020410E-25
z =    0.000000    
time =    70000.00    
y =   0.1766700E-23
z =    0.000000    
time =    80000.00    
y =   0.3050058E-22
z =   0.1401298E-44
time =    90000.00    
y =   0.3543269E-21
z =   0.1261169E-42
time =    100000.0    
y =   0.3028644E-20
z =   0.9172900E-41
time =    200000.0    
y =   0.1192590E-14
z =   0.1422271E-29
time =    300000.0    
y =   0.6677703E-12
z =   0.4459172E-24
time =    400000.0    
y =   0.2881550E-10
z =   0.8303329E-21
time =    500000.0    
y =   0.3190472E-09
z =   0.1017911E-18
time =    600000.0    
y =   0.1532743E-08
z =   0.2349300E-17
time =    700000.0    
y =   0.4212096E-08
z =   0.1774175E-16
time =    800000.0    
y =   0.7793285E-08
z =   0.6073529E-16
time =    900000.0    
y =   0.1077026E-07
z =   0.1159985E-15
time =    1000000.    
y =   0.1192316E-07
z =   0.1421619E-15
time =    2000000.    
y =   0.1117317E-09
z =   0.1248398E-19
time =    3000000.    
y =  -0.9543977E-12
z =   0.9108749E-24
time =    4000000.    
y =   0.1073334E-19
z =   0.1152050E-39
time =    5000000.    
y =   0.2311560E-19
z =   0.5343305E-39
time =    6000000.    
y =   0.3043276E-19
z =   0.9261532E-39
time =    7000000.    
y =   0.3529515E-19
z =   0.1245747E-38
time =    8000000.    
y =   0.4011028E-19
z =   0.1608835E-38
time =    9000000.    
y =   0.4548453E-19
z =   0.2068842E-38

XIV.5.21.2. Macro Uranie

"""
Example of levelE code launching with key output format
"""
import sys
import numpy as np
from rootlogon import ROOT, DataServer, Launcher, Sampler

# Exit if levele not found
if ROOT.gSystem.Exec("which levele"):
    sys.exit(-1)

# Create DataServer and add input attributes
tds1 = DataServer.TDataServer("tds1", "levelE usecase")
tds1.addAttribute(DataServer.TUniformDistribution("t", 100, 1000))
tds1.addAttribute(DataServer.TLogUniformDistribution("kl", 0.001, 0.01))
tds1.addAttribute(DataServer.TLogUniformDistribution("kc", 0.000001, 0.00001))
tds1.addAttribute(DataServer.TLogUniformDistribution("v1", 0.001, 0.1))
tds1.addAttribute(DataServer.TUniformDistribution("l1", 100, 500))
tds1.addAttribute(DataServer.TUniformDistribution("r1", 1, 5))
tds1.addAttribute(DataServer.TUniformDistribution("rc1", 3, 30))
tds1.addAttribute(DataServer.TLogUniformDistribution("v2", 0.01, 0.1))
tds1.addAttribute(DataServer.TUniformDistribution("l2", 50, 200))
tds1.addAttribute(DataServer.TUniformDistribution("r2", 1, 5))
tds1.addAttribute(DataServer.TUniformDistribution("rc2", 3, 30))
tds1.addAttribute(DataServer.TLogUniformDistribution("w", 100000, 10000000))

# Tell the code where to find attribute value in input file
sJDD = "levelE_input_with_values_rows.in"
InType = DataServer.TAttributeFileKey.kNewRow
tds1.getAttribute("t").setFileKey(sJDD, "", "%e", InType)
tds1.getAttribute("kl").setFileKey(sJDD, "", "%e", InType)
tds1.getAttribute("kc").setFileKey(sJDD, "", "%e", InType)
tds1.getAttribute("v1").setFileKey(sJDD, "", "%e", InType)
tds1.getAttribute("l1").setFileKey(sJDD, "", "%e", InType)
tds1.getAttribute("r1").setFileKey(sJDD, "", "%e", InType)
tds1.getAttribute("rc1").setFileKey(sJDD, "", "%e", InType)
tds1.getAttribute("v2").setFileKey(sJDD, "", "%e", InType)
tds1.getAttribute("l2").setFileKey(sJDD, "", "%e", InType)
tds1.getAttribute("r2").setFileKey(sJDD, "", "%e", InType)
tds1.getAttribute("rc2").setFileKey(sJDD, "", "%e", InType)
tds1.getAttribute("w").setFileKey(sJDD, "", "%e", InType)

# Create DOE
ns = 100
samp = Sampler.TSampling(tds1, "lhs", ns)
samp.generateSample()

# How to read ouput files
_fout = Launcher.TOutputFileKey("_output_levelE_withKey_.dat")
_fout.addAttribute(DataServer.TAttribute("tps", DataServer.TAttribute.kVector))
_fout.addAttribute(DataServer.TAttribute("y", DataServer.TAttribute.kVector))
_fout.addAttribute(DataServer.TAttribute("z", DataServer.TAttribute.kVector))

# Creation of Launcher.TCode
tc1 = Launcher.TCode(tds1, "levele 2> /dev/null")
tc1.addOutputFile(_fout)

# Run the code
tl1 = Launcher.TLauncher(tds1, tc1)
tl1.run()

# Draw the results
Can = ROOT.TCanvas("Can", "Can", 1)
Can.SetGrid()
Can.SetLogx()

mean = np.zeros([26])
stand = np.zeros([26])
tds1.computeStatistic("y")
for i in range(26):
    mean[i] = tds1.getAttribute("y").getMean(i)
    stand[i] = tds1.getAttribute("y").getStd(i)

tps = np.array([20000, 30000, 40000, 50000, 60000, 70000, 80000, 90000, 100000,
                200000, 300000, 400000, 500000, 600000, 700000, 800000, 900000,
                1e+06, 2e+06, 3e+06, 4e+06, 5e+06, 6e+06, 7e+06, 8e+06, 9e+06])
Zeros = np.zeros([26])
gr = ROOT.TGraphErrors(26, tps, mean, Zeros, stand)
gr.Draw("A*")
gr.SetTitle("")
gr.GetXaxis().SetTitle("Time")
gr.GetYaxis().SetTitle("<y>")

The levele external code is located in the bin directory.

When looking at the code and comparing it to an usual launcher job, the organisation is completely transparent. The only noticeable (and compulsory) thing to do is to change the default type of the attribute read at the end of the job. This is done in this line:

_fout.addAttribute(DataServer.TAttribute("y", DataServer.TAttribute.kVector));

where the output attribute is provided, changing its nature to a vector, thanks to the second argument of the TAttribute constructor from the default (kReal) to the desired nature (kVector). Once this is done, this information is broadcast internally to the code that knows how to deal with this type of attribute.

XIV.5.21.3. Graph

The results of the previous macro is shown in Figure XIV.38, that displays the average of the hundred dose curve, over the time.

Figure XIV.38. Graph of the macro "launchCodeLevelEOutputKey.py"

Graph of the macro "launchCodeLevelEOutputKey.py"

XIV.5.22. Input/Output with vector and string: introduction to macros with multitype

In order to test the possibility of reading vectors and strings (for jobs that produce those kind of results) but also to re-write them in files when they are requested by a code (as an input) the multitype code has been created. It is just a dummy piece of code that generates outputs containing vectors and strings along with double-precision results, and re-read them to use the information contained and produce a new flat result.

XIV.5.22.1. Producing outputs

Special flags have been added to the multitype code aiming to produce an output containing:

  • 2 words: w1 and w2, at first and last position, drawn randomly from a list that goes from "zero" to "nine".

  • 2 vectors: v1 and v2, at second and third position, filled with and , doubles that follow two different gaussian drawings. These number and are drawn randomly between 1 and 15 and might then changed from one event to another.

  • 1 float, f1, at fourth position, drawn following a gaussian.

The code can produce different kind of output files depending on the way it is called:

  • multitype -mtKey: produces 2 output files (_output_multitype_mt_Key_.dat and _output_multitype_mt_Key_condensate_.dat) written in Key format
  • multitype -mtRow: produces an output file (_output_multitype_mt_Row_.dat) written in Row format
  • multitype -mtCol: produces an output file (_output_multitype_mt_Column_.dat) written in Column format
  • multitype -mtDS: produces an output file (_output_multitype_mt_DataServer_.dat) written in DataServer format
  • multitype -mtXML: produces an output file (_output_multitype_mt_.xml) written in XML format

The code uses an input file called "multitype_input.dat" containing a single double that corresponds to the seed used to generate the outputs. This is the only attribute needed when this -mt option is used for multitype.

XIV.5.22.2. Reading inputs

Another special flag has been added to the multitype code aiming to analyse the output of the step described previously. The idea is to check that vectors and strings are read and replaced carefully as input for the new operation which produces two double-precision outputs: thev1 and thev2. Their values is set to 987654321 by default and when the code is run the idea is:

  • to recover the word w1 and the vector v1.
  • to get the number that corresponds to the words w1 ("two" == 2).
  • to associate thev1 to the w1-Th value of the vector v1 if it exists (and set it to -123456789 otherwise).

This procedure being repeated for w2 and v2 as well.

The code can produce different kinds of output files, from different input files, depending on the way it is called:

  • multitype -ReadmtKey: produces an output files (_output_multitype_readmt_Key_.dat) by reading the input variable in _output_multitype_mt_Key_condensate_.dat).
  • multitype -ReadmtRow: produces an output file (_output_multitype_readmt_Row_.dat) by reading the input variable in _output_multitype_mt_Row_.dat).
  • multitype -ReadmtCol: produces an output file (_output_multitype_readmt_Column_.dat) by reading the input variable in _output_multitype_mt_Column_.dat).
  • multitype -ReadmtDS: produces an output file (_output_multitype_readmt_DataServer_.dat) by reading the input variable in _output_multitype_mt_DataServer_.dat).
  • multitype -ReadmtXML: produces an output file (_output_multitype_readmt_.xml) by reading the input variable in _output_multitype_mt_.xml).

XIV.5.23.  Macro "launchCodeMultiTypeKey.py"

XIV.5.23.1. Objective

The objective of this macro is to test the case where vectors and strings are produced as outputs, using the code described in Section XIV.5.22.1, with a Key format, obtained by doing:

multitype -mtKey

The resulting output file, named _output_multitype_mt_Key_.dat looks like:

w1 = nine
v1 = -0.512095
v1 = 0.039669
v1 = -1.3834
v1 = 1.37667
v1 = 0.220672
v1 = 0.633267
v1 = 1.37027
v1 = -0.765636
v2 = 14.1981
v2 = 14.0855
v2 = 10.7848
v2 = 9.45476
v2 = 9.17308
v2 = 6.60804
v2 = 10.0711
v2 = 14.1761
v2 = 10.318
v2 = 12.5095
v2 = 15.6614
v2 = 10.3452
v2 = 9.41101
v2 = 7.47887
f1 = 32.2723
w2 = eight

XIV.5.23.2. Macro Uranie

"""
Example of multitype code launching with key output format
"""
from rootlogon import ROOT, DataServer, Launcher, Sampler

# Create dataserver with the seed attribute
tds = DataServer.TDataServer("foo", "pouet")
tds.addAttribute(DataServer.TUniformDistribution("seed", 0, 100000))
tds.getAttribute("seed").setFileKey("multitype_input.dat", "",
                                    "%e", DataServer.TAttributeFileKey.kNewRow)

# Create DOE
tsam = Sampler.TSampling(tds, "lhs", 100)
tsam.generateSample()

# Precise output and create Code
out = Launcher.TOutputFileKey("_output_multitype_mt_Key_.dat")
out.addAttribute(DataServer.TAttribute("w1", DataServer.TAttribute.kString))
out.addAttribute(DataServer.TAttribute("w2", DataServer.TAttribute.kString))
out.addAttribute(DataServer.TAttribute("v1", DataServer.TAttribute.kVector))
out.addAttribute(DataServer.TAttribute("v2", DataServer.TAttribute.kVector))
out.addAttribute(DataServer.TAttribute("f1"))
myc = Launcher.TCode(tds, "multitype -mtKey")
myc.addOutputFile(out)

# Create Launcher.TLauncher and run it
tlau = Launcher.TLauncher(tds, myc)
tlau.run()

# Produce control plot
Can = ROOT.TCanvas("Can", "Can", 10, 10, 1000, 800)
pad = ROOT.TPad("pad", "pad", 0, 0.03, 1, 1)
pad.Draw()
pad.cd()
tds.drawPairs("w1:v1:v2:f1:w2")

When looking at the code and comparing it to an usual launcher job, the organisation is completely transparent. A dataserver is created with a simple input (the seed) drawn as an uniform distribution. The design-of-experiments is generated and the TOutputFileKey is created and filled with new attributes. This is the important part, where nature of the attributes are precised:

out = Launcher.TOutputFileKey("_output_multitype_mt_Key_.dat");
out.addAttribute(DataServer.TAttribute("w1",DataServer.TAttribute.kString));
out.addAttribute(DataServer.TAttribute("w2",DataServer.TAttribute.kString));
out.addAttribute(DataServer.TAttribute("v1",DataServer.TAttribute.kVector));
out.addAttribute(DataServer.TAttribute("v2",DataServer.TAttribute.kVector));
out.addAttribute(DataServer.TAttribute("f1"));

The rest is very common and a pair plot is performed to check that the reading of the output went well (see following plot).

XIV.5.23.3. Graph

Figure XIV.39. Graph of the macro "launchCodeMultiTypeKey.py"

Graph of the macro "launchCodeMultiTypeKey.py"

XIV.5.24.  Macro "launchCodeMultiTypeKeyCondensate.py"

XIV.5.24.1. Objective

The objective of this macro is to test the case where vectors and strings are produced as outputs, using the code described in Section XIV.5.22.1, with a Key format, obtained by doing:

multitype -mtKey

The resulting output file, named _output_multitype_mt_Key_condensate_.dat looks like:

w1 = nine
v1 = [ -0.512095,0.039669,-1.3834,1.37667,0.220672,0.633267,1.37027,-0.765636 ]
v2 = [ 14.1981,14.0855,10.7848,9.45476,9.17308,6.60804,10.0711,14.1761,10.318,12.5095,15.6614,10.3452,9.41101,7.47887 ]
f1 = 32.2723
w2 = eight

It is a much more readable format than the previously defined one. Note that the vector-values are comma-separated without blanks. This has been discussed in Section IV.3.1.1 and is compulsory because of the way the files (in the Launcher module) are read.

XIV.5.24.2. Macro Uranie

"""
Example of multitype code launching with key (condensate) output format
"""
from rootlogon import ROOT, DataServer, Launcher, Sampler

# Create dataserver with the seed attribute
tds = DataServer.TDataServer("foo", "pouet")
tds.addAttribute(DataServer.TUniformDistribution("seed", 0, 100000))
tds.getAttribute("seed").setFileKey("multitype_input.dat", "",
                                    "%e", DataServer.TAttributeFileKey.kNewRow)

# Create DOE
tsam = Sampler.TSampling(tds, "lhs", 100)
tsam.generateSample()

# Precise output and create Code
out = Launcher.TOutputFileKey("_output_multitype_mt_Key_condensate_.dat")
out.addAttribute(DataServer.TAttribute("w1", DataServer.TAttribute.kString))
out.addAttribute(DataServer.TAttribute("w2", DataServer.TAttribute.kString))
out.addAttribute(DataServer.TAttribute("v1", DataServer.TAttribute.kVector))
out.addAttribute(DataServer.TAttribute("v2", DataServer.TAttribute.kVector))
out.addAttribute(DataServer.TAttribute("f1"))
# Specify that the output will be separated by commas and
# that [ and ] have to be considered as separator (== ignored)
out.setVectorProperties("[", ",", "]")

myc = Launcher.TCode(tds, "multitype -mtKey")
myc.addOutputFile(out)

# Create Launcher.TLauncher and run it
tlau = Launcher.TLauncher(tds, myc)
tlau.run()

# Produce control plot
Can = ROOT.TCanvas("Can", "Can", 10, 10, 1000, 800)
pad = ROOT.TPad("pad", "pad", 0, 0.03, 1, 1)
pad.Draw()
pad.cd()
tds.drawPairs("w1:v1:v2:f1:w2")

When looking at the code and comparing it to an usual launcher job, the organisation is completely transparent. Actually it is the exact same code as in Section XIV.5.24, up to this line:

##Specify that the output will be separated by commas and that [ and ] have to be considered as separator (== ignored)
out.setVectorProperties("[",",","]");

Thanks to this line, the output file parser will know that all vector values have to be read at once, and it will know how to separate them. This is the line to modify in order to go from key format describe in Section XIV.5.24 to a condensate one. The rest is very common and a pair plot is performed to check that the reading of the output went well (see following plot).

XIV.5.24.3. Graph

Figure XIV.40. Graph of the macro "launchCodeMultiTypeKeyCondensate.py"

Graph of the macro "launchCodeMultiTypeKeyCondensate.py"

XIV.5.25.  Macro "launchCodeMultiTypeDataServer.py"

XIV.5.25.1. Objective

The objective of this macro is to test the case where vectors and strings are produced as outputs, using the code described in Section XIV.5.22.1, with a DataServer format, obtained by doing:

multitype -mtDS

The resulting output file, named _output_multitype_mt_DataServer_.dat looks like:

#COLUMN_NAMES: w1|v1|v2|f1|w2
#COLUMN_TYPES: S|V|V|D|S

nine -0.512095,0.039669,-1.3834,1.37667,0.220672,0.633267,1.37027,-0.765636 14.1981,14.0855,10.7848,9.45476,9.17308,6.60804,10.0711,14.1761,10.318,12.5095,15.6614,10.3452,9.41101,7.47887 32.2723 eight

XIV.5.25.2. Macro Uranie

"""
Example of levelE code launching with dataserver output format
"""
from rootlogon import ROOT, DataServer, Launcher, Sampler

# Create dataserver with the seed attribute
tds = DataServer.TDataServer("foo", "pouet")
tds.addAttribute(DataServer.TUniformDistribution("seed", 0, 100000))
tds.getAttribute("seed").setFileKey("multitype_input.dat", "",
                                    "%e", DataServer.TAttributeFileKey.kNewRow)

# Create DOE
tsam = Sampler.TSampling(tds, "lhs", 100)
tsam.generateSample()

# Precise output and create Code
out = Launcher.TOutputFileDataServer("_output_multitype_mt_DataServer_.dat")
out.addAttribute(DataServer.TAttribute("w1", DataServer.TAttribute.kString))
out.addAttribute(DataServer.TAttribute("w2", DataServer.TAttribute.kString))
out.addAttribute(DataServer.TAttribute("v1", DataServer.TAttribute.kVector))
out.addAttribute(DataServer.TAttribute("v2", DataServer.TAttribute.kVector))
out.addAttribute(DataServer.TAttribute("f1"))
myc = Launcher.TCode(tds, "multitype -mtDS")
myc.addOutputFile(out)

# Create Launcher.TLauncher and run it
tlau = Launcher.TLauncher(tds, myc)
tlau.run()

# Produce control plot
Can = ROOT.TCanvas("Can", "Can", 10, 10, 1000, 800)
pad = ROOT.TPad("pad", "pad", 0, 0.03, 1, 1)
pad.Draw()
pad.cd()
tds.drawPairs("w1:v1:v2:f1:w2")

When looking at the code and comparing it to an usual launcher job, the organisation is completely transparent. A dataserver is created with a simple input (the seed) drawn as an uniform distribution. The design-of-experiments is generated and the TOutputFileDataServer is created and filled with new attributes. This is the important part, where nature of the attributes are precised:

out = Launcher.TOutputFileDataServer("_output_multitype_mt_DataServer_.dat");
out.addAttribute(DataServer.TAttribute("w1",DataServer.TAttribute.kString));
out.addAttribute(DataServer.TAttribute("w2",DataServer.TAttribute.kString));
out.addAttribute(DataServer.TAttribute("v1",DataServer.TAttribute.kVector));
out.addAttribute(DataServer.TAttribute("v2",DataServer.TAttribute.kVector));
out.addAttribute(DataServer.TAttribute("f1"));

The rest is very common and a pair plot is performed to check that the reading of the output went well (see following plot).

XIV.5.25.3. Graph

Figure XIV.41. Graph of the macro "launchCodeMultiTypeDataServer.py"

Graph of the macro "launchCodeMultiTypeDataServer.py"

XIV.5.26.  Macro "launchCodeMultiTypeColumn.py"

XIV.5.26.1. Objective

The objective of this macro is to test the case where vectors and strings are produced as outputs, using the code described in Section XIV.5.22.1, with a Column format, obtained by doing:

multitype -mtCol

The resulting output file, named _output_multitype_mt_Column_.dat looks like:

nine
-0.512095 0.039669 -1.3834 1.37667 0.220672 0.633267 1.37027 -0.765636
14.1981 14.0855 10.7848 9.45476 9.17308 6.60804 10.0711 14.1761 10.318 12.5095 15.6614 10.3452 9.41101 7.47887
32.2723
eight

XIV.5.26.2. Macro Uranie

"""
Example of multitype code launching with column output format
"""
from rootlogon import ROOT, DataServer, Launcher, Sampler

# Create dataserver with the seed attribute
tds = DataServer.TDataServer("foo", "pouet")
tds.addAttribute(DataServer.TUniformDistribution("seed", 0, 100000))
tds.getAttribute("seed").setFileKey("multitype_input.dat", "",
                                    "%e", DataServer.TAttributeFileKey.kNewRow)

# Create DOE
tsam = Sampler.TSampling(tds, "lhs", 100)
tsam.generateSample()

# Precise output and create Code
out = Launcher.TOutputFileColumn("_output_multitype_mt_Column_.dat")
out.addAttribute(DataServer.TAttribute("w1", DataServer.TAttribute.kString), 1)
out.addAttribute(DataServer.TAttribute("w2", DataServer.TAttribute.kString), 5)
out.addAttribute(DataServer.TAttribute("v1", DataServer.TAttribute.kVector), 2)
out.addAttribute(DataServer.TAttribute("v2", DataServer.TAttribute.kVector), 3)
out.addAttribute(DataServer.TAttribute("f1"), 4)
myc = Launcher.TCode(tds, "multitype -mtCol")
myc.addOutputFile(out)

# Create Launcher.TLauncher and run it
tlau = Launcher.TLauncher(tds, myc)
tlau.run()

# Produce control plot
Can = ROOT.TCanvas("Can", "Can", 10, 10, 1000, 800)
pad = ROOT.TPad("pad", "pad", 0, 0.03, 1, 1)
pad.Draw()
pad.cd()
tds.drawPairs("w1:v1:v2:f1:w2")

When looking at the code and comparing it to an usual launcher job, the organisation is completely transparent. A dataserver is created with a simple input (the seed) drawn as an uniform distribution. The design-of-experiments is generated and the TOutputFileColumn is created and filled with new attributes. This is the important part, where nature of the attributes are precised:

out = Launcher.TOutputFileColumn("_output_multitype_mt_Column_.dat");
out.addAttribute(DataServer.TAttribute("w1",DataServer.TAttribute.kString),1);
out.addAttribute(DataServer.TAttribute("w2",DataServer.TAttribute.kString),5);
out.addAttribute(DataServer.TAttribute("v1",DataServer.TAttribute.kVector),2);
out.addAttribute(DataServer.TAttribute("v2",DataServer.TAttribute.kVector),3);
out.addAttribute(DataServer.TAttribute("f1"),4);

The rest is very common and a pair plot is performed to check that the reading of the output went well (see following plot).

XIV.5.26.3. Graph

Figure XIV.42. Graph of the macro "launchCodeMultiTypeColumn.py"

Graph of the macro "launchCodeMultiTypeColumn.py"

XIV.5.27.  Macro "launchCodeMultiTypeRow.py"

XIV.5.27.1. Objective

The objective of this macro is to test the case where vectors and strings are produced as outputs, using the code described in Section XIV.5.22.1, with a Row format, obtained by doing:

multitype -mtRow

When requesting a "row" type output, extra caution has to be taken: the usual separator between two fields are blank and/or tabulation. With this formatting, an output can look like this:

1.234  4.321  5.653
5.321
	  

With this kind of file, it is impossible to know which attributes own the element on the second line (in other words, if it should have been, first, second or third column). The proposed solution is to change the separator between field, using any specific sign, followed by a blank. This is done using ";" and it results in an output file, named _output_multitype_mt_Row_.dat which looks like:

nine; -0.512095; 14.1981; 32.2723; eight
; 0.039669; 14.0855; ; ; 
; -1.3834; 10.7848; ; ; 
; 1.37667; 9.45476; ; ; 
; 0.220672; 9.17308; ; ; 
; 0.633267; 6.60804; ; ; 
; 1.37027; 10.0711; ; ; 
; -0.765636; 14.1761; ; ; 
; ; 10.318; ; ; 
; ; 12.5095; ; ; 
; ; 15.6614; ; ; 
; ; 10.3452; ; ; 
; ; 9.41101; ; ; 
; ; 7.47887; ; ; 

XIV.5.27.2. Macro Uranie

"""
Example of multitype code launching with row output format
"""
from rootlogon import ROOT, DataServer, Launcher, Sampler

# Create dataserver with the seed attribute
tds = DataServer.TDataServer("foo", "pouet")
tds.addAttribute(DataServer.TUniformDistribution("seed", 0, 100000))
tds.getAttribute("seed").setFileKey("multitype_input.dat", "",
                                    "%e", DataServer.TAttributeFileKey.kNewRow)

# Create DOE
tsam = Sampler.TSampling(tds, "lhs", 100)
tsam.generateSample()

# Precise output and create Code
out = Launcher.TOutputFileRow("_output_multitype_mt_Row_.dat")
out.setFieldSeparatorCharacter(";")
out.addAttribute(DataServer.TAttribute("w1", DataServer.TAttribute.kString))
out.addAttribute(DataServer.TAttribute("v1", DataServer.TAttribute.kVector))
out.addAttribute(DataServer.TAttribute("v2", DataServer.TAttribute.kVector))
out.addAttribute(DataServer.TAttribute("f1"))
out.addAttribute(DataServer.TAttribute("w2", DataServer.TAttribute.kString))
myc = Launcher.TCode(tds, "multitype -mtRow")
myc.addOutputFile(out)

# Create Launcher.TLauncher and run it
tlau = Launcher.TLauncher(tds, myc)
tlau.run()

# Produce control plot
Can = ROOT.TCanvas("Can", "Can", 10, 10, 1000, 800)
pad = ROOT.TPad("pad", "pad", 0, 0.03, 1, 1)
pad.Draw()
pad.cd()
tds.drawPairs("w1:v1:v2:f1:w2")

When looking at the code and comparing it to an usual launcher job, the organisation is completely transparent. A dataserver is created with a simple input (the seed) drawn as an uniform distribution. The design-of-experiments is generated and the TOutputFileRow is created and filled with new attributes. This is the important part, where nature of the attributes are precised:

out = Launcher.TOutputFileRow("_output_multitype_mt_Row_.dat");
out.setFieldSeparatorCharacter(";");
out.addAttribute(DataServer.TAttribute("w1",DataServer.TAttribute.kString));
out.addAttribute(DataServer.TAttribute("v1",DataServer.TAttribute.kVector));
out.addAttribute(DataServer.TAttribute("v2",DataServer.TAttribute.kVector));
out.addAttribute(DataServer.TAttribute("f1"));
out.addAttribute(DataServer.TAttribute("w2",DataServer.TAttribute.kString));

The second line is important as it explains the TOutputFileRow object how to read the file to know that some fields are empty. The rest is very common and a pair plot is performed to check that the reading of the output went well (see following plot).

XIV.5.27.3. Graph

Figure XIV.43. Graph of the macro "launchCodeMultiTypeRow.py"

Graph of the macro "launchCodeMultiTypeRow.py"

XIV.5.28.  Macro "launchCodeMultiTypeXML.py"

XIV.5.28.1. Objective

The objective of this macro is to test the case where vectors and strings are produced as outputs, using the code described in Section XIV.5.22.1, with a XML format, obtained by doing:

multitype -mtXML

The resulting output file is named _output_multitype_mt_.xml and looks like:

<?xml version="1.0" encoding="iso-8859-1"?>
<multitypeMT>
 <w1 value="nine"/>
 <v1 n="8">
  <values>
    -0.512095 0.039669 -1.3834 1.37667 0.220672 0.633267 1.37027 -0.765636
  </values>
 </v1>
 <v2 n="14">
  <values>
    14.1981 14.0855 10.7848 9.45476 9.17308 6.60804 10.0711 14.1761 10.318 12.5095 15.6614 10.3452 9.41101 7.47887
  </values>
 </v2>
 <f1 value="32.2723"/>
 <w2 value="eight"/>
</multitypeMT>

XIV.5.28.2. Macro Uranie

"""
Example of multitype code launching with XML output format
"""
from rootlogon import ROOT, DataServer, Launcher, Sampler

# Create dataserver with the seed attribute
tds = DataServer.TDataServer("foo", "pouet")
tds.addAttribute(DataServer.TUniformDistribution("seed", 0, 100000))
tds.getAttribute("seed").setFileKey("multitype_input.dat", "",
                                    "%e", DataServer.TAttributeFileKey.kNewRow)

# Create DOE
tsam = Sampler.TSampling(tds, "lhs", 100)
tsam.generateSample()

# Precise output and create Code
out = Launcher.TOutputFileXML("_output_multitype_mt_.xml")
AttIn = DataServer.TAttributeFileKey.kXMLAttribute
FieIn = DataServer.TAttributeFileKey.kXMLField
out.addAttribute(DataServer.TAttribute("w1", DataServer.TAttribute.kString),
                 "/multitypeMT/w1/@value", AttIn)
out.addAttribute(DataServer.TAttribute("w2", DataServer.TAttribute.kString),
                 "/multitypeMT/w2/@value", AttIn)
out.addAttribute(DataServer.TAttribute("v1", DataServer.TAttribute.kVector),
                 "/multitypeMT/v1/values", FieIn)
out.addAttribute(DataServer.TAttribute("v2", DataServer.TAttribute.kVector),
                 "/multitypeMT/v2/values", FieIn)
out.addAttribute(DataServer.TAttribute("f1"),
                 "/multitypeMT/f1/@value", AttIn)

myc = Launcher.TCode(tds, "multitype -mtXML")
myc.addOutputFile(out)

# Create Launcher.TLauncher and run it
tlau = Launcher.TLauncher(tds, myc)
tlau.run()

# Produce control plot
Can = ROOT.TCanvas("Can", "Can", 10, 10, 1000, 800)
pad = ROOT.TPad("pad", "pad", 0, 0.03, 1, 1)
pad.Draw()
pad.cd()
tds.drawPairs("w1:v1:v2:f1:w2")

When looking at the code and comparing it to an usual launcher job, the organisation is completely transparent. A dataserver is created with a simple input (the seed) drawn as an uniform distribution. The design-of-experiments is generated and the TOutputFileXML is created and filled with new attributes. This is the important part, where nature of the attributes are precised:

out = Launcher.TOutputFileXML("_output_multitype_mt_.xml");
out.addAttribute(DataServer.TAttribute("w1",DataServer.TAttribute.kString), "/multitypeMT/w1/@value", DataServer.TAttributeFileKey.kXMLAttribute );
out.addAttribute(DataServer.TAttribute("w2",DataServer.TAttribute.kString), "/multitypeMT/w2/@value", DataServer.TAttributeFileKey.kXMLAttribute );
out.addAttribute(DataServer.TAttribute("v1",DataServer.TAttribute.kVector), "/multitypeMT/v1/values", DataServer.TAttributeFileKey.kXMLField );
out.addAttribute(DataServer.TAttribute("v2",DataServer.TAttribute.kVector), "/multitypeMT/v2/values", DataServer.TAttributeFileKey.kXMLField );
out.addAttribute(DataServer.TAttribute("f1"),                     "/multitypeMT/f1/@value", DataServer.TAttributeFileKey.kXMLAttribute );

The second line is important as it explains the TOutputFileXML object how to read the file to know that some fields are empty. The rest is very common and a pair plot is performed to check that the reading of the output went well (see following plot).

XIV.5.28.3. Graph

Figure XIV.44. Graph of the macro "launchCodeMultiTypeXML.py"

Graph of the macro "launchCodeMultiTypeXML.py"

XIV.5.29.  Macro "launchCodeReadMultiTypeKey.py"

XIV.5.29.1. Objective

The objective of this macro is to test the case where vectors and strings are used as inputs, using the code described in Section XIV.5.22.2, with a Key format, obtained by doing:

multitype -ReadmtKey

The input values will be read from a database which is produced with the multitype -mt code, as no sampling is available yet to produce vectors and strings. The database file is readmultitype_sampling.dat which looks like this:

#NAME: foo
#TITLE: TDS for flowrate
#DATE: Mon Oct  3 23:50:34 2016
#COLUMN_NAMES: v1| w1| v2| w2| f1| foo__n__iter__
#COLUMN_TYPES: V|S|V|S|D|D

-6.901933299378e-02,-1.292435959913e-01,4.558876683004e-01,5.638486368789e-01,-4.767582766745e-02,7.102109543136e-03,2.819049677902e-01,-2.019788081790e+00,-2.604401028584e+00,-1.617682380292e+00,2.894560949798e-02,-3.493905850261e-01 six 1.142449011404e+01,7.318948216271e+00,1.502260859231e+01,6.041193793062e+00,6.729445145907e+00,1.128096968597e+01 zero 3.425632316777e+01 0.000000000000e+00 
-6.923200061823e-01,-4.798721931875e-01,-1.329893204384e+00,1.292933726829e+00 zero 1.249911290435e+01,6.309239169117e+00,1.596653626442e+01,5.500878012739e+00,1.322535550082e+01,7.070984389647e+00,1.708574150702e+00,1.265915339220e+01 two 4.295175025115e+01 1.000000000000e+00 
5.773813268848e-01,-3.512405673973e-01,-6.870089014992e-01,1.273074555211e-01 nine 1.242682578759e+01,1.109680842701e+01,1.670410641828e+01,7.296321908492e+00,8.732800753443e+00,1.262906549132e+01,8.882310687564e+00,1.104280818003e+01 five 5.591437936893e+01 2.000000000000e+00 
5.518508915499e-01,2.438158138873e-01,1.111784497742e+00,-1.517566514667e+00,7.146879916125e-01,2.328439269321e+00,-1.251913839951e+00,8.876684186954e-01,-1.383023165632e+00,-8.192089693621e-01,-1.079524713568e-01,6.595650273375e-01,-2.275345802432e-03,1.304354557600e+00 nine 1.021975159505e+01,4.995433740783e+00,1.108628156181e+01,1.041110604995e+01,1.111365770153e+01,6.365695806343e+00,6.374053973239e+00,6.854423942510e+00,7.144262333164e+00 two 4.093776591421e+01 3.000000000000e+00 
2.403942476958e-01,6.868091212609e-01,-1.561012830108e+00,1.937806684989e+00,-1.465851888061e+00,5.367279844359e-02,-1.263005327899e+00,-1.132259472701e+00 two 7.382048319627e+00,5.874867917970e+00,1.158191378461e+01,1.073321314846e+01 six 6.980549752305e+01 4.000000000000e+00 
2.220485143391e+00,-5.787212569267e-01,8.843648237689e-01,2.020662891124e+00,1.066403357312e+00,-5.817432767992e-01,3.063023900800e-01,-7.393588637933e-01 two 2.049656723853e+00,9.679003878866e+00,7.338089623518e+00,1.235630702472e+01,1.509238505697e+01,1.034077492413e+01,1.116077550501e+01,7.179221834787e+00,1.582041236432e+01,9.204085091129e+00,4.707490792498e+00,1.618155764288e+01 five 3.507773555061e+01 5.000000000000e+00 
8.908373817765e-01,-2.446355046704e-01,-1.900125532005e+00 seven 1.351254851860e+01,9.297087139459e+00,1.130966904782e+01,1.219245848701e+01,1.012996566249e+01,7.150071600452e+00,1.097549218518e+01,1.443074761657e+01 five 4.464560504112e+01 6.000000000000e+00 
-2.514644600888e+00,1.633579305804e+00 one 1.229098312451e+01,1.013486836958e+01,1.243386772880e+01,1.071783135260e+01,1.453735777922e+01,7.995593455015e+00,9.753966962919e+00,5.924583770352e+00,6.187713988125e+00,1.061975242996e+01,6.650425922126e+00 four 4.553396475968e+01 7.000000000000e+00 
-1.347811599520e+00,-1.259450135534e+00,1.812553405758e+00 five 7.717018655412e+00,1.053283796180e+01,7.404059210327e+00 eight 6.695868880279e+01 8.000000000000e+00 
-1.258360863204e-01,-9.000566818602e-01,7.039146852797e-01,1.015917277706e+00,-2.397650482929e-01 four 4.346717386417e+00,1.033024889324e+01,7.183787459050e+00,8.742095837835e+00,1.277095440277e+01,8.685683828779e+00,9.321006265935e+00,6.353438157123e+00,8.552570119034e+00 six 4.381313066586e+01 9.000000000000e+00 

For every pattern, an input file is created with the Key condensate format, as the other key format is not practical (and usable). This input file looks like this:

w1 = nine
v1 = [ -0.512095,0.039669,-1.3834,1.37667,0.220672,0.633267,1.37027,-0.765636 ]
v2 = [ 14.1981,14.0855,10.7848,9.45476,9.17308,6.60804,10.0711,14.1761,10.318,12.5095,15.6614,10.3452,9.41101,7.47887 ]
f1 = 32.2723
w2 = eight

The resulting output file, named _output_multitype_readmt_Key_.dat looks like:

thev1 = -0.2397650482929
thev2 = 9.321006265935

XIV.5.29.2. Macro Uranie

"""
Example of readmultitype code launching with key output format
"""
from rootlogon import ROOT, DataServer, Launcher

# Create dataserver with a database of 10 runs of the "multitype -mt" code
tds = DataServer.TDataServer("foo", "pouet")
tds.fileDataRead("readmultitype_sampling.dat")

# Explain the name of the input file and the format chosen
inFile = "_output_multitype_mt_Key_condensate_.dat"
inType = DataServer.TAttributeFileKey.kNewKey
tds.getAttribute("w1").setFileKey(inFile, "", "%e", inType)
tds.getAttribute("v1").setFileKey(inFile, "", "%e", inType)
tds.getAttribute("v2").setFileKey(inFile, "", "%e", inType)
tds.getAttribute("f1").setFileKey(inFile, "", "%e", inType)
tds.getAttribute("w2").setFileKey(inFile, "", "%e", inType)

# Create the Class that will handle re-writting the input file
FullinFile = ROOT.gSystem.PrependPathName(ROOT.gSystem.pwd(), inFile)
inFile = Launcher.TInputFileRecreate(FullinFile)

# Add attribute in the correct (needed) order
inFile.addAttribute(tds.getAttribute("w1"))
inFile.addAttribute(tds.getAttribute("v1"))
inFile.addAttribute(tds.getAttribute("v2"))
inFile.addAttribute(tds.getAttribute("f1"))
inFile.addAttribute(tds.getAttribute("w2"))
inFile.setVectorProperties("[", ",", "]")  # Change the vector properties

# Create the output file interface and state that there will be 2 outputs
out = Launcher.TOutputFileKey("_output_multitype_readmt_Key_.dat")
out.addAttribute(DataServer.TAttribute("thev1"))
out.addAttribute(DataServer.TAttribute("thev2"))

# Create the corresponding interface to code
tc1 = Launcher.TCode(tds, "multitype -ReadmtKey")
tc1.addInputFile(inFile)
tc1.addOutputFile(out)

# Create the launcher and run the code
tl1 = Launcher.TLauncher(tds, tc1)
tl1.run()

tds.Scan("thev1:thev2")

When looking at the code and comparing it to an usual launcher job, the organisation is completely transparent. A dataserver is created by reading an input file readmultitype_sampling.dat in which 10 events are stored. The main difference arises from the way the input file is created: it is done explicitly because the order in which the attributes are stored in the database file are not the one needed by the code in the input file (this case is discussed in Section IV.3.1.1). The name of the file given in the construction has to be absolute, as the TCode object will check this in order to know whether the input file should be created.

##Create the Class that will handle re-writing the input file
inFile = Launcher.TInputFileRecreate(ROOT.gSystem.PrependPathName(ROOT.gSystem.pwd(),ROOT.TString("_output_multitype_mt_Key_condensate_.dat")))

## Add attribute in the correct (needed) order
inFile.addAttribute( tds.getAttribute("w1") );
inFile.addAttribute( tds.getAttribute("v1") );
inFile.addAttribute( tds.getAttribute("v2") );
inFile.addAttribute( tds.getAttribute("f1") );
inFile.addAttribute( tds.getAttribute("w2") );
inFile.setVectorProperties("[",",","]"); ## Change the vector properties  

Moreover, an extra line is added to specify that the Key format is a condensate one, so that Uranie knows how to deal with vectors and strings specific case (only vectors here). The rest is very common and a screenshot of the result displayed in console is provided in the following subsection.

XIV.5.29.3. Console

Processing launchCodeReadMultiTypeKey.py...
************************************
*    Row   *     thev1 *     thev2 *
************************************
*        0 * 0.2819049 * 11.424490 *
*        1 * -0.692320 * 15.966536 *
*        2 * -12345678 * 12.629065 *
*        3 * -0.819208 * 11.086281 *
*        4 * -1.561012 * -12345678 *
*        5 * 0.8843648 * 10.340774 *
*        6 * -12345678 * 7.1500716 *
*        7 * 1.6335793 * 14.537357 *
*        8 * -12345678 * -12345678 *
*        9 * -0.239765 * 9.3210062 *
************************************

XIV.5.30.  Macro "launchCodeReadMultiTypeDataServer.py"

XIV.5.30.1. Objective

The objective of this macro is to test the case where vectors and strings are used as inputs, using the code described in Section XIV.5.22.2, with a DataServer format, obtained by doing:

multitype -ReadmtDS

. The input values will be read from a database which is produced with the multitype -mt code, as no sampling is available yet to produce vectors and strings. The database file is readmultitype_sampling.dat which is shown in Section XIV.5.29.1. For every pattern, an input file will be created with the DataServer format. This input file looks like this:

#COLUMN_NAMES: w1|v1|v2|f1|w2
#COLUMN_TYPES: S|V|V|D|S

nine -0.512095,0.039669,-1.3834,1.37667,0.220672,0.633267,1.37027,-0.765636 14.1981,14.0855,10.7848,9.45476,9.17308,6.60804,10.0711,14.1761,10.318,12.5095,15.6614,10.3452,9.41101,7.47887 32.2723 eight

The resulting output file, named _output_multitype_readmt_DataServer_.dat looks like:

#COLUMN_NAMES: thev1|thev2
#COLUMN_TYPES: D|D

-0.2397650482929 9.321006265935

XIV.5.30.2. Macro Uranie

"""
Example of readmultitype code launching with dataserver output format
"""
from rootlogon import ROOT, DataServer, Launcher

# Create dataserver with a database of 10 runs of the "multitype -mt" code
tds = DataServer.TDataServer("foo", "pouet")
tds.fileDataRead("readmultitype_sampling.dat")

# Explain the name of the input file and the format chosen
inFile = "_output_multitype_mt_DataServer_.dat"
inType = DataServer.TAttributeFileKey.kNewTDS
tds.getAttribute("w1").setFileKey(inFile, "", "%e", inType)
tds.getAttribute("v1").setFileKey(inFile, "", "%e", inType)
tds.getAttribute("v2").setFileKey(inFile, "", "%e", inType)
tds.getAttribute("f1").setFileKey(inFile, "", "%e", inType)
tds.getAttribute("w2").setFileKey(inFile, "", "%e", inType)

# Create the Class that will handle re-writting the input file
FullinFile = ROOT.gSystem.PrependPathName(ROOT.gSystem.pwd(), inFile)
inFile = Launcher.TInputFileRecreate(FullinFile)

# Add attribute in the correct (needed) order
inFile.addAttribute(tds.getAttribute("w1"))
inFile.addAttribute(tds.getAttribute("v1"))
inFile.addAttribute(tds.getAttribute("v2"))
inFile.addAttribute(tds.getAttribute("f1"))
inFile.addAttribute(tds.getAttribute("w2"))

# Create the output file interface and state that there will be 2 outputs
OutName = "_output_multitype_readmt_DataServer_.dat"
out = Launcher.TOutputFileDataServer(OutName)
out.addAttribute(DataServer.TAttribute("thev1"))
out.addAttribute(DataServer.TAttribute("thev2"))

# Create the corresponding interface to code
tc1 = Launcher.TCode(tds, "multitype -ReadmtDS")
tc1.addInputFile(inFile)
tc1.addOutputFile(out)

# Create the launcher and run the code
tl1 = Launcher.TLauncher(tds, tc1)
tl1.run()

tds.Scan("thev1:thev2")

When looking at the code and comparing it to an usual launcher job, the organisation is completely transparent. A dataserver is created by reading an input file readmultitype_sampling.dat in which 10 events are stored. The main difference arises from the way the input file is created: it is done explicitly because the order in which the attributes are stored in the database file are not the one needed by the code in the input file (this case is discussed in Section IV.3.1.1). The name of the file given in the construction has to be absolute, as the TCode object will check this in order to know whether the input file should be created.

##Create the Class that will handle re-writing the input file
inFile=Launcher.TInputFileRecreate(ROOT.gSystem.PrependPathName(ROOT.gSystem.pwd(),ROOT.TString("_output_multitype_mt_DataServer_.dat")));

## Add attribute in the correct (needed) order
inFile.addAttribute( tds.getAttribute("w1") );
inFile.addAttribute( tds.getAttribute("v1") );
inFile.addAttribute( tds.getAttribute("v2") );
inFile.addAttribute( tds.getAttribute("f1") );
inFile.addAttribute( tds.getAttribute("w2") );

The rest is very common and a screenshot of the result displayed in console is provided in the following subsections.

XIV.5.30.3. Console

Processing launchCodeReadMultiTypeDataServer.py...
************************************
*    Row   *     thev1 *     thev2 *
************************************
*        0 * 0.2819049 * 11.424490 *
*        1 * -0.692320 * 15.966536 *
*        2 * -12345678 * 12.629065 *
*        3 * -0.819208 * 11.086281 *
*        4 * -1.561012 * -12345678 *
*        5 * 0.8843648 * 10.340774 *
*        6 * -12345678 * 7.1500716 *
*        7 * 1.6335793 * 14.537357 *
*        8 * -12345678 * -12345678 *
*        9 * -0.239765 * 9.3210062 *
************************************

XIV.5.31.  Macro "launchCodeReadMultiTypeColumn.py"

XIV.5.31.1. Objective

The objective of this macro is to test the case where vectors and strings are used as inputs, using the code described in Section XIV.5.22.2, with a Column format, obtained by doing:

multitype -ReadmtCol

The input values will be read from a database which is produced with the multitype -mt code, as no sampling is available yet to produce vectors and strings. The database file is readmultitype_sampling.dat which is shown in Section XIV.5.29.1. For every pattern, an input file will be created with the Column format. This input file looks like this:

nine
-0.512095 0.039669 -1.3834 1.37667 0.220672 0.633267 1.37027 -0.765636
14.1981 14.0855 10.7848 9.45476 9.17308 6.60804 10.0711 14.1761 10.318 12.5095 15.6614 10.3452 9.41101 7.47887
32.2723
eight

The resulting output file, named _output_multitype_readmt_Column_.dat looks like:

-0.2397650482929
9.321006265935

XIV.5.31.2. Macro Uranie

"""
Example of readmultitype code launching with column output format
"""
from rootlogon import ROOT, DataServer, Launcher

# Create dataserver with a database of 10 runs of the "multitype -mt" code
tds = DataServer.TDataServer("foo", "pouet")
tds.fileDataRead("readmultitype_sampling.dat")

# Explain the name of the input file and the format chosen
InFile = "_output_multitype_mt_Column_.dat"
InType = DataServer.TAttributeFileKey.kNewColumn
tds.getAttribute("w1").setFileKey(InFile, "", "%e", InType)
tds.getAttribute("v1").setFileKey(InFile, "", "%e", InType)
tds.getAttribute("v2").setFileKey(InFile, "", "%e", InType)
tds.getAttribute("f1").setFileKey(InFile, "", "%e", InType)
tds.getAttribute("w2").setFileKey(InFile, "", "%e", InType)

# Create the Class that will handle re-writting the input file
FullFileName = ROOT.gSystem.PrependPathName(ROOT.gSystem.pwd(), InFile)
inFile = Launcher.TInputFileRecreate(FullFileName)

# Add attribute in the correct (needed) order
inFile.addAttribute(tds.getAttribute("w1"))
inFile.addAttribute(tds.getAttribute("v1"))
inFile.addAttribute(tds.getAttribute("v2"))
inFile.addAttribute(tds.getAttribute("f1"))
inFile.addAttribute(tds.getAttribute("w2"))

# Create the output file interface and state that there will be 2 outputs
out = Launcher.TOutputFileColumn("_output_multitype_readmt_Column_.dat")
out.addAttribute(DataServer.TAttribute("thev1"))
out.addAttribute(DataServer.TAttribute("thev2"))

# Create the corresponding interface to code
tc1 = Launcher.TCode(tds, "multitype -ReadmtCol")
tc1.addInputFile(inFile)
tc1.addOutputFile(out)

# Create the launcher and run the code
tl1 = Launcher.TLauncher(tds, tc1)
tl1.run()

tds.Scan("thev1:thev2")

When looking at the code and comparing it to an usual launcher job, the organisation is completely transparent. A dataserver is created by reading an input file readmultitype_sampling.dat in which 10 events are stored. The main difference arises from the way the input file is created: it is done explicitly because the order in which the attributes are stored in the database file are not the one needed by the code in the input file (this case is discussed in Section IV.3.1.1). The name of the file given in the construction has to be absolute, as the TCode object will check this in order to know whether the input file should be created.

##Create the Class that will handle re-writing the input file
inFile=Launcher.TInputFileRecreate(ROOT.gSystem.PrependPathName(ROOT.gSystem.pwd(),ROOT.TString("_output_multitype_mt_Column_.dat")));

## Add attribute in the correct (needed) order
inFile.addAttribute( tds.getAttribute("w1") );
inFile.addAttribute( tds.getAttribute("v1") );
inFile.addAttribute( tds.getAttribute("v2") );
inFile.addAttribute( tds.getAttribute("f1") );
inFile.addAttribute( tds.getAttribute("w2") );

The rest is very common and a screenshot of the result displayed in console is provided in the following subsection.

XIV.5.31.3. Console

Processing launchCodeReadMultiTypeColumn.py...
************************************
*    Row   *     thev1 *     thev2 *
************************************
*        0 * 0.2819049 * 11.424490 *
*        1 * -0.692320 * 15.966536 *
*        2 * -12345678 * 12.629065 *
*        3 * -0.819208 * 11.086281 *
*        4 * -1.561012 * -12345678 *
*        5 * 0.8843648 * 10.340774 *
*        6 * -12345678 * 7.1500716 *
*        7 * 1.6335793 * 14.537357 *
*        8 * -12345678 * -12345678 *
*        9 * -0.239765 * 9.3210062 *
************************************

XIV.5.32.  Macro "launchCodeReadMultiTypeRow.py"

XIV.5.32.1. Objective

The objective of this macro is to test the case where vectors and strings are used as inputs, using the code described in Section XIV.5.22.2, with a Row format, obtained by doing:

multitype -ReadmtRow

The input values will be read from a database which has been produced with the multitype -mt code, as no sampling is available yet to produce vectors and strings. The database file is readmultitype_sampling.dat which is shown in Section XIV.5.29.1. For every pattern, an input file will be created with the Row format. This input file is very peculiar as the number of entries per attribute is not equal going from attribute to another (this format is not recommended as discussed in the third item of Section IV.3.1.2.3). It will look like this:

nine; -0.512095; 14.1981; 32.2723; eight
; 0.039669; 14.0855; ; ; 
; -1.3834; 10.7848; ; ; 
; 1.37667; 9.45476; ; ; 
; 0.220672; 9.17308; ; ; 
; 0.633267; 6.60804; ; ; 
; 1.37027; 10.0711; ; ; 
; -0.765636; 14.1761; ; ; 
; ; 10.318; ; ; 
; ; 12.5095; ; ; 
; ; 15.6614; ; ; 
; ; 10.3452; ; ; 
; ; 9.41101; ; ; 
; ; 7.47887; ; ; 

The resulting output file, named _output_multitype_readmt_Row_.dat, looks like:

-0.2397650482929; 9.321006265935

XIV.5.32.2. Macro Uranie

"""
Example of readmultitype code launching with row output format
"""
from rootlogon import ROOT, DataServer, Launcher

# Create dataserver with a database of 10 runs of the "multitype -mt" code
tds = DataServer.TDataServer("foo", "pouet")
tds.fileDataRead("readmultitype_sampling.dat")

# Explain the name of the input file and the format chosen
inFile = "_output_multitype_mt_Row_.dat"
inType = DataServer.TAttributeFileKey.kNewRow
tds.getAttribute("w1").setFileKey(inFile, "", "%e", inType)
tds.getAttribute("v1").setFileKey(inFile, "", "%e", inType)
tds.getAttribute("v2").setFileKey(inFile, "", "%e", inType)
tds.getAttribute("f1").setFileKey(inFile, "", "%e", inType)
tds.getAttribute("w2").setFileKey(inFile, "", "%e", inType)

# Create the Class that will handle re-writting the input file
FullinFile = ROOT.gSystem.PrependPathName(ROOT.gSystem.pwd(), inFile)
inFile = Launcher.TInputFileRecreate(FullinFile)

# Add attribute in the correct (needed) order
inFile.addAttribute(tds.getAttribute("w1"))
inFile.addAttribute(tds.getAttribute("v1"))
inFile.addAttribute(tds.getAttribute("v2"))
inFile.addAttribute(tds.getAttribute("f1"))
inFile.addAttribute(tds.getAttribute("w2"))
inFile.setFieldSeparatorCharacter("; ")  # Change the separator

# Create the output file interface and state that there will be 2 outputs
out = Launcher.TOutputFileRow("_output_multitype_readmt_Row_.dat")
out.addAttribute(DataServer.TAttribute("thev1"))
out.addAttribute(DataServer.TAttribute("thev2"))

# Create the corresponding interface to code
tc1 = Launcher.TCode(tds, "multitype -ReadmtRow")
tc1.addInputFile(inFile)
tc1.addOutputFile(out)

# Create the launcher and run the code
tl1 = Launcher.TLauncher(tds, tc1)
tl1.run()

tds.Scan("thev1:thev2")

When looking at the code and comparing it to an usual launcher job, the organisation is completely transparent. A dataserver is created by reading an input file readmultitype_sampling.dat in which 10 events are stored. The main difference arises from the way the input file is created: it is done explicitly because the order in which the attributes are stored in the database file are not the one needed by the code in the input file (this case is discussed in Section IV.3.1.1). The name of the file given in the construction has to be absolute, as the TCode object will check this in order to know whether the input file should be created.

##Create the Class that will handle re-writing the input file
inFile=Launcher.TInputFileRecreate( ROOT.gSystem.PrependPathName(ROOT.gSystem.pwd(),ROOT.TString("_output_multitype_mt_Row_.dat")));
          
## Add attribute in the correct (needed) order
inFile.addAttribute( tds.getAttribute("w1") );
inFile.addAttribute( tds.getAttribute("v1") );
inFile.addAttribute( tds.getAttribute("v2") );
inFile.addAttribute( tds.getAttribute("f1") );
inFile.addAttribute( tds.getAttribute("w2") );
inFile.setFieldSeparatorCharacter("; "); ## Change the separator

When requesting a "Row" type input, extra caution has to be taken: the usual separator between two fields are blank and/or tabulation. With this formatting, an input can look like this:

1.234  4.321  5.653
5.321

With this kind of file, it is impossible to know which attributes own the element on the second line (in other words, if it should have been, first, second or third column). The proposed solution is to change the separator between field, using any specific sign, followed by a blank. This is done using ";" and it is shown as the last line in previous code. The rest is very common and a screenshot of the result displayed in console is provided in the following subsection.

XIV.5.32.3. Console

Processing launchCodeReadMultiTypeRow.py...
************************************
*    Row   *     thev1 *     thev2 *
************************************
*        0 * 0.2819049 * 11.424490 *
*        1 * -0.692320 * 15.966536 *
*        2 * -12345678 * 12.629065 *
*        3 * -0.819208 * 11.086281 *
*        4 * -1.561012 * -12345678 *
*        5 * 0.8843648 * 10.340774 *
*        6 * -12345678 * 7.1500716 *
*        7 * 1.6335793 * 14.537357 *
*        8 * -12345678 * -12345678 *
*        9 * -0.239765 * 9.3210062 *
************************************

XIV.5.33.  Macro "launchCodeReadMultiTypeXML.py"

XIV.5.33.1. Objective

The objective of this macro is to test the case where vectors and strings are used as inputs, using the code described in Section XIV.5.22.2, with a XML format, obtained by doing:

multitype -ReadmtXML

The input values will be read from a database which is produced with the multitype -mt code, as no sampling is available yet to produce vectors and strings. The database file is readmultitype_sampling.dat which is shown in Section XIV.5.29.1. For every pattern, an input file will be created with the XML format. This input file looks like this:

<?xml version="1.0" encoding="iso-8859-1"?>
<multitypeMT>
 <w1 value="nine"/>
 <v1 n="8">
  <values>
    -0.512095 0.039669 -1.3834 1.37667 0.220672 0.633267 1.37027 -0.765636
  </values>
 </v1>
 <v2 n="14">
  <values>
    14.1981 14.0855 10.7848 9.45476 9.17308 6.60804 10.0711 14.1761 10.318 12.5095 15.6614 10.3452 9.41101 7.47887
  </values>
 </v2>
 <f1 value="32.2723"/>
 <w2 value="eight"/>
</multitypeMT>

The resulting output file is named _output_multitype_readmt_.xml and looks like:

<?xml version="1.0" encoding="iso-8859-1"?>
<multitypeREADMT>
 <thev1 value="-0.2397650482929"/>
 <thev2 value="9.321006265935"/>
</multitypeREADMT>

XIV.5.33.2. Macro Uranie

"""
Example of readmultitype code launching with XML output format
"""
from rootlogon import ROOT, DataServer, Launcher

# Create dataserver with a database of 10 runs of the "multitype -mt" code
tds = DataServer.TDataServer("foo", "pouet")
tds.fileDataRead("readmultitype_sampling.dat")

# Produce the input files
ROOT.gSystem.Exec("multitype -mtXML")

# Explain the name of the input file and the format chosen
inFile = "_output_multitype_mt_.xml"
AttType = DataServer.TAttributeFileKey.kXMLAttribute
FieType = DataServer.TAttributeFileKey.kXMLField
tds.getAttribute("w1").setFileKey(inFile, "w1/@value", "", AttType)
tds.getAttribute("v1").setFileKey(inFile, "v1/values", "", FieType)
tds.getAttribute("v2").setFileKey(inFile, "v2/values", "", FieType)
tds.getAttribute("f1").setFileKey(inFile, "f1/@value", "", AttType)
tds.getAttribute("w2").setFileKey(inFile, "w2/@value", "", AttType)

# Create the Class that will handle re-writting the input file
FullinFile = ROOT.gSystem.PrependPathName(ROOT.gSystem.pwd(), inFile)
inFile = Launcher.TInputFileXML(FullinFile)

# Add attribute in the correct (needed) order
inFile.addAttribute(tds.getAttribute("w1"))
inFile.addAttribute(tds.getAttribute("v1"))
inFile.addAttribute(tds.getAttribute("v2"))
inFile.addAttribute(tds.getAttribute("f1"))
inFile.addAttribute(tds.getAttribute("w2"))

# Create the output file interface and state that there will be 2 outputs
out = Launcher.TOutputFileXML("_output_multitype_readmt_.xml")
out.addAttribute(DataServer.TAttribute("thev1"),
                 "/flowrateREADMT/thev1/@value", AttType)
out.addAttribute(DataServer.TAttribute("thev2"),
                 "/flowrateREADMT/thev2/@value", AttType)

# Create the corresponding interface to code
tc1 = Launcher.TCode(tds, "multitype -ReadmtXML")
tc1.addInputFile(inFile)
tc1.addOutputFile(out)

# Create the launcher and run the code
tl1 = Launcher.TLauncher(tds, tc1)
tl1.run()

tds.Scan("thev1:thev2")

When looking at the code and comparing it to an usual launcher job, the organisation is completely transparent. A dataserver is created by reading an input file readmultitype_sampling.dat in which 10 events are stored. The main difference arises from the way the input file is created: it is done explicitly because the order in which the attributes are stored in the database file are not the one needed by the code in the input file (this case is discussed in Section IV.3.1.1). The name of the file given in the construction has to be absolute, as the TCode object will check this in order to know whether the input file should be created.

##Create the Class that will handle re-writing the input file
inFile=Launcher.TInputFileXML(ROOT.gSystem.PrependPathName(ROOT.gSystem.pwd(),ROOT.TString("_output_multitype_mt_.xml")));

## Add attribute in the correct (needed) order
inFile.addAttribute( tds.getAttribute("w1") );
inFile.addAttribute( tds.getAttribute("v1") );
inFile.addAttribute( tds.getAttribute("v2") );
inFile.addAttribute( tds.getAttribute("f1") );
inFile.addAttribute( tds.getAttribute("w2") );

The class of input file is not a TInputFileRecreate as an example of input file is needed. The class used is so the TInputFileXML and in order to be sure that this file exists, the code is called at first as following to produce the _output_multitype_mt_.xml.

##Produce the input files
gSystem.Exec("multitype -mtXML");

The rest is very common and a screenshot of the result displayed in console is provided in the following subsection.

XIV.5.33.3. Console

Processing launchCodeReadMultiTypeXML.py...
************************************
*    Row   *     thev1 *     thev2 *
************************************
*        0 * 1.2345678 * 1.2345678 *
*        1 * 1.2345678 * 1.2345678 *
*        2 * 1.2345678 * 1.2345678 *
*        3 * 1.2345678 * 1.2345678 *
*        4 * 1.2345678 * 1.2345678 *
*        5 * 1.2345678 * 1.2345678 *
*        6 * 1.2345678 * 1.2345678 *
*        7 * 1.2345678 * 1.2345678 *
*        8 * 1.2345678 * 1.2345678 *
*        9 * 1.2345678 * 1.2345678 *
************************************

XIV.5.34.  Macro "launchCodeFilesWithBlank.py"

XIV.5.34.1. Objective

The objective of this macro is to test the case where input and output key files are dfined with blank space in the key definition. This is a first attempt to overcome this situation and it will be using a newly-made code named withblank that deal with pressure and density of water in a brewery and take its input from the following file withblank_input.dat

water model.brewery pit pressure = 1E5 \\ Double  
I do like Chocolate
residual brew density model.factor for glass = 1E-2 \\ Double aussi

The code itself is meaningless as it only multiply by two (for the pressure) and by three (for the density) and these meaningless information are stored in the output file withblank_output.dat which also is the form of key file, in which the keys contains several blank space, as shown below

Test doubling.water model.brewery pit pressure = 10.55397966411 


 Bla Bla Bla 


Chocolat doubling.residual brew density model.factor for glass = 2.738635531741 

XIV.5.34.2. Macro Uranie

"""
Example of code launching when keys might contain blank
"""
from rootlogon import ROOT, DataServer, Launcher, Sampler

# Create dataserver and add attributes
tds = DataServer.TDataServer("pouet", "foo")
tds.addAttribute(DataServer.TUniformDistribution("pressure", 0, 10))
tds.addAttribute(DataServer.TLogUniformDistribution("density", 0.01, 100))

# Define the input file and the keys for
sFileName = ROOT.TString("withblank_input.dat")
pressName = "water model.brewery pit pressure "
tds.getAttribute("pressure").setFileKey(sFileName, pressName)
densName = "residual brew density model.factor for glass "
tds.getAttribute("density").setFileKey(sFileName, densName)

# Create input file interface before done by the TCode to precise information
inF = Launcher.TInputFileKey(ROOT.gSystem.PrependPathName(ROOT.gSystem.pwd(),
                                                          sFileName))
# Set separator to '=' so that lines could contain blank spaces (specific)
inF.setFieldSeparatorCharacter("=")
inF.setSeparatorCharacter(" ")
inF.addAttribute(tds.getAttribute("pressure"))
inF.addAttribute(tds.getAttribute("density"))

# Generate a doe
sampl = Sampler.TBasicSampling(tds, "srs", 10)
sampl.generateSample()

# Define the output
sOutFileName = "withblank_output.dat"
fout = Launcher.TOutputFileKey(sOutFileName)
# Set separator to '=' so that lines could contain blank spaces (specific)
fout.setFieldSeparatorCharacter("=")
fout.setSeparatorCharacter("")

# Define the attributes and their keys
outAtt = DataServer.TAttribute("outpressure")
outAttName = "Test doubling.water model.brewery pit pressure "
outAtt.setFileKey(sOutFileName, outAttName)
outAtt2 = DataServer.TAttribute("outdensity")
outAtt2Name = "Chocolat doubling.residual brew density model.factor for glass "
outAtt2.setFileKey(sOutFileName, outAtt2Name)
fout.addAttribute(outAtt)
fout.addAttribute(outAtt2)

# Create TCode with the TDS and the command to execute
mycode = Launcher.TCode(tds, "withblank")
# Add the output file
mycode.addInputFile(inF)
mycode.addOutputFile(fout)

# Launcher of the code on the Design of experiments (DoE) in the TDS
tlch = Launcher.TLauncher(tds, mycode)
tlch.setSave(-1)
tlch.setClean()
tlch.run()

tds.Scan("pressure:outpressure:density:outdensity")

As for all launcher's macro, it starts by defining the attributes and precise the key values with setFileKey method. From there, the main difference arise from the few lines below: as for the case introduced Section XIV.5.27 one needs to recreate the input file TInputFileKey as one needs to specify some properties

## Create the input file interface before it's done by the TCode to precise information
infile = Launcher.TInputFileKey(ROOT.gSystem.PrependPathName(ROOT.gSystem.pwd(),sFileName));
## Set the separator to '=' so that the line could contains blank spaces (specific)
infile.setFieldSeparatorCharacter("=");
infile.setSeparatorCharacter("");
infile.addAttribute( tds.getAttribute("pressure") );
infile.addAttribute( tds.getAttribute("density") );

Apart from the creation of the file, the two main functions to be called are setFieldSeparatorCharacter, used to define the "=" character as the field delimiter while the second one setSeparatorCharacter cancel the usual separator cleaning procedure (usually the code is removing few characters such as ";", "\n", "="). Given this option, the file is breakdown, on a line-by-line basis, to find the field separator.

The following block is defining a sampler while the next one is the definition of the output files withblank_output.dat. As previously the output file is created and the two main functions are called with the same consequences: thanks to setFieldSeparatorCharacter and setSeparatorCharacter, used with the already discussed argument, the output keys are also usable with blank.

## Define the output
sOutFileName="withblank_output.dat";
fout = Launcher.TOutputFileKey(sOutFileName);
## Set the separator to '=' so that the line could contains blank spaces (specific)
fout.setFieldSeparatorCharacter("=");
fout.setSeparatorCharacter("");

The rest of this macro is very usual, as one defines the code, the launcher and one runs it, one can check the content through a scan, shown below.xs

XIV.5.34.3. Console

Processing launchCodeFilesWithBlank.py...
************************************************************
*    Row   *  pressure * outpressu *   density * outdensit *
************************************************************
*        0 * 3.3622174 * 6.7244349 * 19.122886 * 57.368659 *
*        1 * 5.4302620 * 10.860524 * 0.0823283 * 0.2469849 *
*        2 * 6.2876717 * 12.575343 * 0.2559847 * 0.7679543 *
*        3 * 3.3986722 * 6.7973444 * 0.0503713 * 0.1511141 *
*        4 * 1.1833060 * 2.3666120 * 0.0364635 * 0.1093906 *
*        5 * 9.3162251 * 18.632450 * 0.0134744 * 0.0404234 *
*        6 * 2.1579343 * 4.3158686 * 0.0431745 * 0.1295236 *
*        7 * 1.2310214 * 2.4620429 * 12.797791 * 38.393373 *
*        8 * 4.5137647 * 9.0275294 * 2.3940563 * 7.1821691 *
*        9 * 8.4025508 * 16.805101 * 65.518819 * 196.55645 *
************************************************************
/language/en