Skip to content

Commit

Permalink
Merge pull request #1112 from oemof/revision/remove_v04_compatibility…
Browse files Browse the repository at this point in the history
…_wrappers

Revision/remove v0.4 compatibility wrappers
  • Loading branch information
p-snft authored Dec 17, 2024
2 parents 794b9b5 + 0588563 commit 9be114c
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 212 deletions.
7 changes: 7 additions & 0 deletions docs/whatsnew/v0-6-0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ API changes
effectively the same) had double weight before. Also, if the
initial storage level is defined, the costs just offset the
objective value without changing anything else.
* Tansitional wrappers that still allowed to use "Transformer" and
"OffsetTransformer" have been removed. Use of the new names
("Converter" and "OffsetConverter") is now obligatory.
* Tansitional wrappers that still allowed to use "investment",
"summed_min", and "summed_max" as arguments to initialise a Flow
have been removed. Use of the new names ("nominal_value",
"full_load_time_min", and "full_load_time_max") is now obligatory.
* Rename custom_attributes to custom_properties for all Nodes.
Setting the oemof.network.Node.custom_properties
using an argument called "custom_attributes" was rather confusing.
Expand Down
4 changes: 0 additions & 4 deletions src/oemof/solph/components/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@

from . import experimental
from ._converter import Converter
from ._converter import Transformer
from ._extraction_turbine_chp import ExtractionTurbineCHP
from ._generic_chp import GenericCHP
from ._generic_storage import GenericStorage
from ._link import Link
from ._offset_converter import OffsetConverter
from ._offset_converter import OffsetTransformer
from ._offset_converter import slope_offset_from_nonconvex_input
from ._offset_converter import slope_offset_from_nonconvex_output
from ._sink import Sink
Expand All @@ -31,9 +29,7 @@
"GenericStorage",
"OffsetConverter",
"Link",
"OffsetTransformer",
"Sink",
"Transformer",
"Source",
"slope_offset_from_nonconvex_input",
"slope_offset_from_nonconvex_output",
Expand Down
30 changes: 0 additions & 30 deletions src/oemof/solph/components/_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
"""

from warnings import warn

from oemof.network import Node
from pyomo.core import BuildAction
from pyomo.core import Constraint
Expand Down Expand Up @@ -137,34 +135,6 @@ def constraint_group(self):
return ConverterBlock


# --- BEGIN: To be removed for versions >= v0.6 ---
class Transformer(Converter):
def __init__(
self,
label=None,
inputs=None,
outputs=None,
conversion_factors=None,
custom_attributes=None,
):
super().__init__(
label=label,
inputs=inputs,
outputs=outputs,
conversion_factors=conversion_factors,
custom_properties=custom_attributes,
)
warn(
"solph.components.Transformer has been renamed to"
" solph.components.Converter. The transitional wrapper"
" will be deleted in the future.",
FutureWarning,
)


# --- END ---


class ConverterBlock(ScalarBlock):
r"""Block for the linear relation of nodes with type
:class:`~oemof.solph.components._converter.ConverterBlock`
Expand Down
23 changes: 1 addition & 22 deletions src/oemof/solph/components/_generic_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,6 @@ class GenericStorage(Node):
To set different values in every time step use a sequence.
max_storage_level : numeric (iterable or scalar), :math:`c_{max}(t)`
see: min_storage_level
investment : :class:`oemof.solph.options.Investment` object
Object indicating if a nominal_capacity of the flow is determined by
the optimization problem. Note: This will refer all attributes to an
investment variable instead of to the nominal_storage_capacity. The
nominal_storage_capacity should not be set (or set to None) if an
investment object is used.
storage_costs : numeric (iterable or scalar), :math:`c_{storage}(t)`
Cost (per energy) for having energy in the storage, starting from
time point :math:`t_{1}`.
Expand Down Expand Up @@ -171,7 +165,6 @@ def __init__(
nominal_capacity=None,
nominal_storage_capacity=None, # Can be removed for versions >= v0.7
initial_storage_level=None,
investment=None,
invest_relation_input_output=None,
invest_relation_input_capacity=None,
invest_relation_output_capacity=None,
Expand Down Expand Up @@ -201,21 +194,7 @@ def __init__(
outputs=outputs,
custom_properties=custom_attributes,
)
# --- BEGIN: The following code can be removed for versions >= v0.6 ---
if investment is not None:
msg = (
"For backward compatibility,"
" the option investment overwrites the option"
+ " nominal_storage_capacity."
+ " Both options cannot be set at the same time."
)
if nominal_capacity is not None:
raise AttributeError(msg)
else:
warn(msg, FutureWarning)
nominal_storage_capacity = investment
# --- END ---
# --- BEGIN: The following code can be removed for versions >= v0.6 ---
# --- BEGIN: The following code can be removed for versions >= v0.7 ---
if nominal_storage_capacity is not None:
msg = (
"For backward compatibility,"
Expand Down
57 changes: 14 additions & 43 deletions src/oemof/solph/components/_offset_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,30 +151,26 @@ def __init__(
custom_properties=custom_properties,
)

# --- BEGIN: To be removed for versions >= v0.7 ---
# this part is used for the transition phase from the old
# OffsetConverter API to the new one. It calcualtes the
# conversion_factors and normed_offsets from the coefficients and the
# outputs information on min and max.
if (
coefficients is not None
and conversion_factors is None
and normed_offsets is None
):
if coefficients is not None:
if conversion_factors is not None or normed_offsets is not None:
msg = (
"The deprecated argument `coefficients` cannot be used "
"in combination with its replacements "
"(`conversion_factors` and `normed_offsets`)."
)
raise TypeError(msg)

normed_offsets, conversion_factors = (
self.normed_offset_and_conversion_factors_from_coefficients(
coefficients
)
)

elif coefficients is not None and (
conversion_factors is not None or normed_offsets is not None
):
msg = (
"The deprecated argument `coefficients` cannot be used in "
"combination with its replacements (`conversion_factors` and "
"`normed_offsets`)."
)
raise TypeError(msg)
# --- END ---

_reference_flow = [v for v in self.inputs.values() if v.nonconvex]
_reference_flow += [v for v in self.outputs.values() if v.nonconvex]
Expand Down Expand Up @@ -252,6 +248,7 @@ def __init__(
def constraint_group(self):
return OffsetConverterBlock

# --- BEGIN: To be removed for versions >= v0.7 ---
def normed_offset_and_conversion_factors_from_coefficients(
self, coefficients
):
Expand Down Expand Up @@ -318,6 +315,8 @@ def normed_offset_and_conversion_factors_from_coefficients(

return normed_offsets, conversion_factors

# --- END ---

def plot_partload(self, bus, tstep):
"""Create a matplotlib figure of the flow to nonconvex flow relation.
Expand Down Expand Up @@ -378,34 +377,6 @@ def plot_partload(self, bus, tstep):
return fig, ax


# --- BEGIN: To be removed for versions >= v0.6 ---
class OffsetTransformer(OffsetConverter):
def __init__(
self,
inputs,
outputs,
label=None,
coefficients=None,
custom_attributes=None,
):
super().__init__(
label=label,
inputs=inputs,
outputs=outputs,
coefficients=coefficients,
custom_properties=custom_attributes,
)
warn(
"solph.components.OffsetTransformer has been renamed to"
" solph.components.OffsetConverter. The transitional wrapper"
" will be deleted in the future.",
FutureWarning,
)


# --- END ---


class OffsetConverterBlock(ScalarBlock):
r"""Block for the relation of nodes with type
:class:`~oemof.solph.components._offset_converter.OffsetConverter`
Expand Down
31 changes: 0 additions & 31 deletions src/oemof/solph/flows/_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,6 @@ def __init__(
lifetime=None,
age=None,
fixed_costs=None,
# --- BEGIN: To be removed for versions >= v0.6 ---
investment=None,
summed_max=None,
summed_min=None,
# --- END ---
custom_attributes=None,
):
# TODO: Check if we can inherit from pyomo.core.base.var _VarData
Expand All @@ -153,32 +148,6 @@ def __init__(
# is created. E.g. create the variable in the energy system and
# populate with information afterwards when creating objects.

# --- BEGIN: The following code can be removed for versions >= v0.6 ---
if investment is not None:
msg = (
"For backward compatibility,"
" the option investment overwrites the option nominal_value."
+ " Both options cannot be set at the same time."
)
if nominal_value is not None:
raise AttributeError(msg)
else:
warn(msg, FutureWarning)
nominal_value = investment

msg = (
"\nThe parameter '{0}' is deprecated and will be removed "
+ "in version v0.6.\nUse the parameter '{1}', "
+ "to avoid this warning and future problems. "
)
if summed_max is not None:
warn(msg.format("summed_max", "full_load_time_max"), FutureWarning)
full_load_time_max = summed_max
if summed_min is not None:
warn(msg.format("summed_min", "full_load_time_min"), FutureWarning)
full_load_time_min = summed_min
# --- END ---

# --- BEGIN: The following code can be removed for versions >= v0.7 ---
if nominal_value is not None:
msg = (
Expand Down
33 changes: 0 additions & 33 deletions tests/test_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,28 +42,6 @@ def test_generic_storage_1():
)


def test_generic_storage_2():
"""Nominal capacity defined with investment model."""
bel = Bus()
with pytest.raises(
AttributeError,
match="For backward compatibility, the option investment overwrites",
):
components.GenericStorage(
label="storage3",
nominal_capacity=45,
inputs={bel: Flow(variable_costs=10e10)},
outputs={bel: Flow(variable_costs=10e10)},
loss_rate=0.00,
initial_storage_level=0,
invest_relation_input_capacity=1 / 6,
invest_relation_output_capacity=1 / 6,
inflow_conversion_factor=1,
outflow_conversion_factor=0.8,
investment=Investment(ep_costs=23),
)


def test_generic_storage_3():
"""Nominal capacity defined with investment model."""
bel = Bus()
Expand Down Expand Up @@ -150,17 +128,6 @@ def test_generic_storage_with_convex_invest_offset():
)


def test_generic_storage_invest_warning():
with pytest.warns(FutureWarning):
bel = Bus()
components.GenericStorage(
label="storage7",
inputs={bel: Flow()},
outputs={bel: Flow()},
investment=Investment(),
)


def test_generic_storage_with_invest_and_fixed_losses_absolute():
"""
Storage with fixed losses in the investment mode but no minimum or existing
Expand Down
2 changes: 1 addition & 1 deletion tests/test_components/test_offset_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def test_wrong_number_of_coefficients():
bus1 = solph.Bus()
bus2 = solph.Bus()
with pytest.raises(ValueError, match="Two coefficients"):
solph.components.OffsetTransformer(
solph.components.OffsetConverter(
inputs={
bus1: solph.Flow(
nominal_capacity=2, nonconvex=solph.NonConvex()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_components/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ def test_invest_content_maximum():
)


# --- BEGIN: The following code can be removed for versions >= v0.6 ---
# --- BEGIN: The following code can be removed for versions >= v0.7 ---
def test_capacity_keyword_wrapper_warning():
with pytest.warns(FutureWarning, match="nominal_storage_capacity"):
bus = solph.Bus()
Expand Down
20 changes: 0 additions & 20 deletions tests/test_flows/test_flow_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,12 @@
SPDX-License-Identifier: MIT
"""

import warnings

import pytest

from oemof.solph import NonConvex
from oemof.solph.flows import Flow


def test_summed_max_future_warning():
"""Can be removed with v0.6."""
msg = "The parameter 'summed_max' is deprecated and will be removed"
with warnings.catch_warnings(record=True) as w:
Flow(nominal_capacity=1, summed_max=2)
assert len(w) == 1
assert msg in str(w[-1].message)


def test_summed_min_future_warning():
"""Can be removed with v0.6."""
msg = "The parameter 'summed_min' is deprecated and will be removed"
with warnings.catch_warnings(record=True) as w:
Flow(nominal_capacity=1, summed_min=2)
assert len(w) == 1
assert msg in str(w[-1].message)


def test_source_with_full_load_time_max():
Flow(nominal_capacity=1, full_load_time_max=2)

Expand Down
27 changes: 0 additions & 27 deletions tests/test_solph_network_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,33 +72,6 @@ def test_converter_missing_input_create_empty_dict(self):
assert converter.inputs == {}


def test_transformer_wrapper():
# two warnings: Wrapper and no inputs/outputs
with pytest.warns(FutureWarning):
with pytest.warns(SuspiciousUsageWarning):
solph.components.Transformer()


def test_offset_transformer_wrapper():
with pytest.warns(FutureWarning):
solph.components.OffsetTransformer(
inputs={solph.Bus("bus"): solph.Flow(nonconvex=solph.NonConvex())},
outputs={},
)


def test_wrong_combination_invest_and_nominal_value():
msg = "For backward compatibility, the option investment overwrites"
with pytest.raises(AttributeError, match=msg):
solph.flows.Flow(investment=solph.Investment(), nominal_value=4)


def test_invest_attribute_warning():
msg = "For backward compatibility, the option investment overwrites"
with pytest.warns(FutureWarning, match=msg):
solph.flows.Flow(investment=solph.Investment())


def test_fixed_costs_warning():
msg = (
"Be aware that the fixed costs attribute is only\n"
Expand Down

0 comments on commit 9be114c

Please sign in to comment.