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,LinkandProcess. 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 tototal_cost, and the cost file adds the risk-weighted operating cost.
Sums and fragments#
The sums#
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
mergerefuses - 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