{ "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\n", "\n", "import datetime" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Last run time: 2024-01-24 09:37:17\n", "ams:0.8.1.post5+ge752692\n" ] } ], "source": [ "print(\"Last run time:\", datetime.datetime.now().strftime(\"%Y-%m-%d %H:%M:%S\"))\n", "\n", "print(f'ams:{ams.__version__}')" ] }, { "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": 3, "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 support 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": 4, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Parsing input file \"/Users/jinningwang/Documents/work/ams/ams/cases/5bus/pjm5bus_uced.xlsx\"...\n", "Input file parsed in 0.1218 seconds.\n", "Zero line rates detacted in rate_a, rate_b, rate_c, adjusted to 999.\n", "If expect a line outage, please set 'u' to 0.\n", "System set up in 0.0021 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 model, and all models are registered to an OrderedDict ``models``." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "OrderedDict([('Summary', Summary (3 devices) at 0x105584d30),\n", " ('Bus', Bus (5 devices) at 0x1056110d0),\n", " ('PQ', PQ (3 devices) at 0x12f9b8df0),\n", " ('PV', PV (3 devices) at 0x12f9caa60),\n", " ('Slack', Slack (1 device) at 0x12f9e0910),\n", " ('Shunt', Shunt (0 devices) at 0x12f9eb3d0),\n", " ('Line', Line (7 devices) at 0x12f9eb880),\n", " ('PVD1', PVD1 (0 devices) at 0x12f9f4f70),\n", " ('ESD1', ESD1 (0 devices) at 0x12fa065b0),\n", " ('REGCA1', REGCA1 (0 devices) at 0x12fa06b20),\n", " ('REGCV1', REGCV1 (0 devices) at 0x12fa11160),\n", " ('REGCV2', REGCV2 (0 devices) at 0x12fa11940),\n", " ('Area', Area (3 devices) at 0x12fa11e80),\n", " ('Region', Region (2 devices) at 0x12fa1e640),\n", " ('SFR', SFR (2 devices) at 0x12fa1edf0),\n", " ('SR', SR (2 devices) at 0x12fa2e490),\n", " ('NSR', NSR (2 devices) at 0x12fa2e8b0),\n", " ('VSGR', VSGR (0 devices) at 0x12fa2ecd0),\n", " ('GCost', GCost (4 devices) at 0x12fa3a160),\n", " ('SFRCost', SFRCost (4 devices) at 0x12fa3a7f0),\n", " ('SRCost', SRCost (4 devices) at 0x12fa3ad90),\n", " ('NSRCost', NSRCost (4 devices) at 0x12fa471f0),\n", " ('VSGCost', VSGCost (0 devices) at 0x12fa47610),\n", " ('DCost', DCost (3 devices) at 0x12fa47910),\n", " ('TimeSlot', TimeSlot (0 devices) at 0x12fa47e80),\n", " ('EDTSlot', EDTSlot (24 devices) at 0x12fa50940),\n", " ('UCTSlot', UCTSlot (24 devices) at 0x12fa50d60)])" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sp.models" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "One can inspect the detailed model data by converting it to a pandas DataFrame." ] }, { "cell_type": "code", "execution_count": 6, "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", "1 | \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", "2 | \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", "3 | \n", "230.0 | \n", "4.0 | \n", "1.3147 | \n", "1.1 | \n", "0.9 | \n", "None | \n", "1.0 | \n", "