Optimization with PandaModels.jl

Introduction

PandaModels.jl (pandapower + PowerModels.jl) is an interface (Julia package) enabling the connection of pandapower and PowerModels in a stable and functional way. Except for calling the implemented optimization models in PowerModels, users can create custom optimization models with PandaModels. Presently, users can solve some reactive power optimization problems with PandaModels.

Installation

If you are not yet using Julia, install it. For the interface to work, note that you need a version that is supported by PowerModels, PyCall and pyjulia. Currently, Former julia versions are available here.

Note

You don’t necessarily need a Julia IDE if you are using PandaModels through pandapower, but it might help for debugging to install an IDE such as Juno. Also, PyCharm has a Julia Plugin.

  1. Add the Julia binary folder (e.g. C:UsersusernameAppDataLocalProgramsJulia-1.8.0bin` on Windows or `/Applications/Julia-1.5.app/Contents/Resources/julia/bin on MacOS) to the system variable PATH. Providing the path is correct, you can now enter the julia prompt by executing julia in your shell (on Windows, rebooting the system is needed to take advantage of changes to the PATH.

  2. 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.

    On Windows:

    ENV["PYTHON"]=raw"C:\Anaconda3\python.exe"

    On MacOS:

    ENV["PYTHON"]="/Users/%Username/opt/anaconda3/bin/python"

  3. Access the package manager by typing ]. Now install the packages: add Ipopt PowerModels PyCall. To pass the python environment variable, running build PyCall inside the julia package manager may be neccessary.

  4. Inside package manager, test your PowerModels installation by executing test PowerModels. Alternatively, you can call using Pkg and then Pkg.test("PowerModels") outside the package manager directly as julia expression. Then, test wether calling Python from Julia works, as described here.

Note

If you cannot plot using PyCall and PyPlot in Julia, see the workarounds offered here.

  1. To call Julia from Python, install the pyjulia package with pip install julia. Afterwards, test if everything works by importing PowerModels from Python with: from julia.PowerModels import run_ac_opf. This takes some time, since Python starts a julia instance in the background, but it if the import completes without error everything is configured correctly and you can now use PowerModels to optimize pandapower networks.

  2. Additional packages are required to use the pandapower - PowerModels.jl interface with all features like TNEP or OTS. Install the “JSON” and “JuMP” packages with, e.g., julia -e 'import Pkg; Pkg.add("JSON"); Pkg.add("JuMP"); and maybe also julia -e ‘import Pkg; Pkg.add(“Cbc”); Pkg.add(“Juniper”)’ to get the TNEP and OTS libraries. Alternatively, install these packages by entering ] inside the julia console and calling add JSON add JuMP

  3. Now install our interface PandaModels.jl by type add PandaModels inside Julia package manager.

  4. Finally, you can then test whether the PandaModels.jl interface works: Navigate to your local pandapower test folder pandapower/pandapower/test/opf folder and run python-jl test_pandamodels_runpm.py or pytest test_pandamodels_runpm.py if pytest is intalled. If everything works there should be no error.

Additional Solvers

Optional additional solvers, such as Gurobi are compatible to PowerModels.jl. To use these solvers, you first have to install the solver itself on your system and then the julia interface. Gurobi is very fast for linear problems such as the DC model and free for academic usage. Let’s do this step by step for Gurobi:

  1. Download and install from Gurobi download (you’ll need an account for this)

  2. Run the file to get the gurobi folder, e.g., in linux you need to run tar -xzf gurobi<version>_linux64.tar.gz

  3. Get your Gurobi license at Gurobi license and download it (remember where you stored it).

  4. Activate the license by calling grbgetkey YOUR_KEY as described on the Gurobi license page.

  5. Add some Gurobi paths and the license path to your local PATH environment variables. In linux you can just open your .bashrc file with, e.g., nano .bashrc in your home folder and add:

# Linux

# gurobi
export GUROBI_HOME="/opt/gurobi_VERSION/linux64"
export PATH="${PATH}:${GUROBI_HOME}/bin"
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${GUROBI_HOME}/lib"
export GRB_LICENSE_FILE="/PATH_TO_YOUR_LICENSE_DIR/gurobi.lic"
# MacOS

# gurobi
export GUROBI_HOME="/Library/gurobiVERSION/mac64"
export PATH="$PATH:$GUROBI_HOME/bin"
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$GUROBI_HOME/lib"
export GRB_LICENSE_FILE="/PATH_TO_YOUR_LICENSE_DIR/gurobi.lic"
  1. Install the julia - Gurobi interface and set the GUROBI_HOME environment with

    julia -e 'import Pkg; Pkg.add("Gurobi");'

    or type

    add Gurobi

    inside Julia package mode.

  2. Build and test your Gurobi installation by entering julia prompt and then import Pkg; Pkg.build("Gurobi"). This should compile without an error.

  3. Now, you can use Gurobi to solve your linear problems, e.g., the DC OPF, with runpm_dc_opf(net, pm_model="DCPPowerModel", pm_solver="gurobi")

Usage

The usage is explained in the PandaModels tutorial.

The TNEP optimization is explained in the PandaModels TNEP tutorial. Additional packages including “juniper”