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 -U pip

pip install -U mlpf

pip install -U mlpf[torch]

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.6.tar.gz (26.5 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.5.6-py3-none-any.whl (34.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mlpf-0.0.5.6.tar.gz
  • Upload date:
  • Size: 26.5 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.5.6.tar.gz
Algorithm Hash digest
SHA256 54cf4ec045d9d674b0d1270667d7bda81c6c873e8d1ee73ae9bc06c26421d3e6
MD5 532068f0bd614e22e48e280b26b9c6bc
BLAKE2b-256 922772f687e5d8c312da2a7d6c76c8ba119249d15be749521e310031a313cdf4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mlpf-0.0.5.6-py3-none-any.whl
  • Upload date:
  • Size: 34.8 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.5.6-py3-none-any.whl
Algorithm Hash digest
SHA256 bed669d2c921eae67dc8c3b1a4d57e3d20a675e64d79c80ccc94ec31869ff735
MD5 aa5e842a9101cee69c158290ce22be63
BLAKE2b-256 f63146b0f4af08d55b89e5cdc2ee099ab0014efe1d3d73ea44cf6005b9eda190

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