Optimization with PowerModels.jl


  1. If you are not yet using Julia, install it.


    You need a version that is supported PowerModels, PyCall and pyjulia for the interface to work. Currently, the most recent version of Julia that supports all these packages is Julia 0.64.

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

  2. Install PowerModels.jl

  3. Configure Julia to be able to call Python

    • open the Julia console
    • set ENV[“PYTHON”] to your Python executable (e.g. ENV[“PYTHON”]=”C:\Anaconda\python.exe”)
    • Install PyCall with Pkg.add(“PyCall”)
    • test if calling Python from Julia works as described here


    PyCall is only tested with Python 3.6 and 3.7, so make sure to use one of those versions

  4. Configure Python to be able to call Julia

    • Add the Julia binary folder (e.g. /Julia-0.6.4/bin) to the system variable PATH
    • Install pyjulia with pip install julia
    • 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.


The usage is explained in the PowerModels tutorial.

pandapower.runpm(net, julia_file=None, pp_to_pm_callback=None, calculate_voltage_angles=True, trafo_model='t', delta=0, trafo3w_losses='hv')

Runs a power system optimization using PowerModels.jl. Flexibilities, constraints and cost parameters are defined in the pandapower element tables.

Flexibilities can be defined in net.sgen / net.gen /net.load net.sgen.controllable if a static generator is controllable. If False, the active and reactive power are assigned as in a normal power flow. If True, the following flexibilities apply:

  • net.sgen.min_p_kw / net.sgen.max_p_kw
  • net.sgen.min_q_kvar / net.sgen.max_q_kvar
  • net.load.min_p_kw / net.load.max_p_kw
  • net.load.min_q_kvar / net.load.max_q_kvar
  • net.gen.min_p_kw / net.gen.max_p_kw
  • net.gen.min_q_kvar / net.gen.max_q_kvar
  • net.ext_grid.min_p_kw / net.ext_grid.max_p_kw
  • net.ext_grid.min_q_kvar / net.ext_grid.max_q_kvar
  • net.dcline.min_q_to_kvar / net.dcline.max_q_to_kvar / net.dcline.min_q_from_kvar / net.dcline.max_q_from_kvar

Controllable loads behave just like controllable static generators. It must be stated if they are controllable. Otherwise, they are not respected as flexibilities. Dc lines are controllable per default

Network constraints can be defined for buses, lines and transformers the elements in the following columns:
  • net.bus.min_vm_pu / net.bus.max_vm_pu
  • net.line.max_loading_percent
  • net.trafo.max_loading_percent
  • net.trafo3w.max_loading_percent

How these costs are combined into a cost function depends on the cost_function parameter.

net - The pandapower format network

julia_file (str, None) - path to a custom julia optimization file

pp_to_pm_callback (function, None) - callback function to add data to the PowerModels data structure