-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ExternalXML in RAVEN Code Interface (#594)
* moved ExternalXML reader to xmlUtils * found common replacement strategy for both ElementTree and InputTree * RrR ExternalXML compatability and test * documentation * pylint file to open fix * reviewer comment
- Loading branch information
1 parent
2235c9b
commit b3fa3b9
Showing
11 changed files
with
221 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,7 +83,7 @@ \subsection{Generic Interface} | |
the GenericCode interface can be invoked using the \xmlNode{outputFile} | ||
node in which the output file name (CSV only) must be specified. | ||
For example, in the previous example, say instead of \texttt{-a gen.two} and \texttt{-o myOut} | ||
in the command line, the code always produce a CSV file named ``[email protected]''; | ||
in the command line, the code always produce a CSV file named ``[email protected]''; | ||
|
||
Then, our example XML for the code would be | ||
|
||
|
@@ -134,9 +134,9 @@ \subsection{RAVEN Interface} | |
\label{subsec:RAVENInterface} | ||
The RAVEN interface is meant to provide the possibility to execute a RAVEN input file | ||
driving a set of SLAVE RAVEN calculations. For example, if the user wants to optimize the parameters | ||
of a surrogate model (e.g. minimizing the distance between the surrogate predictions and the real data), he | ||
of a surrogate model (e.g. minimizing the distance between the surrogate predictions and the real data), he | ||
can achieve this task by setting up a RAVEN input file (master) that performs an optimization on the feature | ||
space characterized by the surrogate model parameters, whose training and validation assessment is performed in the SLAVE | ||
space characterized by the surrogate model parameters, whose training and validation assessment is performed in the SLAVE | ||
RAVEN runs. | ||
\\ There are some limitations for this interface: | ||
\begin{itemize} | ||
|
@@ -150,7 +150,7 @@ \subsection{RAVEN Interface} | |
\\ Similarly to any other code interface, the user provides paths to executables and aliases for sampled variables within the | ||
\xmlNode{Models} block. The \xmlNode{Code} block will contain attributes \xmlAttr{name} and | ||
\xmlAttr{subType}. \xmlAttr{name} identifies that particular \xmlNode{Code} model within RAVEN, and | ||
\xmlAttr{subType} specifies which code interface the model will use (In this case \xmlAttr{subType}=``RAVEN''). | ||
\xmlAttr{subType} specifies which code interface the model will use (In this case \xmlAttr{subType}=``RAVEN''). | ||
The \xmlNode{executable} | ||
block should contain the absolute or relative (with respect to the current working | ||
directory) path to the RAVEN framework script (\textbf{raven\_framework}). | ||
|
@@ -167,45 +167,45 @@ \subsection{RAVEN Interface} | |
\begin{lstlisting}[language=python] | ||
def manipulateScalarSampledVariables(sampledVariables): | ||
""" | ||
This method is aimed to manipulate scalar variables. | ||
The user can create new variables based on the | ||
This method is aimed to manipulate scalar variables. | ||
The user can create new variables based on the | ||
variables sampled by RAVEN | ||
@ In, sampledVariables, dict, dictionary of | ||
@ In, sampledVariables, dict, dictionary of | ||
sampled variables ({"var1":value1,"var2":value2}) | ||
@ Out, None, the new variables should be | ||
@ Out, None, the new variables should be | ||
added in the "sampledVariables" dictionary | ||
""" | ||
newVariableValue = | ||
sampledVariables['Distributions|Uniform@name:a_dist|lowerBound'] | ||
newVariableValue = | ||
sampledVariables['Distributions|Uniform@name:a_dist|lowerBound'] | ||
+ 1.0 | ||
sampledVariables['Distributions|Uniform@name:a_dist|upperBound'] = | ||
sampledVariables['Distributions|Uniform@name:a_dist|upperBound'] = | ||
newVariableValue | ||
return | ||
\end{lstlisting} | ||
|
||
\item \textbf{\textit{convertNotScalarSampledVariables}}, a method that is aimed to convert not scalar variables (e.g. 1D arrays) into multiple scalar variables | ||
\item \textbf{\textit{convertNotScalarSampledVariables}}, a method that is aimed to convert not scalar variables (e.g. 1D arrays) into multiple scalar variables | ||
(e.g. \xmlNode{constant}(s) in a sampling strategy). | ||
This method is going to be required in case not scalar variables are detected by the interface. | ||
This method is going to be required in case not scalar variables are detected by the interface. | ||
Example: | ||
\begin{lstlisting}[language=python] | ||
def convertNotScalarSampledVariables(noScalarVariables): | ||
""" | ||
This method is aimed to convert not scalar | ||
This method is aimed to convert not scalar | ||
variables into multiple scalar variables. The user MUST | ||
create new variables based on the not Scalar Variables | ||
sampled (and passed in) by RAVEN | ||
@ In, noScalarVariables, dict, dictionary of sampled | ||
@ In, noScalarVariables, dict, dictionary of sampled | ||
variables that are not scalar ({"var1":1Darray1,"var2":1Darray2}) | ||
@ Out, newVars, dict, the new variables that have | ||
been created based on the not scalar variables | ||
@ Out, newVars, dict, the new variables that have | ||
been created based on the not scalar variables | ||
contained in "noScalarVariables" dictionary | ||
""" | ||
oneDimensionalArray = | ||
noScalarVariables['temperatureHistory'] | ||
newVars = {} | ||
for cnt, value in enumerate(oneDimensionalArray): | ||
newVars['Samplers|MonteCarlo@name:myMC|constant'+ | ||
'@name=temperatureHistory'+str(cnt)] = | ||
'@name=temperatureHistory'+str(cnt)] = | ||
oneDimensionalArray[cnt] | ||
return newVars | ||
\end{lstlisting} | ||
|
@@ -225,7 +225,7 @@ \subsection{RAVEN Interface} | |
</Code> | ||
\end{lstlisting} | ||
|
||
Like for every other interface, the syntax of the variable names is important to make the parser understand how to perturb an input file. | ||
Like for every other interface, the syntax of the variable names is important to make the parser understand how to perturb an input file. | ||
\\ For the RAVEN interface, a syntax inspired by the XPath nomenclature is used. | ||
\begin{lstlisting}[style=XML] | ||
<Samplers> | ||
|
@@ -251,7 +251,7 @@ \subsection{RAVEN Interface} | |
\begin{lstlisting}[style=XML] | ||
<Models> | ||
<ROM name="ROM1" subType="SciKitLearn"> | ||
... | ||
... | ||
<C>10.0</C> | ||
... | ||
</ROM> | ||
|
@@ -261,7 +261,7 @@ \subsection{RAVEN Interface} | |
\begin{lstlisting}[style=XML] | ||
<Models> | ||
<ROM name="ROM1" subType="SciKitLearn"> | ||
... | ||
... | ||
<tol>0.0001</tol> | ||
... | ||
</ROM> | ||
|
@@ -275,9 +275,9 @@ \subsection{RAVEN Interface} | |
<variable name="var1"> | ||
... | ||
<grid construction="equal" type="value" steps="1">0 1</grid> | ||
... | ||
... | ||
</variable> | ||
|
||
... | ||
</MonteCarlo> | ||
</Samplers> | ||
|
@@ -295,6 +295,12 @@ \subsection{RAVEN Interface} | |
</Files> | ||
\end{lstlisting} | ||
|
||
\subsubsection{ExternalXML and RAVEN interface} | ||
Care must be taken if the SLAVE RAVEN uses \xmlNode{ExternalXML} nodes. In this case, each file containing | ||
external XML nodes must be added in the \xmlNode{Step} as an \xmlNode{Input} class \xmlAttr{Files} to make sure it gets copied to | ||
the individual run directory. The type for these files can be anything, with the exception of type | ||
\xmlString{raven}. | ||
|
||
%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
%%%%%% RELAP5 INTERFACE %%%%%% | ||
%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
|
@@ -1303,20 +1309,20 @@ \subsubsection{Models} | |
... | ||
</Simulation> | ||
\end{lstlisting} | ||
RAVEN works best with Comma-Separated Value (CSV) files. Therefore, the default | ||
RAVEN works best with Comma-Separated Value (CSV) files. Therefore, the default | ||
.mat output type needs to be converted to .csv output. | ||
The Dymola interface will automatically convert the .mat output to human-readable | ||
The Dymola interface will automatically convert the .mat output to human-readable | ||
forms, i.e., .csv output, through its implementation of the finalizeCodeOutput function. | ||
\\In order to speed up the reading and conversion of the .mat file, the user can specify | ||
the list of variables (in addition to the Time variable) that need to be imported and | ||
converted into a csv file minimizing | ||
the IO memory usage as much as possible. Within the \xmlNode{Code} the following | ||
XML | ||
the list of variables (in addition to the Time variable) that need to be imported and | ||
converted into a csv file minimizing | ||
the IO memory usage as much as possible. Within the \xmlNode{Code} the following | ||
XML | ||
node (in addition ot the \xmlNode{executable} one) can be inputted: | ||
|
||
\begin{itemize} | ||
\item \xmlNode{outputVariablesToLoad}, \xmlDesc{space separated list, optional | ||
parameter}, a space separated list of variables that need be exported from the .mat | ||
\item \xmlNode{outputVariablesToLoad}, \xmlDesc{space separated list, optional | ||
parameter}, a space separated list of variables that need be exported from the .mat | ||
file (in addition to the Time variable). \default{all the variables in the .mat file}. | ||
\end{itemize} | ||
For example: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
tests/framework/CodeInterfaceTests/raven_running_raven_internal_models/ext_dataobjects.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<DataObjects> | ||
<PointSet name="inputHolder"> | ||
<Input>DeltaTimeScramToAux,DG1recoveryTime</Input> | ||
<Output>OutputPlaceHolder</Output> | ||
</PointSet> | ||
<PointSet inputTs="2" name="Pointset_from_database_for_rom_trainer"> | ||
<Input>DeltaTimeScramToAux,DG1recoveryTime</Input> | ||
<Output>CladTempThreshold</Output> | ||
</PointSet> | ||
<PointSet historyName="1" inputTs="2" name="data_for_sampling_empty_at_begin"> | ||
<Input>DeltaTimeScramToAux,DG1recoveryTime</Input> | ||
<Output>OutputPlaceHolder</Output> | ||
</PointSet> | ||
<PointSet historyName="1" inputTs="2" name="data_for_sampling_empty_at_begin_nd"> | ||
<Input>DeltaTimeScramToAux,DG1recoveryTime</Input> | ||
<Output>OutputPlaceHolder</Output> | ||
</PointSet> | ||
<PointSet inputTs="2" name="outputMontecarloRom"> | ||
<Input>DeltaTimeScramToAux,DG1recoveryTime</Input> | ||
<Output>CladTempThreshold</Output> | ||
</PointSet> | ||
<HistorySet name="outputMontecarloRomHS"> | ||
<Input>DeltaTimeScramToAux,DG1recoveryTime</Input> | ||
<Output>CladTempThreshold</Output> | ||
</HistorySet> | ||
<PointSet inputTs="2" name="outputMontecarloRomND"> | ||
<Input>DeltaTimeScramToAux,DG1recoveryTime</Input> | ||
<Output>CladTempThreshold</Output> | ||
</PointSet> | ||
</DataObjects> |
Oops, something went wrong.