Skip to content

PyPSA#

You can read the spec of the model that n.optimize() builds in the power system modelling framework PyPSA here, one topic at a time. The spec is one file, examples/pypsa.yaml, of about 5,200 lines, split into 25 whole specs of one topic each (fragments) under examples/pypsa/. merge composes the 25 files into one spec with the same canonical form as the one file. A sample page has one fragment in full beside its math, and PyPSA: scope and refusals lists the n.optimize() keywords that the file states and the data that PyPSA refuses. The relaxed commitment is a patch over the file that relaxes the commitment decisions to shares in [0, 1].

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 Listed 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 Purpose Given Adds to
carrier The growth limits of each carrier 1
cost The expected operating cost and its tail, weighted by scenario 4 total_cost
flow_based Flow-based market coupling 5 Bus_injection
generator PyPSA's Generator 19 Carrier_additions, total_cost, Bus_injection, operational_limit, scenario_opex, primary_energy, tech_capacity_expansion
generator_commitment The commitment rows of PyPSA's Generator 19 scenario_opex
generator_maintenance The maintenance rows of PyPSA's Generator 10
generator_ramping The ramping rows of PyPSA's Generator 15
global_constraints The five system totals that PyPSA caps 6
line PyPSA's Line 9 Carrier_additions, Cycle_angle_sum, total_cost, Bus_injection, tech_capacity_expansion, transmission_expansion_cost, transmission_volume_expansion
link PyPSA's Link 17 Carrier_additions, total_cost, Bus_injection, scenario_opex, tech_capacity_expansion, transmission_expansion_cost, transmission_volume_expansion
link_commitment The commitment rows of PyPSA's Link 18 scenario_opex
link_maintenance The maintenance rows of PyPSA's Link 10
link_ramping The ramping rows of PyPSA's Link 15
load PyPSA's Load 1 Bus_injection
network The buses and the balance at each bus 1
power_flow Kirchhoff's voltage law around each cycle 1
process PyPSA's Process 15 Carrier_additions, total_cost, Bus_injection, scenario_opex, tech_capacity_expansion
process_commitment The commitment rows of PyPSA's Process 18 scenario_opex
process_maintenance The maintenance rows of PyPSA's Process 10
process_ramping The ramping rows of PyPSA's Process 15
security The security-constrained flows over the outages 12
settings The weightings, the risk preference and the flags that the other fragments use 8
storage_unit PyPSA's StorageUnit 14 Carrier_additions, total_cost, Bus_injection, operational_limit, scenario_opex, primary_energy, tech_capacity_expansion
store PyPSA's Store 15 Carrier_additions, total_cost, Bus_injection, operational_limit, scenario_opex, primary_energy, tech_capacity_expansion
transformer PyPSA's Transformer 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

  • Composition, for what merge refuses
  • PyPSA: scope and refusals, for the n.optimize() keywords that the one file states and the data that PyPSA refuses
  • given, for the names a fragment uses but does not declare