Skip to content

Commit

Permalink
still updating docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
michal-g committed Jan 26, 2023
1 parent de47d99 commit 66ab71d
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 67 deletions.
3 changes: 0 additions & 3 deletions vatic/engines.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class Simulator:
Parameters
----------
template_data Static grid properties such as line capacities, thermal
generator cost curves, network topology, etc.
gen_data Forecasted and actual renewable generator outputs.
Expand Down Expand Up @@ -164,8 +163,6 @@ def __init__(self,
output_max_decimals: int, create_plots: bool,
renew_costs, save_to_csv, last_conditions_file) -> None:

import pdb; pdb.set_trace()

self._ruc_solver = self._verify_solver(solver, 'RUC')
self._sced_solver = self._verify_solver(solver, 'SCED')

Expand Down
109 changes: 56 additions & 53 deletions vatic/model_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
import dill as pickle
from pathlib import Path
from copy import copy, deepcopy
from typing import Any, TypeVar, Iterable, Iterator
VModelData = TypeVar('VModelData', bound='VaticModelData')

from egret.data.model_data import ModelData as EgretModel

from typing import TypeVar, Any, Optional, Union, Iterable, Iterator
VModelData = TypeVar('VModelData', bound='VaticModelData')


class ModelError(Exception):
pass
Expand All @@ -18,8 +18,11 @@ class ModelError(Exception):
class VaticModelData(object):
"""Simplified version of egret.data.model_data.ModelData"""

def __init__(self,
source: dict | VModelData | str | Path | None = None) -> None:
def __init__(
self,
source: Optional[Union[VModelData, dict, Path, str]] = None
) -> None:

if isinstance(source, dict):
self._data = deepcopy(source)

Expand Down Expand Up @@ -146,22 +149,22 @@ def get_forecastables(self) -> Iterator[tuple[tuple[str, str],
'system']['reserve_requirement']['values']

def time_series(self,
element_types: Iterable[str] | None = None,
element_types: Optional[Iterable[str]] = None,
include_reserves: bool = True,
**element_args: str) -> Iterator[tuple]:
"""Retrieves timeseries for grid elements that match a set of criteria.
Args
----
element_types Which types of element to search within,
e.g. 'storage', 'load', generator', 'bus', etc.
include_reserves Whether to return reserve requirements, which
will never be returned otherwise.
element_args A set of element property values, all of which must
be present in an element's data entry and equal to
the given value for the element's entry to be
returned. e.g. generator_type='thermal'
in_service=True
Arguments
---------
element_types Which types of element to search within,
e.g. 'storage', 'load', generator', 'bus', etc.
include_reserves Whether to return reserve requirements, which
will never be returned otherwise.
element_args A set of element property values, all of which must be
present in an element's data entry and equal to the
given value for the element's entry to be returned.
e.g. generator_type='thermal' in_service=True
"""
if element_types is None:
Expand All @@ -185,27 +188,27 @@ def time_series(self,
self._data['system']['reserve_requirement'])

def copy_elements(self,
other: VModelData, element_type: str,
attrs: Iterable[str] | None = None,
strict_mode: bool = False, **element_args: str) -> None:
other: Self, element_type: str,
attrs: Optional[Iterable[str]] = None,
strict_mode: bool = False, **element_args: dict) -> None:
"""Replaces grid elements with those in another model data object.
Args
----
other The model data object we will be copying from.
element_type Which type of element to copy from, e.g. 'bus',
'generator', 'load', 'branch', etc.
attrs If given, only copy data from within these element
entry fields, e.g. 'p_min', 'generator_type', etc.
strict_mode Raise an error if an element meeting the criteria
for copying in the other model data object is
not present in this model data object.
Arguments
---------
other The model data object we will be copying from.
element_args A set of element property values, all of which must
be present in an element's data entry and equal to
the given value for the element's entry to be
copied. e.g. generator_type='thermal'
in_service=False
element_type Which type of element to copy from.
e.g. 'bus', 'generator', 'load', 'branch', etc.
attrs If given, only copy data from within these element entry
fields, e.g. 'p_min', 'generator_type', etc.
strict_mode Raise an error if an element meeting the criteria
for copying in the other model data object is not
present in this model data object.
element_args A set of element property values, all of which must be
present in an element's data entry and equal to the
given value for the element's entry to be copied.
e.g. generator_type='thermal' in_service=False
"""
for name, elem in other.elements(element_type, **element_args):
Expand All @@ -228,11 +231,11 @@ def copy_forecastables(self,
time_index: int, other_time_index: int) -> None:
"""Replaces forecastable values with those from another model data.
Args
----
other The model data object we will be copying from.
time_index Which time step to replace in this model data.
other_time_index Which time step to copy from in the other data.
Arguments
---------
other The model data object we will be copying from.
time_index Which time step to replace in this model data.
other_time_index Which time step to copy from in the other data.
"""
for gen, gen_data in other.elements('generator',
Expand Down Expand Up @@ -264,12 +267,12 @@ def set_time_steps(self,
period_minutes: int) -> None:
"""Initializes time indices, creates empty placeholder timeseries.
Args
----
time_steps How many time steps there will be (creating time
indices [1,2,...,<time_steps>]) or a list of the
time indices themselves.
period_minutes How many minutes are in each time step.
Arguments
---------
time_steps How many time steps there will be (creating time
indices [1,2,...,<time_steps>]) or a list of the time
indices themselves.
period_minutes How many minutes are in each time step.
"""
if isinstance(time_steps, int):
Expand All @@ -291,11 +294,11 @@ def honor_reserve_factor(self,
Arguments
---------
reserve_factor The proportion of total system demand (load)
that is necessary for the reserve requirement.
time_index Which time step to set the reserve req at.
"""
reserve_factor The proportion of total system demand (load)
that is necessary for the reserve requirement.
time_index Which time step to set the reserve req at.
"""
if reserve_factor > 0:
total_load = sum(bus_data['p_load']['values'][time_index]
for bus, bus_data in self.elements('load'))
Expand All @@ -305,6 +308,9 @@ def honor_reserve_factor(self,
self._data['system']['reserve_requirement']['values'][time_index] \
= max(reserve_factor * total_load, cur_req)

def to_egret(self) -> EgretModel:
return EgretModel(deepcopy(self._data))

@property
def model_runtime(self):
return self._data['system']['solver_runtime']
Expand Down Expand Up @@ -632,6 +638,3 @@ def storage_types(self):
pass

return

def to_egret(self) -> EgretModel:
return EgretModel(deepcopy(self._data))
37 changes: 26 additions & 11 deletions vatic/simulation_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,20 @@


class VaticSimulationState:
"""A system state that can be updated with data from RUCs and SCEDs."""
"""A system state that can be updated with data from RUCs and SCEDs.
Parameters
----------
ruc_execution_hour Which hour of the day the unit commitment is run.
ruc_every_hours How often to run unit commitments.
sced_frequency_minutes How often to run real-time economic dispatches.
"""

def __init__(self,
ruc_execution_hour: int, ruc_every_hours: int,
sced_frequency_minutes: int):
sced_frequency_minutes: int) -> None:
self._forecasts = None
self._actuals = None
self._commits = dict()
Expand All @@ -25,7 +34,6 @@ def __init__(self,
# timestep durations; how often a SCED is run
self._minutes_per_forecast_step = 60
self._minutes_per_actuals_step = 60
self._sced_frequency = 60

# the current simulation minute and the next minute when forecasts
# should be popped
Expand Down Expand Up @@ -272,9 +280,16 @@ class VaticStateWithOffset:
The offset state is identical to the state being offset, except that time
periods before the offset time are skipped.
Parameters
----------
parent_state The current state we are using as the reference.
offset The number of time periods to skip in the parent state.
"""

def __init__(self, parent_state: VaticSimulationState, offset: int):
def __init__(self,
parent_state: VaticSimulationState, offset: int) -> None:
self._parent = parent_state
self._offset = offset

Expand Down Expand Up @@ -334,13 +349,13 @@ class VaticStateWithScedOffset(VaticStateWithOffset, VaticSimulationState):
is also offset, so that the initial state comes from the Nth time period
of the sced.
Args
----
parent_state The state to project into the future.
sced A sced instance whose state after the offset is used as
the initial state.
offset The number of time periods into the future this state
should reflect.
Parameters
----------
parent_state The state to project into the future.
sced A sced instance whose state after the offset is used as
the initial state here.
offset The # of time periods into the future the state should reflect.
"""

def __init__(self,
Expand Down

0 comments on commit 66ab71d

Please sign in to comment.