diff --git a/docs/whatsnew/v0-6-0.rst b/docs/whatsnew/v0-6-0.rst index 22d4d9009..7ac8f5ac9 100644 --- a/docs/whatsnew/v0-6-0.rst +++ b/docs/whatsnew/v0-6-0.rst @@ -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. diff --git a/src/oemof/solph/components/__init__.py b/src/oemof/solph/components/__init__.py index e53a0659e..53021185e 100644 --- a/src/oemof/solph/components/__init__.py +++ b/src/oemof/solph/components/__init__.py @@ -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 @@ -31,9 +29,7 @@ "GenericStorage", "OffsetConverter", "Link", - "OffsetTransformer", "Sink", - "Transformer", "Source", "slope_offset_from_nonconvex_input", "slope_offset_from_nonconvex_output", diff --git a/src/oemof/solph/components/_converter.py b/src/oemof/solph/components/_converter.py index 8395fac9a..ecc0b42e6 100644 --- a/src/oemof/solph/components/_converter.py +++ b/src/oemof/solph/components/_converter.py @@ -21,8 +21,6 @@ """ -from warnings import warn - from oemof.network import Node from pyomo.core import BuildAction from pyomo.core import Constraint @@ -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` diff --git a/src/oemof/solph/components/_generic_storage.py b/src/oemof/solph/components/_generic_storage.py index cbbd25a17..31493e6b9 100644 --- a/src/oemof/solph/components/_generic_storage.py +++ b/src/oemof/solph/components/_generic_storage.py @@ -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}`. @@ -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, @@ -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," diff --git a/src/oemof/solph/components/_offset_converter.py b/src/oemof/solph/components/_offset_converter.py index cc42f9350..3ef40d259 100644 --- a/src/oemof/solph/components/_offset_converter.py +++ b/src/oemof/solph/components/_offset_converter.py @@ -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] @@ -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 ): @@ -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. @@ -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` diff --git a/src/oemof/solph/flows/_flow.py b/src/oemof/solph/flows/_flow.py index 1452bcfde..e505d2994 100644 --- a/src/oemof/solph/flows/_flow.py +++ b/src/oemof/solph/flows/_flow.py @@ -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 @@ -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 = ( diff --git a/tests/test_components.py b/tests/test_components.py index 0dbc2d993..3d8b16a92 100644 --- a/tests/test_components.py +++ b/tests/test_components.py @@ -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() @@ -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 diff --git a/tests/test_components/test_offset_converter.py b/tests/test_components/test_offset_converter.py index c0d63edb4..a80155f16 100644 --- a/tests/test_components/test_offset_converter.py +++ b/tests/test_components/test_offset_converter.py @@ -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() diff --git a/tests/test_components/test_storage.py b/tests/test_components/test_storage.py index ec6494456..4c45d4871 100644 --- a/tests/test_components/test_storage.py +++ b/tests/test_components/test_storage.py @@ -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() diff --git a/tests/test_flows/test_flow_class.py b/tests/test_flows/test_flow_class.py index 5c3955c83..47957d6de 100644 --- a/tests/test_flows/test_flow_class.py +++ b/tests/test_flows/test_flow_class.py @@ -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) diff --git a/tests/test_solph_network_classes.py b/tests/test_solph_network_classes.py index 5d3a11a50..1addda82f 100644 --- a/tests/test_solph_network_classes.py +++ b/tests/test_solph_network_classes.py @@ -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"