Skip to content

Examples

The examples below demonstrate PyPSA's capabilities for energy system modeling. They cover a broad range of topics, including electricity markets, linear optimal power flow, unit commitment, capacity expansion, grid modelling, and more.

Operational Problems

  • Electricity Market

    Demonstrates basic electricity market modeling with with multiple bidding zones, renewables and storage.

    Go to example

  • Demand and Supply Bids

    Demonstrates market-clearing with supply and demand bids in single and two-zone configurations.

    Go to example

  • Unit Commitment

    Models generator unit commitment with start-up and shut-down costs, ramping limits, minimum part loads, up and down times using binary variables.

    Go to example

  • Negative Prices in Linearized UC

    Shows how negative electricity prices emerge from linearized unit commitment constraints due to the trade-off between cycling costs and operating at minimum load.

    Go to example

  • Meshed AC-DC Networks

    Builds a stylized 3-node AC network coupled via AC-DC converters to a 3-node DC network.

    Go to example

  • SciGRID Network

    Performs linear optimal power flow on a high-resolution German grid model to analyze power flows and nodal prices.

    Go to example

  • Security-Constrained LOPF

    Implements N-1 security constraints in linear optimal power flow models to ensure grid reliability under line outage events.

    Go to example

  • Newton-Raphson Power Flow

    Solves non-linear AC power flow equations using the Newton-Raphson method to inspect voltage magnitudes and angles.

    Go to example

  • Negative LMPs from Line Congestion

    Explores how Kirchhoff's Voltage Law can lead to negative locational marginal prices when lines are congested.

    Go to example

  • Rolling-Horizon Optimization

    Explores how rolling-horizon optimization can be used to account for imperfect forecast horizons in reality.

    Go to example

  • Water Values

    Explores how water values, the marginal values of stored energy, can improve seasonal storage operation in rolling-horizon optimization.

    Go to example

Planning Problems

  • Single-Node Capacity Expansion

    Models investment decisions for generation and storage in a single-node system in the style of model.energy.

    Go to example

  • Three-Node Capacity Expansion

    Co-optimizes generation, storage and transmission investments in a stylized three-node network in Australia 🇦🇺.

    Go to example

  • Pathway Planning

    Optimizes investment decisions across multiple investment periods for a long-term transition pathway with perfect foresight.

    Go to example

  • Myopic Pathway Planning

    Optimizes investment decisions across multiple investment periods for a long-term transition pathway with myopic foresight.

    Go to example

  • Stochastic Optimization

    Demonstrates investment planning under uncertainty with scenario-based two-stage stochastic optimization.

    Go to example

  • Modelling-to-Generate Alternatives

    Explores near-optimal solution diversity by generating alternative system designs with similar costs.

    Go to example

  • Exploring Near-Optimal Spaces

    Explores near-optimal space to understand flexibility in investment decisions while maintaining cost-effectiveness.

    Go to example

  • Modular Capacity Expansion

    Models discrete capacity additions with integer constraints on investment decisions considering predefined unit sizes.

    Go to example

  • Committable and Extendable Components

    Co-optimize capacity expansion and unit commitment using big-M linearization. Demonstrates continuous capacity decisions with start-up/shut-down costs, ramp limits, and minimum load constraints.

    Go to example

  • Modular and Committable Components

    Model discrete capacity blocks with unit commitment where status represents the number of committed modules. Shows modular gas turbines, HVDC links, and multi-module operational dynamics.

    Go to example

Special Problems

  • Redispatch

    Sketches how redispatch can be modelled by separating market clearing and congestion management.

    Go to example

  • Demand Elasticity

    Demonstrates modelling of price-responsive electricity demands and how they affect price formation.

    Go to example

  • Imperfect Competition

    Models oligopolistic behavior in energy markets using Cournot-Nash equilibrium with the fictitious objective approach, avoiding KKT conditions.

    Go to example

  • Screening Curves

    Determines optimal generation capacity mix based on screening curves.

    Go to example

  • Chained Hydro Reservoirs

    Models cascaded hydropower systems with water flow constraints between reservoirs.

    Go to example

  • Transformers

    Shows how transformers can be considered with varying tap ratios and phase shifts.

    Go to example

  • Reserve Constraints

    Implements operating reserve requirements in power system optimization.

    Go to example

  • Link Delay

    Demonstrates time-delayed energy transport through links, modeling pipeline or shipping delays with cyclic and non-cyclic boundary behavior.

    Go to example

Sector Coupling

  • Single-Node Sector-Coupling

    Extends the 1-node capacity expansion example with hydrogen, heat and transport demand.

    Go to example

  • Islanded Methanol Production

    Optimizes islanded renewable methanol production systems in Namibia 🇳🇦 or Argentina 🇦🇷.

    Go to example

  • Electric Vehicles

    Demonstrates how to model flexible electric vehicle charging and discharging.

    Go to example

  • Backpressure CHPs

    Models combined heat and power plants with fixed heat-to-power ratios.

    Go to example

  • Extraction-Condensing CHPs

    Models combined heat and power plants with variable heat-to-power ratios.

    Go to example

  • Heat Pumps and Thermal Storage

    Models sector coupling with heat pumps and thermal energy storage.

    Go to example

  • Carbon Management

    Models carbon flows between atmosphere, biomass, and synthetic fuels.

    Go to example

Complexity Management

  • Time Series Aggregation

    Shows how model complexity can be reduced by aggregating snapshots.

    Go to example

  • Global Sensitivity Analysis

    Combines PyPSA with SALib's Sobol indices to understand how technology cost uncertainties affect optimal system design and total costs.

    Go to example

  • Storage Units as Links & Stores

    Shows how storage units can be replaced by more fundamental links and stores.

    Go to example

  • Tracing Infeasibilities

    Shows how to trace infeasibilities in the optimization problem using Irreducible Infeasible Subsets (IIS).

    Go to example