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

Uploaded CPython 3.10 Windows x86-64

power_grid_model-1.3.252-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (504.1 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

power_grid_model-1.3.252-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (483.8 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

power_grid_model-1.3.252-cp310-cp310-macosx_11_0_arm64.whl (403.2 kB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

power_grid_model-1.3.252-cp310-cp310-macosx_10_15_x86_64.whl (450.2 kB view details)

Uploaded CPython 3.10 macOS 10.15+ x86-64

power_grid_model-1.3.252-cp39-cp39-win_amd64.whl (394.8 kB view details)

Uploaded CPython 3.9 Windows x86-64

power_grid_model-1.3.252-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (504.0 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

power_grid_model-1.3.252-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.252-cp39-cp39-macosx_11_0_arm64.whl (403.0 kB view details)

Uploaded CPython 3.9 macOS 11.0+ ARM64

power_grid_model-1.3.252-cp39-cp39-macosx_10_15_x86_64.whl (449.7 kB view details)

Uploaded CPython 3.9 macOS 10.15+ x86-64

power_grid_model-1.3.252-cp38-cp38-win_amd64.whl (395.1 kB view details)

Uploaded CPython 3.8 Windows x86-64

power_grid_model-1.3.252-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (504.5 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

power_grid_model-1.3.252-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.252-cp38-cp38-macosx_11_0_arm64.whl (403.0 kB view details)

Uploaded CPython 3.8 macOS 11.0+ ARM64

power_grid_model-1.3.252-cp38-cp38-macosx_10_15_x86_64.whl (450.1 kB view details)

Uploaded CPython 3.8 macOS 10.15+ x86-64

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.252-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 7142808cafa9afa5afa73a20479a747b43377c5dd30bcda4badec5992eb922a9
MD5 dd1c4c8e7b3e6e689a53ea51f1e92d00
BLAKE2b-256 f9d1593a73f2132f7b25bfb7616e9a2ce214aa32c052198b48081705ddeb8a96

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.252-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4f6984f0b18f34476240e8a38a5e4fe890cd7a5da0dbe69f930bf1d5f1bed781
MD5 997fba2f5cb7e5fa4514b4012d5f2f65
BLAKE2b-256 2921d5443c804af05f9c1f3a41398c1947f02692892fbac167c4d3db0e4e08dd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.252-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 2a353ef69751c5216566fc7719c9f2fb63d3728e12b1a5b8fa299b371bff5791
MD5 8eaaff2ddf377a9f97dbeefc72fb4070
BLAKE2b-256 7ffa2596117e469d12a4ba7bb4ade9766fd2484b5d4e6bd02cee2121ae5d8a1e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.252-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 95c3dd37e58bf6293d9b430889fbba42a94ee7b942caab254dfe3830a9357555
MD5 ff1ab50ca92ec39dbd3db4a7318fe5b2
BLAKE2b-256 91165e96ec370fe65a2105d2294c984d4e65403dcb892839fc1ff1d9f007fb2b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.252-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 5350b1ac1024e46f84e9d764335f2de8413b6211659e5136aae9e45f1883cd49
MD5 25446e887fbc50e09da69ef0034aeaeb
BLAKE2b-256 d37a43cd3b5c99cf46f9c378a004b53cc44d2af49ca008e3ff2a4aabecbef347

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.252-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 8f5ade7584d3ab40c6b6c02811a9a5d2ede9700b2c76ab9f12b6b21a16ad1791
MD5 748768f622dd5a149bccfb23a8f2f50c
BLAKE2b-256 f5cb51dd593f4b128c68df746e0c05b325f514c595e92237c45a5a4dfd5517a0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.252-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c64e5c0e503332a2667e22b1d68a66f69a8cc41f925ff199e21a48c75751214e
MD5 58c69636b548ba7d53ef343692610d15
BLAKE2b-256 a1c51cc20f23cc616b1e098cfa17381db7fe8bc591d2e2760e1d1e7966372c4a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.252-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 c0792952b0e6bfdfd82199fe880da3037289f2c10ec02394ef1637af182cd015
MD5 26833ded2f61f08db6f377376e20dd3f
BLAKE2b-256 172b44736b4014ebde7ca6d6b58c2fa32bcaf5ff95bac8ed0d283a5376c955be

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.252-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c02f9f9140170b51c6d5921fc7dceff6ac1124e517b6ca46caa277e8a37a0bdb
MD5 f6c55ad652ae33c8e0d5b33fdf56e7ee
BLAKE2b-256 2405666dc4433ec185a2aaee1cef5ab0f686d39b01f568c8a9ddc479cac5cd0d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.252-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 da9f0e47405ad7abd7f1e7a83ea32b21550d0617828639caf8c159faf31f3f21
MD5 b5ce0191dc9468d364f821487d3eef76
BLAKE2b-256 16653a92f2728076d314975512a8bfab91a9c78a04c09853f938915c7ab6d010

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.252-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 e637f49e1cee0f6c1a2e50f8d96daac4fc6eebc8355c2e096d1099a269820650
MD5 0ecfd9da0979a3f60e03bced76653970
BLAKE2b-256 bbbc11c14bf975567d647614293244cce8420a98c39d5d1055184ca7180eb1c3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.252-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 118593c15ee96c2c7e03a7c95b6de688727d3cd202b1a36ff3e4810ef54296aa
MD5 e659a0c9626f6850695a3127591a43ef
BLAKE2b-256 ecefb0fdecc206c27b4f4ecc8768611378759263bb989ce8126e4273a046ff18

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.252-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 72fb46cb9136f2fa13335f7d0483acf227acc0c82bfb47317d455d77fbdadf19
MD5 75c70bc495947d440477d5288dec95bb
BLAKE2b-256 ccdc1298206f19e36a9f4c18d3e7c7563205dadfc020b985142bb7f5df6c1dcb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.252-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 665a583ac4b178014b3e3d97be9bea6b8a4e987149d16137f61faf51fa17641d
MD5 383bc3b1265febc3f3b9945f4c2feabe
BLAKE2b-256 155ea730d71c5929cc69bb124a63436317b4efa4cfad9e87766bc0c5cc235972

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.252-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 7a3d0ccc85868cd6f927088e3e4fdbc349ad42ae466fe509025e419db889c9e6
MD5 0239287a945c62f1b26fd514778ecaa9
BLAKE2b-256 dad402544940aa95b50197ca87882de5f4ef91c59890a818257d6f63eb490f76

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