Skip to content

Commit

Permalink
Merge dev
Browse files Browse the repository at this point in the history
  • Loading branch information
p-snft committed Jan 12, 2024
2 parents 3686b82 + 3ad2fe2 commit cccf8ee
Show file tree
Hide file tree
Showing 58 changed files with 805 additions and 723 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.5.2dev2
current_version = 0.5.2.dev2
commit = True
tag = True

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v1
uses: actions/setup-python@v5
with:
python-version: 3.9

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/packaging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ jobs:
steps:
- uses: actions/checkout@v1
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools setuptools_scm twine wheel
python -m pip install --upgrade pip setuptools setuptools_scm twine wheel build
- name: Create packages
run: python setup.py sdist bdist_wheel
run: python -m build .
- name: Run twine check
run: twine check dist/*
- uses: actions/upload-artifact@v2
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tox_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
uses: actions/checkout@v2

- name: Set up Python ${{ env.default_python || '3.9' }}
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: "${{ env.default_python || '3.9' }}"

Expand All @@ -49,7 +49,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install -U pip
python -m pip install -U setuptools wheel
python -m pip install -U setuptools wheel build
python -m pip install -U tox
- name: Run ${{ matrix.toxenv }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tox_pytests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Install cbc
run: sudo apt install coinor-cbc
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
Expand Down
1 change: 0 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ graft tests

include .bumpversion.cfg
include .coveragerc
include .cookiecutterrc
include .editorconfig

include AUTHORS.rst
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.5.2dev2"
__version__ = "0.5.2.dev2"
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def setup(app):
year = "2014-2023"
author = "oemof-developer-group"
copyright = "{0}, {1}".format(year, author)
version = release = "0.5.2dev2"
version = release = "0.5.2.dev2"

pygments_style = "trac"
templates_path = ["."]
Expand Down
3 changes: 3 additions & 0 deletions docs/whatsnew/v0-5-2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ New features

* Allow for evaluating differences in the remaining vs. the original value
for multi-period investments.
* Allow to define minimum up- and down-time per time step

Documentation
#############
Expand All @@ -23,6 +24,8 @@ Bug fixes
bias towards investments happening earlier in the optimization horizon.
* Fix bugs in multi-period documentation.
* Fix y intersect of OffsetConverter
* Fix minimum uptime being relevant for initial downtime (and vice versa).
* Fix duplicated discounting of fixed costs for multi-period investment

Testing
#######
Expand Down
8 changes: 5 additions & 3 deletions examples/basic_example/basic_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def main():
try:
data = pd.read_csv(filename)
except FileNotFoundError:
msg = "Data file not found: {0}. Only one value used!"
msg = "Data file not found: {0}. Values for one timestep created!"
warnings.warn(msg.format(filename), UserWarning)
data = pd.DataFrame({"pv": [0.3], "wind": [0.6], "demand_el": [500]})

Expand All @@ -109,12 +109,13 @@ def main():
logging.info("Initialize the energy system")
date_time_index = create_time_index(2012, number=number_of_time_steps)

# create the energysystem and assign the time index
energysystem = EnergySystem(
timeindex=date_time_index, infer_last_interval=False
)

##########################################################################
# Create oemof object
# Create oemof objects
##########################################################################

logging.info("Create oemof objects")
Expand All @@ -134,7 +135,7 @@ def main():
# create excess component for the electricity bus to allow overproduction
energysystem.add(cmp.Sink(label="excess_bel", inputs={bel: flows.Flow()}))

# create source object representing the gas commodity (annual limit)
# create source object representing the gas commodity
energysystem.add(
cmp.Source(
label="rgas",
Expand All @@ -159,6 +160,7 @@ def main():
)

# create simple sink object representing the electrical demand
# nominal_value is set to 1 because demand_el is not a normalised series
energysystem.add(
cmp.Sink(
label="demand",
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ exclude = '''
'''

[build-system]
requires = ["setuptools<60.0", "wheel"]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ python_files =
tests.py
addopts =
-ra
--strict
--strict-markers
--ignore=docs/conf.py
--ignore=setup.py
--ignore=ci
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def read(*names, **kwargs):

setup(
name="oemof.solph",
version="0.5.2dev2",
version="0.5.2.dev2",
license="MIT",
description=(
"A model generator for energy system modelling and optimisation."
Expand Down
2 changes: 1 addition & 1 deletion src/oemof/solph/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.5.2dev2"
__version__ = "0.5.2.dev2"

from . import buses
from . import components
Expand Down
10 changes: 7 additions & 3 deletions src/oemof/solph/_energy_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,16 @@ def __init__(
infer_last_interval=None,
periods=None,
use_remaining_value=False,
**kwargs,
groupings=None,
):
# Doing imports at runtime is generally frowned upon, but should work
# for now. See the TODO in :func:`constraint_grouping
# <oemof.solph.groupings.constraint_grouping>` for more information.
from oemof.solph import GROUPINGS

kwargs["groupings"] = GROUPINGS + kwargs.get("groupings", [])
if groupings is None:
groupings = []
groupings = GROUPINGS + groupings

if not (
isinstance(timeindex, pd.DatetimeIndex)
Expand Down Expand Up @@ -161,7 +163,9 @@ def __init__(
raise TypeError(msg)

super().__init__(
timeindex=timeindex, timeincrement=timeincrement, **kwargs
groupings=groupings,
timeindex=timeindex,
timeincrement=timeincrement,
)

self.periods = periods
Expand Down
33 changes: 14 additions & 19 deletions src/oemof/solph/_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
SPDX-License-Identifier: MIT
"""

from oemof.solph._plumbing import sequence


Expand Down Expand Up @@ -184,11 +183,11 @@ class NonConvex:
from the actual output.
inactivity_costs : numeric (iterable or scalar)
Costs associated with not operating the flow.
minimum_uptime : numeric (1 or positive integer)
minimum_uptime : numeric or list of numeric (1 or positive integer)
Minimum number of time steps that a flow must be greater then its
minimum flow after startup. Be aware that minimum up and downtimes
can contradict each other and may lead to infeasible problems.
minimum_downtime : numeric (1 or positive integer)
minimum_downtime : numeric or list of numeric (1 or positive integer)
Minimum number of time steps a flow is forced to zero after
shutting down. Be aware that minimum up and downtimes can
contradict each other and may to infeasible problems.
Expand All @@ -199,12 +198,12 @@ class NonConvex:
initial_status : numeric (0 or 1)
Integer value indicating the status of the flow in the first time step
(0 = off, 1 = on). For minimum up and downtimes, the initial status
is set for the respective values in the edge regions e.g. if a
minimum uptime of four timesteps is defined, the initial status is
fixed for the four first and last timesteps of the optimization period.
If both, up and downtimes are defined, the initial status is set for
the maximum of both e.g. for six timesteps if a minimum downtime of
six timesteps is defined besides a four timestep minimum uptime.
is set for the respective values in the beginning e.g. if a
minimum uptime of four timesteps is defined and the initial status is
set to one, the initial status is fixed for the four first timesteps
of the optimization period. Otherwise if the initial status is set to
zero and the first timesteps are fixed for the number of minimum
downtime steps.
negative_gradient_limit : numeric (iterable, scalar or None)
the normed *upper bound* on the positive difference
(`flow[t-1] < flow[t]`) of two consecutive flow values.
Expand Down Expand Up @@ -232,8 +231,8 @@ def __init__(
custom_attributes = {}

self.initial_status = initial_status
self.minimum_uptime = minimum_uptime
self.minimum_downtime = minimum_downtime
self.minimum_uptime = sequence(minimum_uptime)
self.minimum_downtime = sequence(minimum_downtime)
self.maximum_startups = maximum_startups
self.maximum_shutdowns = maximum_shutdowns

Expand All @@ -247,11 +246,7 @@ def __init__(
for attribute, value in custom_attributes.items():
setattr(self, attribute, value)

@property
def max_up_down(self):
"""Return maximum of minimum_uptime and minimum_downtime.
The maximum of both is used to set the initial status for this
number of time steps within the edge regions.
"""
return max(self.minimum_uptime, self.minimum_downtime)
if initial_status == 0:
self.first_flexible_timestep = self.minimum_downtime[0]
else:
self.first_flexible_timestep = self.minimum_uptime[0]
4 changes: 2 additions & 2 deletions src/oemof/solph/_plumbing.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class _Sequence(UserList):
--------
>>> s = _Sequence(default=42)
>>> len(s)
0
1
>>> s[1]
42
>>> s[2]
Expand All @@ -79,7 +79,7 @@ class _Sequence(UserList):
def __init__(self, *args, **kwargs):
self.default = kwargs["default"]
self.default_changed = False
self.highest_index = -1
self.highest_index = 0
super().__init__(*args)

def __getitem__(self, key):
Expand Down
8 changes: 6 additions & 2 deletions src/oemof/solph/buses/_bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,17 @@ def __init__(
self,
label=None,
*,
balanced=True,
inputs=None,
outputs=None,
balanced=True,
custom_properties=None,
):
if inputs is None:
inputs = {}
if outputs is None:
outputs = {}
super().__init__(
label=label,
label,
inputs=inputs,
outputs=outputs,
custom_properties=custom_properties,
Expand Down
25 changes: 20 additions & 5 deletions src/oemof/solph/buses/experimental/_electrical_bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,23 @@ class ElectricalBus(Bus):
"""

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.slack = kwargs.get("slack", False)
self.v_max = kwargs.get("v_max", 1000)
self.v_min = kwargs.get("v_min", -1000)
def __init__(
self,
label=None,
*,
v_max,
v_min,
inputs=None,
outputs=None,
custom_properties=None,
slack=False,
):
super().__init__(
label,
inputs=inputs,
outputs=outputs,
custom_properties=custom_properties,
)
self.slack = slack
self.v_max = v_max
self.v_min = v_min
8 changes: 5 additions & 3 deletions src/oemof/solph/components/_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,8 @@ def __init__(
custom_attributes=None,
):
if inputs is None:
warn_if_missing_attribute(self, "inputs")
inputs = {}
if outputs is None:
warn_if_missing_attribute(self, "outputs")
outputs = {}

if custom_attributes is None:
Expand All @@ -115,8 +113,12 @@ def __init__(
label=label,
inputs=inputs,
outputs=outputs,
**custom_attributes,
custom_properties=custom_attributes,
)
if not inputs:
warn_if_missing_attribute(self, "inputs")
if not outputs:
warn_if_missing_attribute(self, "outputs")

if conversion_factors is None:
conversion_factors = {}
Expand Down
6 changes: 3 additions & 3 deletions src/oemof/solph/components/_generic_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,10 @@ def __init__(
if custom_attributes is None:
custom_attributes = {}
super().__init__(
label=label,
label,
inputs=inputs,
outputs=outputs,
**custom_attributes,
custom_properties=custom_attributes,
)
# --- BEGIN: The following code can be removed for versions >= v0.6 ---
if investment is not None:
Expand Down Expand Up @@ -1869,7 +1869,7 @@ def _objective_expression(self):
m.es.periods_years[p],
range_limit,
)
) * (1 + m.discount_rate) ** (-m.es.periods_years[p])
)

for n in self.EXISTING_INVESTSTORAGES:
if n.investment.fixed_costs[0] is not None:
Expand Down
Loading

0 comments on commit cccf8ee

Please sign in to comment.