Skip to content

[feature] Improve Python-Based OPF Speed #2933

@determ1ne

Description

@determ1ne

Feature Checklist

Feature Type

  • Adding new functionality to pandapower

  • Changing existing functionality in pandapower

  • Removing existing functionality in pandapower

Problem Description

Hi, pandapower community! I am currently working on a yet another MATPOWER port to Python called pwrs.

Compared to pypower, it was targeted at MATPOWER 7.1.
The OPF related code was updated to the corresponding MATPOWER/MIPS version, and the speed was really great.
Here is a benchmark:

import pwrs as mp
import numpy as np
from pandapower.pypower.opf import opf
from pandapower.pypower.ppoption import ppoption
import time

mpc = mp.case9241pegase()
mp.runpf(mpc)

ppc = mpc.to_dict()

def enlarge(m, col):
    b = np.zeros((m.shape[0], col))
    b[:, :m.shape[1]] = m
    return b

ppc["bus"][:, 0] -= 1
ppc["gen"][:, 0] -= 1
ppc["branch"][:, 0:2] -= 1
ppc["bus"] = enlarge(ppc["bus"], 18)
ppc["gen"] = enlarge(ppc["gen"], 26)
ppc["branch"] = enlarge(ppc["branch"], 27)

# currently pandapower runopp is broken, see #2932 
t = time.perf_counter()
result = opf(ppc, ppoption(VERBOSE=3, PF_DC=0, INIT="flat"))
t2 = time.perf_counter()
print(f"pypower opf took {t2 - t:.4f} seconds")

mpc = mp.case9241pegase()
mp.runpf(mpc)
t = time.perf_counter()
mp.runopf(mpc)
t2 = time.perf_counter()
print(f"pwrs opf took {t2 - t:.4f} seconds")

Output:

...
pypower opf took 319.8075 seconds
...
pwrs opf took 7.4259 seconds

As a comparison, MATPOWER 8.0 (MATLAB R2024a, Windows 11, Intel Core i7 13700K) took 11.69 seconds with runopf(case9241pegase).

The code was oracle tested with MATPOWER, for every data case came bundled with MATPOWER.

Feature Description

Add: pwrs as a new backend for pandapower OPF

Additional Context

No response

Label

  • Relevant labels are selected

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions