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

Set time keys in SCEDs to correct date and time #183

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions prescient/engine/egret/egret_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ def _zero_out_costs(sced_model, hours_in_objective):
# TBD - we probably want to grab topology from somewhere, even if the stochastic
# RUC is not solved with the topology.
def create_sced_instance(data_provider:DataProvider,
when: datetime.datetime,
current_state:SimulationState,
options,
sced_horizon,
Expand Down Expand Up @@ -239,6 +240,12 @@ def create_sced_instance(data_provider:DataProvider,
# make sure the generator can immediately turn off
g_dict['shutdown_capacity'] = max(g_dict['shutdown_capacity'], (60./current_state.minutes_per_step)*g_dict['initial_p_output'] + 1.)

# Set the time keys
timekey_array = sced_md.data['system']['time_keys']
for t in range(sced_horizon):
dt = when + datetime.timedelta(minutes=t*current_state.minutes_per_step)
timekey_array[t] = dt.strftime('%Y-%m-%d %H:%M')

return sced_md

# cache for shutdown curves
Expand Down
2 changes: 2 additions & 0 deletions prescient/engine/egret/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ def create_simulation_actuals(

def create_sced_instance(self,
options: Options,
when: datetime.datetime,
current_state: SimulationState,
hours_in_objective: int,
sced_horizon: int,
Expand All @@ -143,6 +144,7 @@ def create_sced_instance(self,

current_sced_instance = self._p.create_sced_instance(
self._data_provider,
when,
current_state,
options,
sced_horizon,
Expand Down
1 change: 1 addition & 0 deletions prescient/engine/modeling_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def create_simulation_actuals(
@abstractmethod
def create_sced_instance(self,
options: Options,
when: datetime.datetime,
current_state: SimulationState,
hours_in_objective: int,
sced_horizon: int,
Expand Down
12 changes: 7 additions & 5 deletions prescient/simulator/oracle_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def _get_uc_activation_time(self, options, time_step):
ruc_delay = self._get_ruc_delay(options)
activation_time = time_step.datetime + timedelta(hours=ruc_delay)

return (activation_time.hour, activation_time.date())
return activation_time

def _get_projected_state(self, options: Options, time_step: PrescientTime) -> SimulationState:
''' Get the simulation state as we project it will appear after the RUC delay '''
Expand All @@ -59,10 +59,10 @@ def _get_projected_state(self, options: Options, time_step: PrescientTime) -> Si
print("Drawing UC initial conditions for date:", time_step.date, "hour:", time_step.hour, "from prior SCED instance.")
return self.data_manager.current_state

uc_hour, uc_date = self._get_uc_activation_time(options, time_step)
act_time = self._get_uc_activation_time(options, time_step)

print("")
print("Creating and solving SCED to determine UC initial conditions for date:", str(uc_date), "hour:", uc_hour)
print("Creating and solving SCED to determine UC initial conditions for date:", str(act_time.date()), "hour:", act_time.hour)

# determine the SCED execution mode, in terms of how discrepancies between forecast and actuals are handled.
# prescient processing is identical in the case of deterministic and stochastic RUC.
Expand All @@ -81,6 +81,7 @@ def _get_projected_state(self, options: Options, time_step: PrescientTime) -> Si
current_state = self.data_manager.current_state.get_state_with_step_length(60)
projected_sced_instance = self.engine.create_sced_instance(
options,
act_time,
current_state,
hours_in_objective=min(24, current_state.timestep_count),
sced_horizon=min(24, current_state.timestep_count),
Expand Down Expand Up @@ -129,8 +130,8 @@ def call_planning_oracle(self, options: Options, time_step: PrescientTime) -> No
''' Create a new RUC and make it the pending RUC
'''
projected_state = self._get_projected_state(options, time_step)
uc_hour, uc_date = self._get_uc_activation_time(options, time_step)
self._generate_pending_ruc(options, uc_date, uc_hour, projected_state)
act_time = self._get_uc_activation_time(options, time_step)
self._generate_pending_ruc(options, act_time.date(), act_time.hour, projected_state)

def _formulate_ruc(self, options, uc_date, uc_hour, sim_state_for_ruc):
'''Create a RUC model holding forecast data.
Expand Down Expand Up @@ -251,6 +252,7 @@ def call_operation_oracle(self, options: Options, time_step: PrescientTime):
sced_horizon_timesteps = options.sced_horizon
current_sced_instance = self.engine.create_sced_instance(
options,
time_step.datetime,
self.data_manager.current_state.get_state_with_step_length(options.sced_frequency_minutes),
hours_in_objective=1,
sced_horizon=sced_horizon_timesteps,
Expand Down
Loading