Skip to content

Commit 803c6a7

Browse files
committed
Raise error when using relative deployment algo without flow_cap_max
1 parent dfb5014 commit 803c6a7

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

src/calliope/model.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -674,10 +674,15 @@ def _score_integer() -> xr.DataArray:
674674

675675
def _score_relative_deployment() -> xr.DataArray:
676676
"""Relative deployment scoring algorithm."""
677-
previous_cap = latest_results["flow_cap"].where(spores_techs)
678-
relative_cap = previous_cap / self.inputs["flow_cap_max"].where(
679-
spores_techs
680-
)
677+
previous_cap = latest_results["flow_cap"]
678+
if (
679+
"flow_cap_max" not in self.inputs
680+
or (self.inputs["flow_cap_max"].where(spores_techs) == np.inf).any()
681+
):
682+
raise exceptions.BackendError(
683+
"Cannot score SPORES with `relative_deployment` when `flow_cap_max` is undefined for some or all tracked technologies."
684+
)
685+
relative_cap = previous_cap / self.inputs["flow_cap_max"]
681686

682687
new_score = (
683688
# Make sure that penalties are applied only to non-negligible relative capacities

tests/test_core_model.py

+15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
22
from contextlib import contextmanager
33

4+
import numpy as np
45
import numpy.testing
56
import pandas as pd
67
import pytest
@@ -376,6 +377,20 @@ def test_save_per_spore_skip_cost_op(
376377
model_baseline_solved_separately._model_data.flow_cap
377378
)
378379

380+
def test_spores_relative_deployment_needs_max_param(self):
381+
"""Can only run the `relative_deployment` algorithm if all techs have flow_cap_max."""
382+
model = build_model(
383+
{"techs.test_supply_elec.flow_cap_max": np.inf},
384+
"spores,spores_tech_tracking,investment_costs",
385+
)
386+
model.build(mode="spores")
387+
388+
with pytest.raises(
389+
calliope.exceptions.BackendError,
390+
match="Cannot score SPORES with `relative_deployment`",
391+
):
392+
model.solve(**{"spores.scoring_algorithm": "relative_deployment"})
393+
379394

380395
class TestBuild:
381396
@pytest.fixture

0 commit comments

Comments
 (0)