diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2137b1f..da730d8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,7 +10,7 @@ jobs: linters: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: actions/setup-python@v4 with: python-version: "3.12" @@ -27,15 +27,15 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"] - matpower-version: ["7.0", "7.1"] + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] + matpower-version: ["7.0", "7.1", "8.0"] platform: [octave] runs-on: ubuntu-latest steps: - name: Clone this repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v4 @@ -46,24 +46,30 @@ jobs: - name: Install Octave (Linux) if: matrix.platform == 'octave' - uses: MATPOWER/action-install-octave-linux@v1 + run: | + sudo apt-add-repository -y ppa:ubuntuhandbook1/octave > /dev/null 2>&1 + sudo apt -qq update > /dev/null 2>&1 + sudo apt -y -qq install liboctave-dev octave > /dev/null 2>&1 - - name: Download matpower ${{ matrix.python-version }} + - name: Download matpower ${{ matrix.matpower-version }} run: | curl -L https://github.com/MATPOWER/matpower/archive/refs/tags/${{ matrix.matpower-version }}.zip > matpower.zip unzip matpower.zip -d temps mv temps/matpower-${{ matrix.matpower-version }} matpower cp matpowerpip/__init__.py matpower/__init__.py - - name: Install requirements + - name: Upgrade requirements run: | - pip install -r requirements-dev.txt + pip install pru --upgrade + pru -r requirements-dev.txt + + - name: Install requirements + run: pip install -r requirements-dev.txt - name: Install package - run: | - pip install -e . + run: pip install -e ."[dev]" - name: Test package run: | pip install --upgrade --no-cache-dir --force-reinstall jupyter_client ipykernel ipython tornado - pytest -n auto -rA -c pyproject.toml --cov-report term-missing --cov=matpower --nbmake + pytest -rA -c pyproject.toml --cov-report term-missing --cov=matpower --nbmake diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index ba2fae1..f88b8bd 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -7,15 +7,15 @@ jobs: build: strategy: matrix: - python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"] - matpower-version: ["7.0", "7.1"] + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] + matpower-version: ["7.0", "7.1", "8.0"] platform: [octave] runs-on: ubuntu-latest steps: - name: Clone this repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v4 @@ -26,26 +26,33 @@ jobs: - name: Install Octave (Linux) if: matrix.platform == 'octave' - uses: MATPOWER/action-install-octave-linux@v1 + run: | + sudo apt-add-repository -y ppa:ubuntuhandbook1/octave > /dev/null 2>&1 + sudo apt -qq update > /dev/null 2>&1 + sudo apt -y -qq install liboctave-dev octave > /dev/null 2>&1 - - name: Download matpower ${{ matrix.python-version }} + - name: Download matpower ${{ matrix.matpower-version }} run: | curl -L https://github.com/MATPOWER/matpower/archive/refs/tags/${{ matrix.matpower-version }}.zip > matpower.zip unzip matpower.zip -d temps mv temps/matpower-${{ matrix.matpower-version }} matpower cp matpowerpip/__init__.py matpower/__init__.py - - name: Install requirements + - name: Upgrade requirements run: | - pip install -r requirements-dev.txt + pip install pru --upgrade + pru -r requirements-dev.txt + + - name: Install requirements + run: pip install -r requirements-dev.txt - name: Install package - run: | - pip install -e . + run: pip install -e ."[dev]" - name: Test package run: | - pytest -n auto -rA -c pyproject.toml --cov-report term-missing --cov=matpower --nbmake + pip install --upgrade --no-cache-dir --force-reinstall jupyter_client ipykernel ipython tornado + pytest -rA -c pyproject.toml --cov-report term-missing --cov=matpower --nbmake deploy: needs: build @@ -57,7 +64,7 @@ jobs: steps: - name: Clone this repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up Python 3.9 uses: actions/setup-python@v4 diff --git a/.gitignore b/.gitignore index 709a98c..44f8137 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,13 @@ # Acknowledgement # This template is based on: https://raw.githubusercontent.com/github/gitignore/master/Python.gitignore +# Octave +octave-workspace + # Matpower +matpower7.0/ +matpower-7.1/ +matpower-8.0/ matpower/ matpower.zip backups/ @@ -9,9 +15,10 @@ backups/ # Token .pypirc -# Playground +# Private playgrounds/ playground.ipynb +.private/ # Editor .vscode/ diff --git a/COMMANDS.md b/COMMANDS.md index a2105e9..c8ed894 100644 --- a/COMMANDS.md +++ b/COMMANDS.md @@ -4,8 +4,28 @@ Place to save some commands related to matpower-pip development, deployment, and ## Download MATPOWER +### Python + +Directly use `downloader.py`: + +```powershell +cd matpowerpip +py downloader.py +``` + +With `matpowerpip`: + +```python +from matpowerpip.downloader import download_matpower, copy_init + +download_matpower(matpower_version='8.0') +copy_init() +``` + ### Windows (`cmd`) + + MATPOWER 7.1 ```plaintext @@ -31,25 +51,7 @@ Note: Sometimes it is not working from inside `vscode` terminal, since `vscode` - -### Python - -Directly use `downloader.py`: - -```powershell -cd matpowerpip -py downloader.py -``` - -With `matpowerpip`: - -```python -from matpowerpip.downloader import download_matpower, copy_init - -download_matpower(matpower_version='8.0b1') -copy_init() -``` +--> ## Delete dist diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d8d615d..e5602d4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -37,7 +37,34 @@ deactivate ## Install requirements ```shell -pip install -r requirements.txt +pip install pru --upgrade +pru -r requirements-latest.txt +``` + +## Download and copy matpower + +```shell +python3 +``` + +```python +from matpowerpip.downloader import download_matpower, copy_init + +download_matpower(matpower_version='7.1') +copy_init() +``` + +## Install in development mode + +```shell +pip install -e ."[dev]" +``` + +## pytest + +```shell +pytest -n auto -rA -c pyproject.toml --cov-report term-missing --cov=matpower +pytest -rA -c pyproject.toml --cov-report term-missing --cov=matpower --nbmake ``` ## Notebook example @@ -59,8 +86,9 @@ pip install -r requirements.txt ```ipython # install octave - !sudo apt-get -qq update - !sudo apt-get -qq install octave octave-signal liboctave-dev + !sudo apt-add-repository -y ppa:ubuntuhandbook1/octave > /dev/null 2>&1 + !sudo apt -qq update > /dev/null 2>&1 + !sudo apt -y -qq install liboctave-dev octave > /dev/null 2>&1 # install oct2py that compatible with colab import os @@ -100,3 +128,9 @@ Use pandoc and wkhtmltopdf to create README.pdf ```shell pandoc --pdf-engine=wkhtmltopdf README.md -o README.pdf ``` + +## Install oct2py in dev locally + +```shell +cd ../oct2py && pip install -e ".[test]" && cd - +``` diff --git a/dev/check_runpf.ipynb b/dev/check_runpf.ipynb new file mode 100644 index 0000000..c7d82bc --- /dev/null +++ b/dev/check_runpf.ipynb @@ -0,0 +1,1003 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "%load_ext autoreload\n", + "%autoreload 2" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "import oct2py\n", + "\n", + "from matpower import start_instance" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'5.7.0'" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "oct2py.__version__" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\u001b[?2004l\n", + "\u001b[?2004l\n", + "\u001b[?2004l\n", + "\u001b[?2004l\n", + "\u001b[?2004l\n", + "\u001b[?2004l\n", + "\u001b[?2004l\n" + ] + } + ], + "source": [ + "m = start_instance()" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\u001b[?2004l\n", + "\u001b[?2004l\n", + "\u001b[?2004l\n" + ] + } + ], + "source": [ + "m.eval(\"warning('off', 'Octave:classdef-to-struct');\")" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\u001b[?2004l\n", + "\u001b[?2004l\n" + ] + }, + { + "data": { + "text/plain": [ + "{'version': '2',\n", + " 'baseMVA': 100.0,\n", + " 'bus': array([[ 1. , 3. , 0. , 0. , 0. , 0. , 1. , 1. , 0. ,\n", + " 345. , 1. , 1.1, 0.9],\n", + " [ 2. , 2. , 0. , 0. , 0. , 0. , 1. , 1. , 0. ,\n", + " 345. , 1. , 1.1, 0.9],\n", + " [ 3. , 2. , 0. , 0. , 0. , 0. , 1. , 1. , 0. ,\n", + " 345. , 1. , 1.1, 0.9],\n", + " [ 4. , 1. , 0. , 0. , 0. , 0. , 1. , 1. , 0. ,\n", + " 345. , 1. , 1.1, 0.9],\n", + " [ 5. , 1. , 90. , 30. , 0. , 0. , 1. , 1. , 0. ,\n", + " 345. , 1. , 1.1, 0.9],\n", + " [ 6. , 1. , 0. , 0. , 0. , 0. , 1. , 1. , 0. ,\n", + " 345. , 1. , 1.1, 0.9],\n", + " [ 7. , 1. , 100. , 35. , 0. , 0. , 1. , 1. , 0. ,\n", + " 345. , 1. , 1.1, 0.9],\n", + " [ 8. , 1. , 0. , 0. , 0. , 0. , 1. , 1. , 0. ,\n", + " 345. , 1. , 1.1, 0.9],\n", + " [ 9. , 1. , 125. , 50. , 0. , 0. , 1. , 1. , 0. ,\n", + " 345. , 1. , 1.1, 0.9]]),\n", + " 'gen': array([[ 1. , 72.3 , 27.03 , 300. , -300. , 1.04 ,\n", + " 100. , 1. , 250. , 10. , 0. , 0. ,\n", + " 0. , 0. , 0. , 0. , 0. , 0. ,\n", + " 0. , 0. , 0. ],\n", + " [ 2. , 163. , 6.54 , 300. , -300. , 1.025,\n", + " 100. , 1. , 300. , 10. , 0. , 0. ,\n", + " 0. , 0. , 0. , 0. , 0. , 0. ,\n", + " 0. , 0. , 0. ],\n", + " [ 3. , 85. , -10.95 , 300. , -300. , 1.025,\n", + " 100. , 1. , 270. , 10. , 0. , 0. ,\n", + " 0. , 0. , 0. , 0. , 0. , 0. ,\n", + " 0. , 0. , 0. ]]),\n", + " 'branch': array([[ 1.000e+00, 4.000e+00, 0.000e+00, 5.760e-02, 0.000e+00,\n", + " 2.500e+02, 2.500e+02, 2.500e+02, 0.000e+00, 0.000e+00,\n", + " 1.000e+00, -3.600e+02, 3.600e+02],\n", + " [ 4.000e+00, 5.000e+00, 1.700e-02, 9.200e-02, 1.580e-01,\n", + " 2.500e+02, 2.500e+02, 2.500e+02, 0.000e+00, 0.000e+00,\n", + " 1.000e+00, -3.600e+02, 3.600e+02],\n", + " [ 5.000e+00, 6.000e+00, 3.900e-02, 1.700e-01, 3.580e-01,\n", + " 1.500e+02, 1.500e+02, 1.500e+02, 0.000e+00, 0.000e+00,\n", + " 1.000e+00, -3.600e+02, 3.600e+02],\n", + " [ 3.000e+00, 6.000e+00, 0.000e+00, 5.860e-02, 0.000e+00,\n", + " 3.000e+02, 3.000e+02, 3.000e+02, 0.000e+00, 0.000e+00,\n", + " 1.000e+00, -3.600e+02, 3.600e+02],\n", + " [ 6.000e+00, 7.000e+00, 1.190e-02, 1.008e-01, 2.090e-01,\n", + " 1.500e+02, 1.500e+02, 1.500e+02, 0.000e+00, 0.000e+00,\n", + " 1.000e+00, -3.600e+02, 3.600e+02],\n", + " [ 7.000e+00, 8.000e+00, 8.500e-03, 7.200e-02, 1.490e-01,\n", + " 2.500e+02, 2.500e+02, 2.500e+02, 0.000e+00, 0.000e+00,\n", + " 1.000e+00, -3.600e+02, 3.600e+02],\n", + " [ 8.000e+00, 2.000e+00, 0.000e+00, 6.250e-02, 0.000e+00,\n", + " 2.500e+02, 2.500e+02, 2.500e+02, 0.000e+00, 0.000e+00,\n", + " 1.000e+00, -3.600e+02, 3.600e+02],\n", + " [ 8.000e+00, 9.000e+00, 3.200e-02, 1.610e-01, 3.060e-01,\n", + " 2.500e+02, 2.500e+02, 2.500e+02, 0.000e+00, 0.000e+00,\n", + " 1.000e+00, -3.600e+02, 3.600e+02],\n", + " [ 9.000e+00, 4.000e+00, 1.000e-02, 8.500e-02, 1.760e-01,\n", + " 2.500e+02, 2.500e+02, 2.500e+02, 0.000e+00, 0.000e+00,\n", + " 1.000e+00, -3.600e+02, 3.600e+02]]),\n", + " 'gencost': array([[2.000e+00, 1.500e+03, 0.000e+00, 3.000e+00, 1.100e-01, 5.000e+00,\n", + " 1.500e+02],\n", + " [2.000e+00, 2.000e+03, 0.000e+00, 3.000e+00, 8.500e-02, 1.200e+00,\n", + " 6.000e+02],\n", + " [2.000e+00, 3.000e+03, 0.000e+00, 3.000e+00, 1.225e-01, 1.000e+00,\n", + " 3.350e+02]])}" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "mpc = m.loadcase(\"case9\", verbose=False)\n", + "mpc" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\u001b[?2004l\n", + "\n", + "MATPOWER Version 8.0, 17-May-2024\n", + "Power Flow -- AC-polar-power formulation\n", + "\n", + "Newton's method converged in 4 iterations.\n", + "PF successful\n", + "\n", + "Converged in 0.11 seconds\n", + "================================================================================\n", + "| System Summary |\n", + "================================================================================\n", + "\n", + "How many? How much? P (MW) Q (MVAr)\n", + "--------------------- ------------------- ------------- -----------------\n", + "Buses 9 Total Gen Capacity 820.0 -900.0 to 900.0\n", + "Generators 3 On-line Capacity 820.0 -900.0 to 900.0\n", + "Committed Gens 3 Generation (actual) 319.6 22.8\n", + "Loads 3 Load 315.0 115.0\n", + " Fixed 3 Fixed 315.0 115.0\n", + " Dispatchable 0 Dispatchable -0.0 of -0.0 -0.0\n", + "Shunts 0 Shunt (inj) -0.0 0.0\n", + "Branches 9 Losses (I^2 * Z) 4.64 48.38\n", + "Transformers 0 Branch Charging (inj) - 140.5\n", + "Inter-ties 0 Total Inter-tie Flow 0.0 0.0\n", + "Areas 1\n", + "\n", + " Minimum Maximum\n", + " ------------------------- --------------------------------\n", + "Voltage Magnitude 0.996 p.u. @ bus 9 1.040 p.u. @ bus 1\n", + "Voltage Angle -3.99 deg @ bus 9 9.28 deg @ bus 2\n", + "P Losses (I^2*R) - 2.30 MW @ line 8-9\n", + "Q Losses (I^2*X) - 15.83 MVAr @ line 8-2\n", + "\n", + "================================================================================\n", + "| Bus Data |\n", + "================================================================================\n", + " Bus Voltage Generation Load\n", + " # Mag(pu) Ang(deg) P (MW) Q (MVAr) P (MW) Q (MVAr)\n", + "----- ------- -------- -------- -------- -------- --------\n", + " 1 1.040 0.000* 71.64 27.05 - -\n", + " 2 1.025 9.280 163.00 6.65 - -\n", + " 3 1.025 4.665 85.00 -10.86 - -\n", + " 4 1.026 -2.217 - - - -\n", + " 5 1.013 -3.687 - - 90.00 30.00\n", + " 6 1.032 1.967 - - - -\n", + " 7 1.016 0.728 - - 100.00 35.00\n", + " 8 1.026 3.720 - - - -\n", + " 9 0.996 -3.989 - - 125.00 50.00\n", + " -------- -------- -------- --------\n", + " Total: 319.64 22.84 315.00 115.00\n", + "\n", + "================================================================================\n", + "| Branch Data |\n", + "================================================================================\n", + "Brnch From To From Bus Injection To Bus Injection Loss (I^2 * Z)\n", + " # Bus Bus P (MW) Q (MVAr) P (MW) Q (MVAr) P (MW) Q (MVAr)\n", + "----- ----- ----- -------- -------- -------- -------- -------- --------\n", + " 1 1 4 71.64 27.05 -71.64 -23.92 0.000 3.12\n", + " 2 4 5 30.70 1.03 -30.54 -16.54 0.166 0.90\n", + " 3 5 6 -59.46 -13.46 60.82 -18.07 1.354 5.90\n", + " 4 3 6 85.00 -10.86 -85.00 14.96 0.000 4.10\n", + " 5 6 7 24.18 3.12 -24.10 -24.30 0.088 0.75\n", + " 6 7 8 -75.90 -10.70 76.38 -0.80 0.475 4.03\n", + " 7 8 2 -163.00 9.18 163.00 6.65 0.000 15.83\n", + " 8 8 9 86.62 -8.38 -84.32 -11.31 2.300 11.57\n", + " 9 9 4 -40.68 -38.69 40.94 22.89 0.258 2.19\n", + " -------- --------\n", + " Total: 4.641 48.38\n", + "warning: save: wrong type argument 'function handle'\n", + "warning: called from\n", + " _pyeval>save_safe_struct at line 119 column 9\n", + " _pyeval at line 97 column 3\n", + "\n", + "warning: Skipping field \"task\" as it is not an acceptable type.\n", + "warning: called from\n", + " _pyeval>clean_struct at line 138 column 13\n", + " _pyeval>save_safe_struct at line 124 column 25\n", + " _pyeval at line 97 column 3\n", + "\n", + "warning: Skipping field \"om\" as it is not an acceptable type.\n", + "warning: called from\n", + " _pyeval>clean_struct at line 138 column 13\n", + " _pyeval>save_safe_struct at line 124 column 25\n", + " _pyeval at line 97 column 3\n", + "\n" + ] + }, + { + "data": { + "text/plain": [ + "{'version': '2',\n", + " 'baseMVA': 100.0,\n", + " 'bus': array([[ 1. , 3. , 0. , 0. ,\n", + " 0. , 0. , 1. , 1.04 ,\n", + " 0. , 345. , 1. , 1.1 ,\n", + " 0.9 ],\n", + " [ 2. , 2. , 0. , 0. ,\n", + " 0. , 0. , 1. , 1.025 ,\n", + " 9.28000548, 345. , 1. , 1.1 ,\n", + " 0.9 ],\n", + " [ 3. , 2. , 0. , 0. ,\n", + " 0. , 0. , 1. , 1.025 ,\n", + " 4.66475133, 345. , 1. , 1.1 ,\n", + " 0.9 ],\n", + " [ 4. , 1. , 0. , 0. ,\n", + " 0. , 0. , 1. , 1.02578839,\n", + " -2.2167878 , 345. , 1. , 1.1 ,\n", + " 0.9 ],\n", + " [ 5. , 1. , 90. , 30. ,\n", + " 0. , 0. , 1. , 1.01265432,\n", + " -3.68739617, 345. , 1. , 1.1 ,\n", + " 0.9 ],\n", + " [ 6. , 1. , 0. , 0. ,\n", + " 0. , 0. , 1. , 1.03235295,\n", + " 1.96671607, 345. , 1. , 1.1 ,\n", + " 0.9 ],\n", + " [ 7. , 1. , 100. , 35. ,\n", + " 0. , 0. , 1. , 1.01588258,\n", + " 0.72753608, 345. , 1. , 1.1 ,\n", + " 0.9 ],\n", + " [ 8. , 1. , 0. , 0. ,\n", + " 0. , 0. , 1. , 1.02576937,\n", + " 3.71970115, 345. , 1. , 1.1 ,\n", + " 0.9 ],\n", + " [ 9. , 1. , 125. , 50. ,\n", + " 0. , 0. , 1. , 0.99563086,\n", + " -3.98880527, 345. , 1. , 1.1 ,\n", + " 0.9 ]]),\n", + " 'gen': array([[ 1. , 71.64102147, 27.04592353, 300. ,\n", + " -300. , 1.04 , 100. , 1. ,\n", + " 250. , 10. , 0. , 0. ,\n", + " 0. , 0. , 0. , 0. ,\n", + " 0. , 0. , 0. , 0. ,\n", + " 0. ],\n", + " [ 2. , 163. , 6.65366032, 300. ,\n", + " -300. , 1.025 , 100. , 1. ,\n", + " 300. , 10. , 0. , 0. ,\n", + " 0. , 0. , 0. , 0. ,\n", + " 0. , 0. , 0. , 0. ,\n", + " 0. ],\n", + " [ 3. , 85. , -10.85970907, 300. ,\n", + " -300. , 1.025 , 100. , 1. ,\n", + " 270. , 10. , 0. , 0. ,\n", + " 0. , 0. , 0. , 0. ,\n", + " 0. , 0. , 0. , 0. ,\n", + " 0. ]]),\n", + " 'branch': array([[ 1.00000000e+00, 4.00000000e+00, 0.00000000e+00,\n", + " 5.76000000e-02, 0.00000000e+00, 2.50000000e+02,\n", + " 2.50000000e+02, 2.50000000e+02, 0.00000000e+00,\n", + " 0.00000000e+00, 1.00000000e+00, -3.60000000e+02,\n", + " 3.60000000e+02, 7.16410215e+01, 2.70459235e+01,\n", + " -7.16410215e+01, -2.39231270e+01],\n", + " [ 4.00000000e+00, 5.00000000e+00, 1.70000000e-02,\n", + " 9.20000000e-02, 1.58000000e-01, 2.50000000e+02,\n", + " 2.50000000e+02, 2.50000000e+02, 0.00000000e+00,\n", + " 0.00000000e+00, 1.00000000e+00, -3.60000000e+02,\n", + " 3.60000000e+02, 3.07036698e+01, 1.03000637e+00,\n", + " -3.05372629e+01, -1.65433652e+01],\n", + " [ 5.00000000e+00, 6.00000000e+00, 3.90000000e-02,\n", + " 1.70000000e-01, 3.58000000e-01, 1.50000000e+02,\n", + " 1.50000000e+02, 1.50000000e+02, 0.00000000e+00,\n", + " 0.00000000e+00, 1.00000000e+00, -3.60000000e+02,\n", + " 3.60000000e+02, -5.94627371e+01, -1.34566348e+01,\n", + " 6.08165860e+01, -1.80748357e+01],\n", + " [ 3.00000000e+00, 6.00000000e+00, 0.00000000e+00,\n", + " 5.86000000e-02, 0.00000000e+00, 3.00000000e+02,\n", + " 3.00000000e+02, 3.00000000e+02, 0.00000000e+00,\n", + " 0.00000000e+00, 1.00000000e+00, -3.60000000e+02,\n", + " 3.60000000e+02, 8.50000000e+01, -1.08597091e+01,\n", + " -8.50000000e+01, 1.49553273e+01],\n", + " [ 6.00000000e+00, 7.00000000e+00, 1.19000000e-02,\n", + " 1.00800000e-01, 2.09000000e-01, 1.50000000e+02,\n", + " 1.50000000e+02, 1.50000000e+02, 0.00000000e+00,\n", + " 0.00000000e+00, 1.00000000e+00, -3.60000000e+02,\n", + " 3.60000000e+02, 2.41834140e+01, 3.11950842e+00,\n", + " -2.40954175e+01, -2.42958226e+01],\n", + " [ 7.00000000e+00, 8.00000000e+00, 8.50000000e-03,\n", + " 7.20000000e-02, 1.49000000e-01, 2.50000000e+02,\n", + " 2.50000000e+02, 2.50000000e+02, 0.00000000e+00,\n", + " 0.00000000e+00, 1.00000000e+00, -3.60000000e+02,\n", + " 3.60000000e+02, -7.59045825e+01, -1.07041774e+01,\n", + " 7.63798662e+01, -7.97331442e-01],\n", + " [ 8.00000000e+00, 2.00000000e+00, 0.00000000e+00,\n", + " 6.25000000e-02, 0.00000000e+00, 2.50000000e+02,\n", + " 2.50000000e+02, 2.50000000e+02, 0.00000000e+00,\n", + " 0.00000000e+00, 1.00000000e+00, -3.60000000e+02,\n", + " 3.60000000e+02, -1.63000000e+02, 9.17814884e+00,\n", + " 1.63000000e+02, 6.65366032e+00],\n", + " [ 8.00000000e+00, 9.00000000e+00, 3.20000000e-02,\n", + " 1.61000000e-01, 3.06000000e-01, 2.50000000e+02,\n", + " 2.50000000e+02, 2.50000000e+02, 0.00000000e+00,\n", + " 0.00000000e+00, 1.00000000e+00, -3.60000000e+02,\n", + " 3.60000000e+02, 8.66201338e+01, -8.38081740e+00,\n", + " -8.43201625e+01, -1.13127512e+01],\n", + " [ 9.00000000e+00, 4.00000000e+00, 1.00000000e-02,\n", + " 8.50000000e-02, 1.76000000e-01, 2.50000000e+02,\n", + " 2.50000000e+02, 2.50000000e+02, 0.00000000e+00,\n", + " 0.00000000e+00, 1.00000000e+00, -3.60000000e+02,\n", + " 3.60000000e+02, -4.06798375e+01, -3.86872488e+01,\n", + " 4.09373517e+01, 2.28931206e+01]]),\n", + " 'gencost': array([[2.000e+00, 1.500e+03, 0.000e+00, 3.000e+00, 1.100e-01, 5.000e+00,\n", + " 1.500e+02],\n", + " [2.000e+00, 2.000e+03, 0.000e+00, 3.000e+00, 8.500e-02, 1.200e+00,\n", + " 6.000e+02],\n", + " [2.000e+00, 3.000e+03, 0.000e+00, 3.000e+00, 1.225e-01, 1.000e+00,\n", + " 3.350e+02]]),\n", + " 'order': {'bus': {'e2i': <9x1 sparse matrix of type ''\n", + " \twith 9 stored elements in Compressed Sparse Column format>,\n", + " 'i2e': array([[1.],\n", + " [2.],\n", + " [3.],\n", + " [4.],\n", + " [5.],\n", + " [6.],\n", + " [7.],\n", + " [8.],\n", + " [9.]]),\n", + " 'status': {'on': array([[1.],\n", + " [2.],\n", + " [3.],\n", + " [4.],\n", + " [5.],\n", + " [6.],\n", + " [7.],\n", + " [8.],\n", + " [9.]]),\n", + " 'off': []}},\n", + " 'gen': {'e2i': array([[1.],\n", + " [2.],\n", + " [3.]]),\n", + " 'i2e': array([[1.],\n", + " [2.],\n", + " [3.]]),\n", + " 'status': {'on': array([[1.],\n", + " [2.],\n", + " [3.]]),\n", + " 'off': []}},\n", + " 'branch': {'status': {'on': array([[1.],\n", + " [2.],\n", + " [3.],\n", + " [4.],\n", + " [5.],\n", + " [6.],\n", + " [7.],\n", + " [8.],\n", + " [9.]]),\n", + " 'off': []}},\n", + " 'state': 'e',\n", + " 'int': {'bus': array([[ 1. , 3. , 0. , 0. ,\n", + " 0. , 0. , 1. , 1.04 ,\n", + " 0. , 345. , 1. , 1.1 ,\n", + " 0.9 ],\n", + " [ 2. , 2. , 0. , 0. ,\n", + " 0. , 0. , 1. , 1.025 ,\n", + " 9.28000548, 345. , 1. , 1.1 ,\n", + " 0.9 ],\n", + " [ 3. , 2. , 0. , 0. ,\n", + " 0. , 0. , 1. , 1.025 ,\n", + " 4.66475133, 345. , 1. , 1.1 ,\n", + " 0.9 ],\n", + " [ 4. , 1. , 0. , 0. ,\n", + " 0. , 0. , 1. , 1.02578839,\n", + " -2.2167878 , 345. , 1. , 1.1 ,\n", + " 0.9 ],\n", + " [ 5. , 1. , 90. , 30. ,\n", + " 0. , 0. , 1. , 1.01265432,\n", + " -3.68739617, 345. , 1. , 1.1 ,\n", + " 0.9 ],\n", + " [ 6. , 1. , 0. , 0. ,\n", + " 0. , 0. , 1. , 1.03235295,\n", + " 1.96671607, 345. , 1. , 1.1 ,\n", + " 0.9 ],\n", + " [ 7. , 1. , 100. , 35. ,\n", + " 0. , 0. , 1. , 1.01588258,\n", + " 0.72753608, 345. , 1. , 1.1 ,\n", + " 0.9 ],\n", + " [ 8. , 1. , 0. , 0. ,\n", + " 0. , 0. , 1. , 1.02576937,\n", + " 3.71970115, 345. , 1. , 1.1 ,\n", + " 0.9 ],\n", + " [ 9. , 1. , 125. , 50. ,\n", + " 0. , 0. , 1. , 0.99563086,\n", + " -3.98880527, 345. , 1. , 1.1 ,\n", + " 0.9 ]]),\n", + " 'branch': array([[ 1.00000000e+00, 4.00000000e+00, 0.00000000e+00,\n", + " 5.76000000e-02, 0.00000000e+00, 2.50000000e+02,\n", + " 2.50000000e+02, 2.50000000e+02, 0.00000000e+00,\n", + " 0.00000000e+00, 1.00000000e+00, -3.60000000e+02,\n", + " 3.60000000e+02, 7.16410215e+01, 2.70459235e+01,\n", + " -7.16410215e+01, -2.39231270e+01],\n", + " [ 4.00000000e+00, 5.00000000e+00, 1.70000000e-02,\n", + " 9.20000000e-02, 1.58000000e-01, 2.50000000e+02,\n", + " 2.50000000e+02, 2.50000000e+02, 0.00000000e+00,\n", + " 0.00000000e+00, 1.00000000e+00, -3.60000000e+02,\n", + " 3.60000000e+02, 3.07036698e+01, 1.03000637e+00,\n", + " -3.05372629e+01, -1.65433652e+01],\n", + " [ 5.00000000e+00, 6.00000000e+00, 3.90000000e-02,\n", + " 1.70000000e-01, 3.58000000e-01, 1.50000000e+02,\n", + " 1.50000000e+02, 1.50000000e+02, 0.00000000e+00,\n", + " 0.00000000e+00, 1.00000000e+00, -3.60000000e+02,\n", + " 3.60000000e+02, -5.94627371e+01, -1.34566348e+01,\n", + " 6.08165860e+01, -1.80748357e+01],\n", + " [ 3.00000000e+00, 6.00000000e+00, 0.00000000e+00,\n", + " 5.86000000e-02, 0.00000000e+00, 3.00000000e+02,\n", + " 3.00000000e+02, 3.00000000e+02, 0.00000000e+00,\n", + " 0.00000000e+00, 1.00000000e+00, -3.60000000e+02,\n", + " 3.60000000e+02, 8.50000000e+01, -1.08597091e+01,\n", + " -8.50000000e+01, 1.49553273e+01],\n", + " [ 6.00000000e+00, 7.00000000e+00, 1.19000000e-02,\n", + " 1.00800000e-01, 2.09000000e-01, 1.50000000e+02,\n", + " 1.50000000e+02, 1.50000000e+02, 0.00000000e+00,\n", + " 0.00000000e+00, 1.00000000e+00, -3.60000000e+02,\n", + " 3.60000000e+02, 2.41834140e+01, 3.11950842e+00,\n", + " -2.40954175e+01, -2.42958226e+01],\n", + " [ 7.00000000e+00, 8.00000000e+00, 8.50000000e-03,\n", + " 7.20000000e-02, 1.49000000e-01, 2.50000000e+02,\n", + " 2.50000000e+02, 2.50000000e+02, 0.00000000e+00,\n", + " 0.00000000e+00, 1.00000000e+00, -3.60000000e+02,\n", + " 3.60000000e+02, -7.59045825e+01, -1.07041774e+01,\n", + " 7.63798662e+01, -7.97331442e-01],\n", + " [ 8.00000000e+00, 2.00000000e+00, 0.00000000e+00,\n", + " 6.25000000e-02, 0.00000000e+00, 2.50000000e+02,\n", + " 2.50000000e+02, 2.50000000e+02, 0.00000000e+00,\n", + " 0.00000000e+00, 1.00000000e+00, -3.60000000e+02,\n", + " 3.60000000e+02, -1.63000000e+02, 9.17814884e+00,\n", + " 1.63000000e+02, 6.65366032e+00],\n", + " [ 8.00000000e+00, 9.00000000e+00, 3.20000000e-02,\n", + " 1.61000000e-01, 3.06000000e-01, 2.50000000e+02,\n", + " 2.50000000e+02, 2.50000000e+02, 0.00000000e+00,\n", + " 0.00000000e+00, 1.00000000e+00, -3.60000000e+02,\n", + " 3.60000000e+02, 8.66201338e+01, -8.38081740e+00,\n", + " -8.43201625e+01, -1.13127512e+01],\n", + " [ 9.00000000e+00, 4.00000000e+00, 1.00000000e-02,\n", + " 8.50000000e-02, 1.76000000e-01, 2.50000000e+02,\n", + " 2.50000000e+02, 2.50000000e+02, 0.00000000e+00,\n", + " 0.00000000e+00, 1.00000000e+00, -3.60000000e+02,\n", + " 3.60000000e+02, -4.06798375e+01, -3.86872488e+01,\n", + " 4.09373517e+01, 2.28931206e+01]]),\n", + " 'gen': array([[ 1. , 71.64102147, 27.04592353, 300. ,\n", + " -300. , 1.04 , 100. , 1. ,\n", + " 250. , 10. , 0. , 0. ,\n", + " 0. , 0. , 0. , 0. ,\n", + " 0. , 0. , 0. , 0. ,\n", + " 0. ],\n", + " [ 2. , 163. , 6.65366032, 300. ,\n", + " -300. , 1.025 , 100. , 1. ,\n", + " 300. , 10. , 0. , 0. ,\n", + " 0. , 0. , 0. , 0. ,\n", + " 0. , 0. , 0. , 0. ,\n", + " 0. ],\n", + " [ 3. , 85. , -10.85970907, 300. ,\n", + " -300. , 1.025 , 100. , 1. ,\n", + " 270. , 10. , 0. , 0. ,\n", + " 0. , 0. , 0. , 0. ,\n", + " 0. , 0. , 0. , 0. ,\n", + " 0. ]])}},\n", + " 'et': 0.1103510856628418,\n", + " 'success': 1,\n", + " 'iterations': 4.0}" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "m.runpf(mpc, verbose=True)" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\u001b[?2004l\n", + "\u001b[?2004l\n", + "\u001b[?2004l\n", + "\n", + "MATPOWER Version 8.0, 17-May-2024\n", + "Power Flow -- AC-polar-power formulation\n", + "\n", + "Newton's method converged in 4 iterations.\n", + "PF successful\n", + "\n", + "Converged in 0.08 seconds\n", + "================================================================================\n", + "| System Summary |\n", + "================================================================================\n", + "\n", + "How many? How much? P (MW) Q (MVAr)\n", + "--------------------- ------------------- ------------- -----------------\n", + "Buses 9 Total Gen Capacity 820.0 -900.0 to 900.0\n", + "Generators 3 On-line Capacity 820.0 -900.0 to 900.0\n", + "Committed Gens 3 Generation (actual) 319.6 22.8\n", + "Loads 3 Load 315.0 115.0\n", + " Fixed 3 Fixed 315.0 115.0\n", + " Dispatchable 0 Dispatchable -0.0 of -0.0 -0.0\n", + "Shunts 0 Shunt (inj) -0.0 0.0\n", + "Branches 9 Losses (I^2 * Z) 4.64 48.38\n", + "Transformers 0 Branch Charging (inj) - 140.5\n", + "Inter-ties 0 Total Inter-tie Flow 0.0 0.0\n", + "Areas 1\n", + "\n", + " Minimum Maximum\n", + " ------------------------- --------------------------------\n", + "Voltage Magnitude 0.996 p.u. @ bus 9 1.040 p.u. @ bus 1\n", + "Voltage Angle -3.99 deg @ bus 9 9.28 deg @ bus 2\n", + "P Losses (I^2*R) - 2.30 MW @ line 8-9\n", + "Q Losses (I^2*X) - 15.83 MVAr @ line 8-2\n", + "\n", + "================================================================================\n", + "| Bus Data |\n", + "================================================================================\n", + " Bus Voltage Generation Load\n", + " # Mag(pu) Ang(deg) P (MW) Q (MVAr) P (MW) Q (MVAr)\n", + "----- ------- -------- -------- -------- -------- --------\n", + " 1 1.040 0.000* 71.64 27.05 - -\n", + " 2 1.025 9.280 163.00 6.65 - -\n", + " 3 1.025 4.665 85.00 -10.86 - -\n", + " 4 1.026 -2.217 - - - -\n", + " 5 1.013 -3.687 - - 90.00 30.00\n", + " 6 1.032 1.967 - - - -\n", + " 7 1.016 0.728 - - 100.00 35.00\n", + " 8 1.026 3.720 - - - -\n", + " 9 0.996 -3.989 - - 125.00 50.00\n", + " -------- -------- -------- --------\n", + " Total: 319.64 22.84 315.00 115.00\n", + "\n", + "================================================================================\n", + "| Branch Data |\n", + "================================================================================\n", + "Brnch From To From Bus Injection To Bus Injection Loss (I^2 * Z)\n", + " # Bus Bus P (MW) Q (MVAr) P (MW) Q (MVAr) P (MW) Q (MVAr)\n", + "----- ----- ----- -------- -------- -------- -------- -------- --------\n", + " 1 1 4 71.64 27.05 -71.64 -23.92 0.000 3.12\n", + " 2 4 5 30.70 1.03 -30.54 -16.54 0.166 0.90\n", + " 3 5 6 -59.46 -13.46 60.82 -18.07 1.354 5.90\n", + " 4 3 6 85.00 -10.86 -85.00 14.96 0.000 4.10\n", + " 5 6 7 24.18 3.12 -24.10 -24.30 0.088 0.75\n", + " 6 7 8 -75.90 -10.70 76.38 -0.80 0.475 4.03\n", + " 7 8 2 -163.00 9.18 163.00 6.65 0.000 15.83\n", + " 8 8 9 86.62 -8.38 -84.32 -11.31 2.300 11.57\n", + " 9 9 4 -40.68 -38.69 40.94 22.89 0.258 2.19\n", + " -------- --------\n", + " Total: 4.641 48.38\n", + "\u001b[?2004l\n", + "\u001b[?2004l\n" + ] + }, + { + "data": { + "text/plain": [ + "Cell(['version', 'baseMVA', 'bus', 'gen', 'branch', 'gencost', 'order',\n", + " 'task', 'et', 'success', 'iterations', 'om'])" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "m.push(\"_mpc\", mpc, verbose=False)\n", + "m.eval(\"_r1 = runpf(_mpc);\", verbose=True)\n", + "fieldnames_r1 = m.eval(\"fieldnames(_r1);\", verbose=False)\n", + "fieldnames_r1.ravel()" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\u001b[?2004l\n", + "\u001b[?2004l\n", + "\u001b[?2004l\n", + "\u001b[?2004l\n", + "\u001b[?2004l\n", + "\u001b[?2004l\n", + "\u001b[?2004l\n", + "\u001b[?2004l\n", + "\u001b[?2004l\n", + "\u001b[?2004l\n", + "\u001b[?2004l\n", + "\u001b[?2004l\n", + "\u001b[?2004l\n", + "\u001b[?2004l\n", + "\u001b[?2004l\n", + "\u001b[?2004l\n", + "\u001b[?2004l\n", + "\u001b[?2004l\n", + "\u001b[?2004l\n", + "\u001b[?2004l\n", + "\u001b[?2004l\n", + "\u001b[?2004l\n", + "warning: save: wrong type argument 'function handle'\n", + "warning: called from\n", + " _pyeval>save_safe_struct at line 119 column 9\n", + " _pyeval at line 97 column 3\n", + "\n", + "warning: save: wrong type argument 'function handle'\n", + "warning: called from\n", + " _pyeval>save_safe_struct at line 128 column 9\n", + " _pyeval at line 97 column 3\n", + "\n", + "task\n", + "Octave evaluation error:\n", + "error: save: error while writing '' to MAT file\n", + "error: called from:\n", + " _pyeval>save_safe_struct at line 128, column 9\n", + "\u001b[?2004l\n", + "\u001b[?2004l\n", + "mp.task_pf_legacy\n", + "\u001b[?2004l\n", + "\u001b[?2004l\n", + "\u001b[?2004l\n", + "\u001b[?2004l\n", + "\u001b[?2004l\n", + "\u001b[?2004l\n", + "\u001b[?2004l\n", + "\u001b[?2004l\n", + "\u001b[?2004l\n", + "\u001b[?2004l\n", + "warning: save: wrong type argument 'function handle'\n", + "warning: called from\n", + " _pyeval>save_safe_struct at line 119 column 9\n", + " _pyeval at line 97 column 3\n", + "\n", + "warning: save: wrong type argument 'function handle'\n", + "warning: called from\n", + " _pyeval>save_safe_struct at line 128 column 9\n", + " _pyeval at line 97 column 3\n", + "\n", + "om\n", + "Octave evaluation error:\n", + "error: save: error while writing '' to MAT file\n", + "error: called from:\n", + " _pyeval>save_safe_struct at line 128, column 9\n", + "\u001b[?2004l\n", + "\u001b[?2004l\n", + "mp.math_model_pf_acps\n" + ] + } + ], + "source": [ + "for i in fieldnames_r1.ravel():\n", + " # print('start')\n", + " # print(i)\n", + " try:\n", + " val = m.eval(f\"_r1.{i};\", verbose=True)\n", + " # print(type(val))\n", + " # print(val)\n", + " except Exception as e:\n", + " print(i)\n", + " print(e)\n", + " var_type = m.eval(f\"class(_r1.{i});\", verbose=False)\n", + " print(var_type)\n", + " # print('end')" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['aux_data' 'element_classes' 'elements' 'lin' 'nlc' 'nle' 'nli'\n", + " 'prob_type' 'qdc' 'set_types' 'soln' 'userdata' 'var']\n" + ] + } + ], + "source": [ + "for i in [\"om\"]:\n", + " fieldnames_om = m.eval(f\"fieldnames(_r1.{i});\", verbose=False)\n", + " print(fieldnames_om.ravel())" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\u001b[?2004l\n", + "\u001b[?2004l\n", + "\u001b[?2004l\n", + "\u001b[?2004l\n", + "\u001b[?2004l\n", + "\u001b[?2004l\n", + "start\n", + "elements\n", + "'NoneType' object is not iterable\n", + "\u001b[?2004l\n", + "\u001b[?2004l\n", + "mp.mapped_array\n", + "end\n", + "start\n", + "nle\n", + "Octave evaluation error:\n", + "error: invalid dot name structure assignment because the structure array is empty. Specify a subscript on the structure array to resolve.\n", + "error: called from:\n", + " _pyeval>clean_struct at line 143, column 36\n", + " _pyeval>clean_struct at line 141, column 36\n", + " _pyeval>save_safe_struct at line 124, column 25\n", + "struct\n", + "end\n" + ] + } + ], + "source": [ + "for i in fieldnames_om.ravel():\n", + " # print('start')\n", + " # print(i)\n", + " try:\n", + " val = m.eval(f\"_r1.om.{i};\", verbose=False)\n", + " # print(type(val))\n", + " # print(val)\n", + " except Exception as e:\n", + " print(\"start\")\n", + " print(i)\n", + " print(e)\n", + " var_type = m.eval(f\"class(_r1.om.{i});\", verbose=False)\n", + " print(var_type)\n", + " print(\"end\")\n", + " pass\n", + " # print('end')" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\u001b[?2004l\n", + "\n", + "MATPOWER Version 8.0, 17-May-2024\n", + "Optimal Power Flow -- AC-polar-power formulation\n", + "MATPOWER Interior Point Solver -- MIPS, Version 1.5.1, 10-May-2024\n", + " (using built-in linear solver)\n", + "Converged!\n", + "OPF successful\n", + "\n", + "Converged in 0.25 seconds\n", + "Objective Function Value = 5296.69 $/hr\n", + "================================================================================\n", + "| System Summary |\n", + "================================================================================\n", + "\n", + "How many? How much? P (MW) Q (MVAr)\n", + "--------------------- ------------------- ------------- -----------------\n", + "Buses 9 Total Gen Capacity 820.0 -900.0 to 900.0\n", + "Generators 3 On-line Capacity 820.0 -900.0 to 900.0\n", + "Committed Gens 3 Generation (actual) 318.3 -9.6\n", + "Loads 3 Load 315.0 115.0\n", + " Fixed 3 Fixed 315.0 115.0\n", + " Dispatchable 0 Dispatchable -0.0 of -0.0 -0.0\n", + "Shunts 0 Shunt (inj) -0.0 0.0\n", + "Branches 9 Losses (I^2 * Z) 3.31 36.46\n", + "Transformers 0 Branch Charging (inj) - 161.1\n", + "Inter-ties 0 Total Inter-tie Flow 0.0 0.0\n", + "Areas 1\n", + "\n", + " Minimum Maximum\n", + " ------------------------- --------------------------------\n", + "Voltage Magnitude 1.072 p.u. @ bus 9 1.100 p.u. @ bus 8\n", + "Voltage Angle -4.62 deg @ bus 9 4.89 deg @ bus 2\n", + "P Losses (I^2*R) - 1.39 MW @ line 8-9\n", + "Q Losses (I^2*X) - 9.36 MVAr @ line 8-2\n", + "Lambda P 24.03 $/MWh @ bus 2 25.00 $/MWh @ bus 9\n", + "Lambda Q -0.00 $/MWh @ bus 3 0.11 $/MWh @ bus 9\n", + "\n", + "================================================================================\n", + "| Bus Data |\n", + "================================================================================\n", + " Bus Voltage Generation Load Lambda($/MVA-hr)\n", + " # Mag(pu) Ang(deg) P (MW) Q (MVAr) P (MW) Q (MVAr) P Q\n", + "----- ------- -------- -------- -------- -------- -------- ------- -------\n", + " 1 1.100 0.000* 89.80 12.94 - - 24.756 -\n", + " 2 1.097 4.893 134.32 0.05 - - 24.035 -\n", + " 3 1.087 3.249 94.19 -22.62 - - 24.076 -\n", + " 4 1.094 -2.463 - - - - 24.756 0.004\n", + " 5 1.084 -3.982 - - 90.00 30.00 24.998 0.027\n", + " 6 1.100 0.602 - - - - 24.076 -\n", + " 7 1.089 -1.197 - - 100.00 35.00 24.254 0.036\n", + " 8 1.100 0.905 - - - - 24.035 -\n", + " 9 1.072 -4.616 - - 125.00 50.00 24.999 0.112\n", + " -------- -------- -------- --------\n", + " Total: 318.31 -9.63 315.00 115.00\n", + "\n", + "================================================================================\n", + "| Branch Data |\n", + "================================================================================\n", + "Brnch From To From Bus Injection To Bus Injection Loss (I^2 * Z)\n", + " # Bus Bus P (MW) Q (MVAr) P (MW) Q (MVAr) P (MW) Q (MVAr)\n", + "----- ----- ----- -------- -------- -------- -------- -------- --------\n", + " 1 1 4 89.80 12.94 -89.80 -9.02 0.000 3.92\n", + " 2 4 5 35.22 -3.90 -35.04 -13.87 0.181 0.98\n", + " 3 5 6 -54.96 -16.13 55.97 -22.18 1.010 4.40\n", + " 4 3 6 94.19 -22.62 -94.19 27.28 0.000 4.66\n", + " 5 6 7 38.22 -5.10 -38.07 -18.68 0.149 1.26\n", + " 6 7 8 -61.93 -16.32 62.21 0.82 0.279 2.36\n", + " 7 8 2 -134.32 9.32 134.32 0.05 -0.000 9.36\n", + " 8 8 9 72.11 -10.14 -70.72 -18.94 1.394 7.01\n", + " 9 9 4 -54.28 -31.06 54.58 12.92 0.295 2.51\n", + " -------- --------\n", + " Total: 3.307 36.46\n", + "\n", + "================================================================================\n", + "| Voltage Constraints |\n", + "================================================================================\n", + "Bus # Vmin mu Vmin |V| Vmax Vmax mu\n", + "----- -------- ----- ----- ----- --------\n", + " 1 - 0.900 1.100 1.100 8.384\n", + " 6 - 0.900 1.100 1.100 75.329\n", + " 8 - 0.900 1.100 1.100 77.457\n", + "warning: save: wrong type argument 'function handle'\n", + "warning: called from\n", + " _pyeval>save_safe_struct at line 119 column 9\n", + " _pyeval at line 97 column 3\n", + "\n", + "warning: Skipping field \"om\" as it is not an acceptable type.\n", + "warning: called from\n", + " _pyeval>clean_struct at line 138 column 13\n", + " _pyeval>save_safe_struct at line 124 column 25\n", + " _pyeval at line 97 column 3\n", + "\n" + ] + }, + { + "ename": "Oct2PyError", + "evalue": "Octave evaluation error:\nerror: cellfun: all values must be scalars when UniformOutput = true\nerror: called from:\n structfun at line 108, column 18\n _pyeval>is_acceptable_type at line 164, column 16\n is_acceptable_type>@ at line 164, column 37\n structfun at line 108, column 18\n _pyeval>is_acceptable_type at line 164, column 16\n _pyeval>clean_struct at line 137, column 12\n _pyeval>save_safe_struct at line 124, column 25", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mOct2PyError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[12], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mm\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrunopf\u001b[49m\u001b[43m(\u001b[49m\u001b[43mmpc\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mverbose\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mTrue\u001b[39;49;00m\u001b[43m)\u001b[49m\n", + "File \u001b[0;32m~/Documents/Git/oct2py/oct2py/dynamic.py:111\u001b[0m, in \u001b[0;36mOctaveFunctionPtr.__call__\u001b[0;34m(self, *inputs, **kwargs)\u001b[0m\n\u001b[1;32m 107\u001b[0m warnings\u001b[38;5;241m.\u001b[39mwarn(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mKey - value pairs are deprecated, use `func_args`\u001b[39m\u001b[38;5;124m\"\u001b[39m, stacklevel\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m2\u001b[39m)\n\u001b[1;32m 109\u001b[0m inputs \u001b[38;5;241m+\u001b[39m\u001b[38;5;241m=\u001b[39m \u001b[38;5;28mtuple\u001b[39m(item \u001b[38;5;28;01mfor\u001b[39;00m pair \u001b[38;5;129;01min\u001b[39;00m extras\u001b[38;5;241m.\u001b[39mitems() \u001b[38;5;28;01mfor\u001b[39;00m item \u001b[38;5;129;01min\u001b[39;00m pair)\n\u001b[0;32m--> 111\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_ref\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mfeval\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mname\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43minputs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n", + "File \u001b[0;32m~/Documents/Git/oct2py/oct2py/core.py:403\u001b[0m, in \u001b[0;36mOct2Py.feval\u001b[0;34m(self, func_path, *func_args, **kwargs)\u001b[0m\n\u001b[1;32m 400\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m stream_handler:\n\u001b[1;32m 401\u001b[0m stream_handler \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mlogger\u001b[38;5;241m.\u001b[39minfo \u001b[38;5;28;01mif\u001b[39;00m verbose \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mlogger\u001b[38;5;241m.\u001b[39mdebug\n\u001b[0;32m--> 403\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_feval\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 404\u001b[0m \u001b[43m \u001b[49m\u001b[43mfunc_name\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 405\u001b[0m \u001b[43m \u001b[49m\u001b[43mfunc_args\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 406\u001b[0m \u001b[43m \u001b[49m\u001b[43mdname\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mdname\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 407\u001b[0m \u001b[43m \u001b[49m\u001b[43mnout\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mnout\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 408\u001b[0m \u001b[43m \u001b[49m\u001b[43mtimeout\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mtimeout\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 409\u001b[0m \u001b[43m \u001b[49m\u001b[43mstream_handler\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstream_handler\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 410\u001b[0m \u001b[43m \u001b[49m\u001b[43mstore_as\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstore_as\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 411\u001b[0m \u001b[43m \u001b[49m\u001b[43mplot_dir\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mplot_dir\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 412\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n", + "File \u001b[0;32m~/Documents/Git/oct2py/oct2py/core.py:648\u001b[0m, in \u001b[0;36mOct2Py._feval\u001b[0;34m(self, func_name, func_args, dname, nout, timeout, stream_handler, store_as, plot_dir)\u001b[0m\n\u001b[1;32m 646\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m resp[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124merr\u001b[39m\u001b[38;5;124m\"\u001b[39m]:\n\u001b[1;32m 647\u001b[0m msg \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_parse_error(resp[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124merr\u001b[39m\u001b[38;5;124m\"\u001b[39m])\n\u001b[0;32m--> 648\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m Oct2PyError(msg)\n\u001b[1;32m 650\u001b[0m result \u001b[38;5;241m=\u001b[39m resp[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mresult\u001b[39m\u001b[38;5;124m\"\u001b[39m]\u001b[38;5;241m.\u001b[39mravel()\u001b[38;5;241m.\u001b[39mtolist()\n\u001b[1;32m 651\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(result, \u001b[38;5;28mlist\u001b[39m) \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(result) \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m1\u001b[39m:\n", + "\u001b[0;31mOct2PyError\u001b[0m: Octave evaluation error:\nerror: cellfun: all values must be scalars when UniformOutput = true\nerror: called from:\n structfun at line 108, column 18\n _pyeval>is_acceptable_type at line 164, column 16\n is_acceptable_type>@ at line 164, column 37\n structfun at line 108, column 18\n _pyeval>is_acceptable_type at line 164, column 16\n _pyeval>clean_struct at line 137, column 12\n _pyeval>save_safe_struct at line 124, column 25" + ] + } + ], + "source": [ + "m.runopf(mpc, verbose=True)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# TODO: handle runopf\n", + "# Oct2PyError: Octave evaluation error:\n", + "# error: cellfun: all values must be scalars when UniformOutput = true\n", + "# error: called from:\n", + "# structfun at line 108, column 18\n", + "# _pyeval>is_acceptable_type at line 164, column 16\n", + "# is_acceptable_type>@ at line 164, column 37\n", + "# structfun at line 108, column 18\n", + "# _pyeval>is_acceptable_type at line 164, column 16\n", + "# _pyeval>clean_struct at line 137, column 12\n", + "# _pyeval>save_safe_struct at line 124, column 25" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "env", + "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.12.3" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/matpowerpip/__init__.py b/matpowerpip/__init__.py index 53d2355..4a32a7d 100644 --- a/matpowerpip/__init__.py +++ b/matpowerpip/__init__.py @@ -1,5 +1,6 @@ import os import re +import warnings class Matpower: @@ -43,7 +44,12 @@ def start_instance(path_matpower=None, engine="octave", save_path=False): path_matpower = PATH_MATPOWER m.addpath(path_matpower) - m.install_matpower(1, 0, 0) # TODO: explain what is (1, 0, 0) + try: + m.install_matpower(1, 0, 0) # TODO: explain what is (1, 0, 0) + except Exception as e: + # Oct2PyError + warnings.warn(e, stacklevel=2) + m.rmpath(path_matpower) if save_path: diff --git a/notebooks/runopf_pypglib.ipynb b/notebooks/runopf_pypglib.ipynb index 60688c5..62c4194 100644 --- a/notebooks/runopf_pypglib.ipynb +++ b/notebooks/runopf_pypglib.ipynb @@ -42,9 +42,10 @@ } ], "source": [ - "import matpower\n", "import oct2py\n", "\n", + "import matpower\n", + "\n", "print(f\"oct2py version: {oct2py.__version__}\")\n", "print(f\"matpower version: {matpower.__version__}\")" ] @@ -55,9 +56,10 @@ "metadata": {}, "outputs": [], "source": [ - "from matpower import start_instance\n", "from matpowercaseframes import CaseFrames\n", - "from pypglib import pglib_opf_case5_pjm" + "from pypglib import pglib_opf_case5_pjm\n", + "\n", + "from matpower import start_instance" ] }, { diff --git a/pyproject.toml b/pyproject.toml index cb8a16e..adfa27c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta" name = "matpower" description = 'matpower-pip: A Python Package for Easy Access to MATPOWER Power System Simulation Package' readme = "README.md" -requires-python = ">=3.7.1" +requires-python = ">=3.8.1" keywords = [] authors = [ {name = "Muhammad Yasirroni", email = "muhammadyasirroni@gmail.com"}, @@ -16,11 +16,11 @@ maintainers = [ ] classifiers = [ "Programming Language :: Python", - "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", - "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", "Topic :: Scientific/Engineering", "Topic :: Scientific/Engineering :: Mathematics", ] @@ -29,19 +29,24 @@ dynamic = ["version"] [project.optional-dependencies] octave = [ - "oct2py>=5.5.1", + "oct2py>=5.7.0", ] dev = [ - "numpy>=1.21.5", # latest support for 3.7 - "oct2py>=5.5.1", # latest support for 3.7 - "matplotlib>=3.5.3", # latest support of 3.7 "jupyter>=1.0.0", + "matplotlib>=3.5.3", + "matpowercaseframes>=1.0.7", + "nbmake>=1.3.5", + "numpy>=1.21.6", + "oct2py>=5.7.0", + "openpyxl>=3.1.2", + "pandas>=1.3.5", + "pypglib>=0.0.1", "pytest>=7.2.0", + "pytest-cov>=4.1.0", "pytest-xdist>=3.1.0", - "nbmake>=1.3.5", "pre-commit>=2.21.0", - "autopep8>=2.0.1", "ruff>=0.0.254", + "setuptools>=68.0.0" ] [project.urls] diff --git a/requirements-dev.txt b/requirements-dev.txt index f82bd57..6abf6b9 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,17 +1,15 @@ -numpy>=1.21.5 -pandas>=1.3.5 -oct2py>=5.5.1 +jupyter>=1.0.0 matplotlib>=3.5.3 -openpyxl>=3.1.2 - matpowercaseframes>=1.0.7 +nbmake>=1.3.5 +numpy>=1.21.6 +oct2py>=5.7.0 +openpyxl>=3.1.2 +pandas>=1.3.5 pypglib>=0.0.1 - -pytest -pytest-cov -pytest-xdist - -jupyter -nbmake - -setuptools +pytest>=7.2.0 +pytest-cov>=4.1.0 +pytest-xdist>=3.1.0 +pre-commit>=2.21.0 +ruff>=0.0.254 +setuptools>=68.0.0 diff --git a/requirements-latest.txt b/requirements-latest.txt new file mode 100644 index 0000000..3a2f313 --- /dev/null +++ b/requirements-latest.txt @@ -0,0 +1,21 @@ +numpy==1.26.4 +pandas==2.2.2 +oct2py==5.7.0 +matplotlib==3.9.0 +openpyxl==3.1.2 + +matpowercaseframes==1.0.7 +pypglib==0.0.1 + +pytest==8.2.1 +pytest-cov==5.0.0 +pytest-xdist==3.6.1 + +jupyter==1.0.0 +nbmake==1.5.3 + +setuptools==70.0.0 + +pre-commit==3.7.1 +nb-clean==3.2.0 +ruff==0.4.6 diff --git a/requirements-lint.txt b/requirements-lint.txt deleted file mode 100644 index 10a18e3..0000000 --- a/requirements-lint.txt +++ /dev/null @@ -1,19 +0,0 @@ -numpy>=1.21.5 -pandas>=1.3.5 -oct2py>=5.5.1 -matplotlib>=3.5.3 -openpyxl>=3.1.2 - -matpowercaseframes>=1.0.7 -pypglib>=0.0.1 - -pytest -pytest-cov -pytest-xdist - -jupyter -nbmake - -pre-commit==3.7.1 -nb-clean==3.2.0 -ruff==0.4.5 diff --git a/tests/test_core_functionality.py b/tests/test_core_functionality.py index 987f59a..51f2e9e 100644 --- a/tests/test_core_functionality.py +++ b/tests/test_core_functionality.py @@ -1,8 +1,9 @@ -import matpower import numpy as np -from matpower import __MATPOWER_VERSION__, __MATPOWERPIP_VERSION__, Matpower from oct2py import Oct2Py +import matpower +from matpower import __MATPOWER_VERSION__, __MATPOWERPIP_VERSION__, Matpower + """Test using pytest # normal test copy matpowerpip\\__init__.py matpower\\__init__.py @@ -10,11 +11,11 @@ # complete test, including example notebooks copy matpowerpip\\__init__.py matpower\\__init__.py - pytest -n auto -rA -c pyproject.toml --cov-report term-missing --cov=matpower --nbmake + pytest -rA -c pyproject.toml --cov-report term-missing --cov=matpower --nbmake # only run last failed test copy matpowerpip\\__init__.py matpower\\__init__.py - pytest -n auto --lf -rA -c pyproject.toml --cov-report term-missing --cov=matpower --nbmake + pytest --lf -rA -c pyproject.toml --cov-report term-missing --cov=matpower --nbmake """