Skip to main content

Machine learning for power flow

Project description

MLPF is a python library for (optimal) power flow calculations with machine learning. It offers:

  • efficient loss functions compatible with both PyTorch and scikit-learn!
  • utilities such as data structures and loading pipelines that make it easy to go from pandapower nets or PYPOWER case files to arrays and tensors in just one line of code!
  • visualization and description tools to take a quick look at your data

Contributions welcome!

Installation

pip install mlpf

Usage

  1. Load/create data and turn it into the PYPOWER case format
  2. From then on we provide functionality to express the data as numpy arrays or torch tensors.
  3. Feed that data into your ML (scikit-learn or torch) models and use our tried and tested loss functions to train, validate or monitor your model development.
import copy

import pandapower as pp
import pandapower.networks as pn

from pypower.ppoption import ppoption
from pypower.runpf import runpf

net = pn.case118()

ppc = pp.converter.to_ppc(net, init="flat")

ppopt = ppoption(OUT_ALL=0, VERBOSE=0)
ppc, converged = runpf(copy.deepcopy(ppc), ppopt=ppopt)

Loss

numpy / scikit-learn

from mlpf.data.conversion.numpy.power_flow import ppc2power_flow_arrays
from mlpf.loss.numpy.power_flow import power_flow_errors

edge_index, active_powers_pu, reactive_powers_pu, voltages_pu, angles_rad, conductances_pu, susceptances_pu = ppc2power_flow_arrays(ppc)

active_power_losses_pu, reactive_power_losses_pu = power_flow_errors(
  edge_index,
  active_powers_pu,
  reactive_powers_pu,
  voltages_pu,
  angles_rad,
  conductances_pu,
  susceptances_pu
)

torch

from mlpf.data.conversion.torch.power_flow import ppc2power_flow_tensors
from mlpf.loss.torch.power_flow import power_flow_errors

# note: going from float64(standard in PYPOWER) to float32(standard in torch) will increase the PF loss significantly
edge_index, active_powers_pu, reactive_powers_pu, voltages_pu, angles_rad, conductances_pu, susceptances_pu = ppc2power_flow_tensors(ppc, dtype=torch.float64)

active_power_losses_pu, reactive_power_losses_pu = power_flow_errors(
  edge_index,
  active_powers_pu,
  reactive_powers_pu,
  voltages_pu,
  angles_rad,
  conductances_pu,
  susceptances_pu
)

Data loading

  • TODO

Indepth examples

General

Supervised learning

Power flow

Development

git clone https://github.com/viktor-ktorvi/mlpf.git
cd mlpf

conda env create -f environment.yml
conda activate mlpfenv

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mlpf-0.0.5.4.tar.gz (26.4 kB view hashes)

Uploaded Source

Built Distribution

mlpf-0.0.5.4-py3-none-any.whl (34.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page