Skip to main content

A PowerModels Backend for Grid2op using PandaModels through PandaPower

Project description

PandaModelsBackend

PandaModelsBackend provides a high-fidelity backend for Grid2op that uses PowerModels.jl. It achieves this using a pandapower interface that calls PandaModels.jl using PyCall to call Julia functions from Python.

Installation & Usage

pip install pandamodelsbackend

Refer to test_basic_usage for full independently runable example.

import grid2op
import pandapower as pp
from pandamodelsbackend import PandaModelsBackend

...
pp_net = pp.from_json(network_file)  # Load PandaPower JSON
backend = PandaModelsBackend(pp_net)
env = grid2op.make(env_name, backend=backend)

Setting up the Development Environment

For newcomers to Julia, setting up a software stack with compatible Python and Julia is perhaps the trickiest part of using PandaModelsBackend. Like Python, one can get Julia through an installer provided by the language developers or through a package manager, like conda. Both are shown below and are demonstrated (sort-of, for installers) in GitHub Actions CI. You'll need to separately install certain dependencies into Python and others into Julia. You never need to enter the Julia REPL. If you get tangled up, the CI file is a good, proven route to consult. Docs at pandapower may also be helpful. There are a lot of acceptable ways to get Python+Julia working, so as long as python-jl pandamodelsbackend/tests/test_backend_api.py is working at the end, you're probably good to run grid2op.

Notes
  • This software stack won't work on M1 Macs.
  • 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).
  • A few problems and solutions have been collected here.

Using a Python virtual environment

  • Create a python virtual environment python3 -m venv venv

    • If you don't have virtual env installed refer to this link

    • To activate your environment: source venv/bin/activate

    • Install grid2op, pandapower pip install grid2op pandapower pip install julia

  • Julia Installation refer to this

    • set your path variable to find Julia e.g., on MAC export PATH=/Applications/Julia-1.11.app/Contents/Resources/julia/bin:$PATH

    • Add PowerModels, PandaModels Packages in Julia Run Juila on command prompt. Access the package manager in julia by typing ]. Now install the packages: add Ipopt PowerModels.

    • Build PyCall: The library PyCall allows to use Python from inside julia. By default, PyCall uses the Conda.jl package to install a Miniconda distribution private to Julia. To use an already installed Python distribution (e.g. Anaconda), set the PYTHON environment variable inside the Julia prompt.

      Find path to your python in venv: which python e.g., - /bin/python

      On MacOS: ENV["PYTHON"]="<your python path>"

    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.

Using Conda

A Linux install script is provided at linux_conda_install.sh using Conda for Python and Julia dependencies. A snapshot (not necessarily latest) is shown below.

  1. copy a conda env spec file like unix.yaml. Customize python version, environment name, etc.

https://github.com/gt-sse-center/PandaModelsBackend/blob/d13dcd6fd43edecb3819562ec11398aa576d71e7/devtools/linux_conda_install.sh#L16-L58


Build

git clone https://github.com/gt-sse-center/PandaModelsBackend.git
cd PandaModelsBackend
python3 -m build
pip install -e .

Test

cd pandamodelsbackend/tests
python test_backend_api.py
# depending on installation, `python-jl` may be needed instead of `python` above

Release Procedure

  • On a local clone on branch main, update the CHANGELOG with PRs, the new version number, and the release date. Commit it.
  • Make an annotated tag for the new version. Push it along with any cleanup commits (e.g., changelog above). If you've forked the repo, "origin" will probably be "upstream". See git remote -v for names. You may need to disable direct push in Settings (Branches, main, Edit)
git tag -a v0.5.0 -m "v0.5.0"
git push --atomic origin main v0.5.0
  • The CI workflow will take over publication to PyPI and making a GitHub release. You can edit the frontmatter for the latter through the GitHub web interface with any particular details (and perhaps a link to the CHANGELOG section).

Troubleshooting the Software Stack

  1. Problem: Your Python interpreter "/path/to/miniconda/envs/rl2grid/bin/python" is statically linked to libpython. Currently, PyJulia does not fully support such Python interpreter.

    Solution: Use python-jl from conda (or Julia installation) instead of python.

  2. Problem: A pip installation involves compiling, and system compilers aren't working.

    Solution: conda install cxx-compiler -c conda-forge and rerun pip.

  3. Problem: AttributeError in pandapower file d2Sbus_dV2.

    Solution: This was fixed between v2.14.9 and master for csr_matrix?. Alternately, edit the diagV to below:

    /path/to/site-packages/pandapower/pypower/d2Sbus_dV2.py:    try:                         # added
    /path/to/site-packages/pandapower/pypower/d2Sbus_dV2.py:        D = Ybus.H * diagV       # indented
    /path/to/site-packages/pandapower/pypower/d2Sbus_dV2.py:    except AttributeError:       # added
    /path/to/site-packages/pandapower/pypower/d2Sbus_dV2.py:        D = Ybus.getH() * diagV  # added
    
  4. Problem: Package testing for PowerModels, PandaModels, or PandaPower shows a few (not all) failures.

    Solution: For a clean test suite, PowerModels needs Ipopt>=1 and the others need Ipopt<1. To toggle, do something like the below. See CI for a known working testing sequence.

    julia -e 'using Pkg; Pkg.add(Pkg.PackageSpec(;name="Ipopt", version="0.9")); using Ipopt'
    

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pandamodelsbackend-0.1.4.tar.gz (498.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pandamodelsbackend-0.1.4-py3-none-any.whl (22.3 kB view details)

Uploaded Python 3

File details

Details for the file pandamodelsbackend-0.1.4.tar.gz.

File metadata

  • Download URL: pandamodelsbackend-0.1.4.tar.gz
  • Upload date:
  • Size: 498.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pandamodelsbackend-0.1.4.tar.gz
Algorithm Hash digest
SHA256 3634a46d84c72736e3eedb059ee1d47aabe755850c3911a4a80c588568163e28
MD5 9b2224f3a1003e656a8ca2dbefabb372
BLAKE2b-256 a29522301ce7c84f4c9d7e4e2e301107745d8ae6aee38f92d52cc2b76cd2d2be

See more details on using hashes here.

Provenance

The following attestation bundles were made for pandamodelsbackend-0.1.4.tar.gz:

Publisher: ci.yml on gt-sse-center/PandaModelsBackend

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pandamodelsbackend-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for pandamodelsbackend-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 49c7ce70c2ed34a9616021a1d65b59a7c59ebdcca7e9e6e31a25edbe6d58f9b0
MD5 884ed5196658d142ceb3ebb7f98eec6c
BLAKE2b-256 b23ff0e8604456fc97dfb850a03c6c5f12f06d37d8d76d5f2a5484211f1745d3

See more details on using hashes here.

Provenance

The following attestation bundles were made for pandamodelsbackend-0.1.4-py3-none-any.whl:

Publisher: ci.yml on gt-sse-center/PandaModelsBackend

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page