From f434360b9d3f0f6f23f66afe4959ed76b70607ca Mon Sep 17 00:00:00 2001 From: FBumann <117816358+FBumann@users.noreply.github.com> Date: Wed, 30 Jul 2025 13:39:13 +0200 Subject: [PATCH 1/4] Remove warnings filter --- flixopt/aggregation.py | 1 - 1 file changed, 1 deletion(-) diff --git a/flixopt/aggregation.py b/flixopt/aggregation.py index f149d5f20..5fa392ec6 100644 --- a/flixopt/aggregation.py +++ b/flixopt/aggregation.py @@ -34,7 +34,6 @@ if TYPE_CHECKING: import plotly.graph_objects as go -warnings.filterwarnings('ignore', category=DeprecationWarning) logger = logging.getLogger('flixopt') From 4692c9b3060d9aa0303d7dbdb442d4defea7f299 Mon Sep 17 00:00:00 2001 From: FBumann <117816358+FBumann@users.noreply.github.com> Date: Wed, 30 Jul 2025 13:41:57 +0200 Subject: [PATCH 2/4] Improve Sinks and SOurces to also handle multiple Flows --- flixopt/components.py | 151 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 130 insertions(+), 21 deletions(-) diff --git a/flixopt/components.py b/flixopt/components.py index 1f5fe5ece..8a836da2f 100644 --- a/flixopt/components.py +++ b/flixopt/components.py @@ -4,6 +4,7 @@ import logging from typing import TYPE_CHECKING, Dict, List, Literal, Optional, Set, Tuple, Union +import warnings import linopy import numpy as np @@ -586,52 +587,160 @@ class for source (output-flow) and sink (input-flow) in one commponent def __init__( self, label: str, - source: Flow, - sink: Flow, - prevent_simultaneous_sink_and_source: bool = True, + inputs: List[Flow] = None, + outputs: List[Flow] = None, + prevent_simultaneous_flow_rates: bool = True, meta_data: Optional[Dict] = None, + **kwargs, ): """ Args: label: The label of the Element. Used to identify it in the FlowSystem - source: output-flow of this component - sink: input-flow of this component - prevent_simultaneous_sink_and_source: If True, inflow and outflow can not be active simultaniously. + outputs: output-flows of this component + inputs: input-flows of this component + prevent_simultaneous_flow_rates: If True, inflow and outflow can not be active simultaniously. meta_data: used to store more information about the Element. Is not used internally, but saved in the results. Only use python native types. """ + source = kwargs.pop('source', None) + sink = kwargs.pop('sink', None) + prevent_simultaneous_sink_and_source = kwargs.pop('prevent_simultaneous_sink_and_source', None) + if source is not None: + warnings.deprecated( + 'The use of the source argument is deprecated. Use the outputs argument instead.', + stacklevel=2, + ) + if outputs is not None: + raise ValueError('Either source or outputs can be specified, but not both.') + outputs = [source] + + if sink is not None: + warnings.deprecated( + 'The use of the sink argument is deprecated. Use the outputs argument instead.', + stacklevel=2, + ) + if inputs is not None: + raise ValueError('Either sink or outputs can be specified, but not both.') + inputs = [sink] + + if prevent_simultaneous_sink_and_source is not None: + warnings.deprecated( + 'The use of the prevent_simultaneous_sink_and_source argument is deprecated. Use the prevent_simultaneous_flow_rates argument instead.', + stacklevel=2, + ) + prevent_simultaneous_flow_rates = prevent_simultaneous_sink_and_source + super().__init__( label, - inputs=[sink], - outputs=[source], - prevent_simultaneous_flows=[sink, source] if prevent_simultaneous_sink_and_source is True else None, + inputs=inputs, + outputs=outputs, + prevent_simultaneous_flows=inputs + outputs if prevent_simultaneous_flow_rates is True else None, meta_data=meta_data, ) - self.source = source - self.sink = sink - self.prevent_simultaneous_sink_and_source = prevent_simultaneous_sink_and_source + self.prevent_simultaneous_flow_rates = prevent_simultaneous_flow_rates + + @property + def source(self) -> Flow: + warnings.warn( + 'The source property is deprecated. Use the outputs property instead.', + DeprecationWarning, + stacklevel=2, + ) + return self.outputs[0] + + @property + def sink(self) -> Flow: + warnings.warn( + 'The sink property is deprecated. Use the outputs property instead.', + DeprecationWarning, + stacklevel=2, + ) + return self.inputs[0] + + @property + def prevent_simultaneous_sink_and_source(self) -> bool: + warnings.warn( + 'The prevent_simultaneous_sink_and_source property is deprecated. Use the prevent_simultaneous_flow_rates property instead.', + DeprecationWarning, + stacklevel=2, + ) + return self.prevent_simultaneous_flow_rates @register_class_for_io class Source(Component): - def __init__(self, label: str, source: Flow, meta_data: Optional[Dict] = None): + def __init__( + self, + label: str, + outputs: List[Flow] = None, + meta_data: Optional[Dict] = None, + prevent_simultaneous_flow_rates: bool = False, + **kwargs + ): """ Args: label: The label of the Element. Used to identify it in the FlowSystem - source: output-flow of source + outputs: output-flows of source meta_data: used to store more information about the Element. Is not used internally, but saved in the results. Only use python native types. """ - super().__init__(label, outputs=[source], meta_data=meta_data) - self.source = source + source = kwargs.pop('source', None) + if source is not None: + warnings.warn( + 'The use of the source argument is deprecated. Use the outputs argument instead.', + DeprecationWarning, + stacklevel=2, + ) + if outputs is not None: + raise ValueError('Either source or outputs can be specified, but not both.') + outputs = [source] + + self.prevent_simultaneous_flow_rates = prevent_simultaneous_flow_rates + super().__init__(label, outputs=outputs, meta_data=meta_data, prevent_simultaneous_flows=outputs if prevent_simultaneous_flow_rates else None) + + @property + def source(self) -> Flow: + warnings.warn( + 'The source property is deprecated. Use the outputs property instead.', + DeprecationWarning, + stacklevel=2, + ) + return self.outputs[0] @register_class_for_io class Sink(Component): - def __init__(self, label: str, sink: Flow, meta_data: Optional[Dict] = None): + def __init__( + self, + label: str, + inputs: List[Flow] = None, + meta_data: Optional[Dict] = None, + prevent_simultaneous_flow_rates: bool = False, + **kwargs + ): """ Args: label: The label of the Element. Used to identify it in the FlowSystem - meta_data: used to store more information about the element. Is not used internally, but saved in the results - sink: input-flow of sink + inputs: output-flows of source + meta_data: used to store more information about the Element. Is not used internally, but saved in the results. Only use python native types. """ - super().__init__(label, inputs=[sink], meta_data=meta_data) - self.sink = sink + sink = kwargs.pop('sink', None) + if sink is not None: + warnings.warn( + 'The use of the sink argument is deprecated. Use the outputs argument instead.', + DeprecationWarning, + stacklevel=2, + ) + if inputs is not None: + raise ValueError('Either sink or outputs can be specified, but not both.') + inputs = [sink] + + self.prevent_simultaneous_flow_rates = prevent_simultaneous_flow_rates + super().__init__(label, inputs=inputs, meta_data=meta_data, prevent_simultaneous_flows=inputs if prevent_simultaneous_flow_rates else None) + + @property + def sink(self) -> Flow: + warnings.warn( + 'The sink property is deprecated. Use the outputs property instead.', + DeprecationWarning, + stacklevel=2, + ) + return self.inputs[0] \ No newline at end of file From 63a6faaf962cc5fd08f0dca907169cd797bbb2f8 Mon Sep 17 00:00:00 2001 From: FBumann <117816358+FBumann@users.noreply.github.com> Date: Wed, 30 Jul 2025 13:52:09 +0200 Subject: [PATCH 3/4] ruff check --- flixopt/components.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/flixopt/components.py b/flixopt/components.py index 8a836da2f..e06616daf 100644 --- a/flixopt/components.py +++ b/flixopt/components.py @@ -3,8 +3,8 @@ """ import logging -from typing import TYPE_CHECKING, Dict, List, Literal, Optional, Set, Tuple, Union import warnings +from typing import TYPE_CHECKING, Dict, List, Literal, Optional, Set, Tuple, Union import linopy import numpy as np @@ -743,4 +743,4 @@ def sink(self) -> Flow: DeprecationWarning, stacklevel=2, ) - return self.inputs[0] \ No newline at end of file + return self.inputs[0] From 77a68fc4ef6bb0933f083bccec363d11f539d6dd Mon Sep 17 00:00:00 2001 From: FBumann <117816358+FBumann@users.noreply.github.com> Date: Wed, 30 Jul 2025 14:54:13 +0200 Subject: [PATCH 4/4] Add CHANGELOG.md --- CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c52c66a2a..6232a61f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [2.1.6] - 2025-07-30 + +### Changed +- `Sink`, `Source` and `SourceAndSink` now accept multiple `flows` as `inputs` and `outputs` instead of just one. This enables to model more use cases using these classes. +- Further, both `Sink` and `Source` now have a `prevent_simultaneous_flow_rates` argument to prevent simultaneous flow rates of more than one of their Flows. + +### Deprecated +- For the classes `Sink`, `Source` and `SourceAndSink`: `.sink`, `.source` and `.prevent_simultaneous_sink_and_source` are deprecated in favor of the new arguments `inputs`, `outputs` and `prevent_simultaneous_flow_rates`. + ## [2.1.5] - 2025-07-08 ### Fixed