Repository navigation
Walkthrough PyPSA Quickstart 2
PyPSA's Quickstart 2 - Power Flow. Three zones on 11 kV, joined in a triangle by three lines. Zone 1 has two cheap generators; zones 2 and 3 have one each.
| Zone | Load (MW) | Generator | P Nom (MW) | Marginal Cost |
|---|---|---|---|---|
| zone_1 | 50 | gen_A | 140 | 7.5 |
| gen_B | 285 | 6 | ||
| zone_2 | 60 | gen_C | 90 | 14 |
| zone_3 | 300 | gen_D | 85 | 10 |
The question has two halves. First, the least-cost dispatch with the linear power flow (reactance only): the price in each zone and the flow on each line. Then, with that dispatch fixed, a non-linear AC power flow: the losses on the lines, the reactive power, and the voltage at each bus. The slack generator, gen_A, covers the losses.
Files to download
-
generators.csv: the four generators, for step 4.
On Home, click New project, name it Quickstart 2 and click Create project. Then click New network: Name Three-zone market, and under Time axis → Define start at 1 Jan 2026 00:00 for 1 hour. Click Create network.

Open Components → Buses, then ▾ → Add in a panel…. Name: zone_1. Click Add another name twice; it fills in zone_2 and zone_3. v_nom: 11, which applies to all three. Click Add 3 buses to draft.


Open Loads, then ▾ → Add in a panel…. Name load_1, and Add another name twice. Click Separate values beside Bus and beside p_set, and fill in each load's bus and demand. Click Add 3 loads to draft.
| Name | Bus | p_set (MW) |
|---|---|---|
| load_1 | zone_1 | 50 |
| load_2 | zone_2 | 60 |
| load_3 | zone_3 | 300 |

Four generators with different buses and costs are quicker as a file. Download generators.csv. Open Generators, then ▾ → Import CSV…, and choose it. The review lists 4 new rows. Click Import.
generators.csv:
name,bus,p_nom,marginal_cost
gen_A,zone_1,140,7.5
gen_B,zone_1,285,6
gen_C,zone_2,90,14
gen_D,zone_3,85,10

Open Lines, then ▾ → Add in a panel…. Name line_1, and Add another name twice. r: 0.01 Ohm for all three. Click Separate values beside bus0, bus1, x and s_nom, and fill them in from the table. Click Add 3 lines to draft.
| Name | bus0 | bus1 | x (Ohm) | r (Ohm) | s_nom (MVA) |
|---|---|---|---|---|---|
| line_1 | zone_1 | zone_2 | 0.02 | 0.01 | 126 |
| line_2 | zone_1 | zone_3 | 0.02 | 0.01 | 250 |
| line_3 | zone_2 | zone_3 | 0.01 | 0.01 | 130 |

The version chip reads V1 · Draft · 13 changes. Click Save version, give it the title Quickstart 2: three-zone market, and click Save v2.

Click Solve in the header. Keep Method: Optimize and the other defaults, and click Solve. The Solve page follows the run until it succeeds, with objective 2,835.


Click View results: the Components tab opens on the version the solve wrote, with Results on. On Buses, Columns, search v_ang and tick it. Generators show p, and Lines p0 and p1. line_1 is at its 126 MW limit.



Click Solve again. Choose Method → Fix optimal dispatch and click Solve. The run writes v4, whose generator set-points are the dispatch just found.



Click Solve again. The dialog names v4, the version the fix wrote. Choose Method → Power flow and click Solve.


Click View results. Generators: gen_A, the slack, now makes 53.861 MW, covering the losses; Columns adds q. Lines: p0 + p1 is no longer 0, and Columns adds q0 and q1. Buses: Columns adds v_mag_pu beside v_ang.



| Quantity | Value |
|---|---|
| Objective | 2,835 |
| marginal_price zone_1 / zone_2 / zone_3 | 7.5 / 11.25 / 10 |
| p gen_A / gen_B / gen_C / gen_D (MW) | 50 / 285 / 0 / 75 |
| p0 line_1 / line_2 / line_3 (MW) | 126 / 159 / 66 |
| p1 line_1 / line_2 / line_3 (MW) | -126 / -159 / -66 |
| v_ang zone_1 / zone_2 / zone_3, linear (radians) | 0.015702 / -0.005124 / -0.010579 |
| AC power flow | |
| p gen_A, the slack (MW) | 53.860705 |
| p gen_B / gen_D (MW) | 285 / 75 |
| q gen_A (MVar) | 7.379326 |
| p0 line_1 / line_2 / line_3 (MW) | 124.843189 / 164.017515 / 63.554834 |
| p1 line_1 / line_2 / line_3 (MW) | -123.554834 / -161.787249 / -63.212751 |
| q0 line_1 / line_2 / line_3 (MVar) | -1.811567 / 9.190894 / -4.388279 |
| q1 line_1 / line_2 / line_3 (MVar) | 4.388279 / -4.730362 / 4.730362 |
| Losses, sum of p0 + p1 (MW) | 3.860704 |
| v_mag_pu zone_1 / zone_2 / zone_3 | 1 / 0.9902 / 0.985278 |
| v_ang zone_1 / zone_2 / zone_3, AC (radians) | 0 / -0.020992 / -0.026748 |
💡 Key learnings
- Power on a meshed network goes where physics sends it, not where it is sold. In a triangle of lines, power from zone 1 to zone 3 flows partly the direct way and partly through zone 2, split by the lines' reactances. Once line_1 is full, sending more to zone 3 also pushes more onto that line, so the dispatch must work round it.
- A price can sit between the generators' costs. Zone 2's price, 11.25, is no generator's cost: it is the cost of a mix of more gen_D and less gen_A that serves one more MWh at zone 2 without overloading line_1.
- The optimisation uses a linear power flow; an AC power flow checks it. The linear model ignores losses and voltages, which keeps the problem fast. Fixing the dispatch and running an AC power flow shows what it left out: 3.86 MW of losses, about 1% of the load, covered by the slack generator, reactive power, and voltages that sag towards the zone with the most load.
- #2744 After a Fix optimal dispatch run, the Solve page's Solver card keeps that method and shows "This version holds no results…" (open)
- #2745 A power flow or Fix run's Outcome reads "Solve time: None for this method" (open)
- #1803 No view of the optimisation model (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