Repository navigation
Walkthrough PyPSA Capacity Expansion Three Nodes
PyPSA's 3-Node Capacity Expansion (notebook at v1.4.0). Victoria (VIC), South Australia (SA) and New South Wales (NSW) each have their 2011 load. The model sizes wind and solar in each region, with load shedding at 3,000 AUD/MWh. It is solved three times on one growing network:
- wind, solar and load shedding only;
- plus hydrogen (electrolysis, store, turbine) and batteries (charger, store, discharger), with each charger sized at 0.95 × its discharger;
- plus three bidirectional HVDC links.
Upstream keeps every third hour of the year: 2,920 timesteps, each weighted 3 hours
(n.snapshot_weightings = 3). Step 3 sets the same weightings from the time axis's
spacing, so every value is typed as upstream writes it.
Data. Upstream's two files, australia-example-p_set.csv and
australia-example-p_max_pu.csv from tubcloud.tu-berlin.de, cut to every third row, as
upstream does with [::3], so that the time axis can be read from the load file. The
p_max_pu file also has its two header rows (region, technology) merged into one, such as
VIC wind, and the p_set columns are named as the loads, such as VIC load, so that every
column matches by name.
Files to download
| File | What it holds | Step |
|---|---|---|
australia-p_set-3h.csv |
The time axis and each region's load, every third hour of 2011 | 2, 6 |
australia-p_max_pu-3h.csv |
The wind and solar availability of each region | 6 |
cem3-carriers.csv |
The 14 carriers and their colours | 4 |
cem3-buses-1.csv |
The three regions | 4 |
cem3-loads.csv |
The three loads | 4 |
cem3-generators.csv |
Wind, solar and load shedding in each region | 4 |
cem3-buses-2.csv |
A hydrogen and a battery bus in each region | 10 |
cem3-links-2.csv |
Electrolysis, turbine, battery charger and discharger in each region | 10 |
cem3-stores.csv |
A hydrogen and a battery store in each region | 10 |
cem3-links-3.csv |
The three HVDC links | 14 |
The files as published,
australia-example-p_set.csv
and australia-example-p_max_pu.csv,
are used in the side notes of step 6;
prepare.py makes the
files above from them.
| Cost | Upstream | capital_cost in the UI |
|---|---|---|
| Wind | annuity(0.05, 30) × 2,000,000 | 130102.87016055314 |
| Solar | annuity(0.05, 30) × 700,000 | 45536.0045561936 |
| Electrolysis | annuity(0.05, 25) × 2,500,000 | 177381.143248074 |
| Turbine | annuity(0.05, 25) × 2,000,000 | 141904.9145984592 |
| Battery charger | annuity(0.05, 10) × 300,000 | 38851.37248963698 |
| Hydrogen storage | annuity(0.05, 30) × 80 | 5.204114806422125 |
| Battery storage | annuity(0.05, 25) × 250,000 | 17738.1143248074 |
| HVDC, per link | annuity(0.05, 40) × 1,000 × km | 40794.712816224484 (VIC-NSW, 700 km), 37880.804757922735 (VIC-SA, 650 km), 67019.88534094022 (NSW-SA, 1,150 km) |
On Home, click New project. Name: Capacity expansion, three nodes. Click Create project.

Click New network. Name: Australia. Under Time axis, choose Upload CSV and pick australia-p_set-3h.csv: 2,920 steps. Click Create network.
The dialog has no framework choice: the server offers PyPSA only.

On Overview, click Weightings (1 at every snapshot), then Weight by spacing. Weightings now read 3 at every snapshot.
The dialog warns first: "Weightings differ from the spacing (3 hours)". Weight by spacing saves the weightings at once, as a version titled "Weight by spacing".



Open Components. On each type, open the menu beside Add …, choose Import CSV…, choose the file and click Import N …: 14 carriers, 3 buses, 3 loads and 9 generators.
| Type | File | Rows |
|---|---|---|
| Carriers |
cem3-carriers.csv: name, color, as upstream's 14 carriers |
14 |
| Buses |
cem3-buses-1.csv: VIC 145.01 / -37.81, SA 138.63 / -34.93, NSW 151.2 / -33.87 (x / y) |
3 |
| Loads |
cem3-loads.csv: VIC load, SA load, NSW load, on their buses, carrier load
|
3 |
| Generators | cem3-generators.csv |
9 |
cem3-generators.csv:
name,bus,carrier,p_nom,p_nom_extendable,capital_cost,marginal_cost
VIC wind,VIC,wind,,true,130102.87016055314,0.5
SA wind,SA,wind,,true,130102.87016055314,0.5
NSW wind,NSW,wind,,true,130102.87016055314,0.5
VIC solar,VIC,solar,,true,45536.0045561936,
SA solar,SA,solar,,true,45536.0045561936,
NSW solar,NSW,solar,,true,45536.0045561936,
VIC load shedding,VIC,load shedding,9526.119999999999,,,3000
SA load shedding,SA,load shedding,3374.1949999999997,,,3000
NSW load shedding,NSW,load shedding,14552.795,,,3000Load shedding p_nom is each region's hourly peak, as upstream takes it before cutting to 3-hourly. Every type, empty or not, is listed down the left, and the import review lists each row's values before they are added to the draft.



Click Save version, title it Stage 1: wind, solar and load shedding, and click Save v3.

On Loads, hover VIC load's p_set cell and click Add series, then Open in editor. Click Import a sheet and choose australia-p_set-3h.csv: its three columns match the loads by name. Click Import 3 series, then Discard edits to drop the series added by hand. Do the same on Generators, p_max_pu, with australia-p_max_pu-3h.csv and Import 6 series.
The Series page, where Import a sheet lives, is linked from a column's "N series" badge, which shows only once a series exists. A series of zeros added by hand to one cell opens the way; the import then asks to discard it. Each import writes a new version (v4, v5).


Upstream's hourly p_set file, with one column pointed at a load by hand: the count reads
"1 of 3 columns matched", and the fit offers Mean within the timestep or Value at
the timestep, which is upstream's [::3].



Upstream's p_max_pu file, two header rows as published: the import joins them
(VIC onwind, VIC solar), so the solar columns match and the onwind ones need
pointing at the wind generators.



Click Solve, keep the defaults (Optimize, HiGHS), and click Solve. The run's page follows it until it succeeds; hover the objective for its full value.
The objective shows as 3.164 × 10¹⁰; its full value is in the hover title only.


Open Components → Generators with Results on. p_nom_opt holds each generator's size.

Open Visualisation, click Add chart, then Value → Write a formula…: Name average_cost, Expression objective() / sum(withdrawal(Load)), Apply. Add a second: VIC_price, mean(Bus[name="VIC"].marginal_price). Each chart draws one bar; Show data gives its value.
Upstream's average cost sums the 3-hourly load unweighted and divides by 3 again; the withdrawal here is weighted, so neither formula divides by 3. Show data rounds to three decimals.



Under Components, click Advanced fields to list Links and Stores. Import cem3-buses-2.csv on Buses (6 buses), cem3-links-2.csv on Links (12 links: electrolysis, turbine, battery charger and discharger in each region) and cem3-stores.csv on Stores (6 stores).
Links per region (VIC shown; SA and NSW the same):
| name | bus0 | bus1 | efficiency | capital_cost |
|---|---|---|---|---|
| VIC electrolysis | VIC | VIC hydrogen | 0.7 | 177381.143248074 |
| VIC turbine | VIC hydrogen | VIC | 0.4 | 141904.9145984592 |
| VIC battery charger | VIC | VIC battery | 0.95 | 38851.37248963698 |
| VIC battery discharger | VIC battery | VIC | 0.95 |
All with p_nom_extendable. Stores: VIC hydrogen storage on VIC hydrogen, capital_cost
5.204114806422125; VIC battery storage on VIC battery, 17738.1143248074; both
e_nom_extendable and e_cyclic.


Upstream adds one constraint for all chargers; here it takes one per region. On Custom constraints, click Add a constraint: Name VIC charger ratio, Expression sum(Link[name="VIC battery charger"].p_nom) - 0.95 * sum(Link[name="VIC battery discharger"].p_nom) == 0, Apply to draft. Do the same for SA and NSW, then Save version as Stage 2: hydrogen and battery storage.
Written once over every charger, the expression is refused: "The two sides share no component. Each side's components are aligned by name".



Click Solve and Solve, and follow the run until it succeeds.


With Results on, Links p_nom_opt holds each link's size and Stores e_nom_opt each store's: VIC hydrogen storage holds 3,022,369.7 MWh. On Custom constraints, Dual holds each constraint's dual.
The built-in statistics are columns of each grid: Columns → Statistics.



Import cem3-links-3.csv on Links: VIC-NSW, VIC-SA and NSW-SA, carrier HVDC, extendable, p_min_pu -1 so they run both ways. Save version as Stage 3: HVDC links.
name,bus0,bus1,carrier,p_nom_extendable,p_min_pu,capital_cost
VIC-NSW,VIC,NSW,HVDC,true,-1,40794.712816224484
VIC-SA,VIC,SA,HVDC,true,-1,37880.804757922735
NSW-SA,NSW,SA,HVDC,true,-1,67019.88534094022
Click Solve and Solve. This solve takes a few minutes.


With Results on, Links p_nom_opt holds each HVDC link's size; the duals are on Custom constraints and the two values on Visualisation.



On Links with Results on, click the VIC-NSW row's p0 series. A negative p0 is flow from NSW to VIC. Upstream shows the season with a 7-day rolling mean; the chart here draws all 2,920 values.


| Quantity | Value |
|---|---|
| Stage 1 objective | 31,635,086,948.605247 |
| Stage 1 wind VIC / SA / NSW | 55,072.771739 / 12,037.052632 / 84,753.221154 MW |
| Stage 1 average cost | 226.572 |
| Stage 1 VIC mean price | 250.44 |
| Stage 2 objective | 14,034,045,471.284817 |
| Stage 2 NSW battery charger / discharger | 11,425.153082 / 12,026.476928 MW |
| Stage 2 VIC hydrogen store | 3,022,369.74385 MWh |
| Stage 2 charger duals VIC / SA / NSW | 0 / 2,939.550557 / 0 |
| Stage 2 average cost | 100.513 |
| Stage 2 VIC mean price | 97.887 |
| Stage 3 objective | 12,984,993,665.64926 |
| Stage 3 HVDC VIC-NSW / VIC-SA / NSW-SA | 2,512.595216 / 2,349.643925 / 434.719022 MW |
| Stage 3 charger duals VIC / SA / NSW | 1,896.184199 / 849.89539 / 0 |
| Stage 3 average cost | 92.999 |
| Stage 3 VIC mean price | 89.726 |
The HVDC links are lossless and cost nothing to run, so many flow patterns reach the same cost, and the flow on each link can differ from one solve to another.
💡 Key learnings
- Wind and solar alone are an expensive system. With nothing to store energy or move it between regions, each region must meet its own load hour by hour, by overbuilding wind and solar or by shedding load at 3,000 AUD/MWh: the average cost is about 227 AUD/MWh.
- Storage is the biggest saving. Adding batteries for the daily cycle and hydrogen for longer gaps cuts the total cost by more than half, from 31.6 to 14.0 bn AUD, and the average cost to about 101 AUD/MWh.
- Transmission shares the weather. The wind and sun differ between regions at any one time, so HVDC links let one region's surplus cover another's shortfall. They cut the cost again, to 13.0 bn AUD and about 93 AUD/MWh.
- Solving in stages shows what each option is worth. Each stage is one more technology on the same network, and the fall in the objective is its value to the system.
- A dual is the price of a rule. Each charger is tied to 0.95 times its discharger. A dual of 0 means the rule costs nothing in that region: it would size them so anyway. SA's dual of about 2,940 means the rule binds there, and loosening it by 1 MW would save about that much a year.
- #2764 With constraints in the draft, the type picker still reads Custom constraints 0 (open)
- #2765 The top bar cuts the project name with room to spare (open)
- #1796 A constraint covers one pair of components, so one is needed per region (open)
- #1801 No energy balance chart, and no sum of one attribute across components over time (open)
- #1802 No rolling mean or resampling in series charts (open)
- #2750 A custom statistic cannot be saved with the network or shown as one number (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