-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
206 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# install octave\n", | ||
"!sudo apt-get -qq update\n", | ||
"!sudo apt-get -qq install octave octave-signal liboctave-dev\n", | ||
"\n", | ||
"# install oct2py that compatible with colab\n", | ||
"import os\n", | ||
"\n", | ||
"from pkg_resources import get_distribution\n", | ||
"\n", | ||
"os.system(\n", | ||
" f\"pip install -qq\"\n", | ||
" f\" ipykernel=={get_distribution('ipykernel').version}\"\n", | ||
" f\" ipython=={get_distribution('ipython').version}\"\n", | ||
" f\" tornado=={get_distribution('tornado').version}\"\n", | ||
" f\" oct2py\"\n", | ||
")\n", | ||
"\n", | ||
"# install packages\n", | ||
"!pip install -qq matpower matpowercaseframes" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"oct2py version: 5.7.2\n", | ||
"matpower version: 8.0.0.2.2.2\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"import oct2py\n", | ||
"\n", | ||
"import matpower\n", | ||
"\n", | ||
"print(f\"oct2py version: {oct2py.__version__}\")\n", | ||
"print(f\"matpower version: {matpower.__version__}\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from matpower import start_instance" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"m = start_instance()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"mpc = m.loadcase(\"case9\")\n", | ||
"mpopt = m.mpoption(\"verbose\", 2)\n", | ||
"m.push(\"_mpopt\", mpopt)\n", | ||
"m.push(\"_mpc\", mpc, verbose=False)\n", | ||
"m.eval(\"_r1 = runuopf(_mpc, _mpopt);\", verbose=False)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# pull all after cleansing unsupported data\n", | ||
"m.eval(\n", | ||
" \"\"\"\n", | ||
" _r1.raw = rmfield(_r1.raw, 'task');\n", | ||
" _r1 = rmfield(_r1, 'om');\n", | ||
" \"\"\"\n", | ||
")\n", | ||
"mpc = m.pull(\"_r1\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 7, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# selective pull\n", | ||
"r1_mpc = m.eval(\n", | ||
" \"struct('baseMVA', _r1.baseMVA, 'version', _r1.version, 'bus', _r1.bus,\"\n", | ||
" \" 'gen', _r1.gen, 'branch', _r1.branch, 'gencost', _r1.gencost);\"\n", | ||
")\n", | ||
"r1_mpc" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# # NOTE: you also can run like this\n", | ||
"# r1_mpc = m.eval(\n", | ||
"# \"\"\"\n", | ||
"# mpopt = mpoption('verbose', 2);\n", | ||
"# mpc = loadcase('case9');\n", | ||
"# _r1 = runuopf(mpc, mpopt);\n", | ||
"# \"\"\"\n", | ||
"#\n", | ||
"# \"struct(\"\n", | ||
"# \" 'baseMVA', _r1.baseMVA, 'version', _r1.version, 'bus', _r1.bus, 'gen', _r1.gen,\"\n", | ||
"# \" 'branch', _r1.branch, 'gencost', _r1.gencost);\"\n", | ||
"# )\n", | ||
"# r1_mpc" | ||
] | ||
}, | ||
{ | ||
"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.4" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters