Skip to content

Commit a661e6a

Browse files
authored
install script (#6)
* install script * commit sha * if/else * one version * trivia * try script lane * try 2 * try 3 * try 4 * try 5 * try 6 * try 7 * try 8 * try 9 * try 11 * try 12 * try 13 * try 14 * try 15 * try 16 * try 17 * script for rel, ci for repo * fix * fix * fix * checkpoint tag
1 parent 08b4a12 commit a661e6a

File tree

8 files changed

+142
-56
lines changed

8 files changed

+142
-56
lines changed

.github/workflows/ci.yml

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ jobs:
4747
# runs-on: macos-latest # fails b/c cbc can't compile on M1 (the GHA runners)
4848
shell: 'bash -e {0}'
4949

50+
- conda-env: null
51+
python-version: "3.12"
52+
julia-version: "1.10"
53+
label: script
54+
runs-on: ubuntu-latest
55+
shell: 'bash -l {0}'
56+
5057
defaults:
5158
run:
5259
shell: ${{ matrix.cfg.shell }}
@@ -56,16 +63,55 @@ jobs:
5663

5764
steps:
5865
- uses: actions/checkout@v4
66+
if: matrix.cfg.label == 'script'
67+
with:
68+
sparse-checkout: |
69+
devtools/linux_conda_install.sh
70+
devtools/conda-envs/unix.yaml
71+
# last can be removed
72+
sparse-checkout-cone-mode: false
73+
74+
- uses: actions/checkout@v4
75+
if: matrix.cfg.label != 'script'
5976
with:
6077
fetch-depth: 0
6178
persist-credentials: false
6279

80+
- name: Edit env file
81+
if: matrix.cfg.label == 'conda'
82+
run: |
83+
echo "::group::View Env Spec File for Conda (from repo)"
84+
cp devtools/conda-envs/${{ matrix.cfg.conda-env }}.yaml unix.yaml
85+
cat unix.yaml
86+
echo "::endgroup::"
87+
if [[ "${{ runner.os }}" == "Linux" ]]; then
88+
:
89+
sed -i "s;- pandamodelsbackend;#- pandamodelsbackend;g" unix.yaml
90+
fi
91+
if [[ "${{ runner.os }}" == "macOS" ]]; then
92+
:
93+
sed -E -i.bak "s;- pandamodelsbackend;#- pandamodelsbackend;g" unix.yaml
94+
fi
95+
echo "::group::View Env Spec File for Conda (Edited)"
96+
cat unix.yaml
97+
echo "::endgroup::"
98+
pwd
99+
ls -l
100+
101+
- name: Install Conda Python ${{ matrix.cfg.python-version }}
102+
if: matrix.cfg.label == 'script'
103+
uses: conda-incubator/setup-miniconda@v3
104+
with:
105+
show-channel-urls: true
106+
auto-activate-base: true
107+
activate-environment: ""
108+
63109
- name: Install Conda Python ${{ matrix.cfg.python-version }} and power software
64110
if: matrix.cfg.label == 'conda'
65111
uses: conda-incubator/setup-miniconda@v3
66112
with:
67113
activate-environment: test
68-
environment-file: devtools/conda-envs/${{ matrix.cfg.conda-env }}.yaml
114+
environment-file: unix.yaml
69115
python-version: ${{ matrix.cfg.python-version }}
70116
auto-activate-base: false
71117
show-channel-urls: true
@@ -100,6 +146,7 @@ jobs:
100146
cache-packages: false
101147

102148
- name: Install Julia power software
149+
if: matrix.cfg.label != 'script'
103150
run: |
104151
julia -e '
105152
using Pkg
@@ -111,10 +158,12 @@ jobs:
111158
])'
112159
113160
- name: Install PandaModelsBackend
161+
if: matrix.cfg.label != 'script'
114162
run: |
115163
python -m pip install -e .[tests]
116164
117165
- name: Environment information
166+
if: matrix.cfg.label != 'script'
118167
run: |
119168
python -m pip list
120169
python -m pip list | grep -e power -e grid -e panda
@@ -124,14 +173,21 @@ jobs:
124173
julia --version
125174
julia -e 'using Pkg; Pkg.status(); Pkg.status(outdated=true)'
126175
176+
- name: Check all-in-one install script
177+
if: matrix.cfg.label == 'script'
178+
run: |
179+
source devtools/linux_conda_install.sh
180+
127181
- name: Test PowerModels in Julia
128182
# if: false
183+
if: matrix.cfg.label != 'script'
129184
run: |
130185
julia -e 'using PyCall; math = pyimport("math"); print(math.sin(math.pi/4))'
131186
julia -e 'using Pkg; Pkg.test("PowerModels")'
132187
# PM testing above is clean but takes 6m, so optionally toggle off
133188
134189
- name: Test PandaModels in Julia
190+
if: matrix.cfg.label != 'script'
135191
run: |
136192
julia -e 'using Pkg; Pkg.add(Pkg.PackageSpec(;name="Ipopt", version="0.9"))'
137193
julia -e 'using Pkg; Pkg.status(); Pkg.status(outdated=true)'
@@ -154,6 +210,7 @@ jobs:
154210
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
155211
156212
- name: Test PowerModels in PandaPower
213+
if: matrix.cfg.label != 'script'
157214
run: |
158215
which python python-jl
159216
python-jl -m pytest -v $(dirname $(which python))/../lib/python${{ matrix.cfg.python-version }}/site-packages/pandapower/test/opf/test_pandamodels_runpm.py
@@ -162,14 +219,15 @@ jobs:
162219
# PdP testing above has a couple failures b/c Ipopt=1 unless downgrade (taking PM with it)
163220
164221
- name: Test PandaModelsBackend (basic)
165-
if: runner.os == 'Linux'
222+
if: runner.os == 'Linux' && matrix.cfg.label != 'script'
166223
run: |
167224
which python python-jl
168-
python-jl tests/test_basic_usage.py
225+
python-jl pandamodelsbackend/tests/test_basic_usage.py
169226
170227
- name: Test PandaModelsBackend (API)
228+
if: matrix.cfg.label != 'script'
171229
run: |
172-
python-jl tests/test_backend_api.py
230+
python-jl pandamodelsbackend/tests/test_backend_api.py
173231
174232
- name: Install pypa/build & build a binary wheel and a source tarball
175233
if: matrix.cfg.label == 'installer' && runner.os == 'Linux'

README.md

Lines changed: 8 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ PandaModelsBackend provides a high-fidelity backend for [Grid2op](https://github
88

99
```pip install pandamodelsbackend```
1010

11-
Refer to [test_basic_usage](tests/test_basic_usage.py) for full independently runable example.
11+
Refer to [test_basic_usage](pandamodelsbackend/tests/test_basic_usage.py) for full independently runable example.
1212

1313
```
1414
import grid2op
@@ -31,15 +31,15 @@ Both are shown below and are demonstrated (sort-of, for installers) in [GitHub A
3131
You'll need to separately install certain dependencies into Python and others into Julia. You never need to enter the Julia REPL.
3232
If you get tangled up, the CI file is a good, proven route to consult.
3333
[Docs at pandapower](https://pandapower.readthedocs.io/en/v2.6.0/opf/powermodels.html) may also be helpful.
34-
There are a lot of acceptable ways to get Python+Julia working, so as long as [`python-jl tests/test_backend_api.py`](tests/test_backend_api.py) is working at the end, you're probably good to run grid2op.
34+
There are a lot of acceptable ways to get Python+Julia working, so as long as [`python-jl pandamodelsbackend/tests/test_backend_api.py`](pandamodelsbackend/tests/test_backend_api.py) is working at the end, you're probably good to run grid2op.
3535

3636
##### Notes
3737

3838
* This software stack won't work on M1 Macs.
3939
* Conda can be used for Python and Julia for Linux and Intel Macs. There isn't a `julia` package for Silicon Macs, so you'll need to use the Julia installer (+ conda or installer Python).
4040
* A few problems and solutions have been collected [here](#troubleshooting-the-software-stack).
4141

42-
#### Using a Python virtual environment
42+
### Using a Python virtual environment
4343

4444
- Create a python virtual environment
4545
```python3 -m venv venv```
@@ -72,56 +72,13 @@ There are a lot of acceptable ways to get Python+Julia working, so as long as [`
7272

7373
Access the package manager again in julia by typing ]. Now install the packages: ```add PyCall```. To pass the python environment variable, running build PyCall inside the julia package manager may be necessary.
7474

75-
#### Using Conda
75+
### Using Conda
7676

77-
0. copy a conda env spec file like [unix.yaml](devtools/conda-envs/unix.yaml). Customize python version, environment name, etc.
78-
79-
```
80-
# 1. create a new conda env from the spec.
81-
conda env create -f unix.yaml && conda activate test
77+
A Linux install script is provided at [linux_conda_install.sh](devtools/linux_conda_install.sh) using Conda for Python and Julia dependencies. A *snapshot* (not necessarily latest) is shown below.
8278

83-
# 2. install editable PandaModelsBackend
84-
git clone https://github.com/gt-sse-center/PandaModelsBackend.git && cd PandaModelsBackend
85-
pip install -e .
79+
0. copy a conda env spec file like [unix.yaml](devtools/conda-envs/unix.yaml). Customize python version, environment name, etc.
8680

87-
# 3. install PowerModels into Julia
88-
# equivalent to entering pkg mode of Julia REPL, adding packages, and exiting REPL via:
89-
# julia <Enter> ] <Enter> add Ipopt PowerModels PyCall <Enter> # await compilation <Ctrl-D>
90-
julia -e 'using Pkg; Pkg.add(["Ipopt", "PowerModels", "PandaModels", "PyCall"])'
91-
92-
# 4. (optional) check languages and power projects installed. $CONDA_PREFIX is placeholder, not literal
93-
which python julia python-jl
94-
#> $CONDA_PREFIX/bin/python
95-
#> $CONDA_PREFIX/bin/julia
96-
#> $CONDA_PREFIX/bin/python-jl
97-
98-
conda list | grep -e power -e grid -e panda
99-
#>grid2op 1.10.5.post1 pypi_0 pypi
100-
#>pandamodelsbackend 0.1.1 pypi_0 pypi
101-
#>pandapower 2.14.9 pyhd8ed1ab_1 conda-forge
102-
#>pandas 2.2.3 py312hf9745cd_1 conda-forge
103-
104-
# equivalent to `julia <Enter> ] <Enter> status <Enter> # observe <Ctrl-D>
105-
julia -e 'using Pkg; Pkg.status(); Pkg.status(outdated=true)'
106-
#>Status `$CONDA_PREFIX/share/julia/environments/test/Project.toml`
107-
#>⌅ [b6b21f68] Ipopt v0.9.1
108-
#> [2dbab86a] PandaModels v0.7.3
109-
#>⌅ [c36e90e8] PowerModels v0.19.10
110-
#> [438e738f] PyCall v1.96.4
111-
#>Status `$CONDA_PREFIX/share/julia/environments/test/Project.toml`
112-
#>⌅ [b6b21f68] Ipopt v0.9.1 (<v1.7.2): PandaModels
113-
#>⌅ [c36e90e8] PowerModels v0.19.10 (<v0.21.3): PandaModels
114-
115-
# 5. (optional) check Python, Julia, PandaPower functioning together
116-
julia -e 'using PyCall; math = pyimport("math"); print(math.sin(math.pi/4))'
117-
#>0.7071067811865475
118-
pyMm=$(python -c "import sys;print(f'{sys.version_info.major}.{sys.version_info.minor}')")
119-
python-jl $CONDA_PREFIX/lib/python$pyMm/site-packages/pandapower/test/opf/test_pandamodels_runpm.py
120-
#>20 passed, 1 xpassed, 1226 warnings in 267.01s (0:04:27)
121-
python-jl tests/test_backend_api.py
122-
#>Ran 31 tests in 58.499s
123-
#>OK
124-
```
81+
https://github.com/gt-sse-center/PandaModelsBackend/blob/d13dcd6fd43edecb3819562ec11398aa576d71e7/devtools/linux_conda_install.sh#L16-L58
12582

12683
-----
12784

@@ -135,7 +92,7 @@ pip install -e .
13592

13693
## Test
13794
```
138-
cd tests
95+
cd pandamodelsbackend/tests
13996
python test_backend_api.py
14097
# depending on installation, `python-jl` may be needed instead of `python` above
14198
```

changelog.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@
2929
#### Misc.
3030

3131

32+
## v0.1.4 / 2025-03-24
33+
34+
#### New Features
35+
* [\#6] (https://github.com/gt-sse-center/PandaModelsBackend/pull/6) Maint --
36+
added installer script, part I.
37+
38+
3239
## v0.1.3 / 2025-03-17
3340

3441
#### New Features

devtools/conda-envs/unix.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ dependencies:
1616
- setuptools
1717
- pip
1818
- pip:
19+
- pandamodelsbackend # this repo. comment this, clone the repo, and `pip install -e .` to develop
1920
- grid2op
2021
# - lightsim2grid # optional
2122
# - matpowercaseframes # optional
2223
# - cxx-compiler # optional if needed for further pip packages requiring compilation
2324

2425
# Notes:
25-
# * py312 has been tested. others likely work
26+
# * py312 has been tested. others likely work. py313 may be blocked by requiring numpy v1
2627
# * works as-is for Linux and Intel Mac. conda packages for Julia aren't available for Silicon Mac.

devtools/conda-envs/unix_rl2grid.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ dependencies:
1818
- curl<8.10 # avoid segfault in Julia w/ curl v8.10 . recheck periodically
1919
- pip
2020
- pip:
21+
- pandamodelsbackend # this repo. comment this, clone the repo, and `pip install -e .` to develop
2122
- grid2op
2223
- lightsim2grid # optional
2324
- matpowercaseframes # optional

devtools/linux_conda_install.sh

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/usr/bin/env bash
2+
3+
# This assumes you do have Miniconda/Anaconda installed.
4+
# It *doesn't* assume you have Julia installed and instead downloads Julia from Conda.
5+
# It *doesn't* assume you've cloned the PandaModelsBackend and instead installs latest release. Change at step # 2.
6+
7+
# 0. copy a conda env spec file like [unix.yaml](https://github.com/gt-sse-center/PandaModelsBackend/blob/main/devtools/conda-envs/unix.yaml).
8+
# This uses a wget or curl command like the below if not running this script from a repository clone.
9+
# Customize python version, environment name, etc.
10+
if [ -f "./devtools/conda-envs/unix.yaml" ]; then
11+
cp -p ./devtools/conda-envs/unix.yaml .
12+
else
13+
curl -o ./unix.yaml https://raw.githubusercontent.com/gt-sse-center/PandaModelsBackend/refs/heads/main/devtools/conda-envs/unix.yaml
14+
# wget -O ./unix.yaml https://raw.githubusercontent.com/gt-sse-center/PandaModelsBackend/refs/heads/main/devtools/conda-envs/unix.yaml
15+
fi
16+
17+
# 1. create a new conda env from the spec.
18+
cat unix.yaml # TODO RM
19+
conda env create -f ./unix.yaml && conda activate test
20+
21+
# 2. install editable PandaModelsBackend
22+
#git clone https://github.com/gt-sse-center/PandaModelsBackend.git && cd PandaModelsBackend
23+
#pip install -e .
24+
25+
# 3. install PowerModels into Julia
26+
# equivalent to entering pkg mode of Julia REPL, adding packages, and exiting REPL via:
27+
# julia <Enter> ] <Enter> add Ipopt PowerModels PyCall <Enter> # await compilation <Ctrl-D>
28+
julia -e 'using Pkg; Pkg.add(["Ipopt", "PowerModels", "PandaModels", "PyCall"])'
29+
30+
# 4. (optional) check languages and power projects installed. $CONDA_PREFIX is placeholder, not literal
31+
which python julia python-jl
32+
#> $CONDA_PREFIX/bin/python
33+
#> $CONDA_PREFIX/bin/julia
34+
#> $CONDA_PREFIX/bin/python-jl
35+
36+
conda list | grep -e power -e grid -e panda
37+
#>grid2op 1.10.5.post1 pypi_0 pypi
38+
#>pandamodelsbackend 0.1.1 pypi_0 pypi
39+
#>pandapower 2.14.9 pyhd8ed1ab_1 conda-forge
40+
#>pandas 2.2.3 py312hf9745cd_1 conda-forge
41+
42+
julia -e 'using Pkg; Pkg.status(); Pkg.status(outdated=true)'
43+
#>Status `$CONDA_PREFIX/share/julia/environments/test/Project.toml`
44+
#>⌅ [b6b21f68] Ipopt v0.9.1
45+
#> [2dbab86a] PandaModels v0.7.3
46+
#>⌅ [c36e90e8] PowerModels v0.19.10
47+
#> [438e738f] PyCall v1.96.4
48+
#>Status `$CONDA_PREFIX/share/julia/environments/test/Project.toml`
49+
#>⌅ [b6b21f68] Ipopt v0.9.1 (<v1.7.2): PandaModels
50+
#>⌅ [c36e90e8] PowerModels v0.19.10 (<v0.21.3): PandaModels
51+
52+
# 5. (optional) check Python, Julia, PandaPower functioning together
53+
julia -e 'using PyCall; math = pyimport("math"); print(math.sin(math.pi/4))'
54+
#>0.7071067811865475
55+
pyMm=$(python -c "import sys;print(f'{sys.version_info.major}.{sys.version_info.minor}')")
56+
python-jl $CONDA_PREFIX/lib/python$pyMm/site-packages/pandapower/test/opf/test_pandamodels_runpm.py
57+
#>20 passed, 1 xpassed, 1226 warnings in 267.01s (0:04:27)
58+
ls -l $CONDA_PREFIX/lib/python$pyMm/site-packages/pandamodelsbackend/ # TODO RM
59+
#python-jl pandamodelsbackend/tests/test_backend_api.py # TODO REENABLE
60+
#>Ran 31 tests in 58.499s
61+
#>OK
62+
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)