diff --git a/src/muse/constraints.py b/src/muse/constraints.py index 460d95916..64c5591c5 100644 --- a/src/muse/constraints.py +++ b/src/muse/constraints.py @@ -375,6 +375,15 @@ def max_capacity_expansion( # Take the most restrictive constraint b = np.minimum(np.minimum(add_cap, total_cap), growth_cap) + # np.inf values are not allowed in the final constraint - raise error + # Will happen if user provides "inf" for all three parameters for any technology + if np.isinf(b).any(): + inf_replacements = b.replacement[np.isinf(b)].values + raise ValueError( + "Capacity growth constraint cannot be infinite. " + f"Check growth constraint parameters for technologies: {inf_replacements}" + ) + if b.region.dims == (): capa = 1 elif "dst_region" in b.dims: diff --git a/tests/test_constraints.py b/tests/test_constraints.py index 82c5df0c3..67b4f45b2 100644 --- a/tests/test_constraints.py +++ b/tests/test_constraints.py @@ -3,7 +3,7 @@ import numpy as np import pandas as pd import xarray as xr -from pytest import approx, fixture +from pytest import approx, fixture, raises from muse.timeslices import drop_timeslice from muse.utilities import interpolate_capacity, reduce_assets @@ -499,6 +499,19 @@ def test_max_capacity_expansion_no_limits( assert result is None +def test_max_capacity_expansion_infinite_limits( + market_demand, capacity, search_space, technologies +): + from muse.constraints import max_capacity_expansion + + # If all limits are infinite, a ValueError should be raised + technologies["max_capacity_addition"] = np.inf + technologies["max_capacity_growth"] = np.inf + technologies["total_capacity_limit"] = np.inf + with raises(ValueError): + max_capacity_expansion(market_demand, capacity, search_space, technologies) + + def test_max_production(max_production): dims = {"replacement", "asset", "commodity", "timeslice"} assert set(max_production.capacity.dims) == dims