{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# Distributional OPF" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "\n", "import andes\n", "import ams\n", "\n", "import pandas as pd\n", "\n", "import json\n", "\n", "import cvxpy as cp" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'0.6.6.post2.dev0+g9438e64'" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ams.__version__" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "ams.config_logger(stream_level=10)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Input format guessed as matpower.\n", "Parsing input file \"/Users/jinningwang/Documents/work/ams/ams/cases/ieee123/case123_v1.m\"...\n", "Input file parsed in 0.0149 seconds.\n", "Adjust bus index to start from 0.\n", "System set up in 0.0085 seconds.\n" ] } ], "source": [ "sp = ams.load(ams.get_case('ieee123/case123_v1.m'),\n", " setup=True,\n", " )" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "LDOPF data check passed.\n", "- Generating symbols for LDOPF\n", "Set constrs pb: sum(pd) - sum(pg)\n", "Set constrs pinj: CftT@pl - pd - pn\n", "Set constrs lub: PTDF @ (pn - pd) - rate_a\n", "Set constrs llb: - PTDF @ (pn - pd) - rate_a\n", "Set constrs vu: vsq - vmax**2\n", "Set constrs vl: -vsq + vmin**2\n", "Set constrs qinj: CftT@ql - qd - qn\n", "Set constrs qb: sum(qd) - sum(qg)\n", "Set constrs lvd: Cft@vsq - (r * pl + x * ql)\n", "LDOPF model set up in 0.0125 seconds.\n" ] }, { "data": { "text/plain": [ "True" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sp.LDOPF.setup()" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "LDOPF solved as optimal in 0.0543 seconds with exit code 0.\n" ] }, { "data": { "text/plain": [ "True" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sp.LDOPF.run()" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "92.82348461106608" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sp.LDOPF.obj.v" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([0.02000789, 0.01026309, 0.21139 , 0.01026309, 0.01026309,\n", " 0.01026309, 0.01026309, 0.01026309, 0.02000785, 0.02000785,\n", " 0.02000785])" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sp.LDOPF.pg.v" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([0.02000789, 0.01026309, 0.21139 , 0.01026309, 0.01026309,\n", " 0.01026309, 0.01026309, 0.01026309, 0.02000785, 0.02000785,\n", " 0.02000785])" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sp.StaticGen.get(src='p', attr='v', idx=sp.StaticGen.get_idx())" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([0.00100755, 0.00100755, 0.18392451, 0.00100755, 0.00100755,\n", " 0.00100755, 0.00100755, 0.00100755, 0.00100755, 0.00100755,\n", " 0.00100755])" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sp.LDOPF.qg.v" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([0.00100755, 0.00100755, 0.18392451, 0.00100755, 0.00100755,\n", " 0.00100755, 0.00100755, 0.00100755, 0.00100755, 0.00100755,\n", " 0.00100755])" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sp.StaticGen.get(src='q', attr='v', idx=sp.StaticGen.get_idx())" ] } ], "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.16" }, "orig_nbformat": 4, "vscode": { "interpreter": { "hash": "d2b3bf80176349caa68dc4a3c77bd06eaade8abc678330f7d1c813c53380e5d2" } } }, "nbformat": 4, "nbformat_minor": 2 }