# Optimization with PowerModels.jl¶

## Installation¶

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

Note

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”)
• test if calling Python from Julia works as described here

Note

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.

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

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

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

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

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