Skip to content

Commit e857374

Browse files
committed
test PandaModelsBackend with julia
1 parent 4ed5d73 commit e857374

File tree

3 files changed

+178
-1
lines changed

3 files changed

+178
-1
lines changed

.circleci/config.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,66 @@ jobs:
243243
export _GRID2OP_FORCE_TEST=1
244244
python -m unittest grid2op/tests/fromChronix2grid.py
245245
246+
test_powermodels:
247+
executor: python312
248+
resource_class: medium+ # install_julia step killed w/"small"
249+
steps:
250+
- checkout
251+
- run:
252+
command: |
253+
sudo apt-get update
254+
sudo apt-get install -y coinor-cbc
255+
- run: python -m pip install virtualenv
256+
- run: python -m virtualenv venv_test
257+
- run:
258+
name: Install Python dependencies
259+
command: |
260+
source venv_test/bin/activate
261+
python -m pip install -U pip setuptools wheel pytest
262+
- run:
263+
name: Install Grid2op
264+
command: |
265+
source venv_test/bin/activate
266+
# below (1 line) is fine when released pandamodelsbackend works w/grid2op
267+
# python -m pip install -e .[powermodels]
268+
# but when need special PdMdB repo, in this case to work with grid2op 1.11dev, use below (2 lines)
269+
python -m pip install -e .
270+
python -m pip install 'git+https://github.com/MOSSLab-MIT/PandaModelsBackend.git@g2o_v1p11'
271+
pip freeze
272+
- run:
273+
name: Install Julia and power software
274+
command: |
275+
source venv_test/bin/activate
276+
./utils/install_julia.sh 1.10.4
277+
python -m pip install julia
278+
julia -e 'using Pkg; Pkg.add(["PandaModels", "PyCall"])'
279+
- run:
280+
name: Environment information
281+
command: |
282+
source venv_test/bin/activate
283+
pip list
284+
pip list | grep -e power -e grid -e panda
285+
which python python-jl julia
286+
python --version
287+
python-jl --version
288+
julia --version
289+
julia -e 'using Pkg; Pkg.status(); Pkg.status(outdated=true)'
290+
julia -e 'using PyCall; math = pyimport("math"); print(math.sin(math.pi/4))'
291+
- run:
292+
name: Test PowerModels in PandaPower
293+
command: |
294+
source venv_test/bin/activate
295+
pyMm=$(python -c "import sys;print(f'{sys.version_info.major}.{sys.version_info.minor}')")
296+
python -m pytest -v venv_test/lib/python$pyMm/site-packages/pandapower/test/opf/test_pandamodels_runpm.py
297+
# use python-jl instead of python above if get a static libpython error
298+
- run:
299+
name: Test PandaModelsBackend
300+
command: |
301+
source venv_test/bin/activate
302+
pyMm=$(python -c "import sys;print(f'{sys.version_info.major}.{sys.version_info.minor}')")
303+
python venv_test/lib/python$pyMm/site-packages/pandamodelsbackend/tests/test_backend_api.py
304+
# use python-jl instead of python above if get a static libpython error
305+
246306
install39:
247307
executor: python39
248308
resource_class: small
@@ -395,6 +455,7 @@ workflows:
395455
- legacy_lightsim_old_pp
396456
- legacy_lightsim
397457
- test_chronix2grid
458+
- test_powermodels
398459

399460
install:
400461
jobs:

setup.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@ def my_test_suite():
7979
],
8080
"chronix2grid": [
8181
"ChroniX2Grid>=1.2.0.post1"
82-
]
82+
],
83+
"powermodels": [
84+
"PandaModelsBackend"
85+
],
8386
}
8487
}
8588
pkgs["extras"]["test"] += pkgs["extras"]["optional"]

utils/install_julia.sh

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
#!/bin/bash
2+
# install julia vX.Y.Z: ./install-julia.sh X.Y.Z
3+
# install julia nightly: ./install-julia.sh nightly
4+
5+
# LICENSE
6+
#
7+
# Copyright © 2013 by Steven G. Johnson, Fernando Perez, Jeff
8+
# Bezanson, Stefan Karpinski, Keno Fischer, Jake Bolewski, Takafumi
9+
# Arakaki, and other contributors.
10+
#
11+
# Permission is hereby granted, free of charge, to any person obtaining
12+
# a copy of this software and associated documentation files (the
13+
# "Software"), to deal in the Software without restriction, including
14+
# without limitation the rights to use, copy, modify, merge, publish,
15+
# distribute, sublicense, and/or sell copies of the Software, and to
16+
# permit persons to whom the Software is furnished to do so, subject to
17+
# the following conditions:
18+
#
19+
# The above copyright notice and this permission notice shall be
20+
# included in all copies or substantial portions of the Software.
21+
#
22+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26+
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27+
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28+
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29+
30+
# stop on error
31+
set -e
32+
VERSION="$1"
33+
34+
case "$VERSION" in
35+
nightly)
36+
BASEURL="https://julialangnightlies-s3.julialang.org/bin"
37+
JULIANAME="julia-latest"
38+
;;
39+
[0-9]*.[0-9]*.[0-9]*)
40+
BASEURL="https://julialang-s3.julialang.org/bin"
41+
SHORTVERSION="$(echo "$VERSION" | grep -Eo '^[0-9]+\.[0-9]+')"
42+
JULIANAME="$SHORTVERSION/julia-$VERSION"
43+
;;
44+
[0-9]*.[0-9])
45+
BASEURL="https://julialang-s3.julialang.org/bin"
46+
SHORTVERSION="$(echo "$VERSION" | grep -Eo '^[0-9]+\.[0-9]+')"
47+
JULIANAME="$SHORTVERSION/julia-$VERSION-latest"
48+
;;
49+
*)
50+
echo "Unrecognized VERSION=$VERSION, exiting"
51+
exit 1
52+
;;
53+
esac
54+
55+
case $(uname) in
56+
Linux)
57+
case $(uname -m) in
58+
x86_64)
59+
ARCH="x64"
60+
case "$JULIANAME" in
61+
julia-latest)
62+
SUFFIX="linux64"
63+
;;
64+
*)
65+
SUFFIX="linux-x86_64"
66+
;;
67+
esac
68+
;;
69+
i386 | i486 | i586 | i686)
70+
ARCH="x86"
71+
case "$JULIANAME" in
72+
julia-latest)
73+
SUFFIX="linux32"
74+
;;
75+
*)
76+
SUFFIX="linux-i686"
77+
;;
78+
esac
79+
;;
80+
*)
81+
echo "Do not have Julia binaries for this architecture, exiting"
82+
exit 1
83+
;;
84+
esac
85+
echo "$BASEURL/linux/$ARCH/$JULIANAME-$SUFFIX.tar.gz"
86+
curl -L "$BASEURL/linux/$ARCH/$JULIANAME-$SUFFIX.tar.gz" | tar -xz
87+
sudo ln -s $PWD/julia-*/bin/julia /usr/local/bin/julia
88+
julia -e 'import Pkg; Pkg.add("PyCall");'
89+
julia -e 'import Pkg; Pkg.Registry.update(); Pkg.add("PandaModels"); Pkg.build(); Pkg.resolve();'
90+
;;
91+
Darwin)
92+
if [ -e /usr/local/bin/julia ]; then
93+
echo "/usr/local/bin/julia already exists, exiting"
94+
exit 1
95+
elif [ -e julia.dmg ]; then
96+
echo "julia.dmg already exists, exiting"
97+
exit 1
98+
elif [ -e ~/julia ]; then
99+
echo "~/julia already exists, exiting"
100+
exit 1
101+
fi
102+
curl -Lo julia.dmg "$BASEURL/mac/x64/$JULIANAME-mac64.dmg"
103+
hdiutil mount -mountpoint /Volumes/Julia julia.dmg
104+
cp -Ra /Volumes/Julia/*.app/Contents/Resources/julia ~
105+
ln -s ~/julia/bin/julia /usr/local/bin/julia
106+
# TODO: clean up after self?
107+
;;
108+
*)
109+
echo "Do not have Julia binaries for this platform, exiting"
110+
exit 1
111+
;;
112+
esac
113+

0 commit comments

Comments
 (0)