Source-linked AI summary
PyPSA: Python for Power System Analysis
Tom Brown, Jonas Hörsch, David Schlachtberger
TL;DR
Modern power systems require tools that represent fluctuating renewables, electrification, and multiple time periods without oversimplifying electrical networks. This paper presents PyPSA, a free toolbox combining full power-flow analysis with linear multi-period operation and investment optimisation. Demonstrations on German and European transmission datasets illustrate its modelling scope, including storage-cost outcomes under different grid-expansion conditions.
Problem
Increasing renewable generation, electrification, and cross-sector coupling require power-system tools that handle multiple periods while retaining detailed electrical-network representations.
Method
PyPSA combines full AC and DC load-flow models with linear power-flow equations for multi-period optimisation of operation and investment across generation, storage, networks, and coupled energy sectors.
Results
With no grid expansion, the demonstrated system has an average cost of €82/MWh; optimal grid expansion reduces costs to as low as €65/MWh and can eliminate much storage.
Takeaways & Limitations
PyPSA provides a transparent, extensible bridge between traditional power-flow software and broader multi-period energy-system models.
Abstract
from arXiv · showhide
Python for Power System Analysis (PyPSA) is a free software toolbox for simulating and optimising modern electrical power systems over multiple periods. PyPSA includes models for conventional generators with unit commitment, variable renewable generation, storage units, coupling to other energy sectors, and mixed alternating and direct current networks. It is designed to be easily extensible and to scale well with large networks and long time series. In this paper the basic functionality of PyPSA is described, including the formulation of the full power flow equations and the multi-period optimisation of operation and investment with linear power flow equations. PyPSA is positioned in the existing free software landscape as a bridge between traditional power flow analysis tools for steady-state analysis and full multi-period energy system models. The functionality is demonstrated on two open datasets of the transmission system in Germany (based on SciGRID) and Europe (based on GridKit).
I. INTRODUCTION
PyPSA is a free, extensible toolbox designed to bridge steady-state power-system analysis and multi-period energy-system modelling. It combines detailed electrical-network representations with operational and investment optimisation for increasingly renewable and electrified systems.
- Motivation: Increasing renewable generation and electrification create fluctuating flows, higher demand, and a need for multi-period power-system modelling.Multiple periods support generator unit commitment, storage and demand-side management, and infrastructure planning across load and weather conditions.
- Existing tools: Existing power-flow tools commonly focus on single-period network flows, while broader energy-system tools often simplify electrical-grid representations.The paper positions PyPSA between these two software categories.
- PyPSA functionality: PyPSA models conventional and variable renewable generators, storage, sector coupling, and interconnected AC and DC networks over multiple periods.It supports both full load-flow calculations and linearised optimal load flow, including security constraints.
- Transparency and extensibility: PyPSA is released under GPLv3, allowing users to inspect, use, modify, and redistribute the software with source code.The authors connect free software and open data with reproducibility for energy-system modelling.
- Adoption: As of October 2017, PyPSA had been used in six research papers and extended for integer transmission expansion and the open eGo grid-planning tool.The software was available through PyPI, GitHub, Zenodo, and documented online.
- Components: PyPSA represents systems by connecting buses, loads, generators, storage components, passive branches, and controllable links.Buses enforce energy conservation, while passive branches use impedances and equivalent PI models; links represent controllable transfers or energy-conversion processes.
- Components: Links can represent HVDC lines, import-export capacities, or conversion processes such as heaters, heat pumps, and gas boilers.Link efficiencies may vary over time, whereas passive-branch networks obey Kirchhoff’s Voltage Law.
- Components: Storage units and stores represent temporal energy shifting, while generators and links provide component-level representations of fuel conversion and storage charging or discharging.The model tracks energy entering and leaving through generation, demand, storage changes, efficiencies, and network components.
B. Power flow without optimisation
In an unconstrained power-flow calculation, PyPSA takes dispatchable-component setpoints as inputs and computes network voltages and passive-branch flows from the network impedances.
- Power-flow inputs and outputs: PyPSA computes resulting network voltages and passive-branch power flows after the user specifies dispatch for dispatchable components.The dispatchable components include loads, generators, storage units, stores, and links; lines and transformers determine flows through their impedances.
1) Power flow equations for AC networks:
PyPSA formulates AC power flow through complex bus injections, currents, voltages, and the bus admittance matrix, with bus types determining known and unknown quantities. It also describes DC-network equations and a linearised AC approximation with explicit operating assumptions.
- AC network equations: AC power flow relates complex apparent-power injections to bus voltages, currents, and the admittance matrix assembled from branch and shunt contributions.Voltage angles are measured relative to a chosen slack bus.
- Bus types: The slack bus specifies voltage magnitude and angle, while PyPSA solves for its active and reactive powers.This provides the reference state for the remaining bus calculations.
- Solution method: The nonlinear AC equations are solved with Newton-Raphson iteration, using a default flat initial guess that users may replace with a seeded solution.The default sets θ_n = θ_0 and |V_n| = 1 per unit.
- DC networks: DC-network power flow uses real active-power, voltage, current, and conductance quantities and is also solved with Newton-Raphson.The conductance matrix replaces the complex admittance representation used for AC networks.
- Linearised AC equations: Linearised AC power flow approximates active flows from voltage-angle differences and branch reactances under small-angle, fixed-voltage, decoupling, and negligible-resistance assumptions.The approximation is intended for short overhead transmission lines and similar settings where these assumptions are reasonable.
- Linearised AC equations: The linearised formulation relates voltage angles to active-power injections through network incidence and branch-reactance matrices.The resulting matrix is singular for a connected network and becomes invertible after removing the slack-bus row and column.
4) Linearised power flow equations for DC networks:
PyPSA formulates linear power-flow-based optimisation for short-term operation and long-term investment, covering generation, storage, transmission, and energy-sector coupling. Its linear load-flow formulation supports network constraints and can solve up to 20 times faster with cycle equations than standard voltage-angle formulations.
- Optimisation framework: PyPSA optimises short-term operation and long-term investment as a linear problem using linear power-flow equations.The objective includes variable and fixed costs for generation, storage, and transmission subject to technical and physical constraints.
- Model extensions: The framework includes renewable availability, ramp-rate limits, unit-commitment costs, emissions caps, and coupling through buses, links, and converters.The supplied formulation covers generator dispatch, start-up and shut-down terms, global primary-energy constraints, and multiple energy carriers.
- Components and constraints: Generation, storage, and transmission capacities can be constrained or optimised within installable potentials and time-dependent operating limits.Storage energy levels remain consistent across hours and can include efficiencies, inflows, spillage, leakage, and cyclic boundary conditions.
- Network balance: Electricity demand at every bus and time must be met by local generation, storage, or branch flows.Kirchhoff’s Current Law is implemented through the network balance equation.
- Linear network model: Passive branches follow linear power-flow equations with capacity limits, while links are fully controllable and can have time-dependent efficiencies and availabilities.Passive branches are treated as lossless, and Kirchhoff’s Voltage Law is enforced around connected-network cycles.
- Computational formulation: Cycle-based linear load flow solves up to 20 times faster than standard voltage-angle formulations while producing identical results across implemented formulations.PyPSA also implements voltage-angle and PTDF formulations; iterative impedance updates preserve linearity when capacities expand.
D. Coupling to other energy sectors
PyPSA extends optimisation beyond electricity to natural gas, heating, and transport. These sectors are represented through energy-carrier buses connected by loads, sources, and conversion links with efficiency losses.
- Sector coupling: PyPSA can optimise operation and investment in natural gas, heating, and transport alongside electricity.The additional sectors are modelled within the same multi-sector optimisation framework.
- Conversion links: Energy-sector coupling uses networks of links with efficiencies to represent energy-conversion losses.Electricity-to-heat links can represent resistive heaters or heat pumps.
- Conversion links: Heat pumps can use a time-dependent coefficient of performance to capture changing conversion performance.The passage identifies this as important for representing heat-sector behaviour.
E. Unit Commitment
PyPSA adds unit commitment to generator dispatch by introducing binary operating statuses and constraints for output, minimum up and down times, start-up and shut-down costs, and ramping.
- Operating status: Binary status variables indicate whether each generator is running in each period.The status variable equals 1 when operating and 0 when not operating.
- Output constraints: Generator output is forced to zero whenever its unit-commitment status is zero.Output bounds are multiplied by the binary status variable.
- Temporal constraints: Minimum up and down times constrain how long generators must remain running or offline after status changes.A start-up requires operation for at least the specified minimum up time, with analogous minimum down-time restrictions.
- Commitment costs: Start-up and shut-down costs are represented by nonnegative time-dependent variables added to the objective when commitment status changes.The start-up cost variable becomes nonzero when a generator starts.
- Ramping: Ramp-rate limits can be supplemented with separate limits for generator start-up and shut-down.
F. Security-Constrained LOPF
PyPSA supports security-constrained linear optimal power flow by evaluating passive-branch outages with linear outage-distribution factors. The resulting constraints prevent surviving branches from exceeding capacity after selected outages.
- Outage analysis: PyPSA examines steady-state system behaviour after passive-branch outages using linear power-flow analysis.
- Outage factors: The Branch Outage Distribution Factor is calculated from PTDFs and gives the change in linearised flow on one passive branch after another branch outages.
- Security constraints: SCLOPF adds constraints for each selected outage so every other branch remains within its capacity.The post-outage flow combines the original flow with the outage factor multiplied by the outaged branch flow.
G. Network clustering
PyPSA provides network clustering algorithms that reduce the number of buses while preserving important transmission lines.
- PyPSA implements network clustering algorithms to reduce the number of buses while preserving important transmission lines.The k-means algorithm was used to examine how clustering affects investment optimisation results.
H. Planned new features
PyPSA’s planned development includes integer transmission expansion, dynamic investment optimisation, transient and short-circuit analysis, nonlinear power-flow and OPF capabilities, and an interactive web GUI. Its modular Python architecture uses pandas, NumPy, SciPy, Pyomo, notebooks, and visualisation libraries, but it currently lacks a graphical user interface.
- Planned features: Planned features include integer transmission expansion, multi-horizon dynamic investment optimisation, transient analysis, nonlinear power flow, short-circuit analysis, full nonlinear OPF, and a web-based GUI.These items are listed in rough priority order by the development team.
- Implementation and architecture: PyPSA’s Python implementation supports major operating systems and was tested with Python 2.7 and 3.5.The paper attributes the choice of Python to its use in the modelling community, ease of learning, and free implementation.
- Implementation and architecture: Network components are stored in pandas DataFrames containing static and snapshot-indexed time-varying attributes.Attributes such as generator maximum output may be static or time-varying; static values are used when no time series is specified.
- Implementation and architecture: NumPy and SciPy handle matrix calculations and linear-system solutions, while Pyomo formulates solver-agnostic optimisation problems.Pyomo also supports interoperability with other energy-system frameworks using Pyomo.
- Implementation and architecture: PyPSA has no graphical user interface but supports network visualisation through IPython notebooks with Matplotlib or Plotly.The libraries can visualise networks and their properties, including those shown in the paper’s figures.
IV. QUALITY CONTROL
PyPSA is tested against other software and compared with power-system and energy-system tools to clarify its computational performance and distinctive multi-period, network-oriented scope.
- Quality control: PyPSA includes tests covering major functionality and comparisons with PYPOWER and pandapower.Users can report bugs through the GitHub repository or forum.
- Computational performance: Full-load-flow timings were averaged over 10 attempts for each MATPOWER test case using matched numerical tolerances.The experiments compared MATPOWER’s runpf with PyPSA’s network.pf on specified hardware.
- Computational performance: 5 seconds are required to optimise SciGRID dispatch over 4 snapshots using the COIN-OR Clp solver.The model contains 585 buses, 1423 generators, 38 pump storage units, 852 lines, and 96 transformers.
- Comparison with other tools: Many existing tools focus on steady-state, dynamic, or single-period OPF analysis and omit multi-period unit commitment, investment optimisation, and energy-system coupling.The comparison focuses on the Python tools PYPOWER and pandapower.
- Comparison with other tools: PYPOWER lacks multi-period OPF and investment optimisation, while retaining full nonlinear OPF for single snapshots.The paper describes PYPOWER as a Python port of an older MATPOWER version.
- Comparison with other tools: pandapower adds an easier pandas interface and functions such as short-circuit calculations, state estimation, switches, and three-winding transformers, but lacks multi-period OPF.The paper notes ongoing collaboration between the pandapower and PyPSA teams.
- Comparison with other tools: PyPSA offers more detailed power-network modelling than general energy-system models, especially power flow based on network impedances.It does not yet provide the multiyear dynamic investment available in OSeMOSYS.
- Comparison with other tools: PyPSA was developed because power-flow tools lacked structures for multi-period economic optimisation, while energy-system tools lacked tight power-flow integration.The paper presents this combination as the reason for creating a new tool rather than extending an existing one.
VII. DEMONSTRATION OF FEATURES ON THE SCIGRID AND GRIDKIT DATASETS
PyPSA’s demonstrations apply open German and European transmission datasets to show nodal pricing, nonlinear power-flow validation, and generation-storage investment optimisation. The examples illustrate how network constraints shape dispatch and storage needs under deep decarbonisation.
- SciGRID demonstration: Open SciGRID data are extended with power plants, loads, and time series to run German load-flow calculations with nodal pricing.The example uses geo-referenced transmission substations and lines at 220 kV and above.
- SciGRID demonstration: Transmission bottlenecks in central Germany prevent cheap northern wind electricity from reaching southern consumers, where conventional generators set higher prices.The linearly optimised dispatch is subsequently evaluated with a full nonlinear power-flow calculation while buses maintain nominal voltage.
- GridKit demonstration: The European GridKit demonstration clusters the network from 5000 buses to 256 buses for generation and storage investment optimisation targeting a 95% CO2 reduction from 1990 levels.The optimisation concerns the European electricity sector.
- GridKit demonstration: Without grid expansion, local balancing pairs short-term battery storage with southern solar and longer-term hydrogen storage with northern wind.The resulting system has an average cost of e 82/MWh.
- GridKit demonstration: With optimal grid expansion, much storage can be eliminated and costs can fall to e 65/MWh.This comparison is reported for the same European decarbonisation context.
- Demonstrated scope: The paper presents PyPSA as a toolbox covering multi-period operation and investment, steady-state full load flow, and components for renewable, conventional, storage, sector-coupled, AC, and DC systems.The code is free software that users can inspect and extend.