Optimization with PowerModels.jl

Installation

If you are not yet using Julia, install it. Note that you need a version that is supported PowerModels, PyCall and pyjulia for the interface to work. Currently, Julia 1.1 is the most recent version of Julia that supports all these packages.

Note

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. Also, PyCharm has a Julia Plugin.

  1. Add the Julia binary folder (e.g. /Julia-1.1.0/bin) to the system variable PATH. Providing the path is correct, you can now enter the julia prompt by executing julia in your shell.
  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 to e.g.: ENV["PYTHON"]="C:\\Anaconda3\\python.exe".
  3. Access the package mode by typing ]. Now install the packages: add Ipopt PowerModels PyCall.
  4. Test your PowerModels installation by executing test PowerModels. Then, test if 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.

Warning

Windows 10 only: A bug currently makes it necessary to modify a file of the pyjulia package. The exact line which needs to be modified depends on how you installed pyjulia. To find the exact line, have a look at your traceback after you execute the command from julia import Main, e.g. in Pycharm (Corresponding Github Issue):

In this case, it is line no. 686. Replace

with

Now Julia should work in your Python shell, Anaconda prompt and in Spyder, but currently not in Pycharm.

Usage

The usage is explained in the PowerModels tutorial.

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

Runs a non-linear 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_mw / net.sgen.max_p_mw
  • net.sgen.min_q_mvar / net.sgen.max_q_mvar
  • net.load.min_p_mw / net.load.max_p_mw
  • net.load.min_q_mvar / net.load.max_q_mvar
  • net.gen.min_p_mw / net.gen.max_p_mw
  • net.gen.min_q_mvar / net.gen.max_q_mvar
  • net.ext_grid.min_p_mw / net.ext_grid.max_p_mw
  • net.ext_grid.min_q_mvar / net.ext_grid.max_q_mvar
  • net.dcline.min_q_to_mvar / net.dcline.max_q_to_mvar / net.dcline.min_q_from_mvar / net.dcline.max_q_from_mvar

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.

INPUT:
net - The pandapower format network

OPTIONAL:

pp_to_pm_callback (function, None) - callback function to add data to the PowerModels data structure
pandapower.runpm_dc_opf(net, pp_to_pm_callback=None, calculate_voltage_angles=True, trafo_model='t', delta=0, trafo3w_losses='hv', check_connectivity=True)

Runs a linearized 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_mw / net.sgen.max_p_mw
  • net.sgen.min_q_mvar / net.sgen.max_q_mvar
  • net.load.min_p_mw / net.load.max_p_mw
  • net.load.min_q_mvar / net.load.max_q_mvar
  • net.gen.min_p_mw / net.gen.max_p_mw
  • net.gen.min_q_mvar / net.gen.max_q_mvar
  • net.ext_grid.min_p_mw / net.ext_grid.max_p_mw
  • net.ext_grid.min_q_mvar / net.ext_grid.max_q_mvar
  • net.dcline.min_q_to_mvar / net.dcline.max_q_to_mvar / net.dcline.min_q_from_mvar / net.dcline.max_q_from_mvar

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.

INPUT:
net - The pandapower format network
OPTIONAL:
pp_to_pm_callback (function, None) - callback function to add data to the PowerModels data structure
pandapower.runpm(net, julia_file, pp_to_pm_callback=None, calculate_voltage_angles=True, trafo_model='t', delta=0, trafo3w_losses='hv', check_connectivity=True)

Runs a power system optimization using PowerModels.jl. with a custom julia file.

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_mw / net.sgen.max_p_mw
  • net.sgen.min_q_mvar / net.sgen.max_q_mvar
  • net.load.min_p_mw / net.load.max_p_mw
  • net.load.min_q_mvar / net.load.max_q_mvar
  • net.gen.min_p_mw / net.gen.max_p_mw
  • net.gen.min_q_mvar / net.gen.max_q_mvar
  • net.ext_grid.min_p_mw / net.ext_grid.max_p_mw
  • net.ext_grid.min_q_mvar / net.ext_grid.max_q_mvar
  • net.dcline.min_q_to_mvar / net.dcline.max_q_to_mvar / net.dcline.min_q_from_mvar / net.dcline.max_q_from_mvar

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.

INPUT:
net - The pandapower format network
OPTIONAL:

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

The TNEP optimization is explained in the PowerModels TNEP tutorial.

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

Runs a non-linear transmission network extension planning (tnep) optimization using PowerModels.jl.

see above