Add multi-input-multi-output converter #1154
Annotations
6 errors and 1 warning
/home/runner/work/oemof-solph/oemof-solph/src/oemof/solph/components/experimental/_mimo_converter.py#L377
def _input_output_group_relation(block):
for p, t in m.TIMEINDEX:
for n in group:
# Connect input groups
- for i, ii in zip(list(n.input_groups)[:-1], list(n.input_groups)[1:]):
+ for i, ii in zip(
+ list(n.input_groups)[:-1], list(n.input_groups)[1:]
+ ):
block.input_output_relation.add(
(n, i, p, t),
(
block.INPUT_GROUP_FLOW[n, i, p, t]
== block.INPUT_GROUP_FLOW[n, ii, p, t]
),
)
# Connect output groups
- for o, oo in zip(list(n.output_groups)[:-1], list(n.output_groups)[1:]):
+ for o, oo in zip(
+ list(n.output_groups)[:-1], list(n.output_groups)[1:]
+ ):
block.input_output_relation.add(
(n, o, p, t),
(
block.OUTPUT_GROUP_FLOW[n, o, p, t]
== block.OUTPUT_GROUP_FLOW[n, oo, p, t]
|
/home/runner/work/oemof-solph/oemof-solph/tests/test_scripts/test_solph/test_mimo_converter/test_mimo_converter.py#L21
es = EnergySystem(timeindex=idx)
# resources
b_gas = Bus(label="gas")
es.add(b_gas)
- es.add(Source(label="gas_station", outputs={b_gas: Flow(fix=[120, 0], nominal_value=1, variable_costs=20)}))
+ es.add(
+ Source(
+ label="gas_station",
+ outputs={
+ b_gas: Flow(fix=[120, 0], nominal_value=1, variable_costs=20)
+ },
+ )
+ )
b_hydro = Bus(label="hydro")
es.add(b_hydro)
- es.add(Source(label="hydro_station", outputs={b_hydro: Flow(fix=[0, 130], nominal_value=1, variable_costs=20)}))
+ es.add(
+ Source(
+ label="hydro_station",
+ outputs={
+ b_hydro: Flow(fix=[0, 130], nominal_value=1, variable_costs=20)
+ },
+ )
+ )
b_electricity = Bus(label="electricity")
es.add(b_electricity)
es.add(
Sink(
|
/home/runner/work/oemof-solph/oemof-solph/tests/test_scripts/test_solph/test_mimo_converter/test_mimo_converter.py#L41
es.add(
MultiInputMultiOutputConverter(
label="mimo",
inputs={"in": {b_gas: Flow(), b_hydro: Flow()}},
outputs={b_electricity: Flow()},
- conversion_factors={b_gas: 1.2, b_hydro: 1.3}
+ conversion_factors={b_gas: 1.2, b_hydro: 1.3},
)
)
# create an optimization problem and solve it
om = Model(es)
|
/home/runner/work/oemof-solph/oemof-solph/tests/test_scripts/test_solph/test_mimo_converter/test_mimo_converter.py#L54
om.solve(solver="cbc")
# create result object
results = processing.convert_keys_to_strings(processing.results(om))
- assert all(results[("gas", "mimo")]["sequences"]["flow"].values[:-1] == [120.0, 0.0])
- assert all(results[("hydro", "mimo")]["sequences"]["flow"].values[:-1] == [0.0, 130.0])
+ assert all(
+ results[("gas", "mimo")]["sequences"]["flow"].values[:-1]
+ == [120.0, 0.0]
+ )
+ assert all(
+ results[("hydro", "mimo")]["sequences"]["flow"].values[:-1]
+ == [0.0, 130.0]
+ )
def test_flow_shares():
idx = pd.date_range("1/1/2017", periods=2, freq="H")
es = EnergySystem(timeindex=idx)
# resources
b_gas = Bus(label="gas")
es.add(b_gas)
- es.add(Source(label="gas_station", outputs={b_gas: Flow(variable_costs=20)}))
+ es.add(
+ Source(label="gas_station", outputs={b_gas: Flow(variable_costs=20)})
+ )
b_hydro = Bus(label="hydro")
es.add(b_hydro)
- es.add(Source(label="hydro_station", outputs={b_hydro: Flow(variable_costs=20)}))
+ es.add(
+ Source(
+ label="hydro_station", outputs={b_hydro: Flow(variable_costs=20)}
+ )
+ )
b_electricity = Bus(label="electricity")
es.add(b_electricity)
es.add(
Sink(
|
/home/runner/work/oemof-solph/oemof-solph/tests/test_scripts/test_solph/test_mimo_converter/test_mimo_converter.py#L95
MultiInputMultiOutputConverter(
label="mimo",
inputs={"in": {b_gas: Flow(), b_hydro: Flow()}},
outputs={b_electricity: Flow(), b_heat: Flow()},
conversion_factors={b_gas: 1.2, b_hydro: 1.3},
- input_flow_shares={b_gas: [0.8, 0.3]}
+ input_flow_shares={b_gas: [0.8, 0.3]},
)
)
# create an optimization problem and solve it
om = Model(es)
|
/home/runner/work/oemof-solph/oemof-solph/tests/test_scripts/test_solph/test_mimo_converter/test_mimo_converter.py#L108
om.solve(solver="cbc")
# create result object
results = processing.convert_keys_to_strings(processing.results(om))
- assert all(results[("gas", "mimo")]["sequences"]["flow"].values[:-1] == [100 * 0.8 * 1.2, 100 * 0.3 * 1.2])
- assert all(results[("hydro", "mimo")]["sequences"]["flow"].values[:-1] == [100 * 0.2 * 1.3, 100 * 0.7 * 1.3])
+ assert all(
+ results[("gas", "mimo")]["sequences"]["flow"].values[:-1]
+ == [100 * 0.8 * 1.2, 100 * 0.3 * 1.2]
+ )
+ assert all(
+ results[("hydro", "mimo")]["sequences"]["flow"].values[:-1]
+ == [100 * 0.2 * 1.3, 100 * 0.7 * 1.3]
+ )
|
Run linters
The following actions uses node12 which is deprecated and will be forced to run on node16: actions/checkout@v2, actions/setup-python@v1, samuelmeuli/lint-action@v1. For more info: https://github.blog/changelog/2023-06-13-github-actions-all-actions-will-run-on-node16-instead-of-node12-by-default/
|