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

Uploaded CPython 3.10 Windows x86-64

power_grid_model-1.3.246-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.246-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (484.9 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

power_grid_model-1.3.246-cp310-cp310-macosx_11_0_arm64.whl (404.2 kB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

power_grid_model-1.3.246-cp310-cp310-macosx_10_15_x86_64.whl (451.7 kB view details)

Uploaded CPython 3.10 macOS 10.15+ x86-64

power_grid_model-1.3.246-cp39-cp39-win_amd64.whl (394.6 kB view details)

Uploaded CPython 3.9 Windows x86-64

power_grid_model-1.3.246-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (503.1 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

power_grid_model-1.3.246-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (483.9 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

power_grid_model-1.3.246-cp39-cp39-macosx_11_0_arm64.whl (403.8 kB view details)

Uploaded CPython 3.9 macOS 11.0+ ARM64

power_grid_model-1.3.246-cp39-cp39-macosx_10_15_x86_64.whl (451.2 kB view details)

Uploaded CPython 3.9 macOS 10.15+ x86-64

power_grid_model-1.3.246-cp38-cp38-win_amd64.whl (394.9 kB view details)

Uploaded CPython 3.8 Windows x86-64

power_grid_model-1.3.246-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (504.2 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

power_grid_model-1.3.246-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (485.0 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARM64

power_grid_model-1.3.246-cp38-cp38-macosx_11_0_arm64.whl (403.9 kB view details)

Uploaded CPython 3.8 macOS 11.0+ ARM64

power_grid_model-1.3.246-cp38-cp38-macosx_10_15_x86_64.whl (451.7 kB view details)

Uploaded CPython 3.8 macOS 10.15+ x86-64

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.246-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 c918f7a94f78295963892291a1f701e88eac80d12506ede6b6df348137e8bc25
MD5 c0f2a976a8759fddc31352fd3382fe7d
BLAKE2b-256 d5b16a395a3d3092ee3d6c2803034790a1c6fcd40e0cd2936a75d2a6973b283c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.246-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6f4487f7b54ec5c15673fd1bfe539e511442c619515600a8779a91c74936f8ef
MD5 e743cad2dbac80ae5569cad186dca84c
BLAKE2b-256 fdccb408cc66c6132506b6c640add2a4e2e2d622ceac3c44a78d4c8d45053b7f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.246-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 195cb6f8708a5d35672288cdba1ba94a4b6bb2f532c70779714deaeea5e943a2
MD5 a26373eed2adeb1759cc28ae0faecf53
BLAKE2b-256 6c95199a81f2833a3e8534c462d1f6c7dc43309b5f06fe1c914fbe790a7b9035

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.246-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 028a8c6f3250b665093cbbda2082354dcf0b53b5c2181839db399def3b4e036a
MD5 8d28ff6b91a7dd58539b7205c7f86766
BLAKE2b-256 ce11d8c289259c23572c7f616feec8e5fc14123d10f604b1f2d8c22e04507146

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.246-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 c3ac414fa2032a7870dbd30445871a2689ada67d74995863b5aee1cb768c5636
MD5 587193565af122fae8a1bda765aea3c6
BLAKE2b-256 8b889b3e1de08f4ea49e880004da78c957d1ee09ccacf11e8a230c7235984621

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.246-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 fa8bab0883204a75b44bc703eac340393e907f5bf45bf98b6d142dc287661d68
MD5 d64332d826431dc599feab80d16ed69b
BLAKE2b-256 80762a03ab001ca48be7c9f06f96af311b4d681d6026b9aa7bbee53a4de6add8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.246-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ffb2e88715ee835dd8fd6379d300bb1f5eec03b8c5c4137ab78f8833134180a5
MD5 0e67c76d11339bc922519cbc5fdab14e
BLAKE2b-256 9a34c6cb47e9c7293b3932a827fef4aa647b98f2f3f967abd4bad892e81acfd4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.246-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 711fa538863f7f9d60e91790bf5ffea8fdb3981a472a6b2f835e9102e7da2199
MD5 527a70db0c68e3633000169db6d50385
BLAKE2b-256 c4db751d0e64380ea6b913b69aa6663f8a9063fc5de2d7d080bde5c07a1e2597

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.246-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5e974d2091695186428d14a8ec1dc831b12d832d67d941287a97fe4edab513e8
MD5 2dda024d39ebf37c46df375ed7cd2a25
BLAKE2b-256 9365e722c4b960e01a6de6beece6463818dd8b937be9630f00fa8d0e357aaa56

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.246-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 2981686607cf58c29fe92b353cbf4a408215f8b1f22d78ddb9a0c5e451c0f63e
MD5 d1ba53abcbb5dee8385d6c0602be8704
BLAKE2b-256 9b645637f2f3e1ac67ff742881d1b10eb7577334c6ea608548a9c99359a9b7f5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.246-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 695fd786b36b4f966d15894a18b576e4b4c1e6aa9d2f30a446d8b5abf84be33a
MD5 3a18d886a44d1d6a03e1758b879a8d48
BLAKE2b-256 02537af594e574c45446147d90cb67136986acbc9672f08eb015dd408af4d010

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.246-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f65ff019fc9a05eb6bace1babf99b719a3080bb5082043e134a1868b22911d6c
MD5 346f84b72888b2112cc2660ac7d9a4bb
BLAKE2b-256 6838192456064d2baf36cf02d35c050f26457a52a606ba2c7677464f82d43852

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.246-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 729c8901a987abf96eda529c17a44daa4a0581a97d5b84cfd76f6497b20bbc78
MD5 d5ee767dbdfe8ca81049148c1a172fd8
BLAKE2b-256 47ca3c5ebeeade785d841d78cb75d6561d1c8e930908f0316b3e3c05d1134afa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.246-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4f7e1b633946bf43769b9b14be6e70825dba78617e130b7f10f9c036a0de332a
MD5 35bdbc30802514adf8a6f9e30ec8d264
BLAKE2b-256 1520172851aecdda2a2bee85457ef9a07e72ab61bbe78fb316031cbc14550dc9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.246-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 1487af876b6397f574bb235aae9ea46a5bcd7ca72dd308481e5db4f532a0ed54
MD5 3e3a383b23e5915d761daaf526b7e329
BLAKE2b-256 64f4c8649c8026054d411f904b9bd6129b523254b6a7ca572cf4d5628a6df18f

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