diff --git a/tests/test_components/test_offset_converter.py b/tests/test_components/test_offset_converter.py index f329c882c..7553faa85 100644 --- a/tests/test_components/test_offset_converter.py +++ b/tests/test_components/test_offset_converter.py @@ -2,6 +2,7 @@ import numpy as np import pytest +from oemof.tools.debugging import ExperimentalFeatureWarning from oemof import solph from oemof.solph._plumbing import sequence @@ -104,58 +105,67 @@ def check_results( def add_OffsetConverter( es, reference_bus, nominal_value, minimal_value, eta_at_nom, eta_at_min ): + # Use of experimental API to access nodes by label. + # Can be removed with future release of network. + with warnings.catch_warnings( + action="ignore", category=ExperimentalFeatureWarning + ): + oc_inputs = { + b: solph.Flow() + for label, b in es.node.items() + if "bus input" in label + } + oc_outputs = { + b: solph.Flow() + for label, b in es.node.items() + if "bus output" in label + } + + if reference_bus in oc_outputs: + f = oc_outputs[reference_bus] + get_slope_and_offset = slope_offset_from_nonconvex_output + fix = [0] + np.linspace(minimal_value, nominal_value, 9).tolist() + else: + f = oc_inputs[reference_bus] + get_slope_and_offset = slope_offset_from_nonconvex_input + fix = [0] + np.linspace( + minimal_value * eta_at_min[es.node["bus output 0"]], + nominal_value * eta_at_nom[es.node["bus output 0"]], + 9, + ).tolist() + + fix_flow = es.flows()[es.node["bus output 0"], es.node["sink 0"]] + fix_flow.fix = fix + fix_flow.nominal_value = 1 + + slopes = {} + offsets = {} + + for bus in list(oc_inputs) + list(oc_outputs): + if bus == reference_bus: + continue + slope, offset = get_slope_and_offset( + 1, + minimal_value / nominal_value, + eta_at_nom[bus], + eta_at_min[bus], + ) + slopes[bus] = slope + offsets[bus] = offset - oc_inputs = { - b: solph.Flow() for label, b in es.node.items() if "bus input" in label - } - oc_outputs = { - b: solph.Flow() - for label, b in es.node.items() - if "bus output" in label - } + f.nonconvex = solph.NonConvex() + f.nominal_value = nominal_value + f.min = sequence(minimal_value / nominal_value) - if reference_bus in oc_outputs: - f = oc_outputs[reference_bus] - get_slope_and_offset = slope_offset_from_nonconvex_output - fix = [0] + np.linspace(minimal_value, nominal_value, 9).tolist() - else: - f = oc_inputs[reference_bus] - get_slope_and_offset = slope_offset_from_nonconvex_input - fix = [0] + np.linspace( - minimal_value * eta_at_min[es.node["bus output 0"]], - nominal_value * eta_at_nom[es.node["bus output 0"]], - 9, - ).tolist() - - fix_flow = es.flows()[es.node["bus output 0"], es.node["sink 0"]] - fix_flow.fix = fix - fix_flow.nominal_value = 1 - - slopes = {} - offsets = {} - - for bus in list(oc_inputs) + list(oc_outputs): - if bus == reference_bus: - continue - slope, offset = get_slope_and_offset( - 1, minimal_value / nominal_value, eta_at_nom[bus], eta_at_min[bus] + oc = solph.components.OffsetConverter( + label="offset converter", + inputs=oc_inputs, + outputs=oc_outputs, + conversion_factors=slopes, + normed_offsets=offsets, ) - slopes[bus] = slope - offsets[bus] = offset - - f.nonconvex = solph.NonConvex() - f.nominal_value = nominal_value - f.min = sequence(minimal_value / nominal_value) - - oc = solph.components.OffsetConverter( - label="offset converter", - inputs=oc_inputs, - outputs=oc_outputs, - conversion_factors=slopes, - normed_offsets=offsets, - ) - es.add(oc) + es.add(oc) def test_custom_properties(): @@ -476,8 +486,13 @@ def test_two_OffsetConverters_with_and_without_investment(): es.add(oc) - fix_flow = es.flows()[es.node["bus output 0"], es.node["sink 0"]] - fix_flow.fix = [v * 2 for v in fix_flow.fix] + # Use of experimental API to access nodes by label. + # Can be removed with future release of network. + with warnings.catch_warnings( + action="ignore", category=ExperimentalFeatureWarning + ): + fix_flow = es.flows()[es.node["bus output 0"], es.node["sink 0"]] + fix_flow.fix = [v * 2 for v in fix_flow.fix] # if the model solves it is feasible _ = solve_and_extract_results(es) @@ -491,10 +506,15 @@ def test_OffsetConverter_05x_compatibility(): nominal_value = 10 minimal_value = 3 - fix = [0] + np.linspace(minimal_value, nominal_value, 9).tolist() - fix_flow = es.flows()[es.node["bus output 0"], es.node["sink 0"]] - fix_flow.fix = fix - fix_flow.nominal_value = 1 + # Use of experimental API to access nodes by label. + # Can be removed with future release of network. + with warnings.catch_warnings( + action="ignore", category=ExperimentalFeatureWarning + ): + fix = [0] + np.linspace(minimal_value, nominal_value, 9).tolist() + fix_flow = es.flows()[es.node["bus output 0"], es.node["sink 0"]] + fix_flow.fix = fix + fix_flow.nominal_value = 1 eta_at_nom = 0.7 eta_at_min = 0.5 diff --git a/tests/test_components/test_sink.py b/tests/test_components/test_sink.py index 97622a181..00f891ffb 100644 --- a/tests/test_components/test_sink.py +++ b/tests/test_components/test_sink.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- +import warnings import pytest +from oemof.tools.debugging import ExperimentalFeatureWarning from oemof import solph @@ -22,18 +24,22 @@ def test_multi_input_sink(): es.add( solph.components.Source(f"source {i}", outputs={b: solph.Flow()}) ) - - es.add( - solph.components.Sink( - inputs={ - es.node[f"bus input {i}"]: solph.Flow( - nominal_value=1, - variable_costs=costs, - ) - for i in range(num_in) - } + # Use of experimental API to access nodes by label. + # Can be removed with future release of network. + with warnings.catch_warnings( + action="ignore", category=ExperimentalFeatureWarning + ): + es.add( + solph.components.Sink( + inputs={ + es.node[f"bus input {i}"]: solph.Flow( + nominal_value=1, + variable_costs=costs, + ) + for i in range(num_in) + } + ) ) - ) model = solph.Model(es) model.solve("cbc") diff --git a/tests/test_components/test_source.py b/tests/test_components/test_source.py index 16fa294fb..f54977a76 100644 --- a/tests/test_components/test_source.py +++ b/tests/test_components/test_source.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- +import warnings import pytest +from oemof.tools.debugging import ExperimentalFeatureWarning from oemof import solph @@ -21,17 +23,22 @@ def test_multi_output_source(): es.add(b) es.add(solph.components.Sink(f"source {i}", inputs={b: solph.Flow()})) - es.add( - solph.components.Source( - outputs={ - es.node[f"bus input {i}"]: solph.Flow( - nominal_value=1, - variable_costs=costs, - ) - for i in range(num_out) - } + # Use of experimental API to access nodes by label. + # Can be removed with future release of network. + with warnings.catch_warnings( + action="ignore", category=ExperimentalFeatureWarning + ): + es.add( + solph.components.Source( + outputs={ + es.node[f"bus input {i}"]: solph.Flow( + nominal_value=1, + variable_costs=costs, + ) + for i in range(num_out) + } + ) ) - ) model = solph.Model(es) model.solve("cbc") diff --git a/tests/test_solph_network_classes.py b/tests/test_solph_network_classes.py index 46f032da1..35d421d87 100644 --- a/tests/test_solph_network_classes.py +++ b/tests/test_solph_network_classes.py @@ -12,6 +12,7 @@ import warnings import pytest +from oemof.tools.debugging import SuspiciousUsageWarning from oemof import solph @@ -60,20 +61,22 @@ def test_sequence_conversion_factor_from_list_wrong_length(self): with pytest.raises(IndexError): self.a = transf.conversion_factors[self.bus][6] - @pytest.mark.filterwarnings("ignore:Attribute :UserWarning") def test_converter_missing_output_create_empty_dict(self): - trfr = solph.components.Converter(inputs={}) - assert trfr.outputs == {} + with pytest.warns(SuspiciousUsageWarning): + trfr = solph.components.Converter(inputs={}) + assert trfr.outputs == {} - @pytest.mark.filterwarnings("ignore:Attribute :UserWarning") def test_converter_missing_input_create_empty_dict(self): - trfr = solph.components.Converter(outputs={}) - assert trfr.inputs == {} + with pytest.warns(SuspiciousUsageWarning): + trfr = solph.components.Converter(outputs={}) + assert trfr.inputs == {} def test_transformer_wrapper(): with pytest.warns(FutureWarning): - solph.components.Transformer() + # no inputs/outputs + with pytest.warns(SuspiciousUsageWarning): + solph.components.Transformer() def test_offset_transformer_wrapper():