Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
060c420
Replace Inf with inf and Nan with nan
dchassin Jun 12, 2025
c20cca9
Update setup.py
dchassin Jun 12, 2025
84797ed
Create tests folder and add test_cases.py to check all cases in pypow…
dchassin Jun 12, 2025
56f9680
Create run-test-cases.yml
dchassin Jun 12, 2025
57e6478
Update run-test-cases.yml
dchassin Jun 12, 2025
f2ea035
Add output of tests to json
dchassin Jun 12, 2025
506a3f4
Added output of results for diagnostic purposes
dchassin Jun 12, 2025
8fc43c5
Fixed case4gs test failure (OPF is not possible without gencost data)
dchassin Jun 13, 2025
cb5bb8b
Merge branch 'fix-issue-88' into add-tests
dchassin Jun 13, 2025
56059a2
Update .gitignore
dchassin Jun 13, 2025
7a0f7b0
Update requirements.txt
dchassin Jun 13, 2025
5b1b302
Update tox.ini
dchassin Jun 13, 2025
e4f8804
Update test_cases.py
dchassin Jun 13, 2025
c900ec3
Update polycost.py
dchassin Jun 13, 2025
f202870
Update opf_hessfcn.py
dchassin Jun 13, 2025
7bfef23
Update run-test-cases.yml
dchassin Jun 13, 2025
25ba808
Update requirements.txt
dchassin Jun 13, 2025
95e338f
Update test_cases.py
dchassin Jun 13, 2025
89946ba
Update test_cases.py
dchassin Jun 13, 2025
6c220fe
Fixed CPF error
dchassin Jun 13, 2025
4e83138
Update setup.py
dchassin Jun 13, 2025
71efeae
Update test_cases.py
dchassin Jun 13, 2025
66c5e21
Update test_cases.py
dchassin Jun 13, 2025
a91eb49
cleanup
dchassin Jun 13, 2025
b7937c3
Update tox.ini
dchassin Jun 13, 2025
15390c1
Update test docs
dchassin Jun 13, 2025
9117574
Update supported python versions
dchassin Jun 13, 2025
4f847da
Update numpy support to match supported environments
dchassin Jun 13, 2025
66dc5c8
Make test script using tox environments for unit tests
dchassin Jun 13, 2025
5b32fbf
Revert tox test to just run in the current environment
dchassin Jun 13, 2025
57868da
Update README.rst
dchassin Jun 13, 2025
6287071
Update README.rst
dchassin Jun 13, 2025
44a1ee2
Update README.rst
dchassin Jun 13, 2025
6d1b6b1
Update README.rst
dchassin Jun 13, 2025
05812f2
Update README.rst
dchassin Jun 13, 2025
dcfd227
Update run-test-cases.yml
dchassin Jun 13, 2025
a6385bf
Update run-test-cases.yml
dchassin Jun 13, 2025
200c42c
Merge branch 'master' into add-tests
dchassin Jul 30, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions .github/workflows/run-test-cases.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# This workflow run all the cases found in the pypower folder

name: Run test cases

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:

ubuntu-test-matrix:

strategy:
matrix:
# See https://docs.github.com/en/actions/using-github-hosted-runners/using-github-hosted-runners/about-github-hosted-runners#standard-github-hosted-runners-for-public-repositories
version: [22.04,24.04,latest]

runs-on: ubuntu-${{matrix.version}}

steps:
- uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.12'

- name: Install dependencies
run: python3 -m pip install --upgrade pip -r requirements.txt

- name: Run test cases
run: python3 tests/test_cases.py

- name: Upload artifacts on failure
uses: actions/upload-artifact@v4
if: failure()
with:
name: test-results
path: |
tests/

macos-test-matrix:

strategy:
matrix:
# See https://docs.github.com/en/actions/using-github-hosted-runners/using-github-hosted-runners/about-github-hosted-runners#standard-github-hosted-runners-for-public-repositories
version: [13,14,15,latest]

runs-on: macos-${{matrix.version}}

steps:
- uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.12'

- name: Install dependencies
run: python3 -m pip install --upgrade pip -r requirements.txt

- name: Run test cases
run: python3 tests/test_cases.py

- name: Upload artifacts on failure
uses: actions/upload-artifact@v4
if: failure()
with:
name: test-results
path: |
tests/
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
*~
build/
dist/
PYPOWER.egg-info/
*.egg-info/
doc/api/
doc/.build/*
/venv/
*venv/
__pycache__/
43 changes: 31 additions & 12 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,67 +36,83 @@ Prerequisites

PYPOWER depends upon these prerequisites on the level of the operating system:

* Python_ >= 3.5
* Python_ >= 3.10

Virtual Environment
===================

PYPOWER is recommended to be installed into a virtual environment::

$ python3.8 -m venv venv # Or any supported Python version
python3.12 -m venv venv # Or any supported Python version

Dependencies
============

PYPOWER depends upon NumPy, SciPy and PyRLU which can be installed as follows::

$ venv/bin/python -m pip install -r requirements.txt
venv/bin/python -m pip install -r requirements.txt

Installation
============

The recommended way of installing PYPOWER is using pip_::

$ venv/bin/python -m pip install PYPOWER
venv/bin/python -m pip install PYPOWER

Alternatively, `download <http://pypi.python.org/pypi/PYPOWER#downloads>`_ and
unpack the tarball and install::

$ tar zxf PYPOWER-5.x.y.tar.gz
$ venv/bin/python setup.py install
tar zxf PYPOWER-5.x.y.tar.gz
venv/bin/python setup.py install

Testing
=======

PYPOWER can be tested locally using the same tooling as on Travis CI::

$ venv/bin/python -m tox -e py27,py38 # Or any supported Python version
venv/bin/python -m tox -e 3.10,3.11,3.12 # Or any supported Python version

Case Testing
============

The cases in the `pypower` folder can also be tested locally using the command::

python3.x -m venv .venv
. .venv/bin/activate
python3 -m pip install -m pip --upgrade -r requirements.txt
python3 tests/test_cases.py

where `x` is one of the supported python minor version numbers.

See the `tests/test_cases.py <https://github.com/rwl/PYPOWER/blob/master/tests/test_cases.py>`_ script for additional information on the output files.

**Note**: this test first runs the `tox` tests in the current environment.

Using PYPOWER
=============

Installing PYPOWER creates ``pf`` and ``opf`` commands. To list the command
options::

$ venv/bin/pf -h
venv/bin/pf -h

or::

$ venv/bin/opf -h
venv/bin/opf -h

PYPOWER includes a selection of test cases. For example, to run a power flow
on the IEEE 14 bus test case::

$ venv/bin/pf -c case14
venv/bin/pf -c case14

Alternatively, the path to a PYPOWER case data file can be specified::

$ venv/bin/pf /path/to/case14.py
venv/bin/pf /path/to/case14.py

The ``opf`` command has the same calling syntax. For example, to solve an OPF
for the IEEE Reliability Test System and write the solved case to file::

$ venv/bin/opf -c case24_ieee_rts --solvedcase=rtsout.py
venv/bin/opf -c case24_ieee_rts --solvedcase=rtsout.py

For further information please refer to https://rwl.github.io/PYPOWER/ and the
`API documentation`_.
Expand Down Expand Up @@ -142,6 +158,7 @@ Links
* PSAT_ by Federico Milano
* OpenDSS_ from EPRI
* GridLAB-D_ from PNNL
* Arras-Energy_ from `LF Energy <https://lfenergy.org/>`_
* PyCIM_

.. _Python: http://www.python.org
Expand All @@ -160,3 +177,5 @@ Links
.. _TESP: https://tesp.readthedocs.io
.. _Oct2PYPOWER: https://github.com/rwl/oct2pypower
.. _matpower.app: https://matpower.app
.. _Arras-Energy: https://arras.energy/

4 changes: 2 additions & 2 deletions pypower/cpf_p_jac.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'''Computes partial derivatives of CPF parameterization function.
'''

from numpy import r_, zeros, angle
from numpy import r_, zeros, angle, array


def cpf_p_jac(parameterization, z, V, lam, Vprv, lamprv, pv, pq):
Expand Down Expand Up @@ -33,4 +33,4 @@ def cpf_p_jac(parameterization, z, V, lam, Vprv, lamprv, pv, pq):
dP_dV = z[r_[pv, pq, nb+pq]]
dP_dlam = z[2 * nb]

return dP_dV, dP_dlam
return dP_dV, array([dP_dlam])
2 changes: 1 addition & 1 deletion pypower/opf_hessfcn.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def opf_hessfcn(x, lmbda, om, Ybus, Yf, Yt, ppopt, il=None, cost_mult=1.0):
ipolp = find(pcost[:, MODEL] == POLYNOMIAL)
d2f_dPg2[ipolp] = \
baseMVA**2 * polycost(pcost[ipolp, :], Pg[ipolp] * baseMVA, 2)
if any(qcost): ## Qg is not free
if qcost.any(): ## Qg is not free
ipolq = find(qcost[:, MODEL] == POLYNOMIAL)
d2f_dQg2[ipolq] = \
baseMVA**2 * polycost(qcost[ipolq, :], Qg[ipolq] * baseMVA, 2)
Expand Down
2 changes: 1 addition & 1 deletion pypower/polycost.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def polycost(gencost, Pg, der=0):
"""
if gencost.size == 0:
#User has a purely linear piecewise problem, exit early with empty array
return []
return zeros(0)

if any(gencost[:, MODEL] == PW_LINEAR):
sys.stderr.write('polycost: all costs must be polynomial\n')
Expand Down
28 changes: 17 additions & 11 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
# only exact versions allowed (<, >, <=, >= not supported by testing)
appdirs==1.4.4
distlib==0.3.1
filelock==3.0.12
cachetools==6.0.0
chardet==5.2.0
colorama==0.4.6
distlib==0.3.9
filelock==3.18.0
numpy==2.2.6
packaging==20.9
packaging==25.0
pip==21.1
pluggy==0.13.1
py==1.10.0
pyparsing==2.4.7
platformdirs==4.3.8
pluggy==1.6.0
py==1.11.0
pyparsing==3.2.3
pyproject-api==1.9.1
pyrlu==0.2.1
scipy==1.6.1
setuptools==65.5.1
six==1.15.0
scipy==1.15.3
setuptools==80.9.0
six==1.17.0
toml==0.10.2
tox==3.23.0
virtualenv==20.4.3
tox==4.26.0
virtualenv==20.31.2
3 changes: 3 additions & 0 deletions tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.json
*.out
*.err
Loading