Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Clearing Electricity Markets Using PyPSA

In The Supply and Demand of Electricity, we discussed the electricity market and the economic dispatch (ED) optimization problem. In this blog post, we will show how to use PyPSA to recreate the results of Example 2.4. Example 2.4 consists of an electrical grid with two market nodes, A\mathrm{A} and B\mathrm{B}, connected by a lossy transmission line. Node A\mathrm{A} has a generator, G1\mathrm{G1}, and node B\mathrm{B} has another generator G2\mathrm{G2} and two loads L1\mathrm{L1} and L2\mathrm{L2}. The generators and loads have made offers and bids in the electricity market, with price-quantity pairs shown in Figure 3.

Network of Example 2.4.

Figure 1:Network of Example 2.4.

We start by defining a PyPSA Network:

We define the market nodes A\mathrm{A} and B\mathrm{B} as two electrical Bus components.

Transmission lines are modeled by the Line component, but because the transmission line of Example 2.4 has a fixed efficiency for simplicity, we model it as a Link component:

The generators and loads have piecewise linear dispatch curves, but PyPSA supports only linear or quadratic dispatch curves (using the marginal_cost and marginal_cost_quadratic parameters). PyPSA does this because it is designed for planning and research purposes. It is designed to work with the typical marginal cost of each generator, rather than the exact price-quantity pairs that each generator has submitted in the past for each market hour.

Following the approach discussed in Higher-Dimensional Optimization Problems, we will model each resource (generator or load) as multiple resources—one for each price-quantity pair submitted by the resource.

For example, because generator G1\mathrm{G1} submitted two nonzero price-quantity pairs, we will model the generator in PyPSA as two generators. According to its price-quantity pairs, generator G1\mathrm{G1} is willing to produce up to 6 MW6 \ \mathrm{MW} at $2/MWh\$2/\mathrm{MWh}, or up to 9 MW9 \ \mathrm{MW} at $7/MWh\$7/\mathrm{MWh}. We model this as a 6-MW6\text{-}\mathrm{MW} generator that has a marginal cost of $2/MWh\$2/\mathrm{MWh}, plus a 3-MW3\text{-}\mathrm{MW} generator that has a marginal cost of $7/MWh\$7/\mathrm{MWh}.

Thus, we define the Generator components as follows:

We will use the same approach for the loads. PyPSA’s Load component does not support the marginal_cost parameter, but PyPSA’s documentation explicitly states to use the Generator component with a negative sign and negative marginal_cost for this purpose:

Network.optimize() solves the optimal power flow (OPF) problem, which extends economic dispatch with linearized (i.e., approximate) power flow constraints. In this sense, optimize() acts also to simulate the grid and the market clearing process.

By inspecting network.generators_t and network.buses_t, we can see the market-clearing quantities of the generators and loads, as well as the locational marginal prices (LMPs) of the two nodes:

Loading...
Loading...