Version Checks (indicate both or one)
Issue Description
The curtailment() function in PyPSA's expressions module returns zero (LinearExpression +0) when applied to networks with only non-extendable generators, even when actual curtailment is occurring.
Reproducible Example
import pandas as pd
import pypsa
n = pypsa.Network()
n.set_snapshots(pd.date_range("2024", periods=4, freq="h"))
n.add("Carrier", ["AC", "solar", "gas"])
n.add("Bus", "bus0", carrier="AC")
n.add(
"Generator",
"solar0",
bus="bus0",
p_nom=100,
p_nom_extendable=False,
marginal_cost=0,
carrier="solar",
p_max_pu=[1.0, 0.8, 0.6, 0.4],
)
n.add("Generator", "gas0", bus="bus0", p_nom=100, marginal_cost=50, carrier="gas")
n.add("Load", "load0", bus="bus0", p_set=[50, 50, 50, 50])
n.optimize.create_model()
# Test curtailment expression
curtailment_expr = n.optimize.expressions.curtailment(
comps=["Generator"], aggregate_time=False
)
print(f"Expression result: {curtailment_expr}")
Expected Behavior
The curtailment() expression should return a LinearExpression representing the curtailment (available generation minus actual generation) for all generators, including non-extendable ones.
Installed Versions
Details
Replace this line.
Version Checks (indicate both or one)
I have confirmed this bug exists on the lastest release of PyPSA.
I have confirmed this bug exists on the current
masterbranch of PyPSA.Issue Description
The
curtailment()function in PyPSA's expressions module returns zero (LinearExpression +0) when applied to networks with only non-extendable generators, even when actual curtailment is occurring.Reproducible Example
Expected Behavior
The
curtailment()expression should return a LinearExpression representing the curtailment (available generation minus actual generation) for all generators, including non-extendable ones.Installed Versions
Details
Replace this line.