-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Logical model entity. Addition of a test to show how to use it.
- Loading branch information
Showing
33 changed files
with
1,240 additions
and
56 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 |
---|---|---|
@@ -0,0 +1,177 @@ | ||
% | ||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
%%%%%% Logical Model %%%%%% | ||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
% | ||
|
||
\subsection{LogicalModel} | ||
\label{subsec:models_LogicalModel} | ||
The \textbf{LogicalModel} is a model aimed to execute ROMs, | ||
Codes and ExternalModels via a user provided control function. Basically, the control function | ||
utilizes the inputs generated by RAVEN and the control logic provided by the user to determine which | ||
model to execute. | ||
\nb For this type of model, we currently require all models listed under \textbf{LogicalModel} should | ||
have the same inputs and outputs from RAVEN point of view. | ||
|
||
The specifications of a LogicalModel must be defined within the XML block | ||
\xmlNode{LogicalModel}. | ||
% | ||
This XML node needs to contain the attributes: | ||
|
||
\vspace{-5mm} | ||
\begin{itemize} | ||
\itemsep0em | ||
\item \xmlAttr{name}, \xmlDesc{required string attribute}, user-defined name | ||
of this LogicalModel. | ||
% | ||
\nb As with the other objects, this is the name that can be used to refer to | ||
this specific entity from other input blocks in the XML. | ||
\item \xmlAttr{subType}, \xmlDesc{required string attribute}, must be kept | ||
empty. | ||
% | ||
\end{itemize} | ||
\vspace{-5mm} | ||
|
||
Within the \xmlNode{LogicalModel} XML node, the multiple entities that constitute | ||
this LogicalModel needs to be inputted. | ||
|
||
\begin{itemize} | ||
\item \xmlNode{Model}, \xmlDesc{XML node, required parameter}. | ||
% | ||
The text portion of this node needs to contain the name of the Model | ||
% | ||
\assemblerAttrDescription{Model} | ||
% | ||
\nb The user can provided various \xmlNode{Model} entities, including \xmlString{Code}, | ||
\xmlString{ROM} and \xmlString{ExternalModel}. | ||
|
||
\item \xmlNode{ControlFunction}, \xmlDesc{XML node, required parameter}. | ||
% | ||
The text portion of this node needs to contain the name of the function. | ||
% | ||
\assemblerAttrDescription{ControlFunction} | ||
\nb In order to work properly, this function must have a method named ``evaluate" | ||
that returns a single python str object representing the model that would be | ||
executed. | ||
\end{itemize} | ||
|
||
\textbf{Example (LogicalModel using external models):} | ||
\begin{lstlisting}[style=XML,morekeywords={subType,debug,name,class,type}] | ||
<Simulation> | ||
... | ||
<Models> | ||
<ExternalModel ModuleToLoad="sum" name="sum" subType=""> | ||
<variables>x, y, z</variables> | ||
</ExternalModel> | ||
|
||
<ExternalModel ModuleToLoad="minus" name="minus" subType=""> | ||
<variables>x, y, z</variables> | ||
</ExternalModel> | ||
|
||
<ExternalModel ModuleToLoad="multiply" name="multiply" subType=""> | ||
<variables>x, y, z</variables> | ||
</ExternalModel> | ||
|
||
<LogicalModel name="logical" subType=""> | ||
<Model class="Models" type="ExternalModel">sum</Model> | ||
<Model class="Models" type="ExternalModel">minus</Model> | ||
<Model class="Models" type="ExternalModel">multiply</Model> | ||
<ControlFunction class="Functions" type="External">control</ControlFunction> | ||
</LogicalModel> | ||
</Models> | ||
... | ||
<Steps> | ||
<MultiRun name="mc"> | ||
<Input class="DataObjects" type="PointSet">inputHolder</Input> | ||
<Model class="Models" type="LogicalModel">logical</Model> | ||
<Sampler class="Samplers" type="MonteCarlo">MonteCarlo</Sampler> | ||
<Output class="DataObjects" type="PointSet">outSet</Output> | ||
<Output class="DataObjects" type="PointSet">tagetSet</Output> | ||
<Output class="OutStreams" type="Print">dumpOut</Output> | ||
</MultiRun> | ||
</Steps> | ||
... | ||
</Simulation> | ||
|
||
\end{lstlisting} | ||
|
||
Corresponding Python function for \xmlNode{ControlFunction}: | ||
\begin{lstlisting}[language=python] | ||
def evaluate(self): | ||
""" | ||
Method required by RAVEN to run this as an external model. | ||
@ In, self, object, object to store members on | ||
@ Out, model, str, the name of external model that | ||
will be executed by hybrid model | ||
""" | ||
model = None | ||
if self.x > 0 and self.y >1: | ||
model = 'sum' | ||
elif self.x > 0 and self.y <= 1: | ||
model = 'multiply' | ||
else: | ||
model = 'minus' | ||
return model | ||
\end{lstlisting} | ||
|
||
\textbf{Example (LogicalModel using codes):} | ||
\begin{lstlisting}[style=XML,morekeywords={subType,debug,repeat,name,class,type}] | ||
<Simulation> | ||
... | ||
<Models> | ||
<Code name="poly" subType="GenericCode"> | ||
<executable>logicalCode/poly_code.py</executable> | ||
<clargs arg="python" type="prepend"/> | ||
<clargs arg="-i" extension=".one" type="input"/> | ||
<fileargs arg="aux" extension=".two" type="input"/> | ||
<fileargs arg="output" type="output"/> | ||
</Code> | ||
<Code name="exp" subType="GenericCode"> | ||
<executable>logicalCode/exp_code.py</executable> | ||
<clargs arg="python" type="prepend"/> | ||
<clargs arg="-i" extension=".one" type="input"/> | ||
<fileargs arg="aux" extension=".two" type="input"/> | ||
<fileargs arg="output" type="output"/> | ||
</Code> | ||
<LogicalModel name="logical" subType=""> | ||
<Model class="Models" type="Code">poly</Model> | ||
<Model class="Models" type="Code">exp</Model> | ||
<ControlFunction class="Functions" type="External">control</ControlFunction> | ||
</LogicalModel> | ||
</Models> | ||
... | ||
<Steps> | ||
<MultiRun name="logicalModelCode"> | ||
<Input class="Files" type="">gen.one</Input> | ||
<Input class="Files" type="">gen.two</Input> | ||
<Model class="Models" type="LogicalModel">logical</Model> | ||
<Sampler class="Samplers" type="Stratified">LHS</Sampler> | ||
<Output class="DataObjects" type="PointSet">samples</Output> | ||
<Output class="OutStreams" type="Print">samples</Output> | ||
</MultiRun> | ||
</Steps> | ||
... | ||
</Simulation> | ||
\end{lstlisting} | ||
|
||
Corresponding Python function for \xmlNode{ControlFunction}: | ||
\begin{lstlisting}[language=python] | ||
def evaluate(self): | ||
""" | ||
Method required by RAVEN to run this as an external model. | ||
@ In, self, object, object to store members on | ||
@ Out, model, str, the name of external model that | ||
will be executed by hybrid model | ||
""" | ||
model = None | ||
if self.x > 0.5 and self.y > 1.5: | ||
model = 'poly' | ||
else: | ||
model = 'exp' | ||
|
||
return model | ||
\end{lstlisting} | ||
% | ||
\nb For these examples, the user needs to provide all the inputs for the models listed | ||
under \textbf{LogicalModel}, i.e. Files for the \textbf{Code} and DataObject for | ||
the \textbf{ExternalModel} defined in the \textbf{LogicalModel}. |
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
Oops, something went wrong.