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.272-cp310-cp310-win_amd64.whl (396.4 kB view details)

Uploaded CPython 3.10 Windows x86-64

power_grid_model-1.3.272-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (505.7 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

power_grid_model-1.3.272-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (485.7 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

power_grid_model-1.3.272-cp310-cp310-macosx_11_0_arm64.whl (406.0 kB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

power_grid_model-1.3.272-cp310-cp310-macosx_10_15_x86_64.whl (453.1 kB view details)

Uploaded CPython 3.10 macOS 10.15+ x86-64

power_grid_model-1.3.272-cp39-cp39-win_amd64.whl (397.1 kB view details)

Uploaded CPython 3.9 Windows x86-64

power_grid_model-1.3.272-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (506.6 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

power_grid_model-1.3.272-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (486.2 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

power_grid_model-1.3.272-cp39-cp39-macosx_11_0_arm64.whl (405.9 kB view details)

Uploaded CPython 3.9 macOS 11.0+ ARM64

power_grid_model-1.3.272-cp39-cp39-macosx_10_15_x86_64.whl (452.9 kB view details)

Uploaded CPython 3.9 macOS 10.15+ x86-64

power_grid_model-1.3.272-cp38-cp38-win_amd64.whl (397.2 kB view details)

Uploaded CPython 3.8 Windows x86-64

power_grid_model-1.3.272-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (508.0 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

power_grid_model-1.3.272-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (486.4 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARM64

power_grid_model-1.3.272-cp38-cp38-macosx_11_0_arm64.whl (406.1 kB view details)

Uploaded CPython 3.8 macOS 11.0+ ARM64

power_grid_model-1.3.272-cp38-cp38-macosx_10_15_x86_64.whl (453.3 kB view details)

Uploaded CPython 3.8 macOS 10.15+ x86-64

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.272-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 36ec27beef64e48ea444f8fc96562b69babbbc61c0a383cda78b0a16a1e0c26e
MD5 0f6fa1f34caee9625f6344707e302c77
BLAKE2b-256 5908181ae8b2a83ca7fe517ec4629ad1e5b97ab339ebeac3cf57cd7cf446a5ce

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.272-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b1b98e2efcf46de221c3f30f94705aa7f6d7c01162bb2ffa91278e16576f4ff7
MD5 37041bbeb7dba729893e17b4215f3d10
BLAKE2b-256 3ca82723e07b14742cc03560c08335f39c9ab721be3fa0b9f5d4342cf92b2a01

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.272-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 e3f288b8d682bbe71c39c54edf044da06a6f6b9e0eba533662bde2da3832ccf3
MD5 970cf7fd6fb7d59abe903ec8c2de2878
BLAKE2b-256 fce4a3c91c7b7def3832387537edbc99decb1935bf895fb27f51d1d1b1be906d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.272-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3cb6c97d0b61dda741a9be4c3200ba4f0e3e3467c6b55a65a85acf3445768162
MD5 fdf36f750abc521299e60821b3125023
BLAKE2b-256 bfd085cb3778fb6572b9e819a011713a726fc88fb4e3e4a35a30c6f1ee8bf290

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.272-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 fc85fb9abcb863ac270f71c49c78b60d798bad8b546f3592df3a8837c128ea38
MD5 e10cdc3e709aec0ba0ee98114ed65ae0
BLAKE2b-256 37dbec1af8361224e8ec509a6b3e6713118fa3ecc2861c63c9ea1d28f4c3b168

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.272-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 3eba037f46328a6fad9fd3dc3a78cb85a31bec9ec55f597552232ab416974e59
MD5 d0d504869762902ed47226a567828e1f
BLAKE2b-256 efcb4f3e12f69b1f77159582f27c45ea4c81cd7c537837034634c4fcea84eeef

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.272-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 640349426a4ca71c5c1a6ffcc93d72de9bf67d481364ad579bd7fe4e9e6d70d9
MD5 d279424eebb47ebbff4ba0cae37c5636
BLAKE2b-256 62f4bb05cefd60db58056a96d131d50efb98aac5f5027933450f367a339aac46

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.272-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 b60ce57ad31e10cc005347557ff6c082589f5c15f3e444476a16bf4e8d2d34bc
MD5 75a38f622e702c79bbda8fdb61a01e64
BLAKE2b-256 9ce141d8d0c106454f82f3231f153162ed6833f7a3915ae8470a61e18584fcb9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.272-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 bef55a01bd3374db9bc826d353a966074bca4d412b6f463eddaf0fcd624593ca
MD5 ce59e51fb7f3f3bec6d4fd770c108c2f
BLAKE2b-256 f3bb6d09e6e191ad73e6c1fe13fb6252042f9984800bbe96bf82e59697ee01ae

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.272-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 dae87b37d571a018370eec17e5c0c2e8320d3874bccca66c0772347509c657c1
MD5 1f497b7e7174371544567ce3452f279c
BLAKE2b-256 4fd69c36c491bb07208cc7a474a97188f7e2c4f6470ae2cf6c77621ec1504d03

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.272-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 64c3ab7b62583290679be0dd168f4e7d32ccb9e8cd1fc43c27b6c8d9d9639060
MD5 3eb57845dfa29b5f23ad0de0a23df471
BLAKE2b-256 479fca08da19186ac9fc47bf99f2da7990ab0d3e30b0481cd63ccfc1e96a017d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.272-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d1e0d340bb8c092f55adc4c62183aaa6e1ebf2b6b049d9c0e0aeb97582588cd1
MD5 064d9637d21376fd2b5bfa915f0c8383
BLAKE2b-256 a27548889c3a68b1f69adc69096cbd30a5c09e1f4c274fadfab30c5b7e1eb95a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.272-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 19ae201c30f5d09cc826e5ba732ab95bf1d206dd6b03646b0de8cb647e0aec03
MD5 21c2a4ef210f88c4c79d110ed121f370
BLAKE2b-256 b2fbd7d80cb60226c0078d344a69a40740b5f909d8cf970cc799e5c51d1e3b22

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.272-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d64dcc22ccc2f2f39739b5fb63d7c4615543d3770b14d8261634c644b39727cd
MD5 f2dca9310bdda236784de07d0b146877
BLAKE2b-256 7801d15f8648b393d477649ec3fad2f8a050509089e67680315ec338f16c6a7a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.272-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 e0b1b60b4def61623a63354f070435748b9f637af494c66f9077a426092ad9c4
MD5 66866ba942e8f9f95e961922e46f1745
BLAKE2b-256 455f908617bf5f056ed749a63d375826b6c8832533e294101d4a2faa6f286c15

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