Skip to content

Commit

Permalink
Warn if model overwrites timeincrement
Browse files Browse the repository at this point in the history
It seems to be a desired (and tested) feature to do so, but a typical user
will probably not want to do this. So, a warning makes sense.
  • Loading branch information
p-snft committed Jul 3, 2024
1 parent 83e5645 commit 1b04e70
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
13 changes: 9 additions & 4 deletions src/oemof/solph/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,14 @@ def __init__(self, energysystem, discount_rate=None, **kwargs):
self.name = kwargs.get("name", type(self).__name__)

self.es = energysystem
self.timeincrement = kwargs.get("timeincrement", self.es.timeincrement)

if kwargs.get("timeincrement"):
msg = "Resetting timeincrement from EnergySystem in Model."
warnings.warn(msg, debugging.SuspiciousUsageWarning)

self.timeincrement = kwargs.get("timeincrement")
else:
self.timeincrement = self.es.timeincrement

self.objective_weighting = kwargs.get(
"objective_weighting", self.timeincrement
Expand All @@ -182,7 +189,7 @@ def __init__(self, energysystem, discount_rate=None, **kwargs):
self.solver_results = None
self.dual = None
self.rc = None

if discount_rate is not None:
self.discount_rate = discount_rate
elif (
Expand Down Expand Up @@ -343,7 +350,6 @@ def _add_parent_block_variables(self):
for t in self.TIMESTEPS:
self.flow[o, i, t].setlb(0)


def _add_child_blocks(self):
"""Method to add the defined child blocks for components that have
been grouped in the defined constraint groups. This collects all the
Expand Down Expand Up @@ -453,4 +459,3 @@ def relax_problem(self):
relaxer._apply_to(self)

return self

4 changes: 3 additions & 1 deletion tests/test_time_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import pytest

from oemof import solph
from oemof.tools import debugging


def test_energysystem_with_datetimeindex_infer_last_interval():
Expand Down Expand Up @@ -151,7 +152,8 @@ def test_overwrite_timeincrement():
infer_last_interval=True,
)
assert es.timeincrement[0] == 1
m = solph._models.Model(es, timeincrement=[3])
with pytest.warns(debugging.SuspiciousUsageWarning):
m = solph._models.Model(es, timeincrement=[3])
assert m.timeincrement[0] == 3


Expand Down

0 comments on commit 1b04e70

Please sign in to comment.