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

Adapt to new prescient plugin system #2

Merged
merged 7 commits into from
Aug 26, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
171 changes: 59 additions & 112 deletions idaes/apps/grid_integration/coordinator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from optparse import Option
import prescient.plugins
import prescient.plugins as pplugins
from prescient.simulator.config import PrescientConfig
from pyomo.common.config import ConfigDict, ConfigValue

class DoubleLoopCoordinator:

Expand All @@ -23,9 +24,11 @@ def __init__(self, bidder, tracker, projection_tracker):
self.bidder = bidder
self.tracker = tracker
self.projection_tracker = projection_tracker
self.register_callbacks()

def register_callbacks(self):
def register_plugins(self, \
context: pplugins.PluginRegistrationContext,\
options: PrescientConfig,\
plugin_config: ConfigDict):

'''
Register functionalities in Prescient's plugin system.
Expand All @@ -37,18 +40,17 @@ def register_callbacks(self):
None
'''

# self._register_custom_commandline_options()
self._register_initialization_callbacks()
self._register_before_ruc_solve_callbacks()
self._register_before_operations_solve_callbacks()
self._register_after_operations_callbacks()
self._register_update_operations_stats_callbacks()
self._register_after_ruc_activation_callbacks()
self._register_finalization_callbacks()
self._register_initialization_callbacks(context, options, plugin_config)
self._register_before_ruc_solve_callbacks(context, options, plugin_config)
self._register_before_operations_solve_callbacks(context, options, plugin_config)
self._register_after_operations_callbacks(context, options, plugin_config)
self._register_update_operations_stats_callbacks(context, options, plugin_config)
self._register_after_ruc_activation_callbacks(context, options, plugin_config)
self._register_finalization_callbacks(context, options, plugin_config)

return

def _register_custom_commandline_options(self):
def get_configuration(self, key):

'''
Register customized commandline options.
Expand All @@ -60,95 +62,22 @@ def _register_custom_commandline_options(self):
None
'''

config = ConfigDict()

# Add command line options
opt = Option('--track-ruc-signal',
help='When tracking the market signal, RUC signals are used instead of the SCED signal.',
action='store_true',
dest='track_ruc_signal',
default=False)
prescient.plugins.add_custom_commandline_option(opt)

opt = Option('--track-sced-signal',
help='When tracking the market signal, SCED signals are used instead of the RUC signal.',
action='store_true',
dest='track_sced_signal',
default=False)
prescient.plugins.add_custom_commandline_option(opt)

opt = Option('--hybrid-tracking',
help='When tracking the market signal, hybrid model is used.',
action='store_true',
dest='hybrid_tracking',
default=False)
prescient.plugins.add_custom_commandline_option(opt)

opt = Option('--track-horizon',
help="Specifies the number of hours in the look-ahead horizon "
"when each tracking process is executed.",
action='store',
dest='track_horizon',
type='int',
default=48)
prescient.plugins.add_custom_commandline_option(opt)

opt = Option('--bidding-generator',
help="Specifies the generator we derive bidding strategis for.",
action='store',
dest='bidding_generator',
type='string',
default='102_STEAM_3')
prescient.plugins.add_custom_commandline_option(opt)

opt = Option('--bidding',
help="Invoke generator strategic bidding when simulate.",
action='store_true',
dest='bidding',
default=False)
prescient.plugins.add_custom_commandline_option(opt)

opt = Option('--deviation-weight',
help="Set the weight for deviation term when tracking",
action='store',
dest='deviation_weight',
type='float',
default=30)
prescient.plugins.add_custom_commandline_option(opt)

opt = Option('--ramping-weight',
help="Set the weight for ramping term when tracking",
action='store',
dest='ramping_weight',
type='float',
default=20)
prescient.plugins.add_custom_commandline_option(opt)

opt = Option('--cost-weight',
help="Set the weight for cost term when tracking",
action='store',
dest='cost_weight',
type='float',
default=1)
prescient.plugins.add_custom_commandline_option(opt)

opt = Option('--rts_gmlc_data_dir',
help="the relative path to rts gmlc data set",
action='store',
dest='rts_gmlc_data_dir',
type='str',
default='./RTS-GMLC/RTS_Data/SourceData/')
prescient.plugins.add_custom_commandline_option(opt)

opt = Option('--price_forecast_file',
help="the relative path to price forecasts",
action='store',
dest='price_forecast_file',
type='str',
default='../../prescient/plugins/price_forecasts/lmp_forecasts_concat.csv')
prescient.plugins.add_custom_commandline_option(opt)
config.declare('bidding_generator',
ConfigValue(domain = str,
description = 'Specifies the generator we derive bidding strategis for.',
default = None)).declare_as_argument(f'--{key}.bidding-generator')
## How to access this option?
# options.plugin.{key}.bidding_generator
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plugin_config.bidding_generator -- I would refactor this class slightly and store the plugin_config passed into register_plugins somewhere. You probably also don't need the _register_*_callbacks methods anymore.

The declare_as_argument method just has to do with how the command line option is created. Using the key in the name is optional.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Ben! I just pushed a small change to store the plugin_config as a property. I think I should get rid of the bidding_generator option, because the coordinator should get this information from both bidder and tracker.

The _register_*_callbacks methods make it a little easier for me to manage the plugin functions, in case we have more than one callbacks at some plugin points.


return
return config

def _register_initialization_callbacks(self):
def _register_initialization_callbacks(self, \
context: pplugins.PluginRegistrationContext,\
options: PrescientConfig,\
plugin_config: ConfigDict):

'''
Register initialization plugins, which run before Prescient simulation
Expand All @@ -161,9 +90,12 @@ def _register_initialization_callbacks(self):
None
'''

prescient.plugins.register_initialization_callback(self.initialize_customized_results)
context.register_initialization_callback(self.initialize_customized_results)

def _register_before_ruc_solve_callbacks(self):
def _register_before_ruc_solve_callbacks(self, \
context: pplugins.PluginRegistrationContext,\
options: PrescientConfig,\
plugin_config: ConfigDict):

'''
Register plugins that run before Prescient solves Reliability Unit
Expand All @@ -176,9 +108,12 @@ def _register_before_ruc_solve_callbacks(self):
None
'''

prescient.plugins.register_before_ruc_solve_callback(self.bid_into_DAM)
context.register_before_ruc_solve_callback(self.bid_into_DAM)

def _register_before_operations_solve_callbacks(self):
def _register_before_operations_solve_callbacks(self, \
context: pplugins.PluginRegistrationContext,\
options: PrescientConfig,\
plugin_config: ConfigDict):

'''
Register plugins that run before Prescient solves Securitiy Constrained
Expand All @@ -191,9 +126,12 @@ def _register_before_operations_solve_callbacks(self):
None
'''

prescient.plugins.register_before_operations_solve_callback(self.bid_into_RTM)
context.register_before_operations_solve_callback(self.bid_into_RTM)

def _register_after_operations_callbacks(self):
def _register_after_operations_callbacks(self, \
context: pplugins.PluginRegistrationContext,\
options: PrescientConfig,\
plugin_config: ConfigDict):

'''
Register plugins that run after Prescient solves Securitiy Constrained
Expand All @@ -206,9 +144,12 @@ def _register_after_operations_callbacks(self):
None
'''

prescient.plugins.register_after_operations_callback(self.track_sced_signal)
context.register_after_operations_callback(self.track_sced_signal)

def _register_update_operations_stats_callbacks(self):
def _register_update_operations_stats_callbacks(self, \
context: pplugins.PluginRegistrationContext,\
options: PrescientConfig,\
plugin_config: ConfigDict):

'''
Register plugins that update stats of Securitiy Constrained Economic
Expand All @@ -221,9 +162,12 @@ def _register_update_operations_stats_callbacks(self):
None
'''

prescient.plugins.register_update_operations_stats_callback(self.update_observed_thermal_dispatch)
context.register_update_operations_stats_callback(self.update_observed_thermal_dispatch)

def _register_after_ruc_activation_callbacks(self):
def _register_after_ruc_activation_callbacks(self, \
context: pplugins.PluginRegistrationContext,\
options: PrescientConfig,\
plugin_config: ConfigDict):

'''
Register plugins that update stats of Securitiy Constrained Economic
Expand All @@ -236,9 +180,12 @@ def _register_after_ruc_activation_callbacks(self):
None
'''

prescient.plugins.register_after_ruc_activation_callback(self.activate_DA_bids)
context.register_after_ruc_activation_callback(self.activate_DA_bids)

def _register_finalization_callbacks(self):
def _register_finalization_callbacks(self, \
context: pplugins.PluginRegistrationContext,\
options: PrescientConfig,\
plugin_config: ConfigDict):

'''
Register finalization plugins, which run after Prescient simulation
Expand All @@ -251,7 +198,7 @@ def _register_finalization_callbacks(self):
None
'''

prescient.plugins.register_finalization_callback(self.write_plugin_results)
context.register_finalization_callback(self.write_plugin_results)

def initialize_customized_results(self, options, simulator):

Expand Down
11 changes: 2 additions & 9 deletions idaes/apps/grid_integration/examples/test_new_plugin.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ command/exec simulator.py
#--model-directory=..|..|..|..|..|..|doubleloop|Prescient|prescient|models|tight
--output-directory=bidding_plugin_test_output_new_forecasts
#--output-directory=repeat_old_results_output
--run-deterministic-ruc
--start-date=07-10-2020
--num-days=1
--sced-horizon=4
--traceback
#--random-seed=10
--compute-market-settlements
--day-ahead-pricing=LMP
Expand All @@ -25,10 +23,5 @@ command/exec simulator.py
--reserve-factor=0.0
--deterministic-ruc-solver=cbc
--sced-solver=cbc
--plugin=thermal_generator_prescient_plugin
#--rts_gmlc_data_dir=..|..|..|..|..|..|doubleloop|Prescient|downloads|rts_gmlc|RTS-GMLC|RTS_Data|SourceData|
#--price_forecast_file=price_forecasts|102_std1_lmp_forecasts.csv
#--bidding
#--bidding-generator=102_STEAM_3
#--track-sced-signal
#--hybrid-tracking
--plugin=doubleloop:thermal_generator_prescient_plugin.py
--doubleloop.bidding-generator=102_STEAM_3
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import pandas as pd
import pyomo.environ as pyo
from pyomo.common.config import ConfigDict, ConfigValue
import sys
sys.path.append('../')
from tracker import Tracker
from bidder import Bidder
from forecaster import PlaceHolderForecaster
from prescient_plugin import DoubleLoopCoordinator
from coordinator import DoubleLoopCoordinator
from thermal_generator import ThermalGenerator

generator = "102_STEAM_3"
Expand Down Expand Up @@ -55,3 +56,9 @@
coordinator = DoubleLoopCoordinator(bidder = thermal_bidder,\
tracker = thermal_tracker,\
projection_tracker = thermal_projection_tracker)

# Prescient requires the following functions in this module

# This is a required function, must have this name and signature
get_configuration = coordinator.get_configuration
register_plugins = coordinator.register_plugins