{ "cells": [ { "cell_type": "markdown", "source": [ "# Large Scale Production Cost Modeling 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": [ "This example shows a basic PCM simulation using the system data assembled in the\n", "[US-System example](https://nbviewer.jupyter.org/github/NREL-SIIP/SIIPExamples.jl/blob/master/notebook/2_PowerSystems_examples/08_US_system.ipynb)." ], "metadata": {} }, { "cell_type": "markdown", "source": [ "### Dependencies" ], "metadata": {} }, { "outputs": [], "cell_type": "code", "source": [ "using SIIPExamples\n", "using PowerSystems\n", "using PowerSimulations\n", "using PowerGraphics\n", "using Logging\n", "using Dates\n", "\n", "pkgpath = dirname(dirname(pathof(SIIPExamples)))\n", "PSI = PowerSimulations\n", "plotlyjs()" ], "metadata": {}, "execution_count": null }, { "cell_type": "markdown", "source": [ "### Optimization packages\n", "You can use the free solvers as in one of the other PowerSimulations.jl examples, but on\n", "large problems it's useful to have a solver with better performance. I'll use the Xpress\n", "solver since I have a license, but others such as Gurobi or CPLEX work well too." ], "metadata": {} }, { "outputs": [], "cell_type": "code", "source": [ "using Xpress\n", "solver = optimizer_with_attributes(Xpress.Optimizer, \"MIPRELSTOP\" => 0.1, \"OUTPUTLOG\" => 1)" ], "metadata": {}, "execution_count": null }, { "cell_type": "markdown", "source": [ "### Load the US `System`.\n", "If you have run the\n", "[US-System example](https://nbviewer.jupyter.org/github/NREL-SIIP/SIIPExamples.jl/blob/master/notebook/2_PowerSystems_examples/08_US-System.ipynb), the data will\n", "be serialized in the json and H5 format, so we can efficiently deserialize it:" ], "metadata": {} }, { "outputs": [], "cell_type": "code", "source": [ "sys = System(joinpath(pkgpath, \"US-System\", \"SIIP\", \"sys.json\"))\n", "horizon = 24;\n", "interval = Dates.Hour(24);\n", "transform_single_time_series!(sys, horizon, interval);" ], "metadata": {}, "execution_count": null }, { "cell_type": "markdown", "source": [ "### Selecting flow limited lines\n", "Since PowerSimulations will apply constraints by component type (e.g. Line), we need to\n", "change the component type of the lines on which we want to enforce flow limits. So, let's\n", "change the device type of certain branches from Line to MonitoredLine differentiate\n", "treatment when we build the model. Here, we can select inter-regional lines, or lines\n", "above a voltage threshold." ], "metadata": {} }, { "outputs": [], "cell_type": "code", "source": [ "for line in get_components(Line, sys)\n", " if (get_base_voltage(get_from(get_arc(line))) >= 230.0) &&\n", " (get_base_voltage(get_to(get_arc(line))) >= 230.0)\n", " #if get_area(get_from(get_arc(line))) != get_area(get_to(get_arc(line)))\n", " @info \"Changing $(get_name(line)) to MonitoredLine\"\n", " convert_component!(MonitoredLine, line, sys)\n", " end\n", "end" ], "metadata": {}, "execution_count": null }, { "cell_type": "markdown", "source": [ "### Create a `template`\n", "Now we can create a `template` that applies an unbounded formulation to `Line`s and the standard\n", "flow limited formulation to `MonitoredLine`s." ], "metadata": {} }, { "outputs": [], "cell_type": "code", "source": [ "template = ProblemTemplate(DCPPowerModel)\n", "set_device_model!(template, Line, StaticBranchUnbounded)\n", "set_device_model!(template, TapTransformer, StaticBranchUnbounded)\n", "set_device_model!(template, MonitoredLine, StaticBranch)\n", "set_device_model!(template, ThermalStandard, ThermalStandardUnitCommitment)\n", "set_device_model!(template, RenewableDispatch, RenewableFullDispatch)\n", "set_device_model!(template, PowerLoad, StaticPowerLoad)\n", "set_device_model!(template, HydroDispatch, FixedOutput)" ], "metadata": {}, "execution_count": null }, { "cell_type": "markdown", "source": [ "### Build and execute single step problem" ], "metadata": {} }, { "outputs": [], "cell_type": "code", "source": [ "op_problem = DecisionModel(template, sys; optimizer = solver, horizon = 24)\n", "\n", "build!(op_problem, output_dir = mktempdir(), console_level = Logging.Info)\n", "\n", "solve!(op_problem)" ], "metadata": {}, "execution_count": null }, { "cell_type": "markdown", "source": [ "### Analyze results" ], "metadata": {} }, { "outputs": [], "cell_type": "code", "source": [ "res = ProblemResults(op_problem)\n", "plot_fuel(res)" ], "metadata": {}, "execution_count": null }, { "cell_type": "markdown", "source": [ "## Sequential Simulation\n", "In addition to defining the formulation template, sequential simulations require\n", "definitions for how information flows between problems." ], "metadata": {} }, { "outputs": [], "cell_type": "code", "source": [ "sim_folder = mkpath(joinpath(pkgpath, \"Texas-sim\"))\n", "models = SimulationModels(\n", " decision_models = [\n", " DecisionModel(\n", " template,\n", " sys,\n", " name = \"UC\",\n", " optimizer = solver,\n", " system_to_file = false,\n", " ),\n", " ],\n", ")\n", "DA_sequence =\n", " SimulationSequence(models = models, ini_cond_chronology = IntraProblemChronology())" ], "metadata": {}, "execution_count": null }, { "cell_type": "markdown", "source": [ "### Define and build a simulation" ], "metadata": {} }, { "outputs": [], "cell_type": "code", "source": [ "sim = Simulation(\n", " name = \"Texas-test\",\n", " steps = 3,\n", " models = models,\n", " sequence = DA_sequence,\n", " simulation_folder = \"Texas-sim\",\n", ")\n", "\n", "build!(\n", " sim,\n", " console_level = Logging.Info,\n", " file_level = Logging.Debug,\n", " recorders = [:simulation],\n", ")" ], "metadata": {}, "execution_count": null }, { "cell_type": "markdown", "source": [ "### Execute the simulation" ], "metadata": {} }, { "outputs": [], "cell_type": "code", "source": [ "execute!(sim)" ], "metadata": {}, "execution_count": null }, { "cell_type": "markdown", "source": [ "### Load and analyze results" ], "metadata": {} }, { "outputs": [], "cell_type": "code", "source": [ "results = SimulationResults(sim);\n", "uc_results = get_problem_results(results, \"UC\");\n", "\n", "plot_fuel(uc_results)" ], "metadata": {}, "execution_count": null }, { "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 }