Skip to main content

Python/C++ library for distribution power system analysis

Project description

PyPI version License: MIT Build and Test C++ and Python Format Code REUSE Compliance Check

Quality Gate Status Coverage Maintainability Rating Reliability Rating Security Rating Vulnerabilities

Power Grid Model

power-grid-model is a Python library for steady-state distribution power system analysis. The core of the library is written in C++. Currently, it supports the following calculations:

  • Symmetric and asymmetric power flow calculation with Newton-Raphson method and linear method
  • Symmetric and asymmetric state estimation with iterative linear method

Installation

Runtime Dependencies

The only Python runtime dependency is numpy. It will be automatically installed as the requirements. Moreover, the library optionally depends on Intel Math Kernel Library (mkl), for its PARDISO sparse solver. It is recommended to install mkl because it gives huge performance boosts.

The easiest way to install mkl is using pip or conda:

pip install mkl

or

conda install -c conda-forge mkl

You need to add the path to the mkl runtime file libmkl_rt.so or mkl_rt.dll the environment variable LD_LIBRARY_PATH in Linux or Path in Windows (conda does this automatically in the environment). If the library can find mkl runtime, it uses it as the sparse solver. It is recommended to set the environment variable MKL_THREADING_LAYER to SEQUENTIAL, as multi-threading is handled in a higher level. If the library cannot find mkl runtime, it will fall back to an internally built-in (and much slower) Eigen SparseLU solver.

Install from Pre-built Binary Package

The power-grid-model python package is pre-built for Windows, Linux, and macOS (both Intel and Arm-based), for Python version 3.8, 3.9, and 3.10. You can directly install the package from PyPI.

pip install power-grid-model

Build and install from Source

To install the library from source, refer to the Build Guide.

Quick Start

In this quick start a simple 10kV network as below is calculated. A line connects two nodes. One node has a source. One node has a symmetric load. The code in the quick start is in quick_example.py.

node_1 ---line_3--- node_2
 |                    |
source_5            sym_load_4

The library uses a graph data model to represent the physical components and their attributes, see Graph Data Model.

Firstly, import the main model class as well as some helper functions for enumerations and meta data.

from power_grid_model import LoadGenType
from power_grid_model import PowerGridModel
from power_grid_model import initialize_array

Input Data

The library uses dictionary of numpy structured arrays as the main (input and output) data exchange format between Python and C++ core. The documentation Native Data Interface explains the detailed design of this interface.

The helper function initialize_array can be used to easily generate an array of the correct format.

# node
node = initialize_array('input', 'node', 2)
node['id'] = [1, 2]
node['u_rated'] = [10.5e3, 10.5e3]

The code above generates a node input array with two nodes, and assigns the attributes of the nodes to the array. Similarly, we can create input arrays for line, load, and generation.

# line
line = initialize_array('input', 'line', 1)
line['id'] = [3]
line['from_node'] = [1]
line['to_node'] = [2]
line['from_status'] = [1]
line['to_status'] = [1]
line['r1'] = [0.25]
line['x1'] = [0.2]
line['c1'] = [10e-6]
line['tan1'] = [0.0]
line['i_n'] = [1000]
# load
sym_load = initialize_array('input', 'sym_load', 1)
sym_load['id'] = [4]
sym_load['node'] = [2]
sym_load['status'] = [1]
sym_load['type'] = [LoadGenType.const_power]
sym_load['p_specified'] = [2e6]
sym_load['q_specified'] = [0.5e6]
# source
source = initialize_array('input', 'source', 1)
source['id'] = [5]
source['node'] = [1]
source['status'] = [1]
source['u_ref'] = [1.0]
# all
input_data = {
    'node': node,
    'line': line,
    'sym_load': sym_load,
    'source': source
}

Instantiate Model

We can instantiate the model by calling the constructor of PowerGridModel

model = PowerGridModel(input_data, system_frequency=50.0)

Power Flow Calculation

To calculate power flow, call the method calculate_power_flow. This method has many optional arguments, see Python API Reference for a detailed explanation.

result = model.calculate_power_flow()

Both input and output data are dictionaries of structured numpy arrays. We can use pandas to convert them to data frames and print them.

print('Node Input')
print(pd.DataFrame(input_data['node']))
print('Node Result')
print(pd.DataFrame(result['node']))

You can print the data in tables.

Node Input
   id  u_rated
0   1  10500.0
1   2  10500.0
Node Result
   id  energized      u_pu             u   u_angle
0   1          1  0.999964  10499.619561 -0.000198
1   2          1  0.994801  10445.415523 -0.003096

Examples

Please refer to Examples for more detailed examples for power flow and state estimation.

License

This project is licensed under the Mozilla Public License, version 2.0 - see LICENSE for details.

Licenses third-party libraries

This project includes third-party libraries, which are licensed under their own respective Open-Source licenses. SPDX-License-Identifier headers are used to show which license is applicable. The concerning license files can be found in the LICENSES directory.

Intel Math Kernel Library License

The power-grid-model does not bundle or redistribute any MKL runtime library. It only detects if MKL library is installed in the target system. If so, it will use the library to accelerate the calculation. The user is responsible to acquire a suitable MKL license.

Contributing

Please read CODE_OF_CONDUCT and CONTRIBUTING for details on the process for submitting pull requests to us.

Contact

Please read SUPPORT for how to connect and get into contact with the Power Gird Model project.

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

power_grid_model-1.3.269-cp310-cp310-win_amd64.whl (393.7 kB view details)

Uploaded CPython 3.10 Windows x86-64

power_grid_model-1.3.269-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (503.0 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

power_grid_model-1.3.269-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (483.0 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

power_grid_model-1.3.269-cp310-cp310-macosx_11_0_arm64.whl (403.3 kB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

power_grid_model-1.3.269-cp310-cp310-macosx_10_15_x86_64.whl (450.4 kB view details)

Uploaded CPython 3.10 macOS 10.15+ x86-64

power_grid_model-1.3.269-cp39-cp39-win_amd64.whl (394.4 kB view details)

Uploaded CPython 3.9 Windows x86-64

power_grid_model-1.3.269-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (503.9 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

power_grid_model-1.3.269-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (483.5 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

power_grid_model-1.3.269-cp39-cp39-macosx_11_0_arm64.whl (403.3 kB view details)

Uploaded CPython 3.9 macOS 11.0+ ARM64

power_grid_model-1.3.269-cp39-cp39-macosx_10_15_x86_64.whl (450.2 kB view details)

Uploaded CPython 3.9 macOS 10.15+ x86-64

power_grid_model-1.3.269-cp38-cp38-win_amd64.whl (394.4 kB view details)

Uploaded CPython 3.8 Windows x86-64

power_grid_model-1.3.269-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (505.3 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

power_grid_model-1.3.269-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (483.7 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARM64

power_grid_model-1.3.269-cp38-cp38-macosx_11_0_arm64.whl (403.4 kB view details)

Uploaded CPython 3.8 macOS 11.0+ ARM64

power_grid_model-1.3.269-cp38-cp38-macosx_10_15_x86_64.whl (450.6 kB view details)

Uploaded CPython 3.8 macOS 10.15+ x86-64

File details

Details for the file power_grid_model-1.3.269-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for power_grid_model-1.3.269-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 f8a7e9f28f2c99f5a2b3c4a102144797822a057356615af96f1118649f8b18f1
MD5 ab322ba9c8bdef43fc63af13f87e5aad
BLAKE2b-256 6bd239a189e6762b7d675b1991ba928c1369aa94460c7e181231d6252ff4a49c

See more details on using hashes here.

File details

Details for the file power_grid_model-1.3.269-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for power_grid_model-1.3.269-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a015f2700da5c55d65e2f807f12ec19e2fa995129f7715ff4c3c8e5ed2d681f4
MD5 d45d38f3ced6e672d5c3195eda4cf968
BLAKE2b-256 a13a86ca7a2324a0a902dfcc273baa448a8051dd634d298a7880e9e334170ac9

See more details on using hashes here.

File details

Details for the file power_grid_model-1.3.269-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for power_grid_model-1.3.269-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 fbb68f380eafd5caa133ec9c8a4e973508ff9c58cb5a607ca66a0b5cc3c88050
MD5 66c61d3b04976ac9bdaeb21782c1b1ff
BLAKE2b-256 17bf872811f2cc88bb442c0c6947ca7aff64417a8fa41359a30a0ebb3af96c87

See more details on using hashes here.

File details

Details for the file power_grid_model-1.3.269-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for power_grid_model-1.3.269-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d0bad64d74de54b02f0dbcbf201bcd523e876ab970bb46990b6f75e41addc0cf
MD5 7148c732f8a11b6c59c4ecd55ac7290c
BLAKE2b-256 dafc1dec8e04ba7db89d902391b277372e48173a814dd37ab59587fcc1138e8f

See more details on using hashes here.

File details

Details for the file power_grid_model-1.3.269-cp310-cp310-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for power_grid_model-1.3.269-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 213ed032ec2d89881b6d9f4e1dae89a4696ee5888a1b6707d517e103116ad8d6
MD5 401c27b4187e1ab4a181494d019e7562
BLAKE2b-256 c8c20b0e8b8c76a93d326449ecc564f0130faf60808916109d48ca97c0ada04f

See more details on using hashes here.

File details

Details for the file power_grid_model-1.3.269-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for power_grid_model-1.3.269-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 f0210ede521493ad9a3222837f042e141ea9c079983be8d4146b15a75b167e21
MD5 e98f197eecd9ba5bcc089d1b551c99fc
BLAKE2b-256 a2fad01ed32cd3ad747101c8638492cd4da8337b86bfee7914fe0586aeade470

See more details on using hashes here.

File details

Details for the file power_grid_model-1.3.269-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for power_grid_model-1.3.269-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0e5552fa8e63bd362c1de9110f55b98bf84cba134db4db38abad6ffd212da59f
MD5 46e52f3014103efef3582fc699393257
BLAKE2b-256 30048d13b328fbbb97be50a777866792c8f8316af0620bcf5581fbc77c60c50b

See more details on using hashes here.

File details

Details for the file power_grid_model-1.3.269-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for power_grid_model-1.3.269-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 085c3ccd414d80226dee0e60e264ce151270f2231292f547c73ddeb8b7a0c394
MD5 14e2bed9cf932f47768604cf15a46406
BLAKE2b-256 54fa4f88a14519127b0af3087ab009dcc72beb8d5acaa794d7c91f2a734b648b

See more details on using hashes here.

File details

Details for the file power_grid_model-1.3.269-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for power_grid_model-1.3.269-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 72b78864c6cc4d45da505ba2361d313a705461f6b0962cf46d339548f622f51c
MD5 5718cb7cc3c619b135685e0f515c5d03
BLAKE2b-256 75f57cb1081748de65bcf9d85f1925eed556cf4564d8980995392bb6aeb587ca

See more details on using hashes here.

File details

Details for the file power_grid_model-1.3.269-cp39-cp39-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for power_grid_model-1.3.269-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 cbba2f30fa970c713ae0c7b7f653f4a1a46a9188441cf5e224556b776d1d5af8
MD5 903d6281ba5265d338d5e62956bd35da
BLAKE2b-256 248a438a0fc45f188d0e570193bfc68e10e60212cf17ec39d6929949a8f1af59

See more details on using hashes here.

File details

Details for the file power_grid_model-1.3.269-cp38-cp38-win_amd64.whl.

File metadata

File hashes

Hashes for power_grid_model-1.3.269-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 31f224989d12943ed5e6508961543021f4018cdde8e5f9f73c69bd7144336485
MD5 8eb6b8772498e829c9465e4c764de18e
BLAKE2b-256 2117c037f5d88c57fe6ff1e12d64d3ac072d582085aa7fd96e6f01fd88aa121e

See more details on using hashes here.

File details

Details for the file power_grid_model-1.3.269-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for power_grid_model-1.3.269-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 86e9b216b15a70b0fb5113936619fcb9d62c5273b257e933a1ff69a1c308e548
MD5 b291b6f33f26bd467c355171db9de729
BLAKE2b-256 fae5b16d8b51ff0fe8b3325b5ad46a2c3b2475013b123188bfb65dc45307f76f

See more details on using hashes here.

File details

Details for the file power_grid_model-1.3.269-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for power_grid_model-1.3.269-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 1b0f0cff7bf61576e373fd61fd56bb3bc4a7f6fbbd56b55ebbe0c5214bf980e6
MD5 52f16dcbb6c39d30b54b87dad6abe859
BLAKE2b-256 47b4689ab553320a4102302da02882cb2d73fa324a797a76d0d30e7df3a36214

See more details on using hashes here.

File details

Details for the file power_grid_model-1.3.269-cp38-cp38-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for power_grid_model-1.3.269-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 34efba1244fed27f45380594bcba0fbd3e8eb5455748a4bf88530bbb199b14a8
MD5 74e4514f992bff4823cf83fca52273dc
BLAKE2b-256 2c5c0a9343b134a67eec3f969758016117f1a220e18193e14978f88ecf9781e8

See more details on using hashes here.

File details

Details for the file power_grid_model-1.3.269-cp38-cp38-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for power_grid_model-1.3.269-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 9b71f91c7008d8df4626673737e649ff0a6d962367f9a4bb883fe9b459c04333
MD5 69ba789d197beeb903caf2e043efbd7c
BLAKE2b-256 613d4da3519b110a53f3d7f10c46b73b408c67fdeb5bc82cd0068819bf86f0c5

See more details on using hashes here.

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