Skip to content
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

Debug mode #89

Merged
merged 10 commits into from
Jun 8, 2021
Merged
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ __pycache__
/tests/integration_tests/ARMA/Sine/synthetic.*
/tests/integration_tests/*/**/write_inner.py
*Sweep_Runs_o*

*Debug_Run_o*
4 changes: 3 additions & 1 deletion __init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# Copyright 2020, Battelle Energy Alliance, LLC
# ALL RIGHTS RESERVED
# ALL RIGHTS RESERVED

from HERON.src import DispatchPlot
83 changes: 59 additions & 24 deletions src/Cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,13 @@ def get_input_specs(cls):
Example: ``<label name="state">Idaho</label>''""")
input_specs.addSub(label_specs)

mode_options = InputTypes.makeEnumType('ModeOptions', 'ModeOptionsType', ['opt', 'sweep'])
desc_mode_options = r"""determines whether the outer RAVEN should perform
optimization, or a parametric (``sweep'') study. \default{sweep}"""
mode_options = InputTypes.makeEnumType('ModeOptions', 'ModeOptionsType', ['opt', 'sweep', 'debug'])
desc_mode_options = r"""determines the mode of operation for the outer/inner RAVEN.
If ``sweep'' then parametrically sweep over distributed values.
If ``opt'' then search distributed values for economic metric optima.
If ``debug'' then run a simplified one-point outer, one-point inner to check
dispatch behavior, cash flows, and simulation mechanics.
"""
input_specs.addSub(InputData.parameterInputFactory('mode', contentType=mode_options, strictMode=True,
descr=desc_mode_options))

Expand All @@ -74,6 +78,24 @@ def get_input_specs(cls):
# descr=r"""(not implemented) allows differentiation between two HERON runs as a desired
# economic metric."""

# debug mode, for checking dispatch and etc
debug = InputData.parameterInputFactory('debug', descr=r"""Including this node enables a reduced-size
run with increased outputs for checking how the sampling, dispatching, and cashflow mechanics
are working for a particular input. Various options for modifying how the debug mode operates
are included for convenience; however, just including this node will result in a minimal run.""")
debug.addSub(InputData.parameterInputFactory('inner_samples', contentType=InputTypes.IntegerType,
descr=r"""sets the number of inner realizations of the stochastic synthetic histories and dispatch
optimization to run per outer sample. Overrides the \xmlNode{num_arma_steps} option while
\xmlNode{debug} mode is enabled. \default{1}"""))
debug.addSub(InputData.parameterInputFactory('macro_steps', contentType=InputTypes.IntegerType,
descr=r"""sets the number of macro steps (e.g. years) the stochastic synthetic histories and dispatch
optimization should include. \default{1}"""))
debug.addSub(InputData.parameterInputFactory('dispatch_plot', contentType=InputTypes.BoolType,
descr=r"""provides a dispatch plot after running through \xmlNode{inner_samples} and
\xmlNode{macro_steps} provided. To prevent plotting output during debug mode set to "False".
\default{True}"""))
input_specs.addSub(debug)

input_specs.addSub(InputData.parameterInputFactory('num_arma_samples', contentType=InputTypes.IntegerType,
descr=r"""provides the number of synthetic histories that should
be considered per system configuration in order to obtain a
Expand Down Expand Up @@ -159,26 +181,32 @@ def __init__(self, run_dir, **kwargs):
@ Out, None
"""
Base.__init__(self, **kwargs)
self.name = None # case name
self._mode = None # extrema to find: min, max, sweep
self._metric = 'NPV' # UNUSED (future work); economic metric to focus on: lcoe, profit, cost
self.run_dir = run_dir # location of HERON input file

self.dispatch_name = None # name of dispatcher to use
self.dispatcher = None # type of dispatcher to use
self.validator_name = None # name of dispatch validation to use
self.validator = None # type of dispatch validation to use

self._diff_study = None # is this only a differential study?
self._num_samples = 1 # number of ARMA stochastic samples to use ("denoises")
self._hist_interval = None # time step interval, time between production points
self._hist_len = None # total history length, in same units as _hist_interval
self._num_hist = None # number of history steps, hist_len / hist_interval
self._global_econ = {} # global economics settings, as a pass-through
self._increments = {} # stepwise increments for resource balancing
self.name = None # case name
self._mode = None # extrema to find: opt, sweep
self._metric = 'NPV' # UNUSED (future work); economic metric to focus on: lcoe, profit, cost
self.run_dir = run_dir # location of HERON input file

self.dispatch_name = None # name of dispatcher to use
self.dispatcher = None # type of dispatcher to use
self.validator_name = None # name of dispatch validation to use
self.validator = None # type of dispatch validation to use

self._diff_study = None # is this only a differential study?
self._num_samples = 1 # number of ARMA stochastic samples to use ("denoises")
self._hist_interval = None # time step interval, time between production points
self._hist_len = None # total history length, in same units as _hist_interval
self._num_hist = None # number of history steps, hist_len / hist_interval
self._global_econ = {} # global economics settings, as a pass-through
self._increments = {} # stepwise increments for resource balancing
self._time_varname = 'time' # name of the time-variable throughout simulation
self._year_varname = 'Year' # name of the year-variable throughout simulation
self._labels = {} # extra information pertaining to current case
self._labels = {} # extra information pertaining to current case
self.debug = { # debug options, as enabled by the user (defaults included)
'enabled': False, # whether to enable debug mode
'inner_samples': 1, # how many inner realizations to sample
'macro_steps': 1, # how many "years" for inner realizations
'dispatch_plot': True # whether to output a plot in debug mode
}

self._time_discretization = None # (start, end, number) for constructing time discretization, same as argument to np.linspace
self._Resample_T = None # user-set increments for resources
Expand All @@ -197,7 +225,11 @@ def read_input(self, xml):
specs.parseNode(xml)
self.name = specs.parameterValues['name']
for item in specs.subparts:
# TODO move from iterative list to seeking list, at least for required nodes
# TODO move from iterative list to seeking list, at least for required nodes?
if item.getName() == 'debug':
self.debug['enabled'] = True
for node in item.subparts:
self.debug[node.getName()] = node.value
if item.getName() == 'label':
self._labels[item.parameterValues['name']] = item.value
if item.getName() == 'mode':
Expand Down Expand Up @@ -402,7 +434,10 @@ def get_num_samples(self):
@ In, None
@ Out, num_samples, int, number of dispatch realizations to consider
"""
return self._num_samples
if self.debug['enabled']:
return self.debug['inner_samples']
else:
return self._num_samples

def get_num_timesteps(self):
"""
Expand Down Expand Up @@ -560,7 +595,7 @@ def _modify_outer(self, template, components, sources):
samps_node = template.find('Samplers').find('Grid')
# number of denoisings
## assumption: first node is the denoises node
samps_node.find('constant').text = str(self._num_samples)
samps_node.find('constant').text = str(self.get_num_samples())
# add sweep variables to input
dist_template = xmlUtils.newNode('Uniform')
dist_template.append(xmlUtils.newNode('lowerBound'))
Expand Down
4 changes: 1 addition & 3 deletions src/Components.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@
Defines the Component entity.
"""
from __future__ import unicode_literals, print_function
import os
import sys
from collections import defaultdict
import numpy as np
from base import Base
import time
import xml.etree.ElementTree as ET
from Economics import CashFlowUser
from ValuedParams import factory as vp_factory
from ValuedParamHandler import ValuedParamHandler
import _utils as hutils

framework_path = hutils.get_raven_loc()
sys.path.append(framework_path)
from utils import InputData, xmlUtils,InputTypes
Expand All @@ -33,7 +32,6 @@ def factory(xml, method='sweep'):
comp.read_input(xml, method)
return comp


class Component(Base, CashFlowUser):
"""
Represents a unit in the grid analysis. Each component has a single "interaction" that
Expand Down
Loading