Skip to content

Commit

Permalink
Merge remote-tracking branch 'kaitlin/solver-refactor-2' into feature…
Browse files Browse the repository at this point in the history
…/refactor_hopp_solver
  • Loading branch information
bayc committed Apr 19, 2024
2 parents 87e4907 + b63c22c commit 0103e50
Show file tree
Hide file tree
Showing 24 changed files with 1,035 additions and 944 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.. _PowerSourceDispatch:


Power Source Dispatch
=====================

.. toctree::

.. autoclass:: hopp.simulation.technologies.dispatch.power_sources.power_source_dispatch.PowerSourceDispatch
:members:
28 changes: 21 additions & 7 deletions hopp/simulation/technologies/dispatch/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
from hopp.simulation.technologies.dispatch.power_sources.pv_dispatch import PvDispatch
from hopp.simulation.technologies.dispatch.power_sources.wind_dispatch import WindDispatch
from hopp.simulation.technologies.dispatch.power_sources.wind_dispatch import (
WindDispatch,
)
from hopp.simulation.technologies.dispatch.power_sources.csp_dispatch import CspDispatch
from hopp.simulation.technologies.dispatch.power_sources.trough_dispatch import TroughDispatch
from hopp.simulation.technologies.dispatch.power_sources.tower_dispatch import TowerDispatch
from hopp.simulation.technologies.dispatch.power_sources.wave_dispatch import WaveDispatch
from hopp.simulation.technologies.dispatch.power_sources.trough_dispatch import (
TroughDispatch,
)
from hopp.simulation.technologies.dispatch.power_sources.tower_dispatch import (
TowerDispatch,
)
from hopp.simulation.technologies.dispatch.power_sources.wave_dispatch import (
WaveDispatch,
)

from hopp.simulation.technologies.dispatch.grid_dispatch import GridDispatch
from hopp.simulation.technologies.dispatch.hybrid_dispatch_options import HybridDispatchOptions
from hopp.simulation.technologies.dispatch.hybrid_dispatch_options import (
HybridDispatchOptions,
)
from hopp.simulation.technologies.dispatch.hybrid_dispatch import HybridDispatch
from hopp.simulation.technologies.dispatch.dispatch_problem_state import DispatchProblemState
from hopp.simulation.technologies.dispatch.power_storage.simple_battery_dispatch import SimpleBatteryDispatch
from hopp.simulation.technologies.dispatch.dispatch_problem_state import (
DispatchProblemState,
)
from hopp.simulation.technologies.dispatch.power_storage.simple_battery_dispatch import (
SimpleBatteryDispatch,
)
34 changes: 22 additions & 12 deletions hopp/simulation/technologies/dispatch/dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,22 @@
try:
u.USD
except AttributeError:
u.load_definitions_from_strings(['USD = [currency]', 'lifecycle = [energy] / [energy]'])
u.load_definitions_from_strings(
["USD = [currency]", "lifecycle = [energy] / [energy]"]
)


class Dispatch:
"""
""" """

"""
def __init__(self,
pyomo_model: pyomo.ConcreteModel,
index_set: pyomo.Set,
system_model,
financial_model,
block_set_name: str = 'dispatch'):
def __init__(
self,
pyomo_model: pyomo.ConcreteModel,
index_set: pyomo.Set,
system_model,
financial_model,
block_set_name: str = "dispatch",
):

self.block_set_name = block_set_name
self.round_digits = int(4)
Expand All @@ -29,13 +33,19 @@ def __init__(self,

@staticmethod
def dispatch_block_rule(block, t):
raise NotImplemented("This function must be overridden for specific dispatch model")
raise NotImplemented(
"This function must be overridden for specific dispatch model"
)

def initialize_parameters(self):
raise NotImplemented("This function must be overridden for specific dispatch model")
raise NotImplemented(
"This function must be overridden for specific dispatch model"
)

def update_time_series_parameters(self, start_time: int):
raise NotImplemented("This function must be overridden for specific dispatch model")
raise NotImplemented(
"This function must be overridden for specific dispatch model"
)

@staticmethod
def _check_efficiency_value(efficiency):
Expand Down
40 changes: 23 additions & 17 deletions hopp/simulation/technologies/dispatch/dispatch_problem_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ def __init__(self):
self._gap = ()
self._n_non_optimal_solves = 0

def store_problem_metrics(self, solver_results, start_time, n_days, objective_value):
def store_problem_metrics(
self, solver_results, start_time, n_days, objective_value
):
self.start_time = start_time
self.n_days = n_days
self.termination_condition = str(solver_results.solver.termination_condition)
Expand All @@ -35,108 +37,112 @@ def store_problem_metrics(self, solver_results, start_time, n_days, objective_va

# solver_results.solution.Gap not define
if solver_results.problem.upper_bound != 0.0:
self.gap = (abs(solver_results.problem.upper_bound - solver_results.problem.lower_bound)
/ abs(solver_results.problem.upper_bound))
self.gap = abs(
solver_results.problem.upper_bound - solver_results.problem.lower_bound
) / abs(solver_results.problem.upper_bound)
elif solver_results.problem.lower_bound == 0.0:
self.gap = 0.0
else:
self.gap = float('inf')
self.gap = float("inf")

if not solver_results.solver.termination_condition == TerminationCondition.optimal:
if (
not solver_results.solver.termination_condition
== TerminationCondition.optimal
):
self._n_non_optimal_solves += 1

def _update_metric(self, metric_name, value):
data = list(getattr(self, metric_name))
data.append(value)
setattr(self, '_' + metric_name, tuple(data))
setattr(self, "_" + metric_name, tuple(data))

@property
def start_time(self) -> tuple:
return self._start_time

@start_time.setter
def start_time(self, start_hour: int):
self._update_metric('start_time', start_hour)
self._update_metric("start_time", start_hour)

@property
def n_days(self) -> tuple:
return self._n_days

@n_days.setter
def n_days(self, solve_days: int):
self._update_metric('n_days', solve_days)
self._update_metric("n_days", solve_days)

@property
def termination_condition(self) -> tuple:
return self._termination_condition

@termination_condition.setter
def termination_condition(self, condition: str):
self._update_metric('termination_condition', condition)
self._update_metric("termination_condition", condition)

@property
def solve_time(self) -> tuple:
return self._solve_time

@solve_time.setter
def solve_time(self, time: float):
self._update_metric('solve_time', time)
self._update_metric("solve_time", time)

@property
def objective(self) -> tuple:
return self._objective

@objective.setter
def objective(self, objective_value: float):
self._update_metric('objective', objective_value)
self._update_metric("objective", objective_value)

@property
def upper_bound(self) -> tuple:
return self._upper_bound

@upper_bound.setter
def upper_bound(self, bound: float):
self._update_metric('upper_bound', bound)
self._update_metric("upper_bound", bound)

@property
def lower_bound(self) -> tuple:
return self._lower_bound

@lower_bound.setter
def lower_bound(self, bound: float):
self._update_metric('lower_bound', bound)
self._update_metric("lower_bound", bound)

@property
def constraints(self) -> tuple:
return self._constraints

@constraints.setter
def constraints(self, constraint_count: int):
self._update_metric('constraints', constraint_count)
self._update_metric("constraints", constraint_count)

@property
def variables(self) -> tuple:
return self._variables

@variables.setter
def variables(self, variable_count: int):
self._update_metric('variables', variable_count)
self._update_metric("variables", variable_count)

@property
def non_zeros(self) -> tuple:
return self._non_zeros

@non_zeros.setter
def non_zeros(self, non_zeros_count: int):
self._update_metric('non_zeros', non_zeros_count)
self._update_metric("non_zeros", non_zeros_count)

@property
def gap(self) -> tuple:
return self._gap

@gap.setter
def gap(self, mip_gap: int):
self._update_metric('gap', mip_gap)
self._update_metric("gap", mip_gap)

@property
def n_non_optimal_solves(self) -> int:
Expand Down

0 comments on commit 0103e50

Please sign in to comment.