-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Basic Event Scheduler Model #37
base: devel
Are you sure you want to change the base?
Changes from 4 commits
6fab7d1
53b7eaf
512eaf6
27dcbba
571c36c
7eb7c07
a5cb574
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
\section{Basic Event Scheduler Model} | ||
\label{sec:basicEventScheduler} | ||
|
||
This model is designed to read the initial and final time under which a set of basic events | ||
are set to True, and then it generates an HistorySet with the full temporal profile of all | ||
basic events. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I recommend to add another paragraph to explain the structure of generated history set. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added |
||
|
||
|
||
All the specifications of the Basic Event Scheduler model are given in the \xmlNode{ExternalModel} block. | ||
Inside the \xmlNode{ExternalModel} block, the XML | ||
nodes that belong to this models are: | ||
\begin{itemize} | ||
\item \xmlNode{variables}, \xmlDesc{string, required parameter}, a list containing the names of both the input and output variables of the model | ||
\item \xmlNode{BE}, \xmlDesc{string, required parameter}, the name ID of all basic events | ||
\begin{itemize} | ||
\item \xmlAttr{tin}, \xmlDesc{required string attribute}, name ID of the variable describing the initial time of the BE | ||
\item \xmlAttr{tin}, \xmlDesc{required string attribute}, name ID of the variable describing the final time of the BE | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. change 'tin' to 'tfin' There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed, good catch |
||
\end{itemize} | ||
\end{itemize} | ||
|
||
The example of \textbf{basicEventScheduler} model is provided below: | ||
\begin{lstlisting}[style=XML] | ||
<Models> | ||
<ExternalModel name="basicEventScheduler" subType="SR2ML.basicEventScheduler"> | ||
<variables>BE1_tin, BE2_tin, BE3_tin, | ||
BE1_tfin,BE2_tfin,BE3_tfin, | ||
BE1,BE2,BE3,time</variables> | ||
<BE tin='BE1_tin' tfin='BE1_tfin'>BE1</BE> | ||
<BE tin='BE2_tin' tfin='BE2_tfin'>BE2</BE> | ||
<BE tin='BE3_tin' tfin='BE3_tfin'>BE3</BE> | ||
<timeID>time</timeID> | ||
</ExternalModel> | ||
</Models> | ||
\end{lstlisting} | ||
|
||
\subsection{basicEventScheduler Reference Tests} | ||
\begin{itemize} | ||
\item SR2ML/tests/test\_basicEventScheduler.xml | ||
\end{itemize} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
# Copyright 2017 Battelle Energy Alliance, LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please update the copyright info, (The above info is used by raven). Something like:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
""" | ||
Created on June 24, 2020 | ||
|
||
@author: mandd | ||
""" | ||
|
||
#External Modules--------------------------------------------------------------- | ||
import numpy as np | ||
import xarray as xr | ||
import pandas as pd | ||
#External Modules End----------------------------------------------------------- | ||
|
||
#Internal Modules--------------------------------------------------------------- | ||
from PluginBaseClasses.ExternalModelPluginBase import ExternalModelPluginBase | ||
#Internal Modules End----------------------------------------------------------- | ||
|
||
class basicEventScheduler(ExternalModelPluginBase): | ||
""" | ||
This class is designed to create a Maintenance Scheduler model | ||
""" | ||
def __init__(self): | ||
""" | ||
Constructor | ||
@ In, None | ||
@ Out, None | ||
""" | ||
ExternalModelPluginBase.__init__(self) | ||
|
||
def initialize(self, container, runInfoDict, inputFiles): | ||
""" | ||
Method to initialize the Basic Event Scheduler model | ||
@ In, container, object, self-like object where all the variables can be stored | ||
@ In, runInfoDict, dict, dictionary containing all the RunInfo parameters (XML node <RunInfo>) | ||
@ In, inputFiles, list, list of input files (if any) | ||
@ Out, None | ||
""" | ||
|
||
def _readMoreXML(self, container, xmlNode): | ||
""" | ||
Method to read the portion of the XML that belongs to the Basic Event Scheduler model | ||
@ In, container, object, self-like object where all the variables can be stored | ||
@ In, xmlNode, xml.etree.ElementTree.Element, XML node that needs to be read | ||
@ Out, None | ||
""" | ||
container.basicEvents = {} | ||
|
||
for child in xmlNode: | ||
if child.tag == 'BE': | ||
container.basicEvents[child.text.strip()] = [child.get('tin'),child.get('tfin')] | ||
elif child.tag == 'timeID': | ||
container.timeID = child.text.strip() | ||
elif child.tag == 'variables': | ||
variables = [str(var.strip()) for var in child.text.split(",")] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The variables is not directly used in this class, you probably can remove these lines. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The lines are needed as part of the external model class which require the "variables" node There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The variables are processed in ExternalModel class, but you are not using it in your class. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I removed lines 65 and 66 but it errors out of line 68 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are right. We are looping over all nodes, even if they have already processed by other class. I'm ok to keep it here. |
||
else: | ||
raise IOError("basicEventScheduler: xml node " + str(child.tag) + " is not allowed") | ||
|
||
def run(self, container, inputs): | ||
""" | ||
This method generate an historySet from the a pointSet which contains initial and final time of the | ||
basic events | ||
@ In, inputDataset, dict, dictionary of inputs from RAVEN | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. change inputDataset to inputs There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
@ In, container, object, self-like object where all the variables can be stored | ||
@ Out, basicEventHistorySet, Dataset, xarray dataset which contains time series for each basic event | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there is no return for the run method. I think you can move the above line to the method docstring explanation part. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added |
||
""" | ||
dataDict = {} | ||
for key in container.basicEvents.keys(): | ||
dataDict[key] = [] | ||
dataDict[key].append(inputs[container.basicEvents[key][0]][0]) | ||
dataDict[key].append(inputs[container.basicEvents[key][1]][0]) | ||
|
||
inputDataset = pd.DataFrame.from_dict(dataDict, orient='index',columns=['tin', 'tfin']) | ||
|
||
timeArray = np.concatenate([inputDataset['tin'],inputDataset['tfin']]) | ||
timeArraySorted = np.sort(timeArray,axis=0) | ||
timeArrayCleaned = np.unique(timeArraySorted) | ||
|
||
keys = list(container.basicEvents.keys()) | ||
dataVars={} | ||
for key in keys: | ||
dataVars[key]=(['RAVEN_sample_ID',container.timeID],np.zeros((1,timeArrayCleaned.shape[0]))) | ||
|
||
basicEventHistorySet = xr.Dataset(data_vars = dataVars, | ||
coords = dict(time=timeArrayCleaned, | ||
RAVEN_sample_ID=np.zeros(1))) | ||
|
||
for key in container.basicEvents.keys(): | ||
tin = inputs[container.basicEvents[key][0]][0] | ||
tend = inputs[container.basicEvents[key][1]][0] | ||
indexes = np.where(np.logical_and(timeArrayCleaned>tin,timeArrayCleaned<=tend)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why 'timeArrayCleaned>tin', but not 'timeArrayCleaned>=tin'? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is due to to the conversion from interval-based data to instant-based data (i.e., the history set). The convention here is that a logical value set to 1 at a specific time instant implies that the basic event was actually True from the previous time instant There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see your point, it is better to clarify it in the user manual. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree, added text. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Based on the definition, 'tin' is the initial time for the basic event. Based on the calculation |
||
basicEventHistorySet[key][0][indexes] = 1.0 | ||
|
||
container.__dict__[key] = basicEventHistorySet[key].values[0] | ||
|
||
container.__dict__[container.timeID] = timeArrayCleaned | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
<Simulation verbosity="debug"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no gold files for this test There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's weird, i wonder why the regression test was green There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see issue #38 |
||
<TestInfo> | ||
<name>SR2ML/basicEventScheduler</name> | ||
<author>mandd</author> | ||
<created>2021-07-14</created> | ||
<classesTested>SR2ML/basicEventScheduler</classesTested> | ||
<description> | ||
This model provided the schedule of a set of basic events create an history set containing | ||
basic event temporal profiles. Each basic event is represented by the initial and final time | ||
where basic event is set to True (i.e., with probability=1.0) | ||
</description> | ||
</TestInfo> | ||
|
||
<RunInfo> | ||
<WorkingDir>basicEventScheduler</WorkingDir> | ||
<Sequence>simRun</Sequence> | ||
<batchSize>1</batchSize> | ||
</RunInfo> | ||
|
||
<Models> | ||
<ExternalModel name="basicEventScheduler" subType="SR2ML.basicEventScheduler"> | ||
<variables>BE1_tin, BE2_tin, BE3_tin, | ||
BE1_tfin,BE2_tfin,BE3_tfin, | ||
BE1,BE2,BE3,time</variables> | ||
<BE tin='BE1_tin' tfin='BE1_tfin'>BE1</BE> | ||
<BE tin='BE2_tin' tfin='BE2_tfin'>BE2</BE> | ||
<BE tin='BE3_tin' tfin='BE3_tfin'>BE3</BE> | ||
<timeID>time</timeID> | ||
</ExternalModel> | ||
</Models> | ||
|
||
<Distributions> | ||
<Uniform name='BE1_tin_dist'> | ||
<lowerBound>0.</lowerBound> | ||
<upperBound>1.</upperBound> | ||
</Uniform> | ||
<Uniform name='BE2_tin_dist'> | ||
<lowerBound>2.</lowerBound> | ||
<upperBound>3.</upperBound> | ||
</Uniform> | ||
<Uniform name='BE3_tin_dist'> | ||
<lowerBound>1.</lowerBound> | ||
<upperBound>3.</upperBound> | ||
</Uniform> | ||
<Uniform name='BE1_tfin_dist'> | ||
<lowerBound>2.</lowerBound> | ||
<upperBound>3.</upperBound> | ||
</Uniform> | ||
<Uniform name='BE2_tfin_dist'> | ||
<lowerBound>4.</lowerBound> | ||
<upperBound>5.</upperBound> | ||
</Uniform> | ||
<Uniform name='BE3_tfin_dist'> | ||
<lowerBound>3.</lowerBound> | ||
<upperBound>5.</upperBound> | ||
</Uniform> | ||
</Distributions> | ||
|
||
<Samplers> | ||
<MonteCarlo name="MC_external"> | ||
<samplerInit> | ||
<limit>1</limit> | ||
</samplerInit> | ||
<variable name="BE1_tin"> | ||
<distribution>BE1_tin_dist</distribution> | ||
</variable> | ||
<variable name="BE2_tin"> | ||
<distribution>BE2_tin_dist</distribution> | ||
</variable> | ||
<variable name="BE3_tin"> | ||
<distribution>BE3_tin_dist</distribution> | ||
</variable> | ||
<variable name="BE1_tfin"> | ||
<distribution>BE1_tfin_dist</distribution> | ||
</variable> | ||
<variable name="BE2_tfin"> | ||
<distribution>BE2_tfin_dist</distribution> | ||
</variable> | ||
<variable name="BE3_tfin"> | ||
<distribution>BE3_tfin_dist</distribution> | ||
</variable> | ||
</MonteCarlo> | ||
</Samplers> | ||
|
||
<Steps> | ||
<MultiRun name="simRun"> | ||
<Input class="DataObjects" type="PointSet" >inputPlaceHolder</Input> | ||
<Model class="Models" type="ExternalModel" >basicEventScheduler</Model> | ||
<Sampler class="Samplers" type="MonteCarlo" >MC_external</Sampler> | ||
<Output class="DataObjects" type="HistorySet" >sim_HS</Output> | ||
<Output class="OutStreams" type="Print" >Print_sim_HS</Output> | ||
</MultiRun> | ||
</Steps> | ||
|
||
<OutStreams> | ||
<Print name="Print_sim_HS"> | ||
<type>csv</type> | ||
<source>sim_HS</source> | ||
<what>input,output</what> | ||
</Print> | ||
</OutStreams> | ||
|
||
<DataObjects> | ||
<PointSet name="inputPlaceHolder"> | ||
<Input>BE1_tin, BE2_tin, BE3_tin, | ||
BE1_tfin,BE2_tfin,BE3_tfin</Input> | ||
<Output>OutputPlaceHolder</Output> | ||
</PointSet> | ||
<HistorySet name="sim_HS"> | ||
<Input>BE1_tin, BE2_tin, BE3_tin, | ||
BE1_tfin,BE2_tfin,BE3_tfin</Input> | ||
<Output>BE1,BE2,BE3</Output> | ||
<options> | ||
<pivotParameter>time</pivotParameter> | ||
</options> | ||
</HistorySet> | ||
</DataObjects> | ||
|
||
</Simulation> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,4 +107,10 @@ | |
input = 'test_MCSSolver_margin.xml' | ||
UnorderedCsv = 'MCSSolverMargin/Print_sim_PS.csv' | ||
[../] | ||
|
||
[./TestBasicEventScheduler] | ||
type = 'RavenFramework' | ||
input = 'test_basicEventScheduler.xml' | ||
OrderedCsv = 'basicEventScheduler/Print_sim_HS_0.csv' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the csv file is missed in the gold folder There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. change OrderedCsv to csv, otherwise, the test will be be tested. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. changed |
||
[../] | ||
[] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would recommend to use upper case for each leading character when define a class. That is: change basicEventScheduler to BasicEventScheduler
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed