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

Retype Generators Correctly #169

Merged
merged 8 commits into from
Dec 19, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
" \"ruc_every_hours\": 24,\n",
" \"compute_market_settlements\": True,\n",
" \"day_ahead_pricing\": \"LMP\",\n",
" \"ruc_mipgap\": 0.05,\n",
" \"ruc_mipgap\": 0.05 if not TESTING_MODE else 0.5,\n",
" \"symbolic_solver_labels\": True,\n",
" \"reserve_factor\": 0,\n",
" \"deterministic_ruc_solver\": milp_solver,\n",
Expand Down Expand Up @@ -276,7 +276,7 @@
" \"initial_p_output\": 0,\n",
" \"production_cost_bid_pairs\": [(p_min, 0), (wind_pmax, 0)],\n",
" \"startup_cost_pairs\": [(0, 0)],\n",
" \"fixed_commitment\": None,\n",
" \"fixed_commitment\": 1,\n",
"}\n",
"model_data = ThermalGeneratorModelData(**thermal_generator_params)\n",
"\n",
Expand Down Expand Up @@ -309,7 +309,8 @@
"outputs": [],
"source": [
"from idaes.apps.grid_integration.forecaster import Backcaster\n",
"from idaes.apps.grid_integration import Tracker, DoubleLoopCoordinator, Bidder\n",
"from idaes.apps.grid_integration import Tracker, Bidder\n",
"from dispatches.workflow.coordinator import DoubleLoopCoordinator\n",
"\n",
"# Backcaster\n",
"# help(Backcaster)\n",
Expand Down Expand Up @@ -1714,21 +1715,9 @@
}
],
"source": [
"from types import ModuleType\n",
"import shutil\n",
"\n",
"class PrescientPluginModule(ModuleType):\n",
" def __init__(self, get_configuration, register_plugins):\n",
" self.get_configuration = get_configuration\n",
" self.register_plugins = register_plugins\n",
"\n",
"\n",
"plugin_module = PrescientPluginModule(\n",
" get_configuration=coordinator.get_configuration,\n",
" register_plugins=coordinator.register_plugins,\n",
")\n",
"\n",
"prescient_options['plugin']['doubleloop']['module'] = plugin_module\n",
"prescient_options['plugin']['doubleloop']['module'] = coordinator.prescient_plugin_module\n",
"\n",
"if output_dir.exists():\n",
" shutil.rmtree(output_dir)\n",
Expand Down
16 changes: 2 additions & 14 deletions dispatches/case_studies/renewables_case/run_double_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
import idaes
from idaes.apps.grid_integration import (
Tracker,
DoubleLoopCoordinator,
Bidder,
SelfScheduler,
)
from dispatches.workflow.coordinator import DoubleLoopCoordinator
from idaes.apps.grid_integration.forecaster import Backcaster
from idaes.apps.grid_integration.model_data import (
RenewableGeneratorModelData,
Expand Down Expand Up @@ -307,18 +307,6 @@
projection_tracker=project_tracker_object,
)


class PrescientPluginModule(ModuleType):
def __init__(self, get_configuration, register_plugins):
self.get_configuration = get_configuration
self.register_plugins = register_plugins


plugin_module = PrescientPluginModule(
get_configuration=coordinator.get_configuration,
register_plugins=coordinator.register_plugins,
)

prescient_options = {
"data_path": rts_gmlc_data_dir,
"input_format": "rts-gmlc",
Expand All @@ -338,7 +326,7 @@ def __init__(self, get_configuration, register_plugins):
"sced_solver": "xpress_direct",
"plugin": {
"doubleloop": {
"module": plugin_module,
"module": coordinator.prescient_plugin_module,
"bidding_generator": "309_WIND_1",
}
},
Expand Down
94 changes: 94 additions & 0 deletions dispatches/workflow/coordinator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#################################################################################
# DISPATCHES was produced under the DOE Design Integration and Synthesis
# Platform to Advance Tightly Coupled Hybrid Energy Systems program (DISPATCHES),
# and is copyright (c) 2022 by the software owners: The Regents of the University
# of California, through Lawrence Berkeley National Laboratory, National
# Technology & Engineering Solutions of Sandia, LLC, Alliance for Sustainable
# Energy, LLC, Battelle Energy Alliance, LLC, University of Notre Dame du Lac, et
# al. All rights reserved.
#
# Please see the files COPYRIGHT.md and LICENSE.md for full copyright and license
# information, respectively. Both files are also available online at the URL:
# "https://github.com/gmlc-dispatches/dispatches".
#
#################################################################################

from types import ModuleType

from idaes.apps.grid_integration import DoubleLoopCoordinator as _DLC
from idaes.apps.grid_integration.utils import convert_marginal_costs_to_actual_costs


class PrescientPluginModule(ModuleType):
def __init__(self, get_configuration, register_plugins):
self.get_configuration = get_configuration
self.register_plugins = register_plugins


class DoubleLoopCoordinator(_DLC):

def register_plugins(self, context, options, plugin_config):
super().register_plugins(context, options, plugin_config)

context.register_after_get_initial_actuals_model_for_sced_callback(
self.update_static_params
)
context.register_after_get_initial_actuals_model_for_simulation_actuals_callback(
self.update_static_params
)
context.register_after_get_initial_forecast_model_for_ruc_callback(
self.update_static_params
)

@property
def prescient_plugin_module(self):
return PrescientPluginModule(self.get_configuration, self.register_plugins)

def _update_static_params(self, gen_dict):

is_thermal = (
self.bidder.bidding_model_object.model_data.generator_type == "thermal"
)
is_renewable = (
self.bidder.bidding_model_object.model_data.generator_type == "renewable"
)
for param, value in self.bidder.bidding_model_object.model_data:
if param == "gen_name" or value is None:
continue
elif (
param in gen_dict
and isinstance(gen_dict[param], dict)
and gen_dict[param]["data_type"] == "time_series"
):
# don't touch time varying things;
# presumably they be updated later
continue
elif param == "p_cost":
if is_thermal:
curve_value = convert_marginal_costs_to_actual_costs(value)
gen_dict[param] = {
"data_type": "cost_curve",
"cost_curve_type": "piecewise",
"values": curve_value,
}
elif is_renewable:
gen_dict[param] = value
else:
raise NotImplementedError(
"generator_type must be either 'thermal' or 'renewable'"
)

else:
gen_dict[param] = value

def update_static_params(self, options, instance):

gen_name = self.bidder.bidding_model_object.model_data.gen_name
gen_dict = instance.data["elements"]["generator"][gen_name]
self._update_static_params(gen_dict)

def pass_static_params_to_DA(self, *args, **kwargs):
pass

def pass_static_params_to_RT(self, *args, **kwargs):
pass
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class SpecialDependencies:
"jupyter",
# for visualizing DMF provenance
"graphviz",
"gridx-prescient>=2.2",
"gridx-prescient>=2.2.1",
"nrel-pysam>=3.0.1",
*SPECIAL_DEPENDENCIES
],
Expand Down