Skip to content

Walkthrough PyPSA Quickstart 2

James Dunkerley edited this page Dec 3, 2026 · 9 revisions

Quickstart 2: a three-zone market with linear and AC power flow

All walkthroughs

What it models

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

Steps

1. Create the project and the network

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.

New network with one hourly timestep

2. Add the three buses in one panel

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.

The Add bus menu

Three buses in one panel

3. Add the three loads in one panel

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

Three loads with separate values

4. Import the generators from a CSV file

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

Import review with each row's values

Generators in the draft

5. Add the three lines in one panel

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

Three lines with separate values

6. Save the version

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

Draft with 13 changes

7. Optimise

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.

Solve dialog with the Method help open

Solve succeeded

8. Read the prices, dispatch and flows

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.

Bus prices and angles

Generator dispatch

Line flows

9. Fix the optimal dispatch

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

Method menu

Fix optimal dispatch

Fix run succeeded

10. Run the AC power flow

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

Power flow options

Power flow succeeded

11. Read the losses, reactive power and voltages

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.

Generators after the power flow

Lines after the power flow

Buses after the power flow

Results

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.

Bugs

  • #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)

Missing features

  • #1803 No view of the optimisation model (open)

Hard to do

  • #2741 With Results on, output columns come after every input, with no Outputs only view, so p, p0 and p1 are off screen (open)
  • #2742 Bus voltage results v_ang and v_mag_pu are not among the Results columns (open)

Clone this wiki locally