{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# Multi-period Dispatch Simulation" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Multi-period dispatch economic dispatch (ED) and unit commitment (UC) is also available.\n", "\n", "In this case, we will show a 24-hour ED simulation." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import ams\n", "\n", "import datetime" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Last run time: 2024-05-24 20:26:30\n", "ams:0.9.7\n" ] } ], "source": [ "print(\"Last run time:\", datetime.datetime.now().strftime(\"%Y-%m-%d %H:%M:%S\"))\n", "\n", "print(f'ams:{ams.__version__}')" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "ams.config_logger(stream_level=20)" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Load Case" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Parsing input file \"/Users/jinningwang/Documents/work/mambaforge/envs/amsre/lib/python3.9/site-packages/ams/cases/5bus/pjm5bus_demo.xlsx\"...\n", "Input file parsed in 0.1462 seconds.\n", "Zero line rates detacted in rate_b, rate_c, adjusted to 999.\n", "System set up in 0.0033 seconds.\n" ] } ], "source": [ "sp = ams.load(ams.get_case('5bus/pjm5bus_demo.xlsx'),\n", " setup=True,\n", " no_output=True,)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Reginonal Design" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The disaptch models in AMS has develoepd with regional structure, and it can be inspected in device ``Region``." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
idxuname
uid
0ZONE_11.0ZONE 1
1ZONE_21.0ZONE 2
\n", "
" ], "text/plain": [ " idx u name\n", "uid \n", "0 ZONE_1 1.0 ZONE 1\n", "1 ZONE_2 1.0 ZONE 2" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sp.Region.as_df()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In device ``Bus``, the Param ``zone`` indicates the zone of the bus.\n", "Correspondingly, the region of generator and load are determined by the bus they connected." ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
idxunameVnvmaxvminv0a0xcoordycoordareazoneownertype
uid
0Bus_11.0A230.01.10.91.00.0001ZONE_1None1
1Bus_21.0B230.01.10.91.00.0001ZONE_1None1
2Bus_31.0C230.01.10.91.00.0002ZONE_1None1
3Bus_41.0D230.01.10.91.00.0002ZONE_1None1
4Bus_51.0E230.01.10.91.00.0003ZONE_1None1
\n", "
" ], "text/plain": [ " idx u name Vn vmax vmin v0 a0 xcoord ycoord area \\\n", "uid \n", "0 Bus_1 1.0 A 230.0 1.1 0.9 1.0 0.0 0 0 1 \n", "1 Bus_2 1.0 B 230.0 1.1 0.9 1.0 0.0 0 0 1 \n", "2 Bus_3 1.0 C 230.0 1.1 0.9 1.0 0.0 0 0 2 \n", "3 Bus_4 1.0 D 230.0 1.1 0.9 1.0 0.0 0 0 2 \n", "4 Bus_5 1.0 E 230.0 1.1 0.9 1.0 0.0 0 0 3 \n", "\n", " zone owner type \n", "uid \n", "0 ZONE_1 None 1 \n", "1 ZONE_1 None 1 \n", "2 ZONE_1 None 1 \n", "3 ZONE_1 None 1 \n", "4 ZONE_1 None 1 " ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sp.Bus.as_df()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Multi-period Dispatch Base" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In AMS, multi-period dispatch involves devices in group ``Horizon``.\n", "This group is developed to provide time-series data for multi-period dispatch." ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "OrderedDict([('TimeSlot', TimeSlot (0 devices) at 0x168c3a3d0),\n", " ('EDTSlot', EDTSlot (6 devices) at 0x168c3ae50),\n", " ('UCTSlot', UCTSlot (6 devices) at 0x168c462b0)])" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sp.Horizon.models" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can get the idx of StaticGens." ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['Slack_4', 'PV_1', 'PV_3', 'PV_5']" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sp.StaticGen.get_idx()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In ``EDTSlot``, Param ``sd`` refers the load factors of each region in each time slot, and Param ``ug`` represents the generator commitment status in each time slot.\n", "\n", "To be more specific, EDT1 has ``sd=0.0793,0.0``, which means the load factor of region 1 is 0.0793 in the first time slot, and 0.0 in the second time slot.\n", "\n", "Next, EDT1 has ``ug=1,1,1,1``, and it means the commitment status of generator PV_1, PV_3, PV_5, and Slack_4 are all online." ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
idxunamesdug
uid
0EDT11.0EDT10.793,0.01,1,1,1
1EDT21.0EDT20.756,0.01,1,1,1
2EDT31.0EDT30.723,0.01,1,1,1
3EDT41.0EDT40.708,0.01,1,1,1
4EDT51.0EDT50.7,0.01,1,1,1
5EDT61.0EDT60.706,0.01,1,1,1
\n", "
" ], "text/plain": [ " idx u name sd ug\n", "uid \n", "0 EDT1 1.0 EDT1 0.793,0.0 1,1,1,1\n", "1 EDT2 1.0 EDT2 0.756,0.0 1,1,1,1\n", "2 EDT3 1.0 EDT3 0.723,0.0 1,1,1,1\n", "3 EDT4 1.0 EDT4 0.708,0.0 1,1,1,1\n", "4 EDT5 1.0 EDT5 0.7,0.0 1,1,1,1\n", "5 EDT6 1.0 EDT6 0.706,0.0 1,1,1,1" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sp.EDTSlot.as_df()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Solve and Result" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ " initialized in 0.0277 seconds.\n" ] }, { "data": { "text/plain": [ "True" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sp.ED.init()" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ " solved as optimal in 0.0343 seconds, converged in 11 iterations with ECOS.\n" ] }, { "data": { "text/plain": [ "True" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sp.ED.run(solver='CLARABEL')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "All decision variables are collected in the dict ``vars``." ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "OrderedDict([('pg', Var: StaticGen.pg),\n", " ('aBus', Var: Bus.aBus),\n", " ('pi', Var: Bus.pi),\n", " ('plf', Var: Line.plf),\n", " ('pru', Var: StaticGen.pru),\n", " ('prd', Var: StaticGen.prd),\n", " ('prs', Var: StaticGen.prs)])" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sp.ED.vars" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As we can see, the generator output ``pg`` is a 2D array, and the first dimension is the generator index, and the second dimension is the time slot." ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[2. , 2. , 2. , 2. , 2. , 2. ],\n", " [2.1 , 2.1 , 2.1 , 2.1 , 2.1 , 2.1 ],\n", " [3.23, 2.86, 2.53, 2.38, 2.3 , 2.36],\n", " [0.6 , 0.6 , 0.6 , 0.6 , 0.6 , 0.6 ]])" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sp.ED.pg.v" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Partial results can be accessed with desired time slot.\n", "In the retrieved result, the first dimension is the generator index, and the second dimension is the time slot." ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2.099999999839607" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sp.ED.get(src='pg', attr='v', idx='PV_1', horizon=['EDT1'])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Or, get multiple variables in mutliple time slots." ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[2.1 , 2.1 , 2.1 ],\n", " [3.23, 2.86, 2.53]])" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sp.ED.get(src='pg', attr='v', idx=['PV_1', 'PV_3'], horizon=['EDT1', 'EDT2', 'EDT3'])" ] } ], "metadata": { "kernelspec": { "display_name": "ams", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.18" }, "orig_nbformat": 4, "vscode": { "interpreter": { "hash": "d2b3bf80176349caa68dc4a3c77bd06eaade8abc678330f7d1c813c53380e5d2" } } }, "nbformat": 4, "nbformat_minor": 2 }