Repository navigation
Walkthrough PyPSA Unit Commitment
PyPSA's Unit Commitment (notebook at v1.4.0). One bus, one load, and two generators, coal and gas. Each case adds one operating limit and solves a mixed-integer problem: each committable generator is on or off in each timestep. The question is what each limit does to the dispatch, the on/off pattern and the cost.
| Case | What it shows | Timesteps |
|---|---|---|
| Minimum part load | Coal cannot run below 30%, so gas covers the 800 MW hour | 4 |
| Minimum up time | Gas, once on, stays on 3 timesteps | 4 |
| Minimum down time | Coal, once off, stays off 2 timesteps | 4 |
| Start-up and shut-down costs | 5,000 to start coal, 25 to stop gas | 4 |
| Time-varying start-up and shut-down costs | The costs are series, so the cheap unit starts early | 5 |
| Ramp limits | Coal ramps 10% up and 20% down per timestep | 6 |
| Ramp limits with expansion | The same, with coal's size optimised | 6 |
| Ramp limits at start-up and shut-down | Coal reaches only 10% in its first timestep on | 7 |
| Rolling horizon | 30 timesteps, solved upstream in six overlapping windows | 30 |
All nine cases are built in one project, as nine networks; four of them are copies of an earlier one with a few cells changed. Every series, the demands and the time-varying costs, is typed into the UI. Upstream's timesteps are the integers 0, 1, 2 and so on; here they are hours from 1 January 2026, which does not change the answer.
On Home, click New project. Name: Unit commitment. Click Create project.

On the project page, click New network. Name: Minimum part load. Under Time axis, choose Define: from 1 Jan 2026 00:00, for 4 hours, hourly. Click Create network.
The dialog offers no framework choice; a new network is PyPSA.

Open Components. For each type, More ways to add → Add in a panel… opens a form; fill in the values in the table and click Add to draft. committable is a switch in the form's Unit commitment section.
| Type | Name | Bus | Values |
|---|---|---|---|
| Bus | bus | ||
| Load | load | bus | (series in step 5) |
| Generator | coal | bus | p_nom 10000, marginal_cost 20, p_min_pu 0.3, committable on |
| Generator | gas | bus | p_nom 1000, marginal_cost 70, p_min_pu 0.1, committable on |
The form's sections open collapsed. The unit commitment fields give their unit as timesteps, and the form has no initial_status field.


The version chip reads Draft · 4 changes. Click Save version, title it Minimum part load, and click Save v2.

Open Loads, point at load's p_set cell and click Add series. In the panel, click the first value, type 4000 and press Enter, which moves down; type 6000, 5000 and 800 the same way. Save the version as Demand.
Add series starts the series from the static value. Typing at a person's pace into a selected cell replaces its value, and Escape cancels an edit without closing the panel.



Click Solve. The Method is Optimize, the Solver HiGHS and the Algorithm Default. Click Solve: the Solve page follows the run, which succeeds with objective 356,000.
The Method list holds Optimize, Power flow, Fix optimal capacities and Fix optimal
dispatch. None is a rolling horizon. The log shows that the Default algorithm passes
solver: hipo, which HiGHS ignores for a mixed-integer problem with a warning.



Click View results, open Generators, and in Columns tick status, start_up and shut_down. Click the p column's 2 series link: the series page shows each generator's output over time, and its Attribute picker switches to status and start_up.
status, start_up and shut_down are off in the default columns; only p is shown of the time-series outputs. Each value is read with the series page's Download → CSV.


coal · status reads 1, 1, 1, 0: coal is off in the last hour, where the 800 MW load is below its 3,000 MW part load. gas · status reads 0, 0, 0, 1. The chart joins the points with sloped lines rather than steps.

coal · start_up reads 0, 1, 1, 1, though coal starts no time. With no start-up cost the solver may set it to 1; nothing on the column or the page says so.

In the Network menu, click Make a copy…, name it Minimum up time. In Generators, right-click gas, click Edit…, set stand_by_cost 50, up_time_before 0 and min_up_time 3, and click Apply to draft. In load's p_set panel, type 4000, 800, 5000, 3000. Save once and solve: objective 306,150.
The copy holds the load series. The draft holds the generator edit and the series edit together (Draft · 2 changes), and one Save version saves both.




Make a copy… of Minimum part load, named Minimum down time. Edit coal: min_down_time 2, down_time_before 1; gas: p_nom 4000. Type the load as 3000, 800, 3000, 8000, save and solve: objective 486,000. Coal is off for the first two timesteps.

Make a copy… of Minimum down time, named Start-up and shut-down costs. Edit coal: down_time_before 0, start_up_cost 5000; gas: shut_down_cost 25. Solve: objective 491,025. In the results' Columns, tick Opex, Start-up opex and Shut-down opex under Statistics.
Now start_up and shut_down are the events: coal start_up 0, 0, 1, 0; gas shut_down 0, 0, 1, 0. Start-up opex and Shut-down opex split those costs out of Opex: coal's opex, 225,000, is 220,000 of fuel plus the 5,000 start-up.


Open Visualisation and click Add chart. Component: Generators. In Value, click Write a formula…, name it coal_start_ups, type sum(Generator["coal"].start_up) and click Apply. Show data on the new chart reads 1.
Adding the chart saves no new version.


New network Time-varying start-up costs, 5 hours, with a bus, a load and two committable generators. Add series for the load's p_set and for cheap-committable's start_up_cost and shut_down_cost, and type them in. Solve: objective 40. cheap-committable starts where starting is free.
| Name | Values |
|---|---|
| cheap-committable | committable, p_nom 10, marginal_cost 0, p_min_pu 0.01, stand_by_cost 10, up_time_before 0, down_time_before 0 |
| expensive-fallback | committable, p_nom 10, marginal_cost 100, start_up_cost 0.1, shut_down_cost 0.1 |
| Series | Values |
|---|---|
| load p_set | 0, 0.1, 10, 0.1, 0.1 |
| cheap-committable start_up_cost | 0, 0, 100, 100, 100 |
| cheap-committable shut_down_cost | 100, 100, 100, 100, 0 |
The grid draws only the columns near its view; moving right from the name cell with the arrow keys brings start_up_cost into view, where Add series appears.


New network Ramp limits, 6 hours. Neither generator is committable; coal has ramp_limit_up 0.1 and ramp_limit_down 0.2, in the form's Operation section. Type the load and solve: objective 950,000. Coal climbs 1,000 MW a timestep and falls 2,000 MW.
| Name | Values |
|---|---|
| coal | p_nom 10000, marginal_cost 20, ramp_limit_up 0.1, ramp_limit_down 0.2 |
| gas | p_nom 4000, marginal_cost 70 |
Load p_set: 4000, 7000, 7000, 7000, 7000, 3000.

Make a copy… of Ramp limits, named Ramp limits with expansion. Edit coal: switch on p_nom_extendable, capital_cost 100, p_nom 0. Solve: the objective reads 1.675 × 10⁶, and coal's p_nom_opt is 5,000 MW.
Upstream gives no p_nom; 0 is PyPSA's default. With 5,000 MW, coal ramps 500 MW up and 1,000 MW down per timestep. From a million up, the Solve page shows the objective to four significant figures only; the exact value, 1,675,000, is in the solver log.


New network Ramp limits at start-up and shut-down, 7 hours. Coal is committable, with ramp_limit_start_up 0.1 and ramp_limit_shut_down 0.15. Type the load and solve: the objective reads 1.149 × 10⁶. Coal starts at 1,000 MW and holds 1,500 MW before it shuts down.
| Name | Values |
|---|---|
| coal | committable, p_nom 10000, marginal_cost 20, p_min_pu 0.05, ramp_limit_up 0.2, ramp_limit_down 0.25, ramp_limit_start_up 0.1, ramp_limit_shut_down 0.15 |
| gas | p_nom 10000, marginal_cost 70 |
Load p_set: 0, 200, 7000, 7000, 7000, 2000, 0. Upstream also sets initial_status=0 on
coal. PyPSA 1.4.0 has no such attribute and ignores it, so the answer is the same without
it; up_time_before and down_time_before set the state before the first timestep.

New network Rolling horizon, 30 hours, with committable coal and gas as in the table. Type the load, 4000, 5000, 700, 800, 4000 six times, and solve: the objective reads 2.227 × 10⁶. The UI solves all 30 timesteps as one problem; upstream solves six overlapping windows.
| Name | Values |
|---|---|
| coal | committable, p_nom 10000, marginal_cost 20, p_min_pu 0.3, min_up_time 3, min_down_time 2, up_time_before 1, ramp_limit_up 1, ramp_limit_down 1, ramp_limit_start_up 1, ramp_limit_shut_down 1, start_up_cost 200, shut_down_cost 150 |
| gas | committable, p_nom 1000, marginal_cost 70, p_min_pu 0.1, min_up_time 3, up_time_before 2, start_up_cost 50, shut_down_cost 20 |


On the solved Rolling horizon, Solve says the version is already solved with these options, and its Solve is off. Open Advanced, set MIP gap to 0.5, and Solve is on again. The log shows the 50% tolerance, and the objective still reads 2.227 × 10⁶.
Switching on Linearised unit commitment under Advanced → PyPSA also turns Solve on, on the same version; no copy of the network is needed.



"Status" is each committable generator's on/off series, read from the series page's Download → CSV.
| Case | Quantity | Value |
|---|---|---|
| Minimum part load | Objective | 356,000 |
| coal p / status | 4000, 6000, 5000, 0 / 1, 1, 1, 0 | |
| gas p / status | 0, 0, 0, 800 / 0, 0, 0, 1 | |
| Minimum up time | Objective | 306,150 |
| coal p / status | 3900, 0, 4900, 3000 / 1, 0, 1, 1 | |
| gas p / status | 100, 800, 100, 0 / 1, 1, 1, 0 | |
| Minimum down time | Objective | 486,000 |
| coal p / status | 0, 0, 3000, 8000 / 0, 0, 1, 1 | |
| gas p / status | 3000, 800, 0, 0 / 1, 1, 0, 0 | |
| Start-up and shut-down costs | Objective | 491,025 |
| coal start_up / shut_down | 0, 0, 1, 0 / 1, 0, 0, 0 | |
| gas shut_down | 0, 0, 1, 0 | |
| coal Start-up opex / gas Shut-down opex | 5,000 / 25 | |
| coal / gas Opex | 225,000 / 266,025 | |
| coal_start_ups (formula chart) | 1 | |
| Time-varying costs | Objective | 40 |
| cheap-committable start_up / shut_down | 1, 1, 0, 0, 0 / 0, 0, 0, 0, 1 | |
| Ramp limits | Objective | 950,000 |
| coal p | 4000, 5000, 6000, 7000, 5000, 3000 | |
| gas p | 0, 2000, 1000, 0, 2000, 0 | |
| Ramp limits with expansion | Objective | 1.675 × 10⁶ (1,675,000 in the solver log) |
| coal p_nom_opt | 5,000 MW | |
| coal p | 4000, 4500, 5000, 5000, 4000, 3000 | |
| Ramp limits at start-up and shut-down | Objective | 1.149 × 10⁶ (1,149,000 in the solver log) |
| coal p / status | 0, 0, 1000, 3000, 4000, 1500, 0 / 0, 0, 1, 1, 1, 1, 0 | |
| gas p | 0, 200, 6000, 4000, 3000, 500, 0 | |
| Rolling horizon, one window | Objective | 2.227 × 10⁶ |
| coal status | 1, 1, 0, 0, then 1, 1, 1, 0, 0 five times, then 1 | |
| Objective with MIP gap 0.5, same version | 2.227 × 10⁶ |
In the time-varying case, cheap-committable's last hour can be on or off at the same cost: 10 of stand-by cost, or 0.1 MW from expensive-fallback at 100, cost the same.
💡 Key learnings
- A power plant is not a tap. Unit commitment adds the on/off decision, and with it the limits of real plants: a minimum output while on, minimum times on and off, the cost of starting and stopping, and how fast output can change. Each limit stops the cheap coal plant from following the load exactly, so dearer gas fills the gaps and the cost rises.
- On/off decisions make the problem much harder. Each is a yes or no, which makes a mixed-integer problem. Its solve time grows fast with the number of plants and timesteps, and a MIP gap trades a little accuracy for a much faster answer.
- Rolling horizon. Besides accounting for imperfect forecast horizons in reality, rolling horizon optimisation can also help manage computational complexity by breaking up large problems into smaller chunks. The limited foresight leads to suboptimal operational decisions, resulting in additional system costs compared to the perfect foresight case. Here the 30 hours are solved as one window, with perfect foresight; on this short, repeating load the six windows of a rolling horizon would cost the same, but on a longer, less regular profile they need not.
- #2762 The Default algorithm passes solver=hipo, which HiGHS ignores with a warning on every MIP solve (open)
- #2767 Start up and Shut down read 1 when they carry no cost, with no note (open)
- #1413 Support PyPSA's other optimisation methods (rolling horizon, SCLOPF, MGA, AC power-flow check, …) (open)
Using the app
Architecture
- Overview
- Python API
- Domain model
- Backend core
- Composition root and config
- Expression language internals
- Storage
- Execution
- Imports and exports
- Workflow engine
- HTTP API and contracts
- Frontend and desktop
- Build, CI and release
Contributing