Skip to content

Commit

Permalink
Pass meta to validator (#61)
Browse files Browse the repository at this point in the history
* Pass meta to validator

This commit add the meta variable as a parameter to the Validator class method
`validate`.

* Add documentation for meta variable to validator

* Add initial level var to ExampleValidator

* Remove init_level var from ExampleValidator

* Add get_initial_level to ExampleValidator method

* Edit conditional statement
  • Loading branch information
dylanjm authored Jan 27, 2021
1 parent 79b99e6 commit 281b658
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/dispatch/Dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,18 @@ def dispatch(self, case, components, sources):
"""
raise NotImplementedError # must be implemented by inheriting classes

def validate(self, components, activity, times):
def validate(self, components, activity, times, meta):
"""
Method to validate a dispatch activity.
@ In, components, list, HERON components whose cashflows should be evaluated
@ In, activity, DispatchState instance, activity by component/resources/time
@ In, times, np.array(float), time values to evaluate; may be length 1 or longer
@ In, meta, dict, extra information needed for validation
@ Out, validation, dict, information about validation
"""
# default implementation
if self._validator is not None:
return self._validator.validate(components, activity, times)
return self._validator.validate(components, activity, times, meta)
else:
# no validator, nothing needs to be changed
return {}
Expand Down
2 changes: 1 addition & 1 deletion src/dispatch/pyomo_dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def dispatch_window(self, time,
raise RuntimeError
# try validating
print('DEBUGG ... validating ...')
validation_errs = self.validate(m.Components, m.Activity, m.Times)
validation_errs = self.validate(m.Components, m.Activity, m.Times, meta)
if validation_errs:
done_and_checked = False
print('DEBUGG ... validation concerns raised:')
Expand Down
5 changes: 4 additions & 1 deletion src/validators/ExampleValidator.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,22 @@ def read_input(self, inputs):

# ---------------------------------------------
# API
def validate(self, components, dispatch, times):
def validate(self, components, dispatch, times, meta):
"""
Method to validate a dispatch activity.
@ In, components, list, HERON components whose cashflows should be evaluated
@ In, activity, DispatchState instance, activity by component/resources/time
@ In, times, np.array(float), time values to evaluate; may be length 1 or longer
@ In, meta, dict, extra information pertaining to validation
@ Out, errs, list, information about validation failures
"""
errs = [] # TODO best format for this?
for comp, info in dispatch._resources.items():
for res in info:
for t, time in enumerate(times):
current = dispatch.get_activity(comp, res, time)
if comp.get_interaction().is_type('Storage') and t == 0:
init_level = comp.get_interaction().get_initial_level(meta)
if t > 0:
previous = dispatch.get_activity(comp, res, times[t-1])
delta = current - previous
Expand Down
3 changes: 2 additions & 1 deletion src/validators/Validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,14 @@ def initialize(self, case, components, sources, **kwargs):
# ---------------------------------------------
# API
# TODO make this a virtual method?
def validate(self, case, components, sources, dispatch):
def validate(self, case, components, sources, dispatch, meta):
"""
Performs technoeconomic dispatch.
@ In, case, Case, HERON case
@ In, components, list, HERON components
@ In, sources, list, HERON sources
@ In, dispatch, HERON DispatchState, proposed activity
@ In, meta, dict, extra information
@ Out, results, list(dict), list of violations with info about each (see Validator base class)
"""
# The return results should be a list of dictionaries
Expand Down
4 changes: 2 additions & 2 deletions tests/integration_tests/validator/heron_input.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
<Component name="electr_market">
<demands resource="electricity" dispatch="dependent"><!---->
<capacity>
<!-- <fixed_value>-2</fixed_value> -->
<fixed_value>-2</fixed_value>
</capacity>
</demands>
Expand Down Expand Up @@ -105,7 +104,8 @@
</economics>
</Component>

</Components>

</Components>

<DataGenerators>
<ARMA name='Price' variable="Signal">../ARMA/Sine/arma.pk</ARMA>
Expand Down

0 comments on commit 281b658

Please sign in to comment.