{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# Simulate" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This example gives a \"hello world\" example to use AMS." ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Import and Setting the Verbosity Level" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "We first import the `ams` library." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import ams" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "We can configure the verbosity level for logging (output messages) by passing a verbosity level (10-DEBUG, 20-INFO, 30-WARNING, 40-ERROR, 50-CRITICAL) to the `stream_level` argument of `ams.main.config_logger()`. Verbose level 10 is useful for getting debug output.\n", "\n", "The logging level can be altered by calling ``config_logger`` again with new ``stream_level`` and ``file_level``." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "ams.config_logger(stream_level=20)" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "Note that the above ``ams.config_logger()`` is a shorthand to ``ams.main.config_logger()``.\n", "\n", "If this step is omitted, the default `INFO` level (`stream_level=20`) will be used." ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## Run Simulations" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### Load Case" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "AMS supports multiple input file formats, including AMS ``.xlsx`` file, MATPOWER ``.m`` file, PYPOWER ``.py`` file, and PSS/E ``.raw`` file.\n", "\n", "Here we use the AMS ``.xlsx`` file as an example. The source file locates at ``$HOME/ams/ams/cases/ieee39/ieee39_uced.xlsx``." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Parsing input file \"/Users/jinningwang/work/miniconda3/envs/amsre/lib/python3.12/site-packages/ams/cases/5bus/pjm5bus_uced.xlsx\"...\n", "Input file parsed in 0.1254 seconds.\n", "Zero line rates detacted in rate_b, rate_c, adjusted to 999.\n", "System set up in 0.0016 seconds.\n" ] } ], "source": [ "sp = ams.load(ams.get_case('5bus/pjm5bus_uced.xlsx'),\n", " setup=True,\n", " no_output=True,)" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### Inspect Models and Routines" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "In AMS, ``model`` refers to the device-level models, and they are registered to an OrderedDict ``models``." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "OrderedDict([('Summary', Summary (3 devices) at 0x1044cecf0),\n", " ('Bus', Bus (5 devices) at 0x103f4e840),\n", " ('PQ', PQ (3 devices) at 0x336e2ab10),\n", " ('Slack', Slack (1 device) at 0x336e2b620),\n", " ('PV', PV (3 devices) at 0x336e2bfe0),\n", " ('Shunt', Shunt (0 devices) at 0x336e54aa0),\n", " ('Line', Line (7 devices) at 0x336e54e90),\n", " ('Jumper', Jumper (0 devices) at 0x336e55a00),\n", " ('PVD1', PVD1 (0 devices) at 0x336e28890),\n", " ('ESD1', ESD1 (0 devices) at 0x336e56690),\n", " ('EV1', EV1 (0 devices) at 0x336e56ba0),\n", " ('EV2', EV2 (0 devices) at 0x336e571a0),\n", " ('REGCA1', REGCA1 (0 devices) at 0x336e575c0),\n", " ('REGCV1', REGCV1 (0 devices) at 0x336e57d10),\n", " ('REGCV2', REGCV2 (0 devices) at 0x336e883e0),\n", " ('Area', Area (3 devices) at 0x336e88950),\n", " ('Zone', Zone (2 devices) at 0x336c8bd40),\n", " ('SFR', SFR (2 devices) at 0x336e2ae40),\n", " ('SR', SR (2 devices) at 0x336e89b50),\n", " ('NSR', NSR (2 devices) at 0x336e89f40),\n", " ('VSGR', VSGR (0 devices) at 0x336e8a300),\n", " ('GCost', GCost (4 devices) at 0x336e8a6f0),\n", " ('SFRCost', SFRCost (4 devices) at 0x336e8b0b0),\n", " ('SRCost', SRCost (4 devices) at 0x336e8b620),\n", " ('NSRCost', NSRCost (4 devices) at 0x336e8b9e0),\n", " ('VSGCost', VSGCost (0 devices) at 0x336e8bdd0),\n", " ('DCost', DCost (3 devices) at 0x336ec00e0),\n", " ('TimeSlot', TimeSlot (0 devices) at 0x336e57710),\n", " ('EDTSlot', EDTSlot (24 devices) at 0x336ec0c50),\n", " ('UCTSlot', UCTSlot (24 devices) at 0x336ec1040)])" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sp.models" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "We can inspect the detailed model data in the form of DataFrame." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
| \n", " | idx | \n", "u | \n", "name | \n", "bus | \n", "Vn | \n", "p0 | \n", "q0 | \n", "vmax | \n", "vmin | \n", "owner | \n", "ctrl | \n", "
|---|---|---|---|---|---|---|---|---|---|---|---|
| uid | \n", "\n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " |
| 0 | \n", "PQ_1 | \n", "1.0 | \n", "PQ 1 | \n", "Bus_2 | \n", "230.0 | \n", "3.0 | \n", "0.9861 | \n", "1.1 | \n", "0.9 | \n", "None | \n", "1.0 | \n", "
| 1 | \n", "PQ_2 | \n", "1.0 | \n", "PQ 2 | \n", "Bus_3 | \n", "230.0 | \n", "3.0 | \n", "0.9861 | \n", "1.1 | \n", "0.9 | \n", "None | \n", "1.0 | \n", "
| 2 | \n", "PQ_3 | \n", "1.0 | \n", "PQ 3 | \n", "Bus_4 | \n", "230.0 | \n", "4.0 | \n", "1.3147 | \n", "1.1 | \n", "0.9 | \n", "None | \n", "1.0 | \n", "