Skip to content

Commit 101bc7f

Browse files
authored
Add GitHub Actions Testing (#1)
* initial gha * try 2 * try 3 * try 4 * try 5 * try 6 * try 7 * try 8 * try 9 * try 10 * try 11 * try 12 * try 13 * try 14 * try 15 * Update ci.yml * Update linux.yaml * Update ci.yml * Update ci.yml * Update ci.yml * try16 * try 17 * try 18 * try 19 * try 20 * try 21 * try 22
1 parent 515f9ba commit 101bc7f

File tree

4 files changed

+205
-2
lines changed

4 files changed

+205
-2
lines changed

.github/workflows/ci.yml

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
schedule:
11+
- cron: "9 16 * * 1"
12+
13+
jobs:
14+
build:
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
cfg:
19+
- conda-env: unix
20+
python-version: "3.12"
21+
julia-version: "1.10"
22+
label: conda
23+
runs-on: ubuntu-latest
24+
shell: 'bash -l {0}'
25+
26+
- conda-env: null
27+
python-version: "3.12"
28+
julia-version: "1.10"
29+
label: installer
30+
runs-on: ubuntu-latest
31+
shell: 'bash -e {0}'
32+
33+
- conda-env: unix
34+
python-version: "3.12"
35+
julia-version: "1.10"
36+
label: conda
37+
runs-on: macos-13
38+
shell: 'bash -l {0}'
39+
40+
- conda-env: null
41+
python-version: "3.12"
42+
julia-version: "1.10"
43+
label: installer
44+
runs-on: macos-13
45+
# runs-on: macos-latest # fails b/c cbc can't compile on M1 (the GHA runners)
46+
shell: 'bash -e {0}'
47+
48+
defaults:
49+
run:
50+
shell: ${{ matrix.cfg.shell }}
51+
52+
name: "🐍 ${{ matrix.cfg.python-version }} • ${{ matrix.cfg.label }} • ${{ matrix.cfg.runs-on }}"
53+
runs-on: ${{ matrix.cfg.runs-on }}
54+
55+
steps:
56+
- uses: actions/checkout@v4
57+
with:
58+
fetch-depth: 0
59+
60+
- name: Install Conda Python ${{ matrix.cfg.python-version }} and power software
61+
if: matrix.cfg.label == 'conda'
62+
uses: conda-incubator/setup-miniconda@v3
63+
with:
64+
activate-environment: test
65+
environment-file: devtools/conda-envs/${{ matrix.cfg.conda-env }}.yaml
66+
python-version: ${{ matrix.cfg.python-version }}
67+
auto-activate-base: false
68+
show-channel-urls: true
69+
add-pip-as-python-dependency: true
70+
conda-remove-defaults: true
71+
72+
- name: Install Python ${{ matrix.cfg.python-version }}
73+
if: matrix.cfg.label == 'installer'
74+
uses: actions/setup-python@v4
75+
with:
76+
python-version: ${{ matrix.cfg.python-version }}
77+
78+
- name: Install Python power software
79+
if: matrix.cfg.label == 'installer'
80+
run: |
81+
uname -p
82+
which python pip
83+
python --version
84+
python -m pip install numpy pandas scipy pytest grid2op julia "pandapower==2.14.11"
85+
86+
- name: Install Julia ${{ matrix.cfg.julia-version }}
87+
if: matrix.cfg.label == 'installer'
88+
uses: julia-actions/setup-julia@v2
89+
with:
90+
version: ${{ matrix.cfg.julia-version }}
91+
92+
- name: Cache Julia
93+
if: matrix.cfg.label == 'installer'
94+
uses: julia-actions/cache@v2
95+
with:
96+
cache-name: ${{ matrix.cfg-runs-on }}-test-${{ matrix.cfg.julia-version }}-${{ matrix.cfg.python-version }}
97+
cache-packages: false
98+
99+
- name: Install Julia power software
100+
run: |
101+
julia -e '
102+
using Pkg
103+
Pkg.add([
104+
Pkg.PackageSpec(;name="Ipopt"),
105+
Pkg.PackageSpec(;name="PowerModels", version="0.21.3"),
106+
Pkg.PackageSpec(;name="PyCall"),
107+
Pkg.PackageSpec(;url="https://github.com/loriab/PandaModels.jl", rev="update_pm")
108+
])'
109+
110+
- name: Install PandaModelsBackend
111+
run: |
112+
python -m pip install -e .[tests]
113+
114+
- name: Environment information
115+
run: |
116+
python -m pip list
117+
python -m pip list | grep -e power -e grid -e panda
118+
which python python-jl julia
119+
python --version
120+
python-jl --version
121+
julia --version
122+
julia -e 'using Pkg; Pkg.status(); Pkg.status(outdated=true)'
123+
124+
- name: Test PowerModels in Julia
125+
# if: false
126+
run: |
127+
julia -e 'using PyCall; math = pyimport("math"); print(math.sin(math.pi/4))'
128+
julia -e 'using Pkg; Pkg.test("PowerModels")'
129+
# PM testing above is clean but takes 6m, so optionally toggle off
130+
131+
- name: Test PandaModels in Julia
132+
run: |
133+
julia -e 'using Pkg; Pkg.add(Pkg.PackageSpec(;name="Ipopt", version="0.9"))'
134+
julia -e 'using Pkg; Pkg.status(); Pkg.status(outdated=true)'
135+
julia -e 'using PandaModels'
136+
julia -e 'using Pkg; Pkg.test("PandaModels")'
137+
# PdM testing above has a couple failures b/c Ipopt=1 unless downgrade (taking PM with it)
138+
# shortcut this step by commenting out the Pkg.test above
139+
140+
- name: Special setup Mac
141+
if: matrix.cfg.label == 'installer' && runner.os == 'macOS'
142+
run: |
143+
# warning: hard coded path
144+
julia -e 'ENV["PYTHON"]="/Users/runner/hostedtoolcache/Python/3.12.9/x64/bin/python"; using Pkg; Pkg.build("PyCall")'
145+
146+
- 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
149+
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
152+
153+
- name: Test PowerModels in PandaPower
154+
run: |
155+
which python python-jl
156+
python-jl -m pytest -v $(dirname $(which python))/../lib/python${{ matrix.cfg.python-version }}/site-packages/pandapower/test/opf/test_pandamodels_runpm.py
157+
# use python-jl instead of python above if get a static libpython error
158+
# loc is simply $CONDA_PREFIX but the setup-python counterpart env.pythonLocation seems broken
159+
# PdP testing above has a couple failures b/c Ipopt=1 unless downgrade (taking PM with it)
160+
161+
- name: Test PandaModelsBackend
162+
# if: false # for now since there's some issues
163+
run: |
164+
cd tests
165+
which python python-jl
166+
python-jl test_basic_usage.py
167+
# python test_backend_api.py

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ env = grid2op.make(env_name, backend=backend)
5858
## Build
5959
```
6060
git clone https://github.com/gt-sse-center/PandaModelsBackend.git
61-
cd PandaModelBackend.git
61+
cd PandaModelsBackend
6262
python3 -m build
6363
pip install -e .
6464
```
@@ -67,4 +67,4 @@ pip install -e .
6767
```
6868
cd tests
6969
python test_backend_api.py
70-
```
70+
```

devtools/conda-envs/unix.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: test
2+
channels:
3+
- conda-forge
4+
dependencies:
5+
- python=3.12
6+
- pytorch
7+
- tensorboard
8+
- wandb
9+
- gymnasium>=0.29.1
10+
- stable-baselines3>=2.3.2
11+
- scipy
12+
- pyjulia # brings julia
13+
- pandapower=2
14+
- pytest-xdist # optional, for testing
15+
- curl<8.10 # avoid segfault in Julia w/ curl v8.10 . recheck periodically
16+
- pip
17+
- pip:
18+
- grid2op
19+
- lightsim2grid # optional
20+
- matpowercaseframes # optional
21+
# - cxx-compiler # optional if needed for further pip packages
22+
23+
# Notes:
24+
# * defaults and pytorch channels removed as likely unneeded.
25+
# * cpuonly removed b/c not a c-f pkg
26+
# * py312 has been tested. others likely work
27+
# * pytorch was pinned at 2.2.0 and scipy at 1.11.3 . reset if needed for repro, but generic better.
28+
# * recent stable-baselines3 can accommodate gymnasium v1, so pins relaxed to mins. reset if needed for repro. etc.
29+

pyproject.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ requires-python = ">=3.12"
1212
[project.urls]
1313
repository = "https://github.com/gt-sse-center/PandaModelsBackend"
1414

15+
[project.optional-dependencies]
16+
tests = [
17+
"pytest",
18+
"setuptools",
19+
# grid2op uses pkg_resources
20+
]
21+
1522
[build-system]
1623
requires = [
1724
"setuptools",

0 commit comments

Comments
 (0)