Skip to content

Rung 3: expansion — extendable capacity, energy-sum bounds, fixed and set nominal capacities

One rung of the PyPSA corpus: the file pypsa.yaml projected onto what this network builds, attached to that network, and held to what PyPSA solves it to.

✔ Verified against pypsa 1.3.0 — objective 7633.908502024291 on both sides; structure ≠ tech_capacity_expansion_limit 5 vs 1+2+2 — one block per sense — ==, <=, >= — where PyPSA writes one row per labelled constraint whatever its sense; transmission_expansion_cost_limit 2 vs 1+1 — one block per sense — ==, <=, >= — where PyPSA writes one row per labelled constraint whatever its sense; size ✔ 184 rows · ✔ 73 columns · ✔ 328 nonzeros; duals ✔ 184 rows, 4 negated; model for model: 57 blocks equal, 3 documented splits.

Rows and columns, PyPSA against specsolve, name for name
row PyPSA specsolve
Bus-nodal_balance 12 12
Generator-e_sum_max 1 1
Generator-e_sum_min 1 1
Generator-ext-p-lower 8 8
Generator-ext-p-upper 8 8
Generator-ext-p_nom-lower 2 2
Generator-ext-p_nom-upper 2 2
Generator-fix-p-lower 12 12
Generator-fix-p-upper 12 12
Generator-p-ramp_limit_down 3 3
Generator-p-ramp_limit_up 3 3
Generator-p_nom_set 1 1
Link-ext-p-lower 4 4
Link-ext-p-upper 4 4
Link-ext-p_nom-lower 1 1
Link-ext-p_nom-upper 1 1
Link-fix-p-lower 4 4
Link-fix-p-upper 4 4
Link-p-ramp_limit_down 3 3
Link-p-ramp_limit_up 3 3
Link-p_nom_set 1 1
StorageUnit-energy_balance 8 8
StorageUnit-ext-p_dispatch-lower 4 4
StorageUnit-ext-p_dispatch-upper 4 4
StorageUnit-ext-p_nom-lower 1 1
StorageUnit-ext-p_nom-upper 1 1
StorageUnit-ext-p_store-lower 4 4
StorageUnit-ext-p_store-upper 4 4
StorageUnit-ext-state_of_charge-lower 4 4
StorageUnit-ext-state_of_charge-upper 4 4
StorageUnit-fix-p_dispatch-lower 4 4
StorageUnit-fix-p_dispatch-upper 4 4
StorageUnit-fix-p_store-lower 4 4
StorageUnit-fix-p_store-upper 4 4
StorageUnit-fix-state_of_charge-lower 4 4
StorageUnit-fix-state_of_charge-upper 4 4
StorageUnit-p_nom_set 1 1
Store-e_nom_set 1 1
Store-energy_balance 8 8
Store-ext-e-lower 4 4
Store-ext-e-upper 4 4
Store-ext-e_nom-lower 1 1
Store-ext-e_nom-upper 1 1
Store-fix-e-lower 4 4
Store-fix-e-upper 4 4
tech_capacity_expansion_limit 5 ≠ 1+2+2
transmission_expansion_cost_limit 2 ≠ 1+1
transmission_volume_expansion_limit 1 1
column PyPSA specsolve
Generator-p 20 20
Generator-p_nom 2 2
Link-p 8 8
Link-p_nom 1 1
StorageUnit-p_dispatch 8 8
StorageUnit-p_nom 1 1
StorageUnit-p_store 8 8
StorageUnit-state_of_charge 8 8
Store-e 8 8
Store-e_nom 1 1
Store-p 8 8

The model

The same model, as math

The spec of the model a plain n.optimize() builds, in one file. Every declaration is named Component_attribute after the PyPSA statement it stands for, and each constraint's description opens with the linopy name PyPSA gives that row, so the two can be read side by side. PyPSA's regimes — extendable, committable — are data columns and become where: masks. Bounds are the explicit rows PyPSA writes, so their duals are row duals. Parameters no PyPSA table carries verbatim are computed in data prep and say so in their description.

Sets

Symbol Meaning
\(\mathcal{T}\) index \(t\) — snapshot — dispatch periods
\(\mathcal{N}\) index \(n\) — bus with \(\mathrm{Generator\_bus}: \mathcal{G} \to \mathcal{N},\ \mathrm{Link\_bus0}: \mathcal{L} \to \mathcal{N},\ \mathrm{Link\_output\_bus}: \mathcal{O} \to \mathcal{N},\ \mathrm{Load\_bus}: \mathcal{D} \to \mathcal{N},\ \mathrm{StorageUnit\_bus}: \mathcal{S} \to \mathcal{N},\ \mathrm{Store\_bus}: \mathcal{V} \to \mathcal{N}\) — network nodes
\(\mathcal{G}\) index \(g\) — generator with \(\mathrm{Generator\_bus}: \mathcal{G} \to \mathcal{N}\) — generating units, each on one bus
\(\mathcal{L}\) index \(l\) — link with \(\mathrm{Link\_bus0}: \mathcal{L} \to \mathcal{N},\ \mathrm{Link\_output\_link}: \mathcal{O} \to \mathcal{L}\) — controllable connections, each from one bus to the buses it delivers to
\(\mathcal{O}\) index \(o\) — link_output with \(\mathrm{Link\_output\_link}: \mathcal{O} \to \mathcal{L},\ \mathrm{Link\_output\_bus}: \mathcal{O} \to \mathcal{N}\) — a link's output ports, one label per port a link declares — PyPSA's bus1, bus2, … columns read long, so a link of any number of output ports is one term in the balance, data prep
\(\mathcal{D}\) index \(d\) — load with \(\mathrm{Load\_bus}: \mathcal{D} \to \mathcal{N}\) — demands, each on one bus
\(\mathcal{S}\) index \(s\) — storage_unit with \(\mathrm{StorageUnit\_bus}: \mathcal{S} \to \mathcal{N}\) — storage units, dispatch and store behind one bus connection
\(\mathcal{V}\) index \(v\) — store with \(\mathrm{Store\_bus}: \mathcal{V} \to \mathcal{N}\) — pure energy stores, each on one bus
\(\mathcal{B}\) index \(b\) — global_constraint — PyPSA's GlobalConstraint rows, one label per declared limit

Parameters

Symbol Meaning
\(\mathrm{w}\) snapshot_weightings_objective over \(\mathcal{T}\) — PyPSA's snapshot_weightings.objective — hours a snapshot stands for in the cost
\(\mathrm{p}^{\mathrm{nom}}\) Generator_p_nom over \(\mathcal{G}\) — nominal power
\(\mathrm{ext}\) Generator_p_nom_extendable over \(\mathcal{G}\) — whether the nominal power is a decision
\(\underline{\mathrm{p}}\) Generator_p_min_pu over \(\mathcal{T} \times \mathcal{G}\) — least output, per unit of nominal power
\(\overline{\mathrm{p}}\) Generator_p_max_pu over \(\mathcal{T} \times \mathcal{G}\) — most output, per unit of nominal power — an availability profile
\(\mathrm{c}\) Generator_marginal_cost over \(\mathcal{T} \times \mathcal{G}\) — cost of one unit of output
\(\mathrm{com}\) Generator_committable over \(\mathcal{G}\) — whether output is gated by an on/off status decision
\(\mathrm{ru}\) Generator_ramp_limit_up over \(\mathcal{G}\) — most a generator may raise its output between snapshots, per unit of nominal power; no value means no limit
\(\mathrm{rd}\) Generator_ramp_limit_down over \(\mathcal{G}\) — most a generator may lower its output between snapshots, per unit of nominal power; no value means no limit
\(\mathrm{ru}^{\mathrm{up}}\) Generator_ramp_limit_start_up over \(\mathcal{G}\) — most output in the snapshot a unit starts, per unit of nominal power
\(\mathrm{rd}^{\mathrm{dn}}\) Generator_ramp_limit_shut_down over \(\mathcal{G}\) — most output in the snapshot before a unit stops, per unit of nominal power
\(\mathrm{u}^{0}\) Generator_status_initial over \(\mathcal{G}\) — one where the unit was on before the first snapshot, zero where off — PyPSA's up_time_before > 0, data prep
\(\mathrm{ru}^{f}\) Link_ramp_limit_up over \(\mathcal{L}\) — most a link may raise its flow between snapshots, per unit of nominal power; no value means no limit
\(\mathrm{rd}^{f}\) Link_ramp_limit_down over \(\mathcal{L}\) — most a link may lower its flow between snapshots, per unit of nominal power; no value means no limit
\(\mathrm{f}^{\mathrm{nom}}\) Link_p_nom over \(\mathcal{L}\) — nominal power
\(\mathrm{ext}^{f}\) Link_p_nom_extendable over \(\mathcal{L}\) — whether the nominal power is a decision
\(\underline{\mathrm{f}}\) Link_p_min_pu over \(\mathcal{T} \times \mathcal{L}\) — least flow, per unit of nominal power — negative for a link that carries both ways
\(\overline{\mathrm{f}}\) Link_p_max_pu over \(\mathcal{T} \times \mathcal{L}\) — most flow, per unit of nominal power
\(\eta\) Link_efficiency over \(\mathcal{O}\) — share of the flow that arrives at an output port, PyPSA's efficiency, efficiency2, … read long — negative where that port consumes rather than delivers
\(\mathrm{d}^{f}\) Link_output_delay over \(\mathcal{O}\) — snapshots a port's delivery lags its link's flow — PyPSA's delay, delay2, … read long, in snapshot_weightings.generators units, which the file states as whole snapshots; zero for a port that delivers at once
\(\mathrm{cyc}^{f}\) Link_output_cyclic_delay over \(\mathcal{O}\) — whether a delayed port's flow wraps from the horizon's end — PyPSA's cyclic_delay, cyclic_delay2, …; where it does not, the flow still in transit at the first snapshots is lost
\(\mathrm{c}^{f}\) Link_marginal_cost over \(\mathcal{T} \times \mathcal{L}\) — cost of one unit of flow
\(\mathrm{load}\) Load_p_set over \(\mathcal{T} \times \mathcal{D}\) — demand
\(\mathrm{w}^{\mathrm{sto}}\) snapshot_weightings_stores over \(\mathcal{T}\) — PyPSA's snapshot_weightings.stores — hours a snapshot stands for in a storage balance
\(\mathrm{w}^{\mathrm{gen}}\) snapshot_weightings_generators over \(\mathcal{T}\) — PyPSA's snapshot_weightings.generators — hours a snapshot stands for in an energy total
\(\underline{\mathrm{p}}^{\mathrm{nom}}\) Generator_p_nom_min over \(\mathcal{G}\) — least nominal power an extendable generator may be built at
\(\overline{\mathrm{p}}^{\mathrm{nom}}\) Generator_p_nom_max over \(\mathcal{G}\) — most nominal power an extendable generator may be built at
\(\mathrm{c}^{\mathrm{cap}}\) Generator_capital_cost over \(\mathcal{G}\) — cost of one unit of nominal power — PyPSA's capital_cost, periodized as an annuity in data prep
\(\mathrm{p}^{\mathrm{nom,set}}\) Generator_p_nom_set over \(\mathcal{G}\) — a given nominal power for an extendable generator; one without a value has no row here
\(\underline{\mathrm{E}}\) Generator_e_sum_min over \(\mathcal{G}\) — least energy over the horizon; minus infinity where no floor is meant
\(\overline{\mathrm{E}}\) Generator_e_sum_max over \(\mathcal{G}\) — most energy over the horizon — a fuel or emission budget in energy terms; infinity where no cap is meant
\(\underline{\mathrm{f}}^{\mathrm{nom}}\) Link_p_nom_min over \(\mathcal{L}\) — least nominal power an extendable link may be built at
\(\overline{\mathrm{f}}^{\mathrm{nom}}\) Link_p_nom_max over \(\mathcal{L}\) — most nominal power an extendable link may be built at
\(\mathrm{c}^{\mathrm{cap},f}\) Link_capital_cost over \(\mathcal{L}\) — cost of one unit of nominal power — PyPSA's capital_cost, periodized as an annuity in data prep
\(\mathrm{f}^{\mathrm{nom,set}}\) Link_p_nom_set over \(\mathcal{L}\) — a given nominal power for an extendable link; one without a value has no row here
\(\underline{\mathrm{h}}^{\mathrm{nom}}\) StorageUnit_p_nom_min over \(\mathcal{S}\) — least nominal power an extendable storage unit may be built at
\(\overline{\mathrm{h}}^{\mathrm{nom}}\) StorageUnit_p_nom_max over \(\mathcal{S}\) — most nominal power an extendable storage unit may be built at
\(\mathrm{c}^{\mathrm{cap},h}\) StorageUnit_capital_cost over \(\mathcal{S}\) — cost of one unit of nominal power — PyPSA's capital_cost, periodized as an annuity in data prep
\(\mathrm{h}^{\mathrm{nom,set}}\) StorageUnit_p_nom_set over \(\mathcal{S}\) — a given nominal power for an extendable storage unit; one without a value has no row here
\(\underline{\mathrm{e}}^{\mathrm{nom}}\) Store_e_nom_min over \(\mathcal{V}\) — least nominal capacity an extendable store may be built at
\(\overline{\mathrm{e}}^{\mathrm{nom}}\) Store_e_nom_max over \(\mathcal{V}\) — most nominal capacity an extendable store may be built at
\(\mathrm{c}^{\mathrm{cap},e}\) Store_capital_cost over \(\mathcal{V}\) — cost of one unit of nominal capacity — PyPSA's capital_cost, periodized as an annuity in data prep
\(\mathrm{e}^{\mathrm{nom,set}}\) Store_e_nom_set over \(\mathcal{V}\) — a given nominal capacity for an extendable store; one without a value has no row here
\(\mathrm{h}^{\mathrm{nom}}\) StorageUnit_p_nom over \(\mathcal{S}\) — nominal power
\(\mathrm{ext}^{h}\) StorageUnit_p_nom_extendable over \(\mathcal{S}\) — whether the nominal power is a decision
\(\underline{\mathrm{h}}\) StorageUnit_p_min_pu over \(\mathcal{T} \times \mathcal{S}\) — most storing, per unit of nominal power and negated
\(\overline{\mathrm{h}}\) StorageUnit_p_max_pu over \(\mathcal{T} \times \mathcal{S}\) — most dispatch, per unit of nominal power
\(\mathrm{T}^{h}\) StorageUnit_max_hours over \(\mathcal{S}\) — energy capacity, as hours of dispatch at nominal power
\(\eta^{-}\) StorageUnit_efficiency_store over \(\mathcal{S}\) — share of the power drawn from the bus that becomes charge
\(\eta^{+}\) StorageUnit_efficiency_dispatch over \(\mathcal{S}\) — share of the charge drawn down that reaches the bus
\(\rho\) StorageUnit_retention over \(\mathcal{T} \times \mathcal{S}\) — share of charge kept over a snapshot — PyPSA's (1 - standing_loss) ** elapsed hours, data prep
\(\mathrm{soc}^{0}\) StorageUnit_state_of_charge_initial over \(\mathcal{S}\) — charge held before the first snapshot
\(\mathrm{cyc}\) StorageUnit_cyclic_state_of_charge over \(\mathcal{S}\) — whether the horizon closes on itself instead of opening on the initial charge
\(\mathrm{c}^{h}\) StorageUnit_marginal_cost over \(\mathcal{T} \times \mathcal{S}\) — cost of one unit of dispatch
\(\mathrm{c}^{\mathrm{soc}}\) StorageUnit_marginal_cost_storage over \(\mathcal{T} \times \mathcal{S}\) — cost of one unit of charge held over one snapshot
\(\mathrm{e}^{\mathrm{nom}}\) Store_e_nom over \(\mathcal{V}\) — nominal energy capacity
\(\mathrm{ext}^{e}\) Store_e_nom_extendable over \(\mathcal{V}\) — whether the nominal energy capacity is a decision
\(\underline{\mathrm{e}}\) Store_e_min_pu over \(\mathcal{T} \times \mathcal{V}\) — least energy held, per unit of nominal capacity — negative for a store that may go short
\(\overline{\mathrm{e}}\) Store_e_max_pu over \(\mathcal{T} \times \mathcal{V}\) — most energy held, per unit of nominal capacity
\(\rho^{e}\) Store_retention over \(\mathcal{T} \times \mathcal{V}\) — share of energy kept over a snapshot — PyPSA's (1 - standing_loss) ** elapsed hours, data prep
\(\mathrm{e}^{0}\) Store_e_initial over \(\mathcal{V}\) — energy held before the first snapshot
\(\mathrm{cyc}^{e}\) Store_e_cyclic over \(\mathcal{V}\) — whether the horizon closes on itself instead of opening on the initial energy
\(\mathrm{c}^{q}\) Store_marginal_cost over \(\mathcal{T} \times \mathcal{V}\) — cost of one unit of power delivered
\(\mathrm{c}^{e}\) Store_marginal_cost_storage over \(\mathcal{T} \times \mathcal{V}\) — cost of one unit of energy held over one snapshot
\(\mathrm{type}\) GlobalConstraint_type over \(\mathcal{B}\) — which formula the row takes — primary_energy, operational_limit, transmission_volume_expansion_limit, transmission_expansion_cost_limit or tech_capacity_expansion_limit
\(\mathrm{sense}\) GlobalConstraint_sense over \(\mathcal{B}\) — which way the row binds — <=, >= or ==
\(\mathrm{K}\) GlobalConstraint_constant over \(\mathcal{B}\) — the constant the total is held against; what a variable cannot carry — an initial charge, a non-extendable build — is folded in here by data prep
\(\mathrm{len}^{f}\) Link_volume_weight over \(\mathcal{B} \times \mathcal{L}\) — the link's length where its carrier is in the row's set — data prep; a link outside it has no row
\(\mathrm{cc}^{f}\) Link_expansion_cost_weight over \(\mathcal{B} \times \mathcal{L}\) — the link's capital cost where its carrier is in the row's set — data prep; a link outside it has no row
\(\mathrm{m}\) Generator_tech_capacity_weight over \(\mathcal{B} \times \mathcal{G}\) — one where the generator is in the row's carrier-and-bus set — data prep; one outside it has no row
\(\mathrm{m}^{f}\) Link_tech_capacity_weight over \(\mathcal{B} \times \mathcal{L}\) — one where the link is in the row's carrier-and-bus set — data prep; one outside it has no row
\(\mathrm{m}^{h}\) StorageUnit_tech_capacity_weight over \(\mathcal{B} \times \mathcal{S}\) — one where the storage unit is in the row's carrier-and-bus set — data prep; one outside it has no row
\(\mathrm{m}^{e}\) Store_tech_capacity_weight over \(\mathcal{B} \times \mathcal{V}\) — one where the store is in the row's carrier-and-bus set — data prep; one outside it has no row

Variables

Symbol Meaning
\(p\) Generator_p over \(\mathcal{T} \times \mathcal{G}\) — Generator-p — output of a generator in a snapshot
\(f\) Link_p over \(\mathcal{T} \times \mathcal{L}\) — Link-p — PyPSA's p0, the flow measured at the Link_bus0 end: a positive value withdraws there and injects at every bus the link's output ports deliver to
\(h^{+}\) StorageUnit_p_dispatch over \(\mathcal{T} \times \mathcal{S}\) — StorageUnit-p_dispatch — power delivered to the bus
\(h^{-}\) StorageUnit_p_store over \(\mathcal{T} \times \mathcal{S}\) — StorageUnit-p_store — power drawn from the bus into charge
\(\mathit{soc}\) StorageUnit_state_of_charge over \(\mathcal{T} \times \mathcal{S}\) — StorageUnit-state_of_charge — energy held at the end of a snapshot
\(e\) Store_e over \(\mathcal{T} \times \mathcal{V}\) — Store-e — energy held at the end of a snapshot
\(q\) Store_p over \(\mathcal{T} \times \mathcal{V}\) — Store-p — power delivered to the bus; charging is negative
\(P\) Generator_p_nom_ext over \(\mathcal{G}\) — Generator-p_nom — nominal power where it is a decision; the parameter of the same PyPSA name carries the fixed regime
\(F\) Link_p_nom_ext over \(\mathcal{L}\) — Link-p_nom — nominal power where it is a decision; the parameter of the same PyPSA name carries the fixed regime
\(H\) StorageUnit_p_nom_ext over \(\mathcal{S}\) — StorageUnit-p_nom — nominal power where it is a decision; the parameter of the same PyPSA name carries the fixed regime
\(E\) Store_e_nom_ext over \(\mathcal{V}\) — Store-e_nom — nominal capacity where it is a decision; the parameter of the same PyPSA name carries the fixed regime
\(u\) Generator_status over \(\mathcal{T} \times \mathcal{G}\) — Generator-status — how much of a committable unit is on: an integer the rows below cap at one, or at the module count where the build is modular

Definitions

Symbol Meaning
\(\mathit{Generator\_previous\_p}\) Generator_previous_p over \(\mathcal{T} \times \mathcal{G}\) — the output a generator carries into a snapshot — nothing at the start of the horizon, which is why a unit that came in running carries no ramp row there
\(\mathit{Generator\_ramp\_up\_allowance}\) Generator_ramp_up_allowance over \(\mathcal{T} \times \mathcal{G}\) — how far a generator may raise output between two snapshots — its ramp limit of the build while it stays on, plus its start-up ramp in the snapshot it turns on
\(\mathit{Generator\_ramp\_down\_allowance}\) Generator_ramp_down_allowance over \(\mathcal{T} \times \mathcal{G}\) — how far a generator may lower output between two snapshots — its ramp limit of the build while it stays on, plus its shut-down ramp in the snapshot it turns off
\(\mathit{Link\_p\_nom\_effective}\) Link_p_nom_effective over \(\mathcal{L}\) — the build a link's limits are taken against — the chosen one where it is extendable, the given one otherwise
\(\mathit{StorageUnit\_charge\_carried\_in}\) StorageUnit_charge_carried_in over \(\mathcal{T} \times \mathcal{S}\) — the charge a unit opens a snapshot with — its last snapshot's less standing loss where it is cyclic, the given initial charge at the start of the horizon, which no standing loss has touched yet, and the previous snapshot's less standing loss otherwise
\(\mathit{Store\_energy\_carried\_in}\) Store_energy_carried_in over \(\mathcal{T} \times \mathcal{V}\) — the energy a store opens a snapshot with — its last snapshot's less standing loss where it is cyclic, the given initial energy at the start of the horizon, which no standing loss has touched yet, and the previous snapshot's less standing loss otherwise
\(\mathit{Link\_output\_arrival}\) Link_output_arrival over \(\mathcal{T} \times \mathcal{O}\) — what a link delivers to an output port at a snapshot — its flow after the port's efficiency, delayed by the port's delay; where the port is cyclic_delay the delayed flow wraps from the horizon's end, and where it is not the flow still in transit at the first snapshots is lost. A port that does not delay (delay zero) delivers its flow unshifted, cyclic or not
\(\mathit{transmission\_volume\_expansion}\) transmission_volume_expansion over \(\mathcal{B}\) — what a transmission_volume_expansion_limit row totals — length times the chosen build of the row's branches
\(\mathit{transmission\_expansion\_cost}\) transmission_expansion_cost over \(\mathcal{B}\) — what a transmission_expansion_cost_limit row totals — capital cost times the chosen build of the row's branches
\(\mathit{tech\_capacity\_expansion}\) tech_capacity_expansion over \(\mathcal{B}\) — what a tech_capacity_expansion_limit row totals — the chosen build of the row's carrier-and-bus set
\(\mathit{Generator\_previous\_status}\) Generator_previous_status over \(\mathcal{T} \times \mathcal{G}\) — the commitment state a generator carries into a snapshot — the state it brought into the horizon at the first, the previous snapshot's after that
\(\mathit{Generator\_p\_nom\_effective}\) Generator_p_nom_effective over \(\mathcal{G}\) — the build a generator's limits are taken against — the chosen one where it is extendable, the given one otherwise

\(t \ominus k\) denotes cyclic translation: index \(t-k\) taken modulo the size of the dimension (roll). Plain \(t-k\) (shift) has no wraparound — terms translated past the edge are simply absent.

\(t \boxminus_{v} k\) denotes translation with \(v\) standing where index \(t-k\) leaves the dimension (shift(edge=v)), so the row at that boundary is built and carries \(v\) rather than being dropped.

\(\mathrm{pos}(t)\) denotes where index \(t\) sits along its dimension's own order — the order shift steps along, not the order labels sort in — counted from \(0\). The index itself stays the coordinate, so \(t\) compares against labels and \(\mathrm{pos}(t)\) against positions.

Objective

\[ \min \sum_{t \in \mathcal{T},\ g \in \mathcal{G}} p_{t,g} \cdot \mathrm{c}_{t,g} \cdot \mathrm{w}_{t} + \sum_{t \in \mathcal{T},\ l \in \mathcal{L}} f_{t,l} \cdot \mathrm{c}^{f}_{t,l} \cdot \mathrm{w}_{t} + \sum_{t \in \mathcal{T},\ s \in \mathcal{S}} h^{+}_{t,s} \cdot \mathrm{c}^{h}_{t,s} \cdot \mathrm{w}_{t} + \sum_{t \in \mathcal{T},\ s \in \mathcal{S}} \mathit{soc}_{t,s} \cdot \mathrm{c}^{\mathrm{soc}}_{t,s} \cdot \mathrm{w}_{t} + \sum_{t \in \mathcal{T},\ v \in \mathcal{V}} q_{t,v} \cdot \mathrm{c}^{q}_{t,v} \cdot \mathrm{w}_{t} + \sum_{t \in \mathcal{T},\ v \in \mathcal{V}} e_{t,v} \cdot \mathrm{c}^{e}_{t,v} \cdot \mathrm{w}_{t} + \sum_{g \in \mathcal{G}} P_{g} \cdot \mathrm{c}^{\mathrm{cap}}_{g} + \sum_{l \in \mathcal{L}} F_{l} \cdot \mathrm{c}^{\mathrm{cap},f}_{l} + \sum_{s \in \mathcal{S}} H_{s} \cdot \mathrm{c}^{\mathrm{cap},h}_{s} + \sum_{v \in \mathcal{V}} E_{v} \cdot \mathrm{c}^{\mathrm{cap},e}_{v} \]

Subject to

Generator_fix_p_lower

\[ p_{t,g} \ge \underline{\mathrm{p}}_{t,g} \cdot \mathrm{p}^{\mathrm{nom}}_{g} \qquad \forall\, t \in \mathcal{T},\ g \in \mathcal{G} \,:\, \neg \mathrm{ext}_{g} \wedge \neg \mathrm{com}_{g} \]

Generator_fix_p_upper

\[ p_{t,g} \le \overline{\mathrm{p}}_{t,g} \cdot \mathrm{p}^{\mathrm{nom}}_{g} \qquad \forall\, t \in \mathcal{T},\ g \in \mathcal{G} \,:\, \neg \mathrm{ext}_{g} \wedge \neg \mathrm{com}_{g} \]

Link_fix_p_lower

\[ f_{t,l} \ge \underline{\mathrm{f}}_{t,l} \cdot \mathrm{f}^{\mathrm{nom}}_{l} \qquad \forall\, t \in \mathcal{T},\ l \in \mathcal{L} \,:\, \neg \mathrm{ext}^{f}_{l} \]

Link_fix_p_upper

\[ f_{t,l} \le \overline{\mathrm{f}}_{t,l} \cdot \mathrm{f}^{\mathrm{nom}}_{l} \qquad \forall\, t \in \mathcal{T},\ l \in \mathcal{L} \,:\, \neg \mathrm{ext}^{f}_{l} \]

Generator_ext_p_lower

\[ p_{t,g} \ge \underline{\mathrm{p}}_{t,g} \cdot P_{g} \qquad \forall\, t \in \mathcal{T},\ g \in \mathcal{G} \,:\, \mathrm{ext}_{g} \wedge \neg \mathrm{com}_{g} \]

Generator_ext_p_upper

\[ p_{t,g} \le \overline{\mathrm{p}}_{t,g} \cdot P_{g} \qquad \forall\, t \in \mathcal{T},\ g \in \mathcal{G} \,:\, \mathrm{ext}_{g} \wedge \neg \mathrm{com}_{g} \]

Generator_ext_p_nom_lower

\[ P_{g} \ge \underline{\mathrm{p}}^{\mathrm{nom}}_{g} \qquad \forall\, g \in \mathcal{G} \,:\, \mathrm{ext}_{g} \]

Generator_ext_p_nom_upper

\[ P_{g} \le \overline{\mathrm{p}}^{\mathrm{nom}}_{g} \qquad \forall\, g \in \mathcal{G} \,:\, \mathrm{ext}_{g} \wedge \overline{\mathrm{p}}^{\mathrm{nom}}_{g} \text{ is defined} \]

Generator_p_nom_set

\[ P_{g} = \mathrm{p}^{\mathrm{nom,set}}_{g} \qquad \forall\, g \in \mathcal{G} \,:\, \mathrm{ext}_{g} \wedge \mathrm{p}^{\mathrm{nom,set}}_{g} \text{ is defined} \]

Generator_e_sum_min

\[ \sum_{t \in \mathcal{T}} p_{t,g} \cdot \mathrm{w}^{\mathrm{gen}}_{t} \ge \underline{\mathrm{E}}_{g} \qquad \forall\, g \in \mathcal{G} \,:\, \underline{\mathrm{E}}_{g} \text{ is defined} \]

Generator_e_sum_max

\[ \sum_{t \in \mathcal{T}} p_{t,g} \cdot \mathrm{w}^{\mathrm{gen}}_{t} \le \overline{\mathrm{E}}_{g} \qquad \forall\, g \in \mathcal{G} \,:\, \overline{\mathrm{E}}_{g} \text{ is defined} \]

Link_ext_p_lower

\[ f_{t,l} \ge \underline{\mathrm{f}}_{t,l} \cdot F_{l} \qquad \forall\, t \in \mathcal{T},\ l \in \mathcal{L} \,:\, \mathrm{ext}^{f}_{l} \]

Link_ext_p_upper

\[ f_{t,l} \le \overline{\mathrm{f}}_{t,l} \cdot F_{l} \qquad \forall\, t \in \mathcal{T},\ l \in \mathcal{L} \,:\, \mathrm{ext}^{f}_{l} \]

Link_ext_p_nom_lower

\[ F_{l} \ge \underline{\mathrm{f}}^{\mathrm{nom}}_{l} \qquad \forall\, l \in \mathcal{L} \,:\, \mathrm{ext}^{f}_{l} \]

Link_ext_p_nom_upper

\[ F_{l} \le \overline{\mathrm{f}}^{\mathrm{nom}}_{l} \qquad \forall\, l \in \mathcal{L} \,:\, \mathrm{ext}^{f}_{l} \wedge \overline{\mathrm{f}}^{\mathrm{nom}}_{l} \text{ is defined} \]

Link_p_nom_set

\[ F_{l} = \mathrm{f}^{\mathrm{nom,set}}_{l} \qquad \forall\, l \in \mathcal{L} \,:\, \mathrm{ext}^{f}_{l} \wedge \mathrm{f}^{\mathrm{nom,set}}_{l} \text{ is defined} \]

StorageUnit_fix_p_dispatch_lower

\[ h^{+}_{t,s} \ge 0 \qquad \forall\, t \in \mathcal{T},\ s \in \mathcal{S} \,:\, \neg \mathrm{ext}^{h}_{s} \]

StorageUnit_fix_p_dispatch_upper

\[ h^{+}_{t,s} \le \overline{\mathrm{h}}_{t,s} \cdot \mathrm{h}^{\mathrm{nom}}_{s} \qquad \forall\, t \in \mathcal{T},\ s \in \mathcal{S} \,:\, \neg \mathrm{ext}^{h}_{s} \]

StorageUnit_fix_p_store_lower

\[ h^{-}_{t,s} \ge 0 \qquad \forall\, t \in \mathcal{T},\ s \in \mathcal{S} \,:\, \neg \mathrm{ext}^{h}_{s} \]

StorageUnit_fix_p_store_upper

\[ h^{-}_{t,s} \le -\underline{\mathrm{h}}_{t,s} \cdot \mathrm{h}^{\mathrm{nom}}_{s} \qquad \forall\, t \in \mathcal{T},\ s \in \mathcal{S} \,:\, \neg \mathrm{ext}^{h}_{s} \]

StorageUnit_fix_state_of_charge_lower

\[ \mathit{soc}_{t,s} \ge 0 \qquad \forall\, t \in \mathcal{T},\ s \in \mathcal{S} \,:\, \neg \mathrm{ext}^{h}_{s} \]

StorageUnit_fix_state_of_charge_upper

\[ \mathit{soc}_{t,s} \le \mathrm{T}^{h}_{s} \cdot \mathrm{h}^{\mathrm{nom}}_{s} \qquad \forall\, t \in \mathcal{T},\ s \in \mathcal{S} \,:\, \neg \mathrm{ext}^{h}_{s} \]

Generator_p_ramp_limit_up

\[ p_{t,g} - \mathit{Generator\_previous\_p}_{t,g} \le \mathit{Generator\_ramp\_up\_allowance}_{t,g} \qquad \forall\, t \in \mathcal{T},\ g \in \mathcal{G} \,:\, \mathrm{ru}_{g} \text{ is defined} \wedge \neg \left( \mathrm{com}_{g} \wedge \mathrm{ext}_{g} \right) \wedge \left( \mathrm{pos}(t) > 0 \vee \mathrm{com}_{g} \wedge \mathrm{u}^{0}_{g} = 0 \right) \]

Generator_p_ramp_limit_down

\[ \mathit{Generator\_previous\_p}_{t,g} - p_{t,g} \le \mathit{Generator\_ramp\_down\_allowance}_{t,g} \qquad \forall\, t \in \mathcal{T},\ g \in \mathcal{G} \,:\, \mathrm{rd}_{g} \text{ is defined} \wedge \neg \left( \mathrm{com}_{g} \wedge \mathrm{ext}_{g} \right) \wedge \left( \mathrm{pos}(t) > 0 \vee \mathrm{com}_{g} \wedge \mathrm{u}^{0}_{g} = 0 \right) \]

Link_p_ramp_limit_up

\[ f_{t,l} - f_{t - 1,l} \le \mathrm{ru}^{f}_{l} \cdot \mathit{Link\_p\_nom\_effective}_{l} \qquad \forall\, t \in \mathcal{T},\ l \in \mathcal{L} \,:\, \mathrm{ru}^{f}_{l} \text{ is defined} \]

Link_p_ramp_limit_down

\[ f_{t - 1,l} - f_{t,l} \le \mathrm{rd}^{f}_{l} \cdot \mathit{Link\_p\_nom\_effective}_{l} \qquad \forall\, t \in \mathcal{T},\ l \in \mathcal{L} \,:\, \mathrm{rd}^{f}_{l} \text{ is defined} \]

StorageUnit_ext_p_dispatch_lower

\[ h^{+}_{t,s} \ge 0 \qquad \forall\, t \in \mathcal{T},\ s \in \mathcal{S} \,:\, \mathrm{ext}^{h}_{s} \]

StorageUnit_ext_p_dispatch_upper

\[ h^{+}_{t,s} \le \overline{\mathrm{h}}_{t,s} \cdot H_{s} \qquad \forall\, t \in \mathcal{T},\ s \in \mathcal{S} \,:\, \mathrm{ext}^{h}_{s} \]

StorageUnit_ext_p_store_lower

\[ h^{-}_{t,s} \ge 0 \qquad \forall\, t \in \mathcal{T},\ s \in \mathcal{S} \,:\, \mathrm{ext}^{h}_{s} \]

StorageUnit_ext_p_store_upper

\[ h^{-}_{t,s} \le -\underline{\mathrm{h}}_{t,s} \cdot H_{s} \qquad \forall\, t \in \mathcal{T},\ s \in \mathcal{S} \,:\, \mathrm{ext}^{h}_{s} \]

StorageUnit_ext_state_of_charge_lower

\[ \mathit{soc}_{t,s} \ge 0 \qquad \forall\, t \in \mathcal{T},\ s \in \mathcal{S} \,:\, \mathrm{ext}^{h}_{s} \]

StorageUnit_ext_state_of_charge_upper

\[ \mathit{soc}_{t,s} \le \mathrm{T}^{h}_{s} \cdot H_{s} \qquad \forall\, t \in \mathcal{T},\ s \in \mathcal{S} \,:\, \mathrm{ext}^{h}_{s} \]

StorageUnit_ext_p_nom_lower

\[ H_{s} \ge \underline{\mathrm{h}}^{\mathrm{nom}}_{s} \qquad \forall\, s \in \mathcal{S} \,:\, \mathrm{ext}^{h}_{s} \]

StorageUnit_ext_p_nom_upper

\[ H_{s} \le \overline{\mathrm{h}}^{\mathrm{nom}}_{s} \qquad \forall\, s \in \mathcal{S} \,:\, \mathrm{ext}^{h}_{s} \wedge \overline{\mathrm{h}}^{\mathrm{nom}}_{s} \text{ is defined} \]

StorageUnit_p_nom_set

\[ H_{s} = \mathrm{h}^{\mathrm{nom,set}}_{s} \qquad \forall\, s \in \mathcal{S} \,:\, \mathrm{ext}^{h}_{s} \wedge \mathrm{h}^{\mathrm{nom,set}}_{s} \text{ is defined} \]

StorageUnit_energy_balance

\[ \mathit{soc}_{t,s} = \mathit{StorageUnit\_charge\_carried\_in}_{t,s} + \eta^{-}_{s} \cdot h^{-}_{t,s} \cdot \mathrm{w}^{\mathrm{sto}}_{t} - \frac{h^{+}_{t,s} \cdot \mathrm{w}^{\mathrm{sto}}_{t}}{\eta^{+}_{s}} \qquad \forall\, t \in \mathcal{T},\ s \in \mathcal{S} \]

Store_fix_e_lower

\[ e_{t,v} \ge \underline{\mathrm{e}}_{t,v} \cdot \mathrm{e}^{\mathrm{nom}}_{v} \qquad \forall\, t \in \mathcal{T},\ v \in \mathcal{V} \,:\, \neg \mathrm{ext}^{e}_{v} \]

Store_fix_e_upper

\[ e_{t,v} \le \overline{\mathrm{e}}_{t,v} \cdot \mathrm{e}^{\mathrm{nom}}_{v} \qquad \forall\, t \in \mathcal{T},\ v \in \mathcal{V} \,:\, \neg \mathrm{ext}^{e}_{v} \]

Store_ext_e_lower

\[ e_{t,v} \ge \underline{\mathrm{e}}_{t,v} \cdot E_{v} \qquad \forall\, t \in \mathcal{T},\ v \in \mathcal{V} \,:\, \mathrm{ext}^{e}_{v} \]

Store_ext_e_upper

\[ e_{t,v} \le \overline{\mathrm{e}}_{t,v} \cdot E_{v} \qquad \forall\, t \in \mathcal{T},\ v \in \mathcal{V} \,:\, \mathrm{ext}^{e}_{v} \]

Store_ext_e_nom_lower

\[ E_{v} \ge \underline{\mathrm{e}}^{\mathrm{nom}}_{v} \qquad \forall\, v \in \mathcal{V} \,:\, \mathrm{ext}^{e}_{v} \]

Store_ext_e_nom_upper

\[ E_{v} \le \overline{\mathrm{e}}^{\mathrm{nom}}_{v} \qquad \forall\, v \in \mathcal{V} \,:\, \mathrm{ext}^{e}_{v} \wedge \overline{\mathrm{e}}^{\mathrm{nom}}_{v} \text{ is defined} \]

Store_e_nom_set

\[ E_{v} = \mathrm{e}^{\mathrm{nom,set}}_{v} \qquad \forall\, v \in \mathcal{V} \,:\, \mathrm{ext}^{e}_{v} \wedge \mathrm{e}^{\mathrm{nom,set}}_{v} \text{ is defined} \]

Store_energy_balance

\[ e_{t,v} = \mathit{Store\_energy\_carried\_in}_{t,v} - q_{t,v} \cdot \mathrm{w}^{\mathrm{sto}}_{t} \qquad \forall\, t \in \mathcal{T},\ v \in \mathcal{V} \]

GlobalConstraint_transmission_volume_expansion_limit_ub

\[ \mathit{transmission\_volume\_expansion}_{b} \le \mathrm{K}_{b} \qquad \forall\, b \in \mathcal{B} \,:\, \mathrm{type}_{b} = \text{'}\mathrm{transmission\_volume\_expansion\_limit}\text{'} \wedge \mathrm{sense}_{b} = \text{'}\mathrm{<=}\text{'} \]

GlobalConstraint_transmission_expansion_cost_limit_lb

\[ \mathit{transmission\_expansion\_cost}_{b} \ge \mathrm{K}_{b} \qquad \forall\, b \in \mathcal{B} \,:\, \mathrm{type}_{b} = \text{'}\mathrm{transmission\_expansion\_cost\_limit}\text{'} \wedge \mathrm{sense}_{b} = \text{'}\mathrm{>=}\text{'} \]

GlobalConstraint_transmission_expansion_cost_limit_eq

\[ \mathit{transmission\_expansion\_cost}_{b} = \mathrm{K}_{b} \qquad \forall\, b \in \mathcal{B} \,:\, \mathrm{type}_{b} = \text{'}\mathrm{transmission\_expansion\_cost\_limit}\text{'} \wedge \mathrm{sense}_{b} = \text{'}\mathrm{==}\text{'} \]

GlobalConstraint_tech_capacity_expansion_limit_ub

\[ \mathit{tech\_capacity\_expansion}_{b} \le \mathrm{K}_{b} \qquad \forall\, b \in \mathcal{B} \,:\, \mathrm{type}_{b} = \text{'}\mathrm{tech\_capacity\_expansion\_limit}\text{'} \wedge \mathrm{sense}_{b} = \text{'}\mathrm{<=}\text{'} \]

GlobalConstraint_tech_capacity_expansion_limit_lb

\[ \mathit{tech\_capacity\_expansion}_{b} \ge \mathrm{K}_{b} \qquad \forall\, b \in \mathcal{B} \,:\, \mathrm{type}_{b} = \text{'}\mathrm{tech\_capacity\_expansion\_limit}\text{'} \wedge \mathrm{sense}_{b} = \text{'}\mathrm{>=}\text{'} \]

GlobalConstraint_tech_capacity_expansion_limit_eq

\[ \mathit{tech\_capacity\_expansion}_{b} = \mathrm{K}_{b} \qquad \forall\, b \in \mathcal{B} \,:\, \mathrm{type}_{b} = \text{'}\mathrm{tech\_capacity\_expansion\_limit}\text{'} \wedge \mathrm{sense}_{b} = \text{'}\mathrm{==}\text{'} \]

Bus_nodal_balance

\[ \sum_{g \in \mathcal{G} \,:\, \mathrm{Generator\_bus}(g) = n} p_{t,g} + \sum_{s \in \mathcal{S} \,:\, \mathrm{StorageUnit\_bus}(s) = n} \left( h^{+}_{t,s} - h^{-}_{t,s} \right) + \sum_{v \in \mathcal{V} \,:\, \mathrm{Store\_bus}(v) = n} q_{t,v} - \left( \sum_{l \in \mathcal{L} \,:\, \mathrm{Link\_bus0}(l) = n} f_{t,l} \right) + \sum_{o \in \mathcal{O} \,:\, \mathrm{Link\_output\_bus}(o) = n} \mathit{Link\_output\_arrival}_{t,o} = \sum_{d \in \mathcal{D} \,:\, \mathrm{Load\_bus}(d) = n} \mathrm{load}_{t,d} \qquad \forall\, t \in \mathcal{T},\ n \in \mathcal{N} \]

Definitions

Generator_previous_p

\[ \mathit{Generator\_previous\_p}_{t,g} = \begin{cases} 0 & \text{if } \mathrm{pos}(t) = 0 \\ p_{t - 1,g} & \text{otherwise} \end{cases} \qquad \forall\, t \in \mathcal{T},\ g \in \mathcal{G} \]

Generator_ramp_up_allowance

\[ \mathit{Generator\_ramp\_up\_allowance}_{t,g} = \begin{cases} \mathrm{ru}_{g} \cdot \mathrm{p}^{\mathrm{nom}}_{g} \cdot \mathit{Generator\_previous\_status}_{t,g} + \mathrm{ru}^{\mathrm{up}}_{g} \cdot \mathrm{p}^{\mathrm{nom}}_{g} \cdot \left( u_{t,g} - \mathit{Generator\_previous\_status}_{t,g} \right) & \text{if } \mathrm{com}_{g} \\ \mathrm{ru}_{g} \cdot \mathit{Generator\_p\_nom\_effective}_{g} & \text{otherwise} \end{cases} \qquad \forall\, t \in \mathcal{T},\ g \in \mathcal{G} \]

Generator_ramp_down_allowance

\[ \mathit{Generator\_ramp\_down\_allowance}_{t,g} = \begin{cases} \mathrm{rd}_{g} \cdot \mathrm{p}^{\mathrm{nom}}_{g} \cdot u_{t,g} + \mathrm{rd}^{\mathrm{dn}}_{g} \cdot \mathrm{p}^{\mathrm{nom}}_{g} \cdot \left( \mathit{Generator\_previous\_status}_{t,g} - u_{t,g} \right) & \text{if } \mathrm{com}_{g} \\ \mathrm{rd}_{g} \cdot \mathit{Generator\_p\_nom\_effective}_{g} & \text{otherwise} \end{cases} \qquad \forall\, t \in \mathcal{T},\ g \in \mathcal{G} \]

Link_p_nom_effective

\[ \mathit{Link\_p\_nom\_effective}_{l} = \begin{cases} F_{l} & \text{if } \mathrm{ext}^{f}_{l} \\ \mathrm{f}^{\mathrm{nom}}_{l} & \text{otherwise} \end{cases} \qquad \forall\, l \in \mathcal{L} \]

StorageUnit_charge_carried_in

\[ \mathit{StorageUnit\_charge\_carried\_in}_{t,s} = \begin{cases} \rho_{t,s} \cdot \mathit{soc}_{t \ominus 1,s} & \text{if } \mathrm{cyc}_{s} \\ \mathrm{soc}^{0}_{s} & \text{if } \neg \mathrm{cyc}_{s} \wedge \mathrm{pos}(t) = 0 \\ \rho_{t,s} \cdot \mathit{soc}_{t - 1,s} & \text{otherwise} \end{cases} \qquad \forall\, t \in \mathcal{T},\ s \in \mathcal{S} \]

Store_energy_carried_in

\[ \mathit{Store\_energy\_carried\_in}_{t,v} = \begin{cases} \rho^{e}_{t,v} \cdot e_{t \ominus 1,v} & \text{if } \mathrm{cyc}^{e}_{v} \\ \mathrm{e}^{0}_{v} & \text{if } \neg \mathrm{cyc}^{e}_{v} \wedge \mathrm{pos}(t) = 0 \\ \rho^{e}_{t,v} \cdot e_{t - 1,v} & \text{otherwise} \end{cases} \qquad \forall\, t \in \mathcal{T},\ v \in \mathcal{V} \]

Link_output_arrival

\[ \mathit{Link\_output\_arrival}_{t,o} = \begin{cases} f_{t \ominus \mathrm{d}^{f},\mathrm{Link\_output\_link}(o)} \cdot \eta_{o} & \text{if } \mathrm{cyc}^{f}_{o} \\ f_{t \boxminus_{0} \mathrm{d}^{f},\mathrm{Link\_output\_link}(o)} \cdot \eta_{o} & \text{otherwise} \end{cases} \qquad \forall\, t \in \mathcal{T},\ o \in \mathcal{O} \]

transmission_volume_expansion

\[ \mathit{transmission\_volume\_expansion}_{b} = \sum_{l \in \mathcal{L}} F_{l} \cdot \mathrm{len}^{f}_{b,l} \qquad \forall\, b \in \mathcal{B} \]

transmission_expansion_cost

\[ \mathit{transmission\_expansion\_cost}_{b} = \sum_{l \in \mathcal{L}} F_{l} \cdot \mathrm{cc}^{f}_{b,l} \qquad \forall\, b \in \mathcal{B} \]

tech_capacity_expansion

\[ \mathit{tech\_capacity\_expansion}_{b} = \sum_{g \in \mathcal{G}} P_{g} \cdot \mathrm{m}_{b,g} + \sum_{l \in \mathcal{L}} F_{l} \cdot \mathrm{m}^{f}_{b,l} + \sum_{s \in \mathcal{S}} H_{s} \cdot \mathrm{m}^{h}_{b,s} + \sum_{v \in \mathcal{V}} E_{v} \cdot \mathrm{m}^{e}_{b,v} \qquad \forall\, b \in \mathcal{B} \]

Generator_previous_status

\[ \mathit{Generator\_previous\_status}_{t,g} = \begin{cases} \mathrm{u}^{0}_{g} & \text{if } \mathrm{pos}(t) = 0 \\ u_{t - 1,g} & \text{otherwise} \end{cases} \qquad \forall\, t \in \mathcal{T},\ g \in \mathcal{G} \]

Generator_p_nom_effective

\[ \mathit{Generator\_p\_nom\_effective}_{g} = \begin{cases} P_{g} & \text{if } \mathrm{ext}_{g} \\ \mathrm{p}^{\mathrm{nom}}_{g} & \text{otherwise} \end{cases} \qquad \forall\, g \in \mathcal{G} \]

Variable domains

Generator_p

\[ p_{t,g} \in \mathbb{R} \qquad \forall\, t \in \mathcal{T},\ g \in \mathcal{G} \]

Link_p

\[ f_{t,l} \in \mathbb{R} \qquad \forall\, t \in \mathcal{T},\ l \in \mathcal{L} \]

StorageUnit_p_dispatch

\[ h^{+}_{t,s} \in \mathbb{R} \qquad \forall\, t \in \mathcal{T},\ s \in \mathcal{S} \]

StorageUnit_p_store

\[ h^{-}_{t,s} \in \mathbb{R} \qquad \forall\, t \in \mathcal{T},\ s \in \mathcal{S} \]

StorageUnit_state_of_charge

\[ \mathit{soc}_{t,s} \in \mathbb{R} \qquad \forall\, t \in \mathcal{T},\ s \in \mathcal{S} \]

Store_e

\[ e_{t,v} \in \mathbb{R} \qquad \forall\, t \in \mathcal{T},\ v \in \mathcal{V} \]

Store_p

\[ q_{t,v} \in \mathbb{R} \qquad \forall\, t \in \mathcal{T},\ v \in \mathcal{V} \]

Generator_p_nom_ext

\[ P_{g} \in \mathbb{R} \qquad \forall\, g \in \mathcal{G} \,:\, \mathrm{ext}_{g} \]

Link_p_nom_ext

\[ F_{l} \in \mathbb{R} \qquad \forall\, l \in \mathcal{L} \,:\, \mathrm{ext}^{f}_{l} \]

StorageUnit_p_nom_ext

\[ H_{s} \in \mathbb{R} \qquad \forall\, s \in \mathcal{S} \,:\, \mathrm{ext}^{h}_{s} \]

Store_e_nom_ext

\[ E_{v} \in \mathbb{R} \qquad \forall\, v \in \mathcal{V} \,:\, \mathrm{ext}^{e}_{v} \]

Generator_status

\[ u_{t,g} \ge 0, u_{t,g} \in \mathbb{Z} \qquad \forall\, t \in \mathcal{T},\ g \in \mathcal{G} \,:\, \mathrm{com}_{g} \]

The spec, differential/pypsa/rungs/rung_03_expansion.yaml — the file projected onto what this rung builds:

description: The spec of the model a plain `n.optimize()` builds, in one file. Every declaration is named
  `Component_attribute` after the PyPSA statement it stands for, and each constraint's description opens
  with the linopy name PyPSA gives that row, so the two can be read side by side. PyPSA's regimes — extendable,
  committable — are data columns and become `where:` masks. Bounds are the explicit rows PyPSA writes,
  so their duals are row duals. Parameters no PyPSA table carries verbatim are computed in data prep and
  say so in their description.
dimensions:
  snapshot: {description: dispatch periods, dtype: datetime}
  bus: {description: network nodes}
  generator: {description: 'generating units, each on one bus'}
  link: {description: 'controllable connections, each from one bus to the buses it delivers to'}
  link_output: {description: 'a link''s output ports, one label per port a link declares — PyPSA''s `bus1`,
      `bus2`, … columns read long, so a link of any number of output ports is one term in the balance,
      data prep'}
  load: {description: 'demands, each on one bus'}
  storage_unit: {description: 'storage units, dispatch and store behind one bus connection'}
  store: {description: 'pure energy stores, each on one bus'}
  global_constraint: {description: 'PyPSA''s `GlobalConstraint` rows, one label per declared limit'}
relations:
  Generator_bus: {description: the bus a generator sits on, key: generator, values: bus}
  Link_bus0: {description: the bus a link leaves, key: link, values: bus}
  Link_output_link: {description: the link an output port belongs to, key: link_output, values: link}
  Link_output_bus: {description: 'the bus an output port delivers to — PyPSA''s `bus1`, `bus2`, … columns.
      A link of three output ports is three labels here rather than a third relation, so the file states
      any number of them', key: link_output, values: bus}
  Load_bus: {description: the bus a load sits on, key: load, values: bus}
  StorageUnit_bus: {description: the bus a storage unit sits on, key: storage_unit, values: bus}
  Store_bus: {description: the bus a store sits on, key: store, values: bus}
parameters:
  snapshot_weightings_objective:
    description: PyPSA's `snapshot_weightings.objective` — hours a snapshot stands for in the cost
    dims: [snapshot]
  Generator_p_nom:
    description: nominal power
    dims: [generator]
  Generator_p_nom_extendable:
    description: whether the nominal power is a decision
    dims: [generator]
    dtype: bool
  Generator_p_min_pu:
    description: least output, per unit of nominal power
    dims: [snapshot, generator]
  Generator_p_max_pu:
    description: most output, per unit of nominal power — an availability profile
    dims: [snapshot, generator]
  Generator_marginal_cost:
    description: cost of one unit of output
    dims: [snapshot, generator]
  Generator_committable:
    description: whether output is gated by an on/off status decision
    dims: [generator]
    dtype: bool
  Generator_ramp_limit_up:
    description: most a generator may raise its output between snapshots, per unit of nominal power; no
      value means no limit
    dims: [generator]
  Generator_ramp_limit_down:
    description: most a generator may lower its output between snapshots, per unit of nominal power; no
      value means no limit
    dims: [generator]
  Generator_ramp_limit_start_up:
    description: most output in the snapshot a unit starts, per unit of nominal power
    dims: [generator]
  Generator_ramp_limit_shut_down:
    description: most output in the snapshot before a unit stops, per unit of nominal power
    dims: [generator]
  Generator_status_initial:
    description: one where the unit was on before the first snapshot, zero where off — PyPSA's `up_time_before
      > 0`, data prep
    dims: [generator]
    dtype: int
  Link_ramp_limit_up:
    description: most a link may raise its flow between snapshots, per unit of nominal power; no value
      means no limit
    dims: [link]
  Link_ramp_limit_down:
    description: most a link may lower its flow between snapshots, per unit of nominal power; no value
      means no limit
    dims: [link]
  Link_p_nom:
    description: nominal power
    dims: [link]
  Link_p_nom_extendable:
    description: whether the nominal power is a decision
    dims: [link]
    dtype: bool
  Link_p_min_pu:
    description: least flow, per unit of nominal power — negative for a link that carries both ways
    dims: [snapshot, link]
  Link_p_max_pu:
    description: most flow, per unit of nominal power
    dims: [snapshot, link]
  Link_efficiency:
    description: share of the flow that arrives at an output port, PyPSA's `efficiency`, `efficiency2`,
      … read long — negative where that port consumes rather than delivers
    dims: [link_output]
  Link_output_delay:
    description: snapshots a port's delivery lags its link's flow — PyPSA's `delay`, `delay2`, … read
      long, in `snapshot_weightings.generators` units, which the file states as whole snapshots; zero
      for a port that delivers at once
    dims: [link_output]
    dtype: int
  Link_output_cyclic_delay:
    description: whether a delayed port's flow wraps from the horizon's end — PyPSA's `cyclic_delay`,
      `cyclic_delay2`, …; where it does not, the flow still in transit at the first snapshots is lost
    dims: [link_output]
    dtype: bool
  Link_marginal_cost:
    description: cost of one unit of flow
    dims: [snapshot, link]
  Load_p_set:
    description: demand
    dims: [snapshot, load]
  snapshot_weightings_stores:
    description: PyPSA's `snapshot_weightings.stores` — hours a snapshot stands for in a storage balance
    dims: [snapshot]
  snapshot_weightings_generators:
    description: PyPSA's `snapshot_weightings.generators` — hours a snapshot stands for in an energy total
    dims: [snapshot]
  Generator_p_nom_min:
    description: least nominal power an extendable generator may be built at
    dims: [generator]
  Generator_p_nom_max:
    description: most nominal power an extendable generator may be built at
    dims: [generator]
  Generator_capital_cost:
    description: cost of one unit of nominal power — PyPSA's `capital_cost`, periodized as an annuity
      in data prep
    dims: [generator]
  Generator_p_nom_set:
    description: a given nominal power for an extendable generator; one without a value has no row here
    dims: [generator]
  Generator_e_sum_min:
    description: least energy over the horizon; minus infinity where no floor is meant
    dims: [generator]
  Generator_e_sum_max:
    description: most energy over the horizon — a fuel or emission budget in energy terms; infinity where
      no cap is meant
    dims: [generator]
  Link_p_nom_min:
    description: least nominal power an extendable link may be built at
    dims: [link]
  Link_p_nom_max:
    description: most nominal power an extendable link may be built at
    dims: [link]
  Link_capital_cost:
    description: cost of one unit of nominal power — PyPSA's `capital_cost`, periodized as an annuity
      in data prep
    dims: [link]
  Link_p_nom_set:
    description: a given nominal power for an extendable link; one without a value has no row here
    dims: [link]
  StorageUnit_p_nom_min:
    description: least nominal power an extendable storage unit may be built at
    dims: [storage_unit]
  StorageUnit_p_nom_max:
    description: most nominal power an extendable storage unit may be built at
    dims: [storage_unit]
  StorageUnit_capital_cost:
    description: cost of one unit of nominal power — PyPSA's `capital_cost`, periodized as an annuity
      in data prep
    dims: [storage_unit]
  StorageUnit_p_nom_set:
    description: a given nominal power for an extendable storage unit; one without a value has no row
      here
    dims: [storage_unit]
  Store_e_nom_min:
    description: least nominal capacity an extendable store may be built at
    dims: [store]
  Store_e_nom_max:
    description: most nominal capacity an extendable store may be built at
    dims: [store]
  Store_capital_cost:
    description: cost of one unit of nominal capacity — PyPSA's `capital_cost`, periodized as an annuity
      in data prep
    dims: [store]
  Store_e_nom_set:
    description: a given nominal capacity for an extendable store; one without a value has no row here
    dims: [store]
  StorageUnit_p_nom:
    description: nominal power
    dims: [storage_unit]
  StorageUnit_p_nom_extendable:
    description: whether the nominal power is a decision
    dims: [storage_unit]
    dtype: bool
  StorageUnit_p_min_pu:
    description: most storing, per unit of nominal power and negated
    dims: [snapshot, storage_unit]
  StorageUnit_p_max_pu:
    description: most dispatch, per unit of nominal power
    dims: [snapshot, storage_unit]
  StorageUnit_max_hours:
    description: energy capacity, as hours of dispatch at nominal power
    dims: [storage_unit]
  StorageUnit_efficiency_store:
    description: share of the power drawn from the bus that becomes charge
    dims: [storage_unit]
  StorageUnit_efficiency_dispatch:
    description: share of the charge drawn down that reaches the bus
    dims: [storage_unit]
  StorageUnit_retention:
    description: share of charge kept over a snapshot — PyPSA's `(1 - standing_loss) ** elapsed hours`,
      data prep
    dims: [snapshot, storage_unit]
  StorageUnit_state_of_charge_initial:
    description: charge held before the first snapshot
    dims: [storage_unit]
  StorageUnit_cyclic_state_of_charge:
    description: whether the horizon closes on itself instead of opening on the initial charge
    dims: [storage_unit]
    dtype: bool
  StorageUnit_marginal_cost:
    description: cost of one unit of dispatch
    dims: [snapshot, storage_unit]
  StorageUnit_marginal_cost_storage:
    description: cost of one unit of charge held over one snapshot
    dims: [snapshot, storage_unit]
  Store_e_nom:
    description: nominal energy capacity
    dims: [store]
  Store_e_nom_extendable:
    description: whether the nominal energy capacity is a decision
    dims: [store]
    dtype: bool
  Store_e_min_pu:
    description: least energy held, per unit of nominal capacity — negative for a store that may go short
    dims: [snapshot, store]
  Store_e_max_pu:
    description: most energy held, per unit of nominal capacity
    dims: [snapshot, store]
  Store_retention:
    description: share of energy kept over a snapshot — PyPSA's `(1 - standing_loss) ** elapsed hours`,
      data prep
    dims: [snapshot, store]
  Store_e_initial:
    description: energy held before the first snapshot
    dims: [store]
  Store_e_cyclic:
    description: whether the horizon closes on itself instead of opening on the initial energy
    dims: [store]
    dtype: bool
  Store_marginal_cost:
    description: cost of one unit of power delivered
    dims: [snapshot, store]
  Store_marginal_cost_storage:
    description: cost of one unit of energy held over one snapshot
    dims: [snapshot, store]
  GlobalConstraint_type:
    description: which formula the row takes — `primary_energy`, `operational_limit`, `transmission_volume_expansion_limit`,
      `transmission_expansion_cost_limit` or `tech_capacity_expansion_limit`
    dims: [global_constraint]
    dtype: str
  GlobalConstraint_sense:
    description: which way the row binds — `<=`, `>=` or `==`
    dims: [global_constraint]
    dtype: str
  GlobalConstraint_constant:
    description: the constant the total is held against; what a variable cannot carry — an initial charge,
      a non-extendable build — is folded in here by data prep
    dims: [global_constraint]
  Link_volume_weight:
    description: the link's length where its carrier is in the row's set — data prep; a link outside it
      has no row
    dims: [global_constraint, link]
  Link_expansion_cost_weight:
    description: the link's capital cost where its carrier is in the row's set — data prep; a link outside
      it has no row
    dims: [global_constraint, link]
  Generator_tech_capacity_weight:
    description: one where the generator is in the row's carrier-and-bus set — data prep; one outside
      it has no row
    dims: [global_constraint, generator]
  Link_tech_capacity_weight:
    description: one where the link is in the row's carrier-and-bus set — data prep; one outside it has
      no row
    dims: [global_constraint, link]
  StorageUnit_tech_capacity_weight:
    description: one where the storage unit is in the row's carrier-and-bus set — data prep; one outside
      it has no row
    dims: [global_constraint, storage_unit]
  Store_tech_capacity_weight:
    description: one where the store is in the row's carrier-and-bus set — data prep; one outside it has
      no row
    dims: [global_constraint, store]
variables:
  Generator_p:
    description: '`Generator-p` — output of a generator in a snapshot'
    dims: [snapshot, generator]
  Link_p:
    description: '`Link-p` — PyPSA''s `p0`, the flow measured at the `Link_bus0` end: a positive value
      withdraws there and injects at every bus the link''s output ports deliver to'
    dims: [snapshot, link]
  StorageUnit_p_dispatch:
    description: '`StorageUnit-p_dispatch` — power delivered to the bus'
    dims: [snapshot, storage_unit]
  StorageUnit_p_store:
    description: '`StorageUnit-p_store` — power drawn from the bus into charge'
    dims: [snapshot, storage_unit]
  StorageUnit_state_of_charge:
    description: '`StorageUnit-state_of_charge` — energy held at the end of a snapshot'
    dims: [snapshot, storage_unit]
  Store_e:
    description: '`Store-e` — energy held at the end of a snapshot'
    dims: [snapshot, store]
  Store_p:
    description: '`Store-p` — power delivered to the bus; charging is negative'
    dims: [snapshot, store]
  Generator_p_nom_ext:
    description: '`Generator-p_nom` — nominal power where it is a decision; the parameter of the same
      PyPSA name carries the fixed regime'
    dims: [generator]
    where: Generator_p_nom_extendable
  Link_p_nom_ext:
    description: '`Link-p_nom` — nominal power where it is a decision; the parameter of the same PyPSA
      name carries the fixed regime'
    dims: [link]
    where: Link_p_nom_extendable
  StorageUnit_p_nom_ext:
    description: '`StorageUnit-p_nom` — nominal power where it is a decision; the parameter of the same
      PyPSA name carries the fixed regime'
    dims: [storage_unit]
    where: StorageUnit_p_nom_extendable
  Store_e_nom_ext:
    description: '`Store-e_nom` — nominal capacity where it is a decision; the parameter of the same PyPSA
      name carries the fixed regime'
    dims: [store]
    where: Store_e_nom_extendable
  Generator_status:
    description: '`Generator-status` — how much of a committable unit is on: an integer the rows below
      cap at one, or at the module count where the build is modular'
    dims: [snapshot, generator]
    where: Generator_committable
    domain: integer
    bounds: {lower: 0}
constraints:
  Generator_fix_p_lower:
    description: '`Generator-fix-p-lower` — a fixed generator outputs at least its minimum'
    dims: [snapshot, generator]
    where: not Generator_p_nom_extendable AND not Generator_committable
    expression: Generator_p >= Generator_p_min_pu * Generator_p_nom
  Generator_fix_p_upper:
    description: '`Generator-fix-p-upper` — a fixed generator outputs at most what is available'
    dims: [snapshot, generator]
    where: not Generator_p_nom_extendable AND not Generator_committable
    expression: Generator_p <= Generator_p_max_pu * Generator_p_nom
  Link_fix_p_lower:
    description: '`Link-fix-p-lower` — a fixed link carries at least its minimum, negative for the other
      way'
    dims: [snapshot, link]
    where: not Link_p_nom_extendable
    expression: Link_p >= Link_p_min_pu * Link_p_nom
  Link_fix_p_upper:
    description: '`Link-fix-p-upper` — a fixed link carries at most its nominal power'
    dims: [snapshot, link]
    where: not Link_p_nom_extendable
    expression: Link_p <= Link_p_max_pu * Link_p_nom
  Generator_ext_p_lower:
    description: '`Generator-ext-p-lower` — an extendable generator outputs at least its minimum of the
      chosen build'
    dims: [snapshot, generator]
    where: Generator_p_nom_extendable AND not Generator_committable
    expression: Generator_p >= Generator_p_min_pu * Generator_p_nom_ext
  Generator_ext_p_upper:
    description: '`Generator-ext-p-upper` — an extendable generator outputs at most what is available
      of the chosen build'
    dims: [snapshot, generator]
    where: Generator_p_nom_extendable AND not Generator_committable
    expression: Generator_p <= Generator_p_max_pu * Generator_p_nom_ext
  Generator_ext_p_nom_lower:
    description: '`Generator-ext-p_nom-lower` — the chosen build is at least its floor'
    dims: [generator]
    where: Generator_p_nom_extendable
    expression: Generator_p_nom_ext >= Generator_p_nom_min
  Generator_ext_p_nom_upper:
    description: '`Generator-ext-p_nom-upper` — the chosen build is at most its cap; a cap of infinity
      is no row'
    dims: [generator]
    where: Generator_p_nom_extendable AND Generator_p_nom_max
    expression: Generator_p_nom_ext <= Generator_p_nom_max
  Generator_p_nom_set:
    description: '`Generator-p_nom_set` — the chosen build pinned, wherever a value is given'
    dims: [generator]
    where: Generator_p_nom_extendable AND Generator_p_nom_set
    expression: Generator_p_nom_ext == Generator_p_nom_set
  Generator_e_sum_min:
    description: '`Generator-e_sum_min` — energy over the horizon is at least its floor; a floor of minus
      infinity is no row'
    dims: [generator]
    where: Generator_e_sum_min
    expression: sum(Generator_p * snapshot_weightings_generators, over=snapshot) >= Generator_e_sum_min
  Generator_e_sum_max:
    description: '`Generator-e_sum_max` — energy over the horizon is at most its budget; a budget of infinity
      is no row'
    dims: [generator]
    where: Generator_e_sum_max
    expression: sum(Generator_p * snapshot_weightings_generators, over=snapshot) <= Generator_e_sum_max
  Link_ext_p_lower:
    description: '`Link-ext-p-lower` — an extendable link carries at least its minimum of the chosen build,
      negative for the other way'
    dims: [snapshot, link]
    where: Link_p_nom_extendable
    expression: Link_p >= Link_p_min_pu * Link_p_nom_ext
  Link_ext_p_upper:
    description: '`Link-ext-p-upper` — an extendable link carries at most the chosen build'
    dims: [snapshot, link]
    where: Link_p_nom_extendable
    expression: Link_p <= Link_p_max_pu * Link_p_nom_ext
  Link_ext_p_nom_lower:
    description: '`Link-ext-p_nom-lower` — the chosen build is at least its floor'
    dims: [link]
    where: Link_p_nom_extendable
    expression: Link_p_nom_ext >= Link_p_nom_min
  Link_ext_p_nom_upper:
    description: '`Link-ext-p_nom-upper` — the chosen build is at most its cap; a cap of infinity is no
      row'
    dims: [link]
    where: Link_p_nom_extendable AND Link_p_nom_max
    expression: Link_p_nom_ext <= Link_p_nom_max
  Link_p_nom_set:
    description: '`Link-p_nom_set` — the chosen build pinned, wherever a value is given'
    dims: [link]
    where: Link_p_nom_extendable AND Link_p_nom_set
    expression: Link_p_nom_ext == Link_p_nom_set
  StorageUnit_fix_p_dispatch_lower:
    description: '`StorageUnit-fix-p_dispatch-lower` — dispatch is non-negative'
    dims: [snapshot, storage_unit]
    where: not StorageUnit_p_nom_extendable
    expression: StorageUnit_p_dispatch >= 0
  StorageUnit_fix_p_dispatch_upper:
    description: '`StorageUnit-fix-p_dispatch-upper` — a fixed unit dispatches at most its nominal power'
    dims: [snapshot, storage_unit]
    where: not StorageUnit_p_nom_extendable
    expression: StorageUnit_p_dispatch <= StorageUnit_p_max_pu * StorageUnit_p_nom
  StorageUnit_fix_p_store_lower:
    description: '`StorageUnit-fix-p_store-lower` — storing is non-negative'
    dims: [snapshot, storage_unit]
    where: not StorageUnit_p_nom_extendable
    expression: StorageUnit_p_store >= 0
  StorageUnit_fix_p_store_upper:
    description: '`StorageUnit-fix-p_store-upper` — a fixed unit stores at most its nominal power, the
      minimum-per-unit column carrying that cap negated'
    dims: [snapshot, storage_unit]
    where: not StorageUnit_p_nom_extendable
    expression: StorageUnit_p_store <= -StorageUnit_p_min_pu * StorageUnit_p_nom
  StorageUnit_fix_state_of_charge_lower:
    description: '`StorageUnit-fix-state_of_charge-lower` — charge is non-negative'
    dims: [snapshot, storage_unit]
    where: not StorageUnit_p_nom_extendable
    expression: StorageUnit_state_of_charge >= 0
  StorageUnit_fix_state_of_charge_upper:
    description: '`StorageUnit-fix-state_of_charge-upper` — a fixed unit holds at most its hours at nominal
      power'
    dims: [snapshot, storage_unit]
    where: not StorageUnit_p_nom_extendable
    expression: StorageUnit_state_of_charge <= StorageUnit_max_hours * StorageUnit_p_nom
  Generator_p_ramp_limit_up:
    description: '`Generator-p-ramp_limit_up` — a generator raises output no faster than its ramp limit
      of the build, and a committed one no further than its start-up ramp in the snapshot it turns on.
      A unit that came into the horizon running brought an unknown output, so it carries no row at the
      first snapshot — nor does any unit a big M releases instead'
    dims: [snapshot, generator]
    where: Generator_ramp_limit_up AND NOT (Generator_committable AND Generator_p_nom_extendable) AND
      (position(snapshot) > 0 OR (Generator_committable AND Generator_status_initial == 0))
    expression: Generator_p - Generator_previous_p <= Generator_ramp_up_allowance
  Generator_p_ramp_limit_down:
    description: '`Generator-p-ramp_limit_down` — a generator lowers output no faster than its ramp limit
      of the build, and a committed one no further than its shut-down ramp in the snapshot it turns off.
      A unit that came into the horizon running brought an unknown output, so it carries no row at the
      first snapshot — nor does any unit a big M releases instead'
    dims: [snapshot, generator]
    where: Generator_ramp_limit_down AND NOT (Generator_committable AND Generator_p_nom_extendable) AND
      (position(snapshot) > 0 OR (Generator_committable AND Generator_status_initial == 0))
    expression: Generator_previous_p - Generator_p <= Generator_ramp_down_allowance
  Link_p_ramp_limit_up:
    description: '`Link-p-ramp_limit_up` — a link raises flow no faster than its limit of the build. The
      translated term vacates the first snapshot, where a plain optimize builds no row either'
    dims: [snapshot, link]
    where: Link_ramp_limit_up
    expression: Link_p - shift(Link_p, along=snapshot, offset=1) <= Link_ramp_limit_up * Link_p_nom_effective
  Link_p_ramp_limit_down:
    description: '`Link-p-ramp_limit_down` — a link lowers flow no faster than its limit of the build'
    dims: [snapshot, link]
    where: Link_ramp_limit_down
    expression: shift(Link_p, along=snapshot, offset=1) - Link_p <= Link_ramp_limit_down * Link_p_nom_effective
  StorageUnit_ext_p_dispatch_lower:
    description: '`StorageUnit-ext-p_dispatch-lower` — dispatch is non-negative'
    dims: [snapshot, storage_unit]
    where: StorageUnit_p_nom_extendable
    expression: StorageUnit_p_dispatch >= 0
  StorageUnit_ext_p_dispatch_upper:
    description: '`StorageUnit-ext-p_dispatch-upper` — an extendable unit dispatches at most the chosen
      build'
    dims: [snapshot, storage_unit]
    where: StorageUnit_p_nom_extendable
    expression: StorageUnit_p_dispatch <= StorageUnit_p_max_pu * StorageUnit_p_nom_ext
  StorageUnit_ext_p_store_lower:
    description: '`StorageUnit-ext-p_store-lower` — storing is non-negative'
    dims: [snapshot, storage_unit]
    where: StorageUnit_p_nom_extendable
    expression: StorageUnit_p_store >= 0
  StorageUnit_ext_p_store_upper:
    description: '`StorageUnit-ext-p_store-upper` — an extendable unit stores at most the chosen build,
      the minimum-per-unit column carrying that cap negated'
    dims: [snapshot, storage_unit]
    where: StorageUnit_p_nom_extendable
    expression: StorageUnit_p_store <= -StorageUnit_p_min_pu * StorageUnit_p_nom_ext
  StorageUnit_ext_state_of_charge_lower:
    description: '`StorageUnit-ext-state_of_charge-lower` — charge is non-negative'
    dims: [snapshot, storage_unit]
    where: StorageUnit_p_nom_extendable
    expression: StorageUnit_state_of_charge >= 0
  StorageUnit_ext_state_of_charge_upper:
    description: '`StorageUnit-ext-state_of_charge-upper` — an extendable unit holds at most its hours
      at the chosen build'
    dims: [snapshot, storage_unit]
    where: StorageUnit_p_nom_extendable
    expression: StorageUnit_state_of_charge <= StorageUnit_max_hours * StorageUnit_p_nom_ext
  StorageUnit_ext_p_nom_lower:
    description: '`StorageUnit-ext-p_nom-lower` — the chosen build is at least its floor'
    dims: [storage_unit]
    where: StorageUnit_p_nom_extendable
    expression: StorageUnit_p_nom_ext >= StorageUnit_p_nom_min
  StorageUnit_ext_p_nom_upper:
    description: '`StorageUnit-ext-p_nom-upper` — the chosen build is at most its cap; a cap of infinity
      is no row'
    dims: [storage_unit]
    where: StorageUnit_p_nom_extendable AND StorageUnit_p_nom_max
    expression: StorageUnit_p_nom_ext <= StorageUnit_p_nom_max
  StorageUnit_p_nom_set:
    description: '`StorageUnit-p_nom_set` — the chosen build pinned, wherever a value is given'
    dims: [storage_unit]
    where: StorageUnit_p_nom_extendable AND StorageUnit_p_nom_set
    expression: StorageUnit_p_nom_ext == StorageUnit_p_nom_set
  StorageUnit_energy_balance:
    description: '`StorageUnit-energy_balance` — the charge carried in, plus what is stored after its
      efficiency, less what dispatch draws down before its own, plus inflow not spilled'
    dims: [snapshot, storage_unit]
    expression: StorageUnit_state_of_charge == StorageUnit_charge_carried_in + StorageUnit_efficiency_store
      * StorageUnit_p_store * snapshot_weightings_stores - StorageUnit_p_dispatch * snapshot_weightings_stores
      / StorageUnit_efficiency_dispatch
  Store_fix_e_lower:
    description: '`Store-fix-e-lower` — a fixed store holds at least its floor'
    dims: [snapshot, store]
    where: not Store_e_nom_extendable
    expression: Store_e >= Store_e_min_pu * Store_e_nom
  Store_fix_e_upper:
    description: '`Store-fix-e-upper` — a fixed store holds at most its nominal capacity'
    dims: [snapshot, store]
    where: not Store_e_nom_extendable
    expression: Store_e <= Store_e_max_pu * Store_e_nom
  Store_ext_e_lower:
    description: '`Store-ext-e-lower` — an extendable store holds at least its floor of the chosen build'
    dims: [snapshot, store]
    where: Store_e_nom_extendable
    expression: Store_e >= Store_e_min_pu * Store_e_nom_ext
  Store_ext_e_upper:
    description: '`Store-ext-e-upper` — an extendable store holds at most the chosen build'
    dims: [snapshot, store]
    where: Store_e_nom_extendable
    expression: Store_e <= Store_e_max_pu * Store_e_nom_ext
  Store_ext_e_nom_lower:
    description: '`Store-ext-e_nom-lower` — the chosen build is at least its floor'
    dims: [store]
    where: Store_e_nom_extendable
    expression: Store_e_nom_ext >= Store_e_nom_min
  Store_ext_e_nom_upper:
    description: '`Store-ext-e_nom-upper` — the chosen build is at most its cap; a cap of infinity is
      no row'
    dims: [store]
    where: Store_e_nom_extendable AND Store_e_nom_max
    expression: Store_e_nom_ext <= Store_e_nom_max
  Store_e_nom_set:
    description: '`Store-e_nom_set` — the chosen build pinned, wherever a value is given'
    dims: [store]
    where: Store_e_nom_extendable AND Store_e_nom_set
    expression: Store_e_nom_ext == Store_e_nom_set
  Store_energy_balance:
    description: '`Store-energy_balance` — the energy carried in, less what is delivered to the bus'
    dims: [snapshot, store]
    expression: Store_e == Store_energy_carried_in - Store_p * snapshot_weightings_stores
  GlobalConstraint_transmission_volume_expansion_limit_ub:
    description: '`transmission_volume_expansion_limit` — its total, at most its constant'
    dims: [global_constraint]
    where: GlobalConstraint_type == 'transmission_volume_expansion_limit' AND GlobalConstraint_sense ==
      '<='
    expression: transmission_volume_expansion <= GlobalConstraint_constant
  GlobalConstraint_transmission_expansion_cost_limit_lb:
    description: '`transmission_expansion_cost_limit` — its total, at least its constant'
    dims: [global_constraint]
    where: GlobalConstraint_type == 'transmission_expansion_cost_limit' AND GlobalConstraint_sense ==
      '>='
    expression: transmission_expansion_cost >= GlobalConstraint_constant
  GlobalConstraint_transmission_expansion_cost_limit_eq:
    description: '`transmission_expansion_cost_limit` — its total, at its constant'
    dims: [global_constraint]
    where: GlobalConstraint_type == 'transmission_expansion_cost_limit' AND GlobalConstraint_sense ==
      '=='
    expression: transmission_expansion_cost == GlobalConstraint_constant
  GlobalConstraint_tech_capacity_expansion_limit_ub:
    description: '`tech_capacity_expansion_limit` — its total, at most its constant'
    dims: [global_constraint]
    where: GlobalConstraint_type == 'tech_capacity_expansion_limit' AND GlobalConstraint_sense == '<='
    expression: tech_capacity_expansion <= GlobalConstraint_constant
  GlobalConstraint_tech_capacity_expansion_limit_lb:
    description: '`tech_capacity_expansion_limit` — its total, at least its constant'
    dims: [global_constraint]
    where: GlobalConstraint_type == 'tech_capacity_expansion_limit' AND GlobalConstraint_sense == '>='
    expression: tech_capacity_expansion >= GlobalConstraint_constant
  GlobalConstraint_tech_capacity_expansion_limit_eq:
    description: '`tech_capacity_expansion_limit` — its total, at its constant'
    dims: [global_constraint]
    where: GlobalConstraint_type == 'tech_capacity_expansion_limit' AND GlobalConstraint_sense == '=='
    expression: tech_capacity_expansion == GlobalConstraint_constant
  Bus_nodal_balance:
    description: '`Bus-nodal_balance` — what is generated at a bus, storage dispatch and stores included,
      less what the links take away, plus what arrives over them after losses and any delay at every port
      they deliver to, meets the load there. A bus nothing is attached to has no row; PyPSA refuses one
      that carries load, and this file does not yet.'
    dims: [snapshot, bus]
    expression: sum(Generator_p, by=Generator_bus, over=generator, into=bus) + sum(StorageUnit_p_dispatch
      - StorageUnit_p_store, by=StorageUnit_bus, over=storage_unit, into=bus) + sum(Store_p, by=Store_bus,
      over=store, into=bus) - sum(Link_p, by=Link_bus0, over=link, into=bus) + sum(Link_output_arrival,
      by=Link_output_bus, over=link_output, into=bus) == sum(Load_p_set, by=Load_bus, over=load, into=bus)
expressions:
  Generator_previous_p:
    description: the output a generator carries into a snapshot — nothing at the start of the horizon,
      which is why a unit that came in running carries no ramp row there
    dims: [snapshot, generator]
    cases:
      opening: {when: position(snapshot) == 0, expression: 0}
    otherwise: shift(Generator_p, along=snapshot, offset=1)
  Generator_ramp_up_allowance:
    description: how far a generator may raise output between two snapshots — its ramp limit of the build
      while it stays on, plus its start-up ramp in the snapshot it turns on
    dims: [snapshot, generator]
    cases:
      committed: {when: Generator_committable, expression: Generator_ramp_limit_up * Generator_p_nom *
          Generator_previous_status + Generator_ramp_limit_start_up * Generator_p_nom * (Generator_status
          - Generator_previous_status)}
    otherwise: Generator_ramp_limit_up * Generator_p_nom_effective
  Generator_ramp_down_allowance:
    description: how far a generator may lower output between two snapshots — its ramp limit of the build
      while it stays on, plus its shut-down ramp in the snapshot it turns off
    dims: [snapshot, generator]
    cases:
      committed: {when: Generator_committable, expression: Generator_ramp_limit_down * Generator_p_nom
          * Generator_status + Generator_ramp_limit_shut_down * Generator_p_nom * (Generator_previous_status
          - Generator_status)}
    otherwise: Generator_ramp_limit_down * Generator_p_nom_effective
  Link_p_nom_effective:
    description: the build a link's limits are taken against — the chosen one where it is extendable,
      the given one otherwise
    dims: [link]
    cases:
      extendable: {when: Link_p_nom_extendable, expression: Link_p_nom_ext}
    otherwise: Link_p_nom
  StorageUnit_charge_carried_in:
    description: the charge a unit opens a snapshot with — its last snapshot's less standing loss where
      it is cyclic, the given initial charge at the start of the horizon, which no standing loss has touched
      yet, and the previous snapshot's less standing loss otherwise
    dims: [snapshot, storage_unit]
    cases:
      cyclic: {when: StorageUnit_cyclic_state_of_charge, expression: 'StorageUnit_retention * shift(StorageUnit_state_of_charge,
          along=snapshot, offset=1, edge=''wrap'')'}
      opening: {when: not StorageUnit_cyclic_state_of_charge AND position(snapshot) == 0, expression: StorageUnit_state_of_charge_initial}
    otherwise: StorageUnit_retention * shift(StorageUnit_state_of_charge, along=snapshot, offset=1)
  Store_energy_carried_in:
    description: the energy a store opens a snapshot with — its last snapshot's less standing loss where
      it is cyclic, the given initial energy at the start of the horizon, which no standing loss has touched
      yet, and the previous snapshot's less standing loss otherwise
    dims: [snapshot, store]
    cases:
      cyclic: {when: Store_e_cyclic, expression: 'Store_retention * shift(Store_e, along=snapshot, offset=1,
          edge=''wrap'')'}
      opening: {when: not Store_e_cyclic AND position(snapshot) == 0, expression: Store_e_initial}
    otherwise: Store_retention * shift(Store_e, along=snapshot, offset=1)
  Link_output_arrival:
    description: what a link delivers to an output port at a snapshot — its flow after the port's efficiency,
      delayed by the port's `delay`; where the port is `cyclic_delay` the delayed flow wraps from the
      horizon's end, and where it is not the flow still in transit at the first snapshots is lost. A port
      that does not delay (`delay` zero) delivers its flow unshifted, cyclic or not
    dims: [snapshot, link_output]
    cases:
      wrapping: {when: Link_output_cyclic_delay, expression: 'shift(at(Link_p, by=Link_output_link, over=link,
          into=link_output) * Link_efficiency, along=snapshot, offset=Link_output_delay, edge=''wrap'')'}
    otherwise: shift(at(Link_p, by=Link_output_link, over=link, into=link_output) * Link_efficiency, along=snapshot,
      offset=Link_output_delay, edge=0)
  transmission_volume_expansion: {description: what a `transmission_volume_expansion_limit` row totals
      — length times the chosen build of the row's branches, expression: 'sum(Link_p_nom_ext * Link_volume_weight,
      over=link)'}
  transmission_expansion_cost: {description: what a `transmission_expansion_cost_limit` row totals — capital
      cost times the chosen build of the row's branches, expression: 'sum(Link_p_nom_ext * Link_expansion_cost_weight,
      over=link)'}
  tech_capacity_expansion: {description: what a `tech_capacity_expansion_limit` row totals — the chosen
      build of the row's carrier-and-bus set, expression: 'sum(Generator_p_nom_ext * Generator_tech_capacity_weight,
      over=generator) + sum(Link_p_nom_ext * Link_tech_capacity_weight, over=link) + sum(StorageUnit_p_nom_ext
      * StorageUnit_tech_capacity_weight, over=storage_unit) + sum(Store_e_nom_ext * Store_tech_capacity_weight,
      over=store)'}
  Generator_previous_status:
    description: the commitment state a generator carries into a snapshot — the state it brought into
      the horizon at the first, the previous snapshot's after that
    dims: [snapshot, generator]
    cases:
      opening: {when: position(snapshot) == 0, expression: Generator_status_initial}
    otherwise: shift(Generator_status, along=snapshot, offset=1)
  Generator_p_nom_effective:
    description: the build a generator's limits are taken against — the chosen one where it is extendable,
      the given one otherwise
    dims: [generator]
    cases:
      extendable: {when: Generator_p_nom_extendable, expression: Generator_p_nom_ext}
    otherwise: Generator_p_nom
objective: {sense: minimize, description: 'operating cost, each snapshot weighted by the hours it stands
    for', expression: sum(Generator_p * Generator_marginal_cost * snapshot_weightings_objective) + sum(Link_p
    * Link_marginal_cost * snapshot_weightings_objective) + sum(StorageUnit_p_dispatch * StorageUnit_marginal_cost
    * snapshot_weightings_objective) + sum(StorageUnit_state_of_charge * StorageUnit_marginal_cost_storage
    * snapshot_weightings_objective) + sum(Store_p * Store_marginal_cost * snapshot_weightings_objective)
    + sum(Store_e * Store_marginal_cost_storage * snapshot_weightings_objective) + sum(Generator_p_nom_ext
    * Generator_capital_cost) + sum(Link_p_nom_ext * Link_capital_cost) + sum(StorageUnit_p_nom_ext *
    StorageUnit_capital_cost) + sum(Store_e_nom_ext * Store_capital_cost)}

The prep — every table the spec declares, from the network — and the solve:

from differential.pypsa.prep import relation, static, varying, weighting


def _carrier_list(gc: pd.Series) -> list[str]:
    return [c.strip().strip('[]()') for c in str(gc['carrier_attribute']).split(',')]


def _emissions(n: pypsa.Network, gc: pd.Series) -> pd.Series:
    """The nonzero values of the carrier attribute a `primary_energy` row weighs."""
    values = n.carriers[gc['carrier_attribute']]
    return values[values != 0]


def _gc_constants(n: pypsa.Network) -> pd.DataFrame:
    """Each row's constant, net of the initial charge PyPSA folds into its side of the row.

    A `primary_energy` or `operational_limit` row counts what its non-cyclic
    storage draws down, so PyPSA adds the initial charge as a constant on the
    variable side; the file keeps the variables and moves it here.
    """
    rows = []
    for label, gc in n.global_constraints.iterrows():
        constant = float(gc['constant'])
        if gc['type'] == 'primary_energy':
            emissions = _emissions(n, gc)
            sus = n.storage_units
            member = sus['carrier'].isin(emissions.index) & ~sus['cyclic_state_of_charge']
            constant -= float(
                (sus.loc[member, 'carrier'].map(emissions) * sus.loc[member, 'state_of_charge_initial']).sum()
            )
            stores = n.stores
            member = stores['carrier'].isin(emissions.index) & ~stores['e_cyclic']
            constant -= float((stores.loc[member, 'carrier'].map(emissions) * stores.loc[member, 'e_initial']).sum())
        if gc['type'] == 'operational_limit':
            sus = n.storage_units
            member = (sus['carrier'] == gc['carrier_attribute']) & ~sus['cyclic_state_of_charge']
            constant -= float(sus.loc[member, 'state_of_charge_initial'].sum())
            stores = n.stores
            member = (stores['carrier'] == gc['carrier_attribute']) & ~stores['e_cyclic']
            constant -= float(stores.loc[member, 'e_initial'].sum())
        rows.append({'global_constraint': str(label), 'value': constant})
    return pd.DataFrame(rows, columns=['global_constraint', 'value']).astype({'value': float})


def _in_tech_set(gc: pd.Series, component: pd.Series, nominal: str, bus: str) -> bool:
    """PyPSA's membership for a `tech_capacity_expansion_limit` row: extendable, the carrier, and the bus if named."""
    at_bus = not gc.get('bus') or str(component[bus]) == str(gc['bus'])
    return bool(component[f'{nominal}_extendable'] and component['carrier'] == gc['carrier_attribute'] and at_bus)


def _link_ports(n: pypsa.Network) -> pd.DataFrame:
    """A link's output ports read long — one row per port a link declares, carrying the link, the bus it delivers to and its efficiency.

    PyPSA spells the ports across columns — ``bus1``/``efficiency``, ``bus2``/``efficiency2``, … — and a
    link declares a port by naming a bus in one, so a link of any port count is as many rows here and
    one term in the balance. The label is the link and the column the port came from.
    """
    links = n.static('Link')
    blank = pd.Series('', index=links.index, dtype=str)
    frames = []
    for port in ['1', *n.components.links.additional_ports]:
        suffix = '' if port == '1' else port
        buses = links.get(f'bus{port}', blank).astype(str)
        # `efficiency`, `delay` and `cyclic_delay` are PyPSA's unsuffixed attributes: port 1
        # spells them bare and every port after it takes the number
        efficiencies = links.get(f'efficiency{suffix}', pd.Series(1.0, index=links.index)).astype(float)
        delays = links.get(f'delay{suffix}', pd.Series(0, index=links.index)).fillna(0).astype(int)
        cyclic = links.get(f'cyclic_delay{suffix}', pd.Series(False, index=links.index)).fillna(False).astype(bool)
        frame = pd.DataFrame(
            keyed(links.index, 'link')
            | {
                'bus': buses.to_numpy(),
                'value': efficiencies.to_numpy(),
                'delay': delays.to_numpy(),
                'cyclic_delay': cyclic.to_numpy(),
                'port': int(port),
            }
        )
        frames.append(frame[buses.to_numpy() != ''])
    ports = pd.concat(frames, ignore_index=True).sort_values(['link', 'port'], kind='stable')
    ports['link_output'] = ports['link'] + '_bus' + ports['port'].astype(str)
    return ports.drop(columns='port').reset_index(drop=True)


def _per_port(n: pypsa.Network, column: str, as_name: str | None = None) -> pd.DataFrame:
    """One column of the long port table keyed by ``link_output`` — what a port names, or what it carries.

    *as_name* is what the file calls it: a relation keeps its target dimension's
    own name, and every parameter over the ports lands under ``value``.
    """
    ports = _link_ports(n)
    keys = [key for key in ('scenario', 'link_output') if key in ports.columns]
    return ports[[*keys, column]].rename(columns={column: as_name or column})


def _retention(n: pypsa.Network, component: str, dim: str) -> pd.DataFrame:
    losses = n.static(component)['standing_loss']
    hours = n.snapshot_weightings['stores'].to_numpy()
    dense = pd.DataFrame({name: (1.0 - loss) ** hours for name, loss in losses.items()}, index=timesteps(n))
    table = dense.melt(ignore_index=False, var_name=dim).reset_index(names='snapshot')
    return table.astype({dim: str, 'value': float})


def _weights(gcs: pd.DataFrame, components: pd.DataFrame, dim: str, value) -> pd.DataFrame:
    """One row per (global constraint, member): *value* returns the weight, or 0/None outside the row's set."""
    rows = [
        {'global_constraint': str(label), dim: str(name), 'value': float(v)}
        for label, gc in gcs.iterrows()
        for name, component in components.iterrows()
        if (v := value(gc, component))
    ]
    return pd.DataFrame(rows, columns=['global_constraint', dim, 'value']).astype({'value': float})


n = build()  # the network from the PyPSA tab

sources = {
    'snapshot': pl.Series('snapshot', list(timesteps(n)), dtype=pl.Datetime('us')),
    'bus': pl.Series('bus', list(names(n.buses.index).astype(str)), dtype=pl.String),
    'generator': pl.Series('generator', list(names(generators.index).astype(str)), dtype=pl.String),
    'link': pl.Series('link', list(names(links.index).astype(str)), dtype=pl.String),
    'link_output': pl.Series('link_output', list(pd.unique(_link_ports(n)['link_output'])), dtype=pl.String),
    'load': pl.Series('load', list(names(loads.index).astype(str)), dtype=pl.String),
    'storage_unit': pl.Series('storage_unit', list(names(storage_units.index).astype(str)), dtype=pl.String),
    'store': pl.Series('store', list(names(stores.index).astype(str)), dtype=pl.String),
    'global_constraint': pl.Series(
            'global_constraint', list(names(n.global_constraints.index).astype(str)), dtype=pl.String
        ),
        **scenarios(n),
        **periods(n),
        **carriers(n),
    'Generator_bus': relation(n, 'Generator', 'bus'),
    'Link_bus0': relation(n, 'Link', 'bus0'),
    'Link_output_link': _per_port(n, 'link'),
    'Link_output_bus': _per_port(n, 'bus'),
    'Load_bus': relation(n, 'Load', 'bus'),
    'StorageUnit_bus': relation(n, 'StorageUnit', 'bus'),
    'Store_bus': relation(n, 'Store', 'bus'),
    'snapshot_weightings_objective': weighting(n, 'objective'),
    'Generator_p_nom': static(n, 'Generator', 'p_nom'),
    'Generator_p_nom_extendable': static(n, 'Generator', 'p_nom_extendable'),
    'Generator_p_min_pu': varying(n, 'Generator', 'p_min_pu'),
    'Generator_p_max_pu': varying(n, 'Generator', 'p_max_pu'),
    'Generator_marginal_cost': varying(n, 'Generator', 'marginal_cost'),
    'Generator_committable': static(n, 'Generator', 'committable'),
    'Generator_ramp_limit_up': static(n, 'Generator', 'ramp_limit_up').dropna(),
    'Generator_ramp_limit_down': static(n, 'Generator', 'ramp_limit_down').dropna(),
    'Generator_ramp_limit_start_up': static(n, 'Generator', 'ramp_limit_start_up').fillna({'value': 1.0}),
    'Generator_ramp_limit_shut_down': static(n, 'Generator', 'ramp_limit_shut_down').fillna({'value': 1.0}),
    'Generator_status_initial': pd.DataFrame(
            keyed(generators.index, 'generator')
            | {
                'value': (generators['up_time_before'] > 0).astype(int).to_numpy(),
            }
        ),
    'Link_ramp_limit_up': static(n, 'Link', 'ramp_limit_up').dropna(),
    'Link_ramp_limit_down': static(n, 'Link', 'ramp_limit_down').dropna(),
    'Link_p_nom': static(n, 'Link', 'p_nom'),
    'Link_p_nom_extendable': static(n, 'Link', 'p_nom_extendable'),
    'Link_p_min_pu': varying(n, 'Link', 'p_min_pu'),
    'Link_p_max_pu': varying(n, 'Link', 'p_max_pu'),
    'Link_efficiency': _per_port(n, 'value'),
    'Link_output_delay': _per_port(n, 'delay', 'value'),
    'Link_output_cyclic_delay': _per_port(n, 'cyclic_delay', 'value'),
    'Link_marginal_cost': varying(n, 'Link', 'marginal_cost'),
    'Load_p_set': varying(n, 'Load', 'p_set'),
    'snapshot_weightings_stores': weighting(n, 'stores'),
    'snapshot_weightings_generators': weighting(n, 'generators'),
    'Generator_p_nom_min': static(n, 'Generator', 'p_nom_min'),
    'Generator_p_nom_max': static(n, 'Generator', 'p_nom_max'),
    'Generator_capital_cost': static(n, 'Generator', 'capital_cost'),
    'Generator_p_nom_set': static(n, 'Generator', 'p_nom_set').dropna(),
    'Generator_e_sum_min': static(n, 'Generator', 'e_sum_min'),
    'Generator_e_sum_max': static(n, 'Generator', 'e_sum_max'),
    'Link_p_nom_min': static(n, 'Link', 'p_nom_min'),
    'Link_p_nom_max': static(n, 'Link', 'p_nom_max'),
    'Link_capital_cost': static(n, 'Link', 'capital_cost'),
    'Link_p_nom_set': static(n, 'Link', 'p_nom_set').dropna(),
    'StorageUnit_p_nom_min': static(n, 'StorageUnit', 'p_nom_min'),
    'StorageUnit_p_nom_max': static(n, 'StorageUnit', 'p_nom_max'),
    'StorageUnit_capital_cost': static(n, 'StorageUnit', 'capital_cost'),
    'StorageUnit_p_nom_set': static(n, 'StorageUnit', 'p_nom_set').dropna(),
    'Store_e_nom_min': static(n, 'Store', 'e_nom_min'),
    'Store_e_nom_max': static(n, 'Store', 'e_nom_max'),
    'Store_capital_cost': static(n, 'Store', 'capital_cost'),
    'Store_e_nom_set': static(n, 'Store', 'e_nom_set').dropna(),
    'StorageUnit_p_nom': static(n, 'StorageUnit', 'p_nom'),
    'StorageUnit_p_nom_extendable': static(n, 'StorageUnit', 'p_nom_extendable'),
    'StorageUnit_p_min_pu': varying(n, 'StorageUnit', 'p_min_pu'),
    'StorageUnit_p_max_pu': varying(n, 'StorageUnit', 'p_max_pu'),
    'StorageUnit_max_hours': static(n, 'StorageUnit', 'max_hours'),
    'StorageUnit_efficiency_store': static(n, 'StorageUnit', 'efficiency_store'),
    'StorageUnit_efficiency_dispatch': static(n, 'StorageUnit', 'efficiency_dispatch'),
    'StorageUnit_retention': _retention(n, 'StorageUnit', 'storage_unit'),
    'StorageUnit_state_of_charge_initial': static(n, 'StorageUnit', 'state_of_charge_initial'),
    'StorageUnit_cyclic_state_of_charge': static(n, 'StorageUnit', 'cyclic_state_of_charge'),
    'StorageUnit_marginal_cost': varying(n, 'StorageUnit', 'marginal_cost'),
    'StorageUnit_marginal_cost_storage': varying(n, 'StorageUnit', 'marginal_cost_storage'),
    'Store_e_nom': static(n, 'Store', 'e_nom'),
    'Store_e_nom_extendable': static(n, 'Store', 'e_nom_extendable'),
    'Store_e_min_pu': varying(n, 'Store', 'e_min_pu'),
    'Store_e_max_pu': varying(n, 'Store', 'e_max_pu'),
    'Store_retention': _retention(n, 'Store', 'store'),
    'Store_e_initial': static(n, 'Store', 'e_initial'),
    'Store_e_cyclic': static(n, 'Store', 'e_cyclic'),
    'Store_marginal_cost': varying(n, 'Store', 'marginal_cost'),
    'Store_marginal_cost_storage': varying(n, 'Store', 'marginal_cost_storage'),
    'GlobalConstraint_type': static(n, 'GlobalConstraint', 'type').astype({'value': str}),
    'GlobalConstraint_sense': static(n, 'GlobalConstraint', 'sense').astype({'value': str}),
    'GlobalConstraint_constant': _gc_constants(n),
    'Link_volume_weight': _weights(
            volume,
            links,
            'link',
            lambda gc, c: c['length'] if c['p_nom_extendable'] and c['carrier'] in _carrier_list(gc) else 0.0,
        ),
    'Link_expansion_cost_weight': _weights(
            expansion_cost,
            links,
            'link',
            lambda gc, c: c['capital_cost'] if c['p_nom_extendable'] and c['carrier'] in _carrier_list(gc) else 0.0,
        ),
    'Generator_tech_capacity_weight': _weights(
            tech, generators, 'generator', lambda gc, c: float(_in_tech_set(gc, c, 'p_nom', 'bus'))
        ),
    'Link_tech_capacity_weight': _weights(
            tech, links, 'link', lambda gc, c: float(_in_tech_set(gc, c, 'p_nom', 'bus0'))
        ),
    'StorageUnit_tech_capacity_weight': _weights(
            tech, storage_units, 'storage_unit', lambda gc, c: float(_in_tech_set(gc, c, 'p_nom', 'bus'))
        ),
    'Store_tech_capacity_weight': _weights(
            tech, stores, 'store', lambda gc, c: float(_in_tech_set(gc, c, 'e_nom', 'bus'))
        ),
}

with sps.solve('differential/pypsa/rungs/rung_03_expansion.yaml', sources) as solution:
    solution.objective  # 7633.908502024291

The network, rung_03_expansion.py in the corpus — the spine plus what this rung adds:

"""Rung 3: expansion — extendable capacity, energy-sum bounds, fixed and set nominal capacities."""

from __future__ import annotations

import spine


def build():
    """The spine plus this rung's additions, as a ``pypsa.Network``."""
    n = spine.build()
    n.add('Bus', 'island')
    n.add('Carrier', 'onwind')
    n.add('Carrier', 'solarpv')
    n.add('Carrier', 'dc')
    n.add('Carrier', 'phs')
    n.add('Carrier', 'h2')
    n.add(
        'Generator',
        'wind',
        bus='north',
        carrier='onwind',
        p_nom_extendable=True,
        capital_cost=50,
        p_nom_min=5,
        p_nom_max=80,
        marginal_cost=0,
        e_sum_min=40,
        ramp_limit_up=0.4,
        ramp_limit_down=0.4,
        p_max_pu=[0.3, 0.8, 0.5, 0.9],
    )
    n.add(
        'Generator',
        'solar',
        bus='north',
        carrier='solarpv',
        p_nom_extendable=True,
        capital_cost=60,
        p_nom_max=40,
        marginal_cost=0,
        p_nom_set=15,
        p_max_pu=[0.5, 0.6, 0.4, 0.2],
    )
    n.add('Generator', 'diesel', bus='island', marginal_cost=40, p_nom=60, e_sum_max=70)
    n.add(
        'Link',
        'cable',
        bus0='north',
        bus1='island',
        carrier='dc',
        length=120,
        p_nom_extendable=True,
        capital_cost=20,
        p_nom_max=30,
        efficiency=0.95,
        p_nom_set=25,
        ramp_limit_up=0.3,
        ramp_limit_down=0.3,
    )
    n.add('Load', 'island_load', bus='island', p_set=10)
    n.add(
        'StorageUnit',
        'pump',
        bus='north',
        carrier='phs',
        p_nom_extendable=True,
        capital_cost=15,
        p_nom_max=30,
        max_hours=4,
        efficiency_store=0.9,
        efficiency_dispatch=0.9,
        cyclic_state_of_charge=True,
        p_nom_set=20,
    )
    n.add('StorageUnit', 'ice', bus='island', max_hours=2, p_nom=8, state_of_charge_initial=6)
    n.add(
        'Store',
        'tank',
        bus='north',
        carrier='h2',
        e_nom_extendable=True,
        capital_cost=2,
        e_nom_max=80,
        e_cyclic=True,
        e_nom_set=50,
    )
    n.add('Store', 'keg', bus='island', e_nom=15, e_initial=5)
    n.add(
        'GlobalConstraint',
        'tech_wind',
        type='tech_capacity_expansion_limit',
        carrier_attribute='onwind',
        sense='==',
        constant=50,
    )
    n.add(
        'GlobalConstraint',
        'tech_solar',
        type='tech_capacity_expansion_limit',
        carrier_attribute='solarpv',
        sense='>=',
        constant=10,
    )
    n.add(
        'GlobalConstraint',
        'tech_dc',
        type='tech_capacity_expansion_limit',
        carrier_attribute='dc',
        sense='<=',
        constant=28,
    )
    n.add(
        'GlobalConstraint',
        'tech_phs',
        type='tech_capacity_expansion_limit',
        carrier_attribute='phs',
        sense='<=',
        constant=25,
    )
    n.add(
        'GlobalConstraint',
        'tech_h2',
        type='tech_capacity_expansion_limit',
        carrier_attribute='h2',
        sense='>=',
        constant=30,
    )
    n.add(
        'GlobalConstraint',
        'vol_dc',
        type='transmission_volume_expansion_limit',
        carrier_attribute='dc',
        sense='<=',
        constant=3500,
    )
    n.add(
        'GlobalConstraint',
        'cost_dc',
        type='transmission_expansion_cost_limit',
        carrier_attribute='dc',
        sense='>=',
        constant=400,
    )
    n.add(
        'GlobalConstraint',
        'cost_dc_exact',
        type='transmission_expansion_cost_limit',
        carrier_attribute='dc',
        sense='==',
        constant=500,
    )
    return n
n = build()
n.optimize(solver_name='highs')
n.objective  # 7633.908502024291

The data

The tables this rung is the first to declare (36), as the prep produced them:

Generator_capital_cost.csv

generator,value
coal,0.0
diesel,0.0
gas,0.0
solar,60.0
wind,50.0

Generator_e_sum_max.csv

generator,value
coal,inf
diesel,70.0
gas,inf
solar,inf
wind,inf

Generator_e_sum_min.csv

generator,value
coal,-inf
diesel,-inf
gas,-inf
solar,-inf
wind,40.0

Generator_p_nom_max.csv

generator,value
coal,inf
diesel,inf
gas,inf
solar,40.0
wind,80.0

Generator_p_nom_min.csv

generator,value
coal,0.0
diesel,0.0
gas,0.0
solar,0.0
wind,5.0

Generator_p_nom_set.csv

generator,value
solar,15.0

Generator_ramp_limit_down.csv

generator,value
wind,0.4

Generator_ramp_limit_shut_down.csv

generator,value
coal,1.0
diesel,1.0
gas,1.0
solar,1.0
wind,1.0

Generator_ramp_limit_start_up.csv

generator,value
coal,1.0
diesel,1.0
gas,1.0
solar,1.0
wind,1.0

Generator_ramp_limit_up.csv

generator,value
wind,0.4

Generator_status_initial.csv

generator,value
coal,1
diesel,1
gas,1
solar,1
wind,1

Generator_tech_capacity_weight.csv

global_constraint,generator,value
tech_solar,solar,1.0
tech_wind,wind,1.0

GlobalConstraint_constant.csv

global_constraint,value
cost_dc,400.0
cost_dc_exact,500.0
tech_dc,28.0
tech_h2,30.0
tech_phs,25.0
tech_solar,10.0
tech_wind,50.0
vol_dc,3500.0

GlobalConstraint_sense.csv

global_constraint,value
cost_dc,>=
cost_dc_exact,==
tech_dc,<=
tech_h2,>=
tech_phs,<=
tech_solar,>=
tech_wind,==
vol_dc,<=

GlobalConstraint_type.csv

global_constraint,value
cost_dc,transmission_expansion_cost_limit
cost_dc_exact,transmission_expansion_cost_limit
tech_dc,tech_capacity_expansion_limit
tech_h2,tech_capacity_expansion_limit
tech_phs,tech_capacity_expansion_limit
tech_solar,tech_capacity_expansion_limit
tech_wind,tech_capacity_expansion_limit
vol_dc,transmission_volume_expansion_limit

Link_capital_cost.csv

link,value
cable,20.0
wire,0.0

Link_expansion_cost_weight.csv

global_constraint,link,value
cost_dc,cable,20.0
cost_dc_exact,cable,20.0

Link_p_nom_max.csv

link,value
cable,30.0
wire,inf

Link_p_nom_min.csv

link,value
cable,0.0
wire,0.0

Link_p_nom_set.csv

link,value
cable,25.0

Link_ramp_limit_down.csv

link,value
cable,0.3

Link_ramp_limit_up.csv

link,value
cable,0.3

Link_tech_capacity_weight.csv

global_constraint,link,value
tech_dc,cable,1.0

Link_volume_weight.csv

global_constraint,link,value
vol_dc,cable,120.0

StorageUnit_capital_cost.csv

storage_unit,value
ice,0.0
pump,15.0

StorageUnit_p_nom_max.csv

storage_unit,value
ice,inf
pump,30.0

StorageUnit_p_nom_min.csv

storage_unit,value
ice,0.0
pump,0.0

StorageUnit_p_nom_set.csv

storage_unit,value
pump,20.0

StorageUnit_tech_capacity_weight.csv

global_constraint,storage_unit,value
tech_phs,pump,1.0

Store_capital_cost.csv

store,value
keg,0.0
tank,2.0

Store_e_nom_max.csv

store,value
keg,inf
tank,80.0

Store_e_nom_min.csv

store,value
keg,0.0
tank,0.0

Store_e_nom_set.csv

store,value
tank,50.0

Store_tech_capacity_weight.csv

global_constraint,store,value
tech_h2,tank,1.0

global_constraint.csv

global_constraint
cost_dc
cost_dc_exact
tech_dc
tech_h2
tech_phs
tech_solar
tech_wind
vol_dc

snapshot_weightings_generators.csv

snapshot,value
2015-01-01T00:00:00.000000,1.5
2015-01-01T01:00:00.000000,0.5
2015-01-01T02:00:00.000000,3.0
2015-01-01T03:00:00.000000,2.0