matpower

A Python Package for Easy Access to MATPOWER Power System Simulation Package

https://github.com/yasirroni/matpower-pip

Science Score: 67.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 7 DOI reference(s) in README
  • Academic publication links
    Links to: researchgate.net, ieee.org, zenodo.org
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (13.6%) to scientific vocabulary
Last synced: 6 months ago · JSON representation ·

Repository

A Python Package for Easy Access to MATPOWER Power System Simulation Package

Basic Info
  • Host: GitHub
  • Owner: yasirroni
  • License: mit
  • Language: Jupyter Notebook
  • Default Branch: master
  • Homepage:
  • Size: 803 KB
Statistics
  • Stars: 25
  • Watchers: 2
  • Forks: 2
  • Open Issues: 5
  • Releases: 3
Created about 4 years ago · Last pushed 7 months ago
Metadata Files
Readme Contributing License Citation

README.md

matpower-pip

PyPI version License: MIT DOI

matpower-pip: A Python Package for Easy Access to MATPOWER Power System Simulation Package

This package is intended to make MATPOWER installable from PyPI. We did not change anything from MATPOWER package, instead, we used a copy of MATPOWER (currently Version 8.1) and wrapped it as python package published on PyPI. Use this package with mypower (the recommended way) or oct2py to run MATPOWER using octave client. matlab.engine is also supported. For the latest docs, read README on GitHub.

This project is also listed on related links on MATPOWER official website. Please visit that site to find other useful resources.

Installation

matpower

For downloading MATPOWER only (maybe you will run it using matlab.engine or any other method, or simply want an easy MATPOWER downloader):

plaintext pip install matpower

oct2py (Windows)

For callable matpower via oct2py (require octave on environment system PATH). You can follow the oct2py instalation tutorial in mypower repository.

Usage

Open In Colab

See notebooks/ for complete examples. All examples should be compatible with Google Colab.

Running with an engine (require oct2py or matlab.engine)

If oct2py or matlab.engine is installed, matpower.start_instance can be used to run octave or MATLAB with MATPOWER path added. The default engine is octave. You also can use mypower for added functionality as shown in mypower tutorial.

```python from matpower import start_instance

m = start_instance() m.runpf() ```

```python from matpower import start_instance

m = start_instance() mpc = m.eval('case9', verbose=False) mpc = m.runpf(mpc) ```

```python from matpower import Matpower

with Matpower(engine='octave') as m: # run as context manager mpc = m.eval('case9', verbose=False) mpc = m.runpf(mpc)

print(m._engine is None) # engine cleanly terminated ```

```python from matpower import path_matpower

print(path_matpower) # matpower installation location ```

Since mpc = m.runopf() will make mpc contain unsupported <object opf_model>, we can avoid it by requesting a maximum number of outputs using nout='max_nout' in octave.

```python from matpower import start_instance

m = start_instance()

mpc = m.loadcase('case9') mpopt = m.mpoption('verbose', 2) [baseMVA, bus, gen, gencost, branch, f, success, et] = m.runopf(mpc, mpopt, nout='max_nout') ```

Or we can remove unsupported objects.

```python from matpower import start_instance

m = start_instance()

mpc = m.loadcase('case9') mpopt = m.mpoption('verbose', 2) m.push("mpopt", mpopt) m.push("mpc", mpc, verbose=False)

m.eval("r1 = runopf(mpc, _mpopt);", verbose=False)

_r1 containts unsupported <object opf_model>, needs to be removed first

m.eval( """ r1.raw = rmfield(r1.raw, 'task'); r1 = rmfield(r1, 'om'); """ ) mpc = m.pull("_r1") ```

Alternatively, only select values that will be used on python using oct2py .eval method. Combine it with the use of ; to avoid octave print output on running the command.

```python

import start_instance to start matpower instance

from matpower import start_instance

start instance

m = start_instance()

m.eval( """ mpopt = mpoption('verbose', 2); mpc = loadcase('case9'); _r1 = runopf(mpc, mpopt); """ )

fech data to python (.eval is used because .pull is not working in acessing field)

r1_mpc = m.eval( "struct(" " 'baseMVA', _r1.baseMVA, 'version', _r1.version, 'bus', _r1.bus, 'gen', _r1.gen," " 'branch', _r1.branch, 'gencost', _r1.gencost);" )

modify variable if necessary

[GENBUS, PG, QG, QMAX, QMIN, VG, MBASE, GENSTATUS, PMAX, PMIN, MUPMAX, MUPMIN, MUQMAX, MUQMIN, PC1, PC2, QC1MIN, QC1MAX, QC2MIN, QC2MAX, RAMPAGC, RAMP10, RAMP30, RAMPQ, APF] = m.idxgen(nout='maxnout') genindex = 2 # index of generator to be changed genindex_ = int(genindex - 1) # -1 due to python indexing start from 0 PMAX = int(PMAX -1) # -1 due to python indexing start from 0 r1_mpc['gen'][genindex,PMAX_] = 110 # in this example, we modify PMAX to be 110

[PQ, PV, REF, NONE, BUSI, BUSTYPE, PD, QD, GS, BS, BUSAREA, VM, VA, BASEKV, ZONE, VMAX, VMIN, LAMP, LAMQ, MUVMAX, MUVMIN] = m.idxbus(nout='maxnout') busindex = 7 # index of bus to be changed busindex_ = int(busindex - 1) # -1 due to python indexing start from 0 PD = int(PD-1) # -1 due to python indexing start from 0 r1_mpc['bus'][busindex,int(PD-1)] = 80 # in this example, we modify PD to be 150

push back value to octave client

m.push('mpc', r1mpc) # push r1mpc in python to mpc in octave

test if we can retrive pushed value

mpc = m.pull('mpc')

test if our pushed variable can be used

m.eval("_r1 = runopf(mpc, mpopt);") ```

matpower-pip also support using matlab.engine.

```python from matpower import start_instance

m = start_instance(engine='matlab') # specify using matlab.engine instead of oct2py mpc = m.runpf('case5', nargout=0) ```

Known engine issue

Octave

  1. m.runopf() will make mpc contain unsupported <object opf_model>. See: https://github.com/MATPOWER/matpower/issues/134#issuecomment-1007798733

    Impacted case:

    python _r1 = m.runopf(mpc)

    Solution:

    ```python m.push('mpc', mpc) r1_mpc = m.eval( """ mpopt = mpoption('verbose', 2); _r1 = runopf(mpc, mpopt); """

    "struct("
    " 'baseMVA', _r1.baseMVA, 'version', _r1.version, 'bus', _r1.bus, 'gen', _r1.gen,"
    " 'branch', _r1.branch, 'gencost', _r1.gencost);"
    

    ) ```

Versioning

This package maintains MATPOWER version with an added version mark, i.e. MATPOWER 8.1 becomes 8.1.0.x.x.x where the .x.x.x comes from matpower-pip versioning. The matpower-pip versioning is not released on pypi since matpower-pip is restricted for development only (and development should use git instead).

TODO

  1. conda and docker installation that includes octave-cli installation.

Authors

Cite

We do request that publications derived from the use of matpower-pip explicitly acknowledge that fact by including all related MATPOWER publications and the following citation:

M. Yasirroni, Sarjiya, and L. M. Putranto, "matpower-pip: A Python Package for Easy Access to MATPOWER Power System Simulation Package," [Online]. Available: https://github.com/yasirroni/matpower-pip.

M. Yasirroni, Sarjiya, and L. M. Putranto, "matpower-pip". Zenodo, Jun. 13, 2024. doi: 10.5281/zenodo.11626845.

```bibtex @misc{matpower-pip, author = {Yasirroni, M. and Sarjiya and Putranto, L. M.}, title = {matpower-pip: A Python Package for Easy Access to MATPOWER Power System Simulation Package}, year = {2023}, howpublished = {\url{https://github.com/yasirroni/matpower-pip}}, }

@software{yasirroni202411626845, author = {Yasirroni, Muhammad and Sarjiya, Sarjiya and Putranto, Lesnanto Multa}, title = {matpower-pip}, month = jun, year = 2024, publisher = {Zenodo}, version = {8.0.0.2.1.8}, doi = {10.5281/zenodo.11626845}, url = {\url{https://doi.org/10.5281/zenodo.11626845}} } ```

If a journal publication from the author appears soon should be cited instead.

Contributing

See the CONTRIBUTING.md.

Acknowledgment

This repository was supported by the Faculty of Engineering, Universitas Gadjah Mada under the supervision of Mr. Sarjiya. If you use this package, we would be very glad if you cite any relevant publication under Mr. Sarjiya's name that can be found in the semantic scholar or IEEE in the meantime, since publication related to this repository is ongoing. This work is also partly motivated after I found out that oct2py supports running octave client from python, but the only implementation for running MATPOWER that I know is oct2pypower which requires docker and is not newbie-friendly. Nevertheless, I would like to say thank you to all the people who have contributed to oct2py, oct2pypower, and more importantly MATPOWER.

Owner

  • Name: Muhammad Yasirroni
  • Login: yasirroni
  • Kind: user
  • Location: Indonesia
  • Company: Universitas Gadjah Mada

Citation (CITATION.bib)

@misc{matpower-pip,
  author       = {Yasirroni, M. and Sarjiya and Putranto, L. M.},
  title        = {matpower-pip: A Python Package for Easy Access to MATPOWER Power System Simulation Package},
  year         = {2023},
  howpublished = {\url{https://github.com/yasirroni/matpower-pip}},
}

@software{yasirroni_2024_11626845,
  author       = {Yasirroni, Muhammad and
                  Sarjiya, Sarjiya and
                  Putranto, Lesnanto Multa},
  title        = {matpower-pip},
  month        = jun,
  year         = 2024,
  publisher    = {Zenodo},
  version      = {8.0.0.2.1.8},
  doi          = {10.5281/zenodo.11626845},
  url          = {https://doi.org/10.5281/zenodo.11626845}
}

GitHub Events

Total
  • Issues event: 3
  • Watch event: 5
  • Issue comment event: 1
  • Push event: 4
  • Pull request event: 4
  • Fork event: 2
  • Create event: 2
Last Year
  • Issues event: 3
  • Watch event: 5
  • Issue comment event: 1
  • Push event: 4
  • Pull request event: 4
  • Fork event: 2
  • Create event: 2

Committers

Last synced: almost 3 years ago

All Time
  • Total Commits: 122
  • Total Committers: 1
  • Avg Commits per committer: 122.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Muhammad Yasirroni 4****i@u****m 122

Issues and Pull Requests

Last synced: 7 months ago

All Time
  • Total issues: 18
  • Total pull requests: 4
  • Average time to close issues: 23 days
  • Average time to close pull requests: 6 days
  • Total issue authors: 5
  • Total pull request authors: 1
  • Average comments per issue: 2.67
  • Average comments per pull request: 0.25
  • Merged pull requests: 4
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 5
  • Pull requests: 0
  • Average time to close issues: about 2 months
  • Average time to close pull requests: N/A
  • Issue authors: 1
  • Pull request authors: 0
  • Average comments per issue: 0.2
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • yasirroni (10)
  • chiru7187 (5)
  • yasirroni-au (1)
  • thomsonian2023 (1)
  • hany-dev (1)
  • 1rashiid (1)
Pull Request Authors
  • yasirroni (6)
  • NaufalAfrizal55 (2)
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 259 last-month
  • Total dependent packages: 1
  • Total dependent repositories: 1
  • Total versions: 24
  • Total maintainers: 1
pypi.org: matpower

matpower-pip: A Python Package for Easy Access to MATPOWER Power System Simulation Package

  • Versions: 24
  • Dependent Packages: 1
  • Dependent Repositories: 1
  • Downloads: 259 Last month
Rankings
Dependent packages count: 4.8%
Downloads: 15.1%
Stargazers count: 15.6%
Average: 17.4%
Dependent repos count: 21.6%
Forks count: 29.8%
Maintainers (1)
Last synced: 7 months ago

Dependencies

.github/workflows/build.yml actions
  • MATPOWER/action-install-octave-linux v1 composite
  • actions/checkout v3 composite
  • actions/setup-python v3 composite
.github/workflows/publish.yml actions
  • MATPOWER/action-install-octave-linux v1 composite
  • actions/checkout v3 composite
  • actions/setup-python v3 composite
  • pypa/gh-action-pypi-publish release/v1 composite
requirements-dev.txt pypi
  • numpy >=1.19.0 development
  • oct2py >=5.5.1 development
  • pytest * development
  • pytest-cov * development
pyproject.toml pypi
setup.py pypi
requirements-latest.txt pypi
  • jupyter ==1.1.1 test
  • matplotlib ==3.10.5 test
  • matpowercaseframes ==1.1.4 test
  • nb-clean ==4.0.1 test
  • nbmake ==1.5.5 test
  • numpy ==2.3.2 test
  • oct2py ==5.8.0 test
  • openpyxl ==3.1.5 test
  • pandas ==2.3.1 test
  • pre-commit ==3.7.1 test
  • pypglib ==0.0.3 test
  • pytest ==8.4.1 test
  • pytest-cov ==6.2.1 test
  • pytest-xdist ==3.8.0 test
  • ruff ==0.12.9 test
  • setuptools ==80.9.0 test