Skip to content

Commit f288313

Browse files
authored
rearrange and new api tests (#3)
* rearrange and new api tests * try 2 * try 3 * try 4 * try 5 * try 7 * try 8 * try 9 * try 10 * try 11 * try 12 * try 13 * try 14 * Add files via upload * Update README.md * try 15 * try 12 * try 17 * try 18
1 parent 37458c3 commit f288313

File tree

10 files changed

+192
-23
lines changed

10 files changed

+192
-23
lines changed

.github/workflows/ci.yml

Lines changed: 115 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ jobs:
5656
- uses: actions/checkout@v4
5757
with:
5858
fetch-depth: 0
59+
persist-credentials: false
5960

6061
- name: Install Conda Python ${{ matrix.cfg.python-version }} and power software
6162
if: matrix.cfg.label == 'conda'
@@ -144,11 +145,11 @@ jobs:
144145
julia -e 'ENV["PYTHON"]="/Users/runner/hostedtoolcache/Python/3.12.9/x64/bin/python"; using Pkg; Pkg.build("PyCall")'
145146
146147
- name: Special setup download delay
147-
if: runner.os == 'macOS'
148-
# file download in next section is flaky, esp. for Mac. use `sed -i "s;;;g"` for non-Mac
148+
if: false # runner.os == 'macOS'
149+
# file download in (basic) section is flaky for Mac. use `sed -i "s;;;g"` for non-Mac
149150
run: |
150-
sed -E -i.bak "s;nb_retry=10;nb_retry=50;g" $(dirname $(which python))/../lib/python${{ matrix.cfg.python-version }}/site-packages/grid2op/MakeEnv/Make.py
151-
sed -E -i.bak "s;time.sleep(1);time.sleep(3);g" $(dirname $(which python))/../lib/python${{ matrix.cfg.python-version }}/site-packages/grid2op/MakeEnv/Make.py
151+
sed -E -i.bak "s;nb_retry=10;nb_retry=100;g" $(dirname $(which python))/../lib/python${{ matrix.cfg.python-version }}/site-packages/grid2op/MakeEnv/Make.py
152+
sed -E -i.bak "s;time.sleep(1);time.sleep(8);g" $(dirname $(which python))/../lib/python${{ matrix.cfg.python-version }}/site-packages/grid2op/MakeEnv/Make.py
152153
153154
- name: Test PowerModels in PandaPower
154155
run: |
@@ -158,10 +159,115 @@ jobs:
158159
# loc is simply $CONDA_PREFIX but the setup-python counterpart env.pythonLocation seems broken
159160
# PdP testing above has a couple failures b/c Ipopt=1 unless downgrade (taking PM with it)
160161
161-
- name: Test PandaModelsBackend
162-
# if: false # for now since there's some issues
162+
- name: Test PandaModelsBackend (basic)
163+
if: runner.os == 'Linux'
163164
run: |
164-
cd tests
165165
which python python-jl
166-
python-jl test_basic_usage.py
167-
# python test_backend_api.py
166+
python-jl tests/test_basic_usage.py
167+
168+
- name: Test PandaModelsBackend (API)
169+
run: |
170+
python-jl tests/test_backend_api.py
171+
172+
- name: Install pypa/build & build a binary wheel and a source tarball
173+
if: matrix.cfg.label == 'installer' && runner.os == 'Linux'
174+
run: |
175+
python -m pip install build --user
176+
python -m build
177+
178+
- name: Store the distribution packages
179+
if: matrix.cfg.label == 'installer' && runner.os != 'macOS'
180+
uses: actions/upload-artifact@v4
181+
with:
182+
name: python-package-distributions
183+
path: dist/
184+
185+
publish-to-pypi:
186+
name: >-
187+
Publish Python 🐍 distribution 📦 to PyPI
188+
if: startsWith(github.ref, 'refs/tags/') # only publish to PyPI on tag pushes
189+
needs:
190+
- build
191+
runs-on: ubuntu-latest
192+
environment:
193+
name: pypi
194+
url: https://pypi.org/p/pandamodelsbackend
195+
permissions:
196+
id-token: write # IMPORTANT: mandatory for trusted publishing
197+
198+
steps:
199+
- name: Download all the dists
200+
uses: actions/download-artifact@v4
201+
with:
202+
name: python-package-distributions
203+
path: dist/
204+
- name: Publish distribution 📦 to PyPI
205+
uses: pypa/gh-action-pypi-publish@release/v1
206+
207+
github-release:
208+
name: >-
209+
Sign the Python 🐍 distribution 📦 with Sigstore
210+
and upload them to GitHub Release
211+
needs:
212+
- publish-to-pypi
213+
runs-on: ubuntu-latest
214+
215+
permissions:
216+
contents: write # IMPORTANT: mandatory for making GitHub Releases
217+
id-token: write # IMPORTANT: mandatory for sigstore
218+
219+
steps:
220+
- name: Download all the dists
221+
uses: actions/download-artifact@v4
222+
with:
223+
name: python-package-distributions
224+
path: dist/
225+
- name: Sign the dists with Sigstore
226+
uses: sigstore/gh-action-sigstore-python@v3.0.0
227+
with:
228+
inputs: >-
229+
./dist/*.tar.gz
230+
./dist/*.whl
231+
- name: Create GitHub Release
232+
env:
233+
GITHUB_TOKEN: ${{ github.token }}
234+
run: >-
235+
gh release create
236+
"$GITHUB_REF_NAME"
237+
--repo "$GITHUB_REPOSITORY"
238+
--notes ""
239+
- name: Upload artifact signatures to GitHub Release
240+
env:
241+
GITHUB_TOKEN: ${{ github.token }}
242+
# Upload to GitHub Release using the `gh` CLI.
243+
# `dist/` contains the built packages, and the
244+
# sigstore-produced signatures and certificates.
245+
run: >-
246+
gh release upload
247+
"$GITHUB_REF_NAME" dist/**
248+
--repo "$GITHUB_REPOSITORY"
249+
250+
publish-to-testpypi:
251+
name: Publish Python 🐍 distribution 📦 to TestPyPI
252+
needs:
253+
- build
254+
runs-on: ubuntu-latest
255+
256+
environment:
257+
name: testpypi
258+
url: https://test.pypi.org/p/pandamodelsbackend
259+
260+
permissions:
261+
id-token: write # IMPORTANT: mandatory for trusted publishing
262+
263+
steps:
264+
- name: Download all the dists
265+
uses: actions/download-artifact@v4
266+
with:
267+
name: python-package-distributions
268+
path: dist/
269+
- name: Publish distribution 📦 to TestPyPI
270+
uses: pypa/gh-action-pypi-publish@release/v1
271+
with:
272+
repository-url: https://test.pypi.org/legacy/
273+
verbose: true

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
# PandaModelsBackend
2-
Provides a high fidelity backend for grid2op that uses PowerModels.jl. It achieves this using pandapower interface that calls PandaModels using PyCall to call julia functions from python.
2+
3+
PandaModelsBackend provides a high-fidelity backend for [Grid2op](https://github.com/Grid2op/grid2op) that uses [PowerModels.jl](https://github.com/lanl-ansi/PowerModels.jl). It achieves this using a [pandapower](https://github.com/e2nIEE/pandapower) interface that calls [PandaModels.jl](https://github.com/e2nIEE/PandaModels.jl) using PyCall to call Julia functions from Python.
4+
5+
<img src="https://github.com/gt-sse-center/PandaModelsBackend/blob/rearr/devtools/power_software_map.png" height=450>
36

47
## Installation
58
```pip install pandamodelsbackend```
69

710
## Refer to [tests/test_basic_usage.py]()
811

912
```
10-
from PandaModelsBackend import PandaModelsBackend
13+
from pandamodelsbackend import PandaModelsBackend
1114
1215
pp_net = pp.from_json(network_file) # Load PandaPower JSON
1316
.

changelog.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Changelog
2+
3+
<!--
4+
## vX.Y.0 / 2025-MM-DD (Unreleased)
5+
6+
#### Breaking Changes
7+
8+
#### New Features
9+
10+
#### Enhancements
11+
12+
#### Bug Fixes
13+
14+
#### Misc.
15+
16+
-->
17+
18+
19+
## v0.1.0 / 2025-MM-DD (Unreleased)
20+
21+
#### Breaking Changes
22+
23+
#### New Features
24+
* [\#1] (https://github.com/gt-sse-center/PandaModelsBackend/pull/1) Maint --
25+
added CI to show how to set up working environment with and without conda.
26+
* [\#2] (https://github.com/gt-sse-center/PandaModelsBackend/pull/2) Main --
27+
copied backend from grid2op, made modifications to call PandaPower, checked
28+
against AAA backend tests, and excused some until next v0.11 grid2op release.
29+
30+
#### Enhancements
31+
32+
#### Bug Fixes
33+
34+
#### Misc.
35+

devtools/power_software_map.png

483 KB
Loading

pandamodelsbackend/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
__all__ = ["PandaModelsBackend"]
2+
3+
from .pandaModelsBackend import PandaModelsBackend

pyproject.toml

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,58 @@
11
[project]
2-
name = "PandaModelsBackend"
3-
version = "0.0.1"
4-
description = "A PowerModels Backend for Grid2Op using PandaModels"
2+
name = "pandamodelsbackend"
3+
dynamic = ["version"]
4+
description = "A PowerModels Backend for Grid2op using PandaModels through PandaPower"
55
authors = [
66
{ name = "Ketan Bhardwaj", email = "ketanbj@gmail.com" }
77
]
88
readme = "README.md"
99
license = { file = "LICENSE" }
1010
requires-python = ">=3.12"
11+
# py312 taken from Donti env; other py versions untested
12+
classifiers = [
13+
"Development Status :: 4 - Beta",
14+
"Intended Audience :: Science/Research",
15+
"Programming Language :: Python :: 3 :: Only",
16+
"Programming Language :: Python :: 3",
17+
"Programming Language :: Python :: 3.12",
18+
"Programming Language :: Python :: 3.13",
19+
]
20+
dependencies = [
21+
"numpy",
22+
"scipy",
23+
"pandas",
24+
"pandapower",
25+
# packaging?
26+
"grid2op",
27+
]
1128

1229
[project.urls]
1330
repository = "https://github.com/gt-sse-center/PandaModelsBackend"
31+
changelog = "https://github.com/gt-sse-center/PandaModelsBackend/blob/main/changelog.md"
32+
issues = "https://github.com/gt-sse-center/PandaModelsBackend/issues"
1433

1534
[project.optional-dependencies]
1635
tests = [
17-
"pytest",
1836
"setuptools",
37+
# "pytest",
1938
# grid2op uses pkg_resources
2039
]
40+
numba = [
41+
"numba",
42+
]
2143

2244
[build-system]
2345
requires = [
24-
"setuptools",
25-
"setuptools-scm",
46+
"setuptools>=64",
47+
"setuptools-scm>=8",
2648
"wheel",
2749
"pip"
2850
]
2951
build-backend = "setuptools.build_meta"
3052

53+
[tool.setuptools]
54+
packages = ["pandamodelsbackend"]
55+
3156
[tool.setuptools_scm]
3257
version_scheme = "guess-next-dev"
3358
local_scheme = "no-local-version"

src/PandaModelsBackend/__init__.py

Lines changed: 0 additions & 3 deletions
This file was deleted.

tests/test_backend_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import unittest
22
from grid2op.tests.aaa_test_backend_interface import AAATestBackendAPI
33

4-
from PandaModelsBackend import PandaModelsBackend
4+
from pandamodelsbackend import PandaModelsBackend
55

66
class TestBackendAPI_PandaModelsBackend(AAATestBackendAPI, unittest.TestCase):
77
def make_backend(self, detailed_infos_for_cascading_failures=False):

tests/test_basic_usage.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import grid2op
2-
from PandaModelsBackend import PandaModelsBackend
2+
from pandamodelsbackend import PandaModelsBackend
33
import pandapower as pp
44
import pandapower.converter as pp_converter
55
import os
@@ -77,4 +77,4 @@ def test_grid2op_pandapower():
7777

7878
# Run the test
7979
if __name__ == "__main__":
80-
test_grid2op_pandapower()
80+
test_grid2op_pandapower()

0 commit comments

Comments
 (0)