{ "cells": [ { "cell_type": "markdown", "source": [ "# 5-bus Market simulation with [PowerSimulations.jl](https://github.com/NREL-SIIP/PowerSimulations.jl)" ], "metadata": {} }, { "cell_type": "markdown", "source": [ "**Originally Contributed by**: Clayton Barrows" ], "metadata": {} }, { "cell_type": "markdown", "source": [ "## Introduction" ], "metadata": {} }, { "cell_type": "markdown", "source": [ "PowerSimulations.jl supports simulations that consist of sequential optimization problems\n", "where results from previous problems inform subsequent problems in a variety of ways. This\n", "example demonstrates some of these capabilities to represent electricity market clearing." ], "metadata": {} }, { "cell_type": "markdown", "source": [ "## Dependencies and Data\n", "First, let's create `System`s to represent the Day-Ahead and Real-Time market clearing\n", "process with hourly, and 5-minute time series data, respectively." ], "metadata": {} }, { "cell_type": "markdown", "source": [ "### Modeling Packages" ], "metadata": {} }, { "outputs": [], "cell_type": "code", "source": [ "using PowerSystems\n", "using PowerSimulations\n", "using PowerSystemCaseBuilder" ], "metadata": {}, "execution_count": null }, { "cell_type": "markdown", "source": [ "### Data management packages" ], "metadata": {} }, { "outputs": [], "cell_type": "code", "source": [ "using Dates\n", "using DataFrames" ], "metadata": {}, "execution_count": null }, { "cell_type": "markdown", "source": [ "### Optimization packages" ], "metadata": {} }, { "outputs": [], "cell_type": "code", "source": [ "using HiGHS # mip solver\n", "solver = optimizer_with_attributes(HiGHS.Optimizer, \"mip_rel_gap\" => 0.5)" ], "metadata": {}, "execution_count": null }, { "cell_type": "markdown", "source": [ "### 5-bus Data\n", "The five bus system data here includes hourly day-ahead data, 5-minute real-time market\n", "data, and 6-second actual data. We'll only use the hourly and 5-minute data for the\n", "example simulations below, but the 6-second data is included for future development." ], "metadata": {} }, { "outputs": [], "cell_type": "code", "source": [ "sys_DA = build_system(SIIPExampleSystems, \"5_bus_matpower_DA\")\n", "sys_RT = build_system(SIIPExampleSystems, \"5_bus_matpower_RT\")" ], "metadata": {}, "execution_count": null }, { "cell_type": "markdown", "source": [ "## `ProblemTemplate`s" ], "metadata": {} }, { "outputs": [], "cell_type": "code", "source": [ "template_uc = template_unit_commitment(use_slacks = true)\n", "template_ed = template_economic_dispatch(\n", " network = NetworkModel(CopperPlatePowerModel, duals = [CopperPlateBalanceConstraint]),\n", ")" ], "metadata": {}, "execution_count": null }, { "cell_type": "markdown", "source": [ "### Define the Simulation Sequence" ], "metadata": {} }, { "outputs": [], "cell_type": "code", "source": [ "models = SimulationModels(\n", " decision_models = [\n", " DecisionModel(template_uc, sys_DA, name = \"UC\", optimizer = solver),\n", " DecisionModel(template_ed, sys_RT, name = \"ED\", optimizer = solver),\n", " ],\n", ")\n", "\n", "feedforward = Dict(\n", " \"ED\" => [\n", " SemiContinuousFeedforward(\n", " component_type = ThermalStandard,\n", " source = OnVariable,\n", " affected_values = [ActivePowerVariable],\n", " ),\n", " ],\n", ")\n", "\n", "DA_RT_sequence = SimulationSequence(\n", " models = models,\n", " ini_cond_chronology = InterProblemChronology(),\n", " feedforwards = feedforward,\n", ")" ], "metadata": {}, "execution_count": null }, { "cell_type": "markdown", "source": [ "## `Simulation`" ], "metadata": {} }, { "outputs": [], "cell_type": "code", "source": [ "file_path = mktempdir(\".\", cleanup = true)\n", "sim = Simulation(\n", " name = \"5bus-test\",\n", " steps = 1,\n", " models = models,\n", " sequence = DA_RT_sequence,\n", " simulation_folder = file_path,\n", ")" ], "metadata": {}, "execution_count": null }, { "cell_type": "markdown", "source": [ "### Build simulation" ], "metadata": {} }, { "outputs": [], "cell_type": "code", "source": [ "build!(sim)" ], "metadata": {}, "execution_count": null }, { "cell_type": "markdown", "source": [ "### Execute simulation" ], "metadata": {} }, { "outputs": [], "cell_type": "code", "source": [ "execute!(sim, enable_progress_bar = false)\n", "\n", "# Results" ], "metadata": {}, "execution_count": null }, { "cell_type": "markdown", "source": [ "First we can load the result metadata" ], "metadata": {} }, { "outputs": [], "cell_type": "code", "source": [ "results = SimulationResults(sim);\n", "uc_results = get_problem_results(results, \"UC\")\n", "ed_results = get_problem_results(results, \"ED\");" ], "metadata": {}, "execution_count": null }, { "cell_type": "markdown", "source": [ "Then we can read and examine the results of interest. For example, if we want to read\n", "marginal prices of the balance constraint, we can see what dual values are available:" ], "metadata": {} }, { "outputs": [], "cell_type": "code", "source": [ "list_dual_names(ed_results)" ], "metadata": {}, "execution_count": null }, { "cell_type": "markdown", "source": [ "Then, we can read the results of the dual" ], "metadata": {} }, { "outputs": [], "cell_type": "code", "source": [ "prices = read_dual(ed_results, \"CopperPlateBalanceConstraint__System\")" ], "metadata": {}, "execution_count": null }, { "cell_type": "markdown", "source": [ "or if we want to look at the realized values" ], "metadata": {} }, { "outputs": [], "cell_type": "code", "source": [ "read_realized_dual(ed_results, \"CopperPlateBalanceConstraint__System\")" ], "metadata": {}, "execution_count": null }, { "cell_type": "markdown", "source": [ "*note that in this simulation the prices are all equal to the balance slack\n", "penalty value of $100000/MWh because there is unserved energy in the result*" ], "metadata": {} }, { "cell_type": "markdown", "source": [ "---\n", "\n", "*This notebook was generated using [Literate.jl](https://github.com/fredrikekre/Literate.jl).*" ], "metadata": {} } ], "nbformat_minor": 3, "metadata": { "language_info": { "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", "version": "1.7.2" }, "kernelspec": { "name": "julia-1.7", "display_name": "Julia 1.7.2", "language": "julia" } }, "nbformat": 4 }