Post · 13 min read· pp. 109–122

Committable + Extendable Components

This tutorial demonstrates how to create components (Generators and Links) that are both committable and extendable simultaneously. This enables co-optimizing capacity expansion with unit commitment decisions—determining both the optimal capacity to build AND when to turn units on or off.

PyPSA uses a big-M formulation to linearize the nonlinear product of binary status variables and continuous capacity variables, maintaining the Mixed-Integer Linear Programming (MILP) structure.

For the complete mathematical formulation, constraint names, and detailed explanation of the big-M linearization, see Capacity Limits: Committable and Extendable Components.

For discrete capacity expansion with unit commitment (where capacity is built in fixed blocks), see the Modular Committable Components tutorial.

In [2]:

Copied! diagram

ipynb
import matplotlib.pyplot as plt
import pandas as pd

import pypsa

import matplotlib.pyplot as plt import pandas as pd import pypsa

Basic Example: Committable + Extendable Generator

Let's start with a simple example where a gas generator can be both expanded AND committed (turned on/off). The optimizer will decide both how much capacity to build AND when to turn the unit on or off.

To see on/off behavior, we include a load profile that drops to zero in some periods.

In [3]:

Copied! diagram

ipynb
n = pypsa.Network(snapshots=range(6))

n.add("Bus", "bus", carrier="electricity")
n.add("Carrier", "electricity")

# Load profile with zero demand in period 3 - forcing generator to turn off
load_profile = [300, 500, 400, 0, 200, 350]
n.add("Load", "load", bus="bus", p_set=load_profile)

# Add a generator that is BOTH committable AND extendable
n.add(
    "Generator",
    "gas_ccgt",
    bus="bus",
    p_nom_extendable=True,  # Can expand capacity
    committable=True,  # Can be turned on/off
    p_nom_max=1000,  # Maximum capacity that can be built
    p_min_pu=0.3,  # 30% minimum load when running
    marginal_cost=50,
    capital_cost=80_000,  # Cost per MW of capacity
    start_up_cost=500,  # Cost to start the unit
    shut_down_cost=200,  # Cost to shut down the unit
)

n = pypsa.Network(snapshots=range(6)) n.add("Bus", "bus", carrier="electricity") n.add("Carrier", "electricity")

Load profile with zero demand in period 3 - forcing generator to turn off

load_profile = [300, 500, 400, 0, 200, 350] n.add("Load", "load", bus="bus", p_set=load_profile)

Add a generator that is BOTH committable AND extendable

n.add( "Generator", "gas_ccgt", bus="bus", p_nom_extendable=True, # Can expand capacity committable=True, # Can be turned on/off p_nom_max=1000, # Maximum capacity that can be built p_min_pu=0.3, # 30% minimum load when running marginal_cost=50, capital_cost=80_000, # Cost per MW of capacity start_up_cost=500, # Cost to start the unit shut_down_cost=200, # Cost to shut down the unit )

text
/tmp/ipykernel_2989/3487676383.py:1: PyPSA2Warning: pandas reads strings as `str` dtype since 3.0. PyPSA converts them back to object dtype on import, but keeps `str` from PyPSA 2.0 on. Set `pypsa.options.future.string_dtype` to True to opt in now or to False to keep the current behaviour.
  n = pypsa.Network(snapshots=range(6))

In [4]:

Copied! diagram

ipynb
n.optimize(log_to_console=False)

n.optimize(log_to_console=False)

text
/tmp/ipykernel_2989/4229533631.py:1: PyPSA2Warning: From PyPSA 2.0 on, the objective leaves out the capital costs of existing capacity on extendable assets, which improves LP conditioning. Pass `include_objective_constant` to `n.optimize` to choose per call. Set `pypsa.options.future.exclude_objective_constant` to True to opt in now or to False to keep the current behaviour.
  n.optimize(log_to_console=False)
text
INFO:linopy.model: Solve problem using Gurobi solver
text
INFO:linopy.model:Solver options:
 - log_to_console: False
text
INFO:linopy.io: Writing time: 0.06s
text
Set parameter WLSAccessID
text
Set parameter WLSSecret
text
Set parameter LicenseID to value 2537914
text
Academic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.de
text
Read LP format model from file /tmp/linopy-problem-7wazntr1.lp
text
Reading time = 0.00 seconds
text
obj: 62 rows, 25 columns, 108 nonzeros
text
Set parameter LogToConsole to value 0
text
WARNING:linopy.solvers:Dual values of MILP couldn't be parsed
text
INFO:linopy.constants: Optimization successful: 
Status: ok
Termination condition: optimal
Solution: 25 primals, 0 duals
Objective: 4.01e+07
Solver: gurobi
Runtime: 0.00s
MIP gap: 0.00e+00
Dual bound: 4.01e+07
Solver model: available
Solver message: 2
text
INFO:pypsa.optimization.optimize:No shadow prices were assigned to the network.

Out[4]:

text
('ok', 'optimal')

Let's examine the results. The optimizer has determined both the optimal capacity AND the commitment schedule:

In [5]:

Copied! diagram

ipynb
print(f"Optimal capacity built: {n.generators.p_nom_opt['gas_ccgt']:.1f} MW")

print(f"Optimal capacity built: {n.generators.p_nom_opt['gas_ccgt']:.1f} MW")

text
Optimal capacity built: 500.0 MW

In [6]:

Copied! diagram

ipynb
# Show commitment status and dispatch
results = pd.DataFrame(
    {
        "Load": load_profile,
        "Status": n.generators_t.status["gas_ccgt"],
        "Dispatch": n.generators_t.p["gas_ccgt"],
    }
)
results

Show commitment status and dispatch

results = pd.DataFrame( { "Load": load_profile, "Status": n.generators_t.status["gas_ccgt"], "Dispatch": n.generators_t.p["gas_ccgt"], } ) results

Out[6]:

LoadStatusDispatch
snapshot
03001.0300.0
15001.0500.0
24001.0400.0
300.0-0.0
42001.0200.0
53501.0350.0

Notice how the generator:

  • Is turned OFF when load is zero (no need to generate)
  • Is turned ON when there is demand
  • Always respects the minimum part-load constraint when online (dispatch >= 30% of capacity)

In [7]:

Copied! diagram

ipynb
fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(10, 6), sharex=True)

# Plot dispatch vs load
ax1.plot(results.index, results["Load"], "o-", label="Load", color="red")
ax1.bar(
    results.index, results["Dispatch"], alpha=0.7, label="Dispatch", color="steelblue"
)
min_stable = n.generators.p_nom_opt["gas_ccgt"] * 0.3
ax1.axhline(
    y=min_stable,
    color="orange",
    linestyle="--",
    label=f"Min stable gen ({min_stable:.0f} MW)",
)
ax1.set_ylabel("Power [MW]")
ax1.legend()
ax1.set_title("Dispatch Profile")

# Plot commitment status
ax2.bar(results.index, results["Status"], color="green", alpha=0.7)
ax2.set_ylabel("Status (1=ON, 0=OFF)")
ax2.set_xlabel("Hour")
ax2.set_title("Commitment Status")
ax2.set_ylim(-0.1, 1.1)

plt.tight_layout()

fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(10, 6), sharex=True)

Plot dispatch vs load

ax1.plot(results.index, results["Load"], "o-", label="Load", color="red") ax1.bar( results.index, results["Dispatch"], alpha=0.7, label="Dispatch", color="steelblue" ) min_stable = n.generators.p_nom_opt["gas_ccgt"] * 0.3 ax1.axhline( y=min_stable, color="orange", linestyle="--", label=f"Min stable gen ({min_stable:.0f} MW)", ) ax1.set_ylabel("Power [MW]") ax1.legend() ax1.set_title("Dispatch Profile")

Plot commitment status

ax2.bar(results.index, results["Status"], color="green", alpha=0.7) ax2.set_ylabel("Status (1=ON, 0=OFF)") ax2.set_xlabel("Hour") ax2.set_title("Commitment Status") ax2.set_ylim(-0.1, 1.1) plt.tight_layout()

No description has been provided for this image

Ramp Rate Limits with Committable + Extendable

Ramp rate limits are fully compatible with the big-M formulation. This is important for modeling thermal generators with limited ramping capabilities.

In [8]:

Copied! diagram

ipynb
n = pypsa.Network(snapshots=range(11))

n.add("Bus", "bus", carrier="electricity")
n.add("Carrier", "electricity")

# Load profile with low periods to trigger shut-downs
load_profile = [150, 200, 180, 500, 700, 650, 500, 180, 150, 500, 180]
n.add("Load", "load", bus="bus", p_set=load_profile)

# Fast-ramping peaker (expensive to build and run)
n.add(
    "Generator",
    "fast_peaker",
    bus="bus",
    p_nom_extendable=True,
    p_nom_max=800,
    marginal_cost=140,
    capital_cost=2000,
)

# Slow-ramping baseload with commitment
n.add(
    "Generator",
    "slow_baseload",
    bus="bus",
    p_nom_extendable=True,
    committable=True,
    p_nom_max=800,
    p_min_pu=0.6,
    marginal_cost=30,
    capital_cost=200,
    ramp_limit_up=0.6,  # Can ramp up 60% of capacity per hour
    ramp_limit_down=0.6,  # Can ramp down 60% of capacity per hour
    start_up_cost=800,
)

n = pypsa.Network(snapshots=range(11)) n.add("Bus", "bus", carrier="electricity") n.add("Carrier", "electricity")

Load profile with low periods to trigger shut-downs

load_profile = [150, 200, 180, 500, 700, 650, 500, 180, 150, 500, 180] n.add("Load", "load", bus="bus", p_set=load_profile)

Fast-ramping peaker (expensive to build and run)

n.add( "Generator", "fast_peaker", bus="bus", p_nom_extendable=True, p_nom_max=800, marginal_cost=140, capital_cost=2000, )

Slow-ramping baseload with commitment

n.add( "Generator", "slow_baseload", bus="bus", p_nom_extendable=True, committable=True, p_nom_max=800, p_min_pu=0.6, marginal_cost=30, capital_cost=200, ramp_limit_up=0.6, # Can ramp up 60% of capacity per hour ramp_limit_down=0.6, # Can ramp down 60% of capacity per hour start_up_cost=800, )

In [9]:

Copied! diagram

ipynb
n.optimize(log_to_console=False)

n.optimize(log_to_console=False)

text
INFO:linopy.model: Solve problem using Gurobi solver
text
INFO:linopy.model:Solver options:
 - log_to_console: False
text
INFO:linopy.io: Writing time: 0.08s
text
Set parameter WLSAccessID
text
Set parameter WLSSecret
text
Set parameter LicenseID to value 2537914
text
Academic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.de
text
Read LP format model from file /tmp/linopy-problem-cr66ps2r.lp
text
Reading time = 0.00 seconds
text
obj: 176 rows, 57 columns, 404 nonzeros
text
Set parameter LogToConsole to value 0
text
WARNING:linopy.solvers:Dual values of MILP couldn't be parsed
text
INFO:linopy.constants: Optimization successful: 
Status: ok
Termination condition: optimal
Solution: 57 primals, 0 duals
Objective: 7.68e+05
Solver: gurobi
Runtime: 0.00s
MIP gap: 0.00e+00
Dual bound: 7.68e+05
Solver model: available
Solver message: 2
text
INFO:pypsa.optimization.optimize:No shadow prices were assigned to the network.

Out[9]:

text
('ok', 'optimal')

In [10]:

Copied! diagram

ipynb
print("Optimal Capacities:")
print(n.generators[["p_nom_opt", "ramp_limit_up", "ramp_limit_down"]])

print("\nCommitment status (slow_baseload):")
status = n.generators_t.status["slow_baseload"].round(0)
print(status)

print("Optimal Capacities:") print(n.generators[["p_nom_opt", "ramp_limit_up", "ramp_limit_down"]]) print("\nCommitment status (slow_baseload):") status = n.generators_t.status["slow_baseload"].round(0) print(status)

text
Optimal Capacities:
               p_nom_opt  ramp_limit_up  ramp_limit_down
name                                                    
fast_peaker        200.0            NaN              NaN
slow_baseload      650.0            0.6              0.6

Commitment status (slow_baseload):
snapshot
0     0.0
1     0.0
2     0.0
3     1.0
4     1.0
5     1.0
6     1.0
7     0.0
8     0.0
9     1.0
10    0.0
Name: slow_baseload, dtype: float64

In [11]:

Copied! diagram

ipynb
# Check ramp rates are respected
dispatch = n.generators_t.p["slow_baseload"]
ramps = dispatch.diff().dropna()
p_nom = n.generators.p_nom_opt["slow_baseload"]
ramp_limit = n.generators.ramp_limit_up["slow_baseload"]

print(f"\nSlow baseload capacity: {p_nom:.1f} MW")
print(f"Max allowed ramp ({ramp_limit:.0%}): {p_nom * ramp_limit:.1f} MW/h")
print("\nActual ramps (MW/h):")
print(ramps)

Check ramp rates are respected

dispatch = n.generators_t.p["slow_baseload"] ramps = dispatch.diff().dropna() p_nom = n.generators.p_nom_opt["slow_baseload"] ramp_limit = n.generators.ramp_limit_up["slow_baseload"] print(f"\nSlow baseload capacity: {p_nom:.1f} MW") print(f"Max allowed ramp ({ramp_limit:.0%}): {p_nom * ramp_limit:.1f} MW/h") print("\nActual ramps (MW/h):") print(ramps)

text
Slow baseload capacity: 650.0 MW
Max allowed ramp (60%): 390.0 MW/h

Actual ramps (MW/h):
snapshot
1       0.0
2       0.0
3     500.0
4     150.0
5       0.0
6    -150.0
7    -500.0
8       0.0
9     500.0
10   -500.0
Name: slow_baseload, dtype: float64

In [12]:

Copied! diagram

ipynb
n.generators_t.p

n.generators_t.p

Out[12]:

namefast_peakerslow_baseload
snapshot
0150.00.0
1200.00.0
2180.00.0
30.0500.0
450.0650.0
50.0650.0
60.0500.0
7180.00.0
8150.00.0
90.0500.0
10180.00.0

In [13]:

Copied! diagram

ipynb
# Visualize dispatch and commitment with ramp constraints
fig, (ax1, ax2) = plt.subplots(
    2, 1, figsize=(10, 7), sharex=True, gridspec_kw={"height_ratios": [3, 1]}
)

n.generators_t.p.plot.area(ax=ax1, alpha=0.7, linewidth=0)
ax1.plot(range(len(load_profile)), load_profile, "k--", linewidth=2, label="Load")
ax1.set_ylabel("Power [MW]")
ax1.set_title("Dispatch with Ramp Rate Constraints")
ax1.legend(loc="upper right")

status = n.generators_t.status["slow_baseload"].round(0)
ax2.step(status.index, status.values, where="mid", color="tab:green", linewidth=2)
ax2.set_ylabel("Status")
ax2.set_xlabel("Hour")
ax2.set_ylim(-0.1, 1.1)
ax2.set_yticks([0, 1])
ax2.set_yticklabels(["OFF", "ON"])

plt.tight_layout()

Visualize dispatch and commitment with ramp constraints

fig, (ax1, ax2) = plt.subplots( 2, 1, figsize=(10, 7), sharex=True, gridspec_kw={"height_ratios": [3, 1]} ) n.generators_t.p.plot.area(ax=ax1, alpha=0.7, linewidth=0) ax1.plot(range(len(load_profile)), load_profile, "k--", linewidth=2, label="Load") ax1.set_ylabel("Power [MW]") ax1.set_title("Dispatch with Ramp Rate Constraints") ax1.legend(loc="upper right") status = n.generators_t.status["slow_baseload"].round(0) ax2.step(status.index, status.values, where="mid", color="tab:green", linewidth=2) ax2.set_ylabel("Status") ax2.set_xlabel("Hour") ax2.set_ylim(-0.1, 1.1) ax2.set_yticks([0, 1]) ax2.set_yticklabels(["OFF", "ON"]) plt.tight_layout()

No description has been provided for this image

Big-M Configuration

The big-M formulation uses a large constant MM to linearize constraints. PyPSA automatically infers an appropriate value based on the network's peak load (M=10×M = 10 \times peak load), but you can override it manually if needed.

For details on the big-M linearization and configuration options, see Big-M Parameter Configuration.

In [14]:

Copied! diagram

ipynb
# The big-M value can be set via the committable_big_m parameter
# None means PyPSA will auto-infer from network peak load
print("By default, PyPSA auto-infers big-M from network peak load")

The big-M value can be set via the committable_big_m parameter

None means PyPSA will auto-infer from network peak load

print("By default, PyPSA auto-infers big-M from network peak load")

text
By default, PyPSA auto-infers big-M from network peak load

In [15]:

Copied! diagram

ipynb
# You can set a custom big-M value using the committable_big_m parameter
n.optimize(committable_big_m=10000, log_to_console=False)
print("Optimization with custom big-M (10000) successful!")

You can set a custom big-M value using the committable_big_m parameter

n.optimize(committable_big_m=10000, log_to_console=False) print("Optimization with custom big-M (10000) successful!")

text
INFO:linopy.model: Solve problem using Gurobi solver
text
INFO:linopy.model:Solver options:
 - log_to_console: False
text
INFO:linopy.io: Writing time: 0.08s
text
Set parameter WLSAccessID
text
Set parameter WLSSecret
text
Set parameter LicenseID to value 2537914
text
Academic license 2537914 - for non-commercial use only - registered to l.___@tu-berlin.de
text
Read LP format model from file /tmp/linopy-problem-tucqvq9p.lp
text
Reading time = 0.00 seconds
text
obj: 176 rows, 57 columns, 404 nonzeros
text
Set parameter LogToConsole to value 0
text
WARNING:linopy.solvers:Dual values of MILP couldn't be parsed
text
INFO:linopy.constants: Optimization successful: 
Status: ok
Termination condition: optimal
Solution: 57 primals, 0 duals
Objective: 7.68e+05
Solver: gurobi
Runtime: 0.00s
MIP gap: 0.00e+00
Dual bound: 7.68e+05
Solver model: available
Solver message: 2
text
INFO:pypsa.optimization.optimize:No shadow prices were assigned to the network.
text
Optimization with custom big-M (10000) successful!

Summary

This tutorial demonstrated committable + extendable components in PyPSA:

  1. Basic Usage: Set both committable=True and p_nom_extendable=True on a Generator or Link
  2. Mixed Portfolios: Combine different generator types with various attribute combinations
  3. Ramp Limits: Fully compatible with ramp rate constraints
  4. Configuration: Automatic big-M inference with manual override option

Learn More:

diagram 2026-08-05

diagram 2026-02-17