Skip to content

PyPSA in 25 files#

This section states the PyPSA spec one topic at a time. PyPSA in one file states it as examples/pypsa.yaml, one spec of about 5,100 lines. Here the same spec is split into 25 whole specs of one topic each (fragments), under examples/pypsa/. merge composes the 25 files into one spec, which has the same canonical form as the one file.

Each fragment loads and prints on its own, and advice runs on each fragment alone. A fragment lists each name that it uses but does not declare under given.

Some sums take a share from every component, such as the bus balance or the operating cost. A component states its share of such a sum as an expression of its own, a term, whose adds_to: key is the sum. For each sum, one fragment lists it under given: and adds nothing to it, so every term adds to a sum that some fragment lists. A component is one file, and adding it leaves the network file unchanged.

tools/pypsa_split.py writes the 25 files from the one file, and a test compares them with it, so the two always agree.

The four kinds of fragment#

  • A component file states the PyPSA class of that name: its dimension, its data, its variables, its rows and its share of each sum. The committable classes are Generator, Link and Process. Each of them is split by feature into four files: the class, its commitment, its ramping and its maintenance. The three sets of four files are alike, because PyPSA builds the same rows for each class.
  • A file that describes a sum lists it under given: with its description, and states the row that contains it. The network and power flow files are of this kind.
  • A file of one feature states rows that span several classes. The cost, carrier, global constraints and security files state the risk-weighted operating cost, the growth limits, the five caps and the outage rows.
  • The settings file states the weightings and the flags that the other fragments use. It also lists the totals that the cost, carrier and global constraints files list, because a spec may leave those files out. Its objective minimises total_cost. Each component adds its capital cost to total_cost, and the cost file adds the risk-weighted operating cost.

Sums and fragments#

The sums#

Sum Over Read in The terms, by the fragment that adds each
Bus_injection bus, scenario, snapshot network FlowBased_injection, Generator_injection, Line_injection, Link_injection, Load_injection, Process_injection, StorageUnit_injection, Store_injection, Transformer_injection
total_cost scalar settings risk_weighted_opex, Generator_capex, Line_capex, Link_capex, Process_capex, StorageUnit_capex, Store_capex, Transformer_capex
scenario_opex scenario settings Generator_opex, Generator_commitment_opex, Link_opex, Link_commitment_opex, Process_opex, Process_commitment_opex, StorageUnit_opex, Store_opex
Carrier_additions carrier, period settings Generator_additions, Line_additions, Link_additions, Process_additions, StorageUnit_additions, Store_additions
tech_capacity_expansion global_constraint settings Generator_tech_capacity_expansion, Line_tech_capacity_expansion, Link_tech_capacity_expansion, Process_tech_capacity_expansion, StorageUnit_tech_capacity_expansion, Store_tech_capacity_expansion
operational_limit global_constraint, scenario settings Generator_operational_limit, StorageUnit_operational_limit, Store_operational_limit
primary_energy global_constraint, scenario settings Generator_primary_energy, StorageUnit_primary_energy, Store_primary_energy
Cycle_angle_sum cycle, scenario, snapshot power_flow Line_angle_sum, Transformer_angle_sum
transmission_expansion_cost global_constraint, scenario settings Line_transmission_expansion_cost, Link_transmission_expansion_cost
transmission_volume_expansion global_constraint, scenario settings Line_transmission_volume_expansion, Link_transmission_volume_expansion

The fragments#

Fragment Parameters Variables Constraints Reads Adds to
carrier 2 0 1 1
cost 1 3 2 4 total_cost
flow_based 4 1 2 5 Bus_injection
generator 24 4 11 19 Carrier_additions, total_cost, Bus_injection, operational_limit, scenario_opex, primary_energy, tech_capacity_expansion
generator_commitment 12 3 18 19 scenario_opex
generator_maintenance 5 4 13 10
generator_ramping 5 0 6 15
global_constraints 3 0 15 6
line 22 4 14 9 Carrier_additions, Cycle_angle_sum, total_cost, Bus_injection, tech_capacity_expansion, transmission_expansion_cost, transmission_volume_expansion
link 26 3 11 17 Carrier_additions, total_cost, Bus_injection, scenario_opex, tech_capacity_expansion, transmission_expansion_cost, transmission_volume_expansion
link_commitment 10 3 18 18 scenario_opex
link_maintenance 5 4 13 10
link_ramping 5 0 6 15
load 3 0 0 1 Bus_injection
network 1 0 1 1
power_flow 1 0 1 1
process 24 3 11 15 Carrier_additions, total_cost, Bus_injection, scenario_opex, tech_capacity_expansion
process_commitment 10 3 18 18 scenario_opex
process_maintenance 5 4 13 10
process_ramping 5 0 6 15
security 2 0 8 12
settings 9 0 0 8
storage_unit 36 6 21 14 Carrier_additions, total_cost, Bus_injection, operational_limit, scenario_opex, primary_energy, tech_capacity_expansion
store 42 6 22 15 Carrier_additions, total_cost, Bus_injection, operational_limit, scenario_opex, primary_energy, tech_capacity_expansion
transformer 24 5 16 5 Cycle_angle_sum, total_cost, Bus_injection

Leaving a file out#

A spec may leave out a component family, the cost, the carriers, the global constraints or security. What remains is a whole spec, with nothing left under given:. Lines and transformers leave only together with security, because security lists Line_s_nom and four more line names, and the same for transformers, under given:. While a component is in, a spec may not leave out the network, power flow or settings. The terms of the component would then add to a sum that no fragment lists, and merge refuses the files.

See also