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

The previous command will install all the dependencies for working with numpy and scikit-learn. It will not, however, install all the dependencies needed for working in torch. To use the torch functionalities, please install PyTorch, PyTorch Geometric with its dependencies(torch-scatter etc.) and optionally TorchMetrics.

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 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(ppc, ppopt=ppopt)

Loss

numpy / scikit-learn

import numpy as np

from mlpf.data.conversion.numpy.power_flow import ppc2power_flow_arrays
from mlpf.loss.numpy.power_flow import active_power_errors, reactive_power_errors

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

active_errors = active_power_errors(edge_index, active_powers_pu, voltages_pu, angles_rad, conductances_pu, susceptances_pu)
reactive_errors = reactive_power_errors(edge_index, reactive_powers_pu, voltages_pu, angles_rad, conductances_pu, susceptances_pu)

print(f"Total P loss = {np.sum(active_errors):.3e} p.u.")
print(f"Total Q loss = {np.sum(reactive_errors):.3e} p.u.")

torch

import torch

from mlpf.data.conversion.torch.power_flow import ppc2power_flow_tensors
from mlpf.loss.torch.power_flow import active_power_errors, reactive_power_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_errors = active_power_errors(edge_index, active_powers_pu, voltages_pu, angles_rad, conductances_pu, susceptances_pu)
reactive_errors = reactive_power_errors(edge_index, reactive_powers_pu, voltages_pu, angles_rad, conductances_pu, susceptances_pu)

print(f"Total P loss = {torch.sum(active_errors):.3e} p.u.")
print(f"Total Q loss = {torch.sum(reactive_errors):.3e} p.u.")

Data loading

  • TODO

Indepth examples

General

Supervised learning

Power flow

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.7.tar.gz (27.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mlpf-0.0.7-py3-none-any.whl (34.7 kB view details)

Uploaded Python 3

File details

Details for the file mlpf-0.0.7.tar.gz.

File metadata

  • Download URL: mlpf-0.0.7.tar.gz
  • Upload date:
  • Size: 27.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for mlpf-0.0.7.tar.gz
Algorithm Hash digest
SHA256 5a63b979c39dac53d89a08d10d014fbbbcc1fe7f9d03fefe8abfef2a69bb6d9c
MD5 d9264e6490ad0a6126affcae0c7276b4
BLAKE2b-256 f8e9e6dd9323b1c52308e6acc36cbe9f0c3a68e32fc41b58449e39c07c11d45c

See more details on using hashes here.

File details

Details for the file mlpf-0.0.7-py3-none-any.whl.

File metadata

  • Download URL: mlpf-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 34.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for mlpf-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 31773d6fb42f33a0966618e51d5722971f8bda80553c503073d7d698513792b7
MD5 aaaed4aa8efed98f9e297a64b62c168c
BLAKE2b-256 33ed8fd32fa597fcafe360ba47c94570110d66bedb1b5f32f3d170e7ed304f86

See more details on using hashes here.

Supported by

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