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.273-cp311-cp311-win_amd64.whl (396.1 kB view details)

Uploaded CPython 3.11 Windows x86-64

power_grid_model-1.3.273-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (505.8 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

power_grid_model-1.3.273-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (486.1 kB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

power_grid_model-1.3.273-cp311-cp311-macosx_11_0_arm64.whl (405.2 kB view details)

Uploaded CPython 3.11 macOS 11.0+ ARM64

power_grid_model-1.3.273-cp311-cp311-macosx_10_15_x86_64.whl (451.9 kB view details)

Uploaded CPython 3.11 macOS 10.15+ x86-64

power_grid_model-1.3.273-cp310-cp310-win_amd64.whl (396.4 kB view details)

Uploaded CPython 3.10 Windows x86-64

power_grid_model-1.3.273-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.273-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.273-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.273-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.273-cp39-cp39-win_amd64.whl (397.0 kB view details)

Uploaded CPython 3.9 Windows x86-64

power_grid_model-1.3.273-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.273-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.273-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.273-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.273-cp38-cp38-win_amd64.whl (397.1 kB view details)

Uploaded CPython 3.8 Windows x86-64

power_grid_model-1.3.273-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.273-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.273-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.273-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.273-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for power_grid_model-1.3.273-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 e3de5c25d0fade2aee6ae778503055f40a8a3640f6f634d8c3051923f83407d6
MD5 82e13b5451431d94fdab62a9a3d93632
BLAKE2b-256 123d0c90b82cf733abd6c2e5de4de97c5d0e6dd5772dffc4948cc666ca75a4a5

See more details on using hashes here.

File details

Details for the file power_grid_model-1.3.273-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for power_grid_model-1.3.273-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1d47e99b293b0d28331888aea0da734914bbf9feb38e3fca26e1f17c78f6a9dd
MD5 ab039a9afbffe31dec25dcdf55dd63a8
BLAKE2b-256 0fdaa1770c3d5a4cc9ccac21a6b64bc120fe18f7af4069b93c5c51926fe97e89

See more details on using hashes here.

File details

Details for the file power_grid_model-1.3.273-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for power_grid_model-1.3.273-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 46fdea8c1f6dff2572c8a2711a80719747f34484d44d615d8acabe010bfac997
MD5 525209cf39f3f40f769ef5b70663ebaf
BLAKE2b-256 89230167f1465934b38530683810f02c1fb9000f409c287694a623a5138a958c

See more details on using hashes here.

File details

Details for the file power_grid_model-1.3.273-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for power_grid_model-1.3.273-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c37a5677fbe344c7234170134e608108896da895c1467b9417b08ad126e10064
MD5 4d755d0b36875c0187e3431ec49d39b8
BLAKE2b-256 2819ab99162b01d772e4df37756cf59b790ab52649a3f5f9a8747a90dfc31147

See more details on using hashes here.

File details

Details for the file power_grid_model-1.3.273-cp311-cp311-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for power_grid_model-1.3.273-cp311-cp311-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 9bb07027f239dc187945d63a8f0ffd6ad1a21c40dd3c0a40cec94f42e2a45f77
MD5 411c0e44e7d41304952644719c417edd
BLAKE2b-256 128638dc674f7240c2bddd23baab10f6bbc0e23343b582cd3d7c917916b80140

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.273-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 216d7590c40d72190c7cbfcf2703a307c7ae97edf12361bb49c7322919b724a6
MD5 f3450bec81c6905eb4260d0a1425eb21
BLAKE2b-256 b5d8da676860ab90333c461d0f2c0ec0554a621a621e056363e1ddd86d588777

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.273-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f3df2d9dbc2daba856d0191b30fe92e4c54020949a23a4f6a76ff18f1041c322
MD5 bbd14bd6fbf4fc01d6c35aeb657c9c50
BLAKE2b-256 a1d207a0fcccca0dffa4288c347c5f8c228abed311090e2da8fcab378a1ac11f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.273-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 90e0f282bacd6e1e583d6fd34e69e8a1b36146fe6cb356c2e7a65073ba7c42e7
MD5 2acf02fb962c11b2d3499939930cd61e
BLAKE2b-256 191a7156b4895902c3a686edcf11da1460ec7004c015f51f47025d37556891a9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.273-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 89cc31cdadc9da1faca6fe20784dfa6e0ca6279ad61235641434e43d22952f3f
MD5 0d2c7fd79dc38b8f8cb04293ed2cf77f
BLAKE2b-256 9c8b994c1cd8413cccdd715ee9dd8ae0149fa01f4b0600640c8e9cea10a84b45

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.273-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 afc8724f54df338edfb4fe48557a9b6e3e2bd19db6f7a7e47241319bf9a486b0
MD5 9b530ac9cfff4ad4060de1f019a825c6
BLAKE2b-256 042daa95630697bed74e12862c001212a0c199dda1437807f94d839b9c79c884

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.273-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 800fb216a4080efd3949a2d205e8dcaaa684c5de3442c503867cfc53486aa11f
MD5 4879f70d223c4c2501bb50930d780f4e
BLAKE2b-256 f23756836f1417a8be707268ee2f6b76c02fc6b47b742dc6947ec61a5fa56941

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.273-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0f444c430b0d4aee6c0594a3d6ce97cb7d34eb520cbf7353adecb1527898be62
MD5 2788af2af7129f0148bb0a43069fe1f8
BLAKE2b-256 3c15e24e81197710fd07e7c1d8d269b5085b6da20d6692a50b094f497a5d5035

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.273-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 7bed69db2cd147198e241ea67776df53d4c718a9b8b763160fce8d38114fd8b8
MD5 47fcc66d04377a85b50cc0dbcf93f225
BLAKE2b-256 6e66ecd3894e93748196403c37cfb439f850620d0e7e8c14a56e49c3be77e77a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.273-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e3519cad3581566436d2f249f70968340975d00e512f270f63c8154cc07cf38e
MD5 9d4f9c4b0b46720e91a2e173b77e5f09
BLAKE2b-256 012e11318f2f0dd95914f0b1347774b51e95587de601378a3640fe4f2f8ac2d6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.273-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 ddff644d65316bbd1430fdf80e38f3210482c18e0aa05d9d137e0ea1e17d9fd8
MD5 a0e42e30295d13307cdecac6f1174b4d
BLAKE2b-256 e15bbe2e6781898e20ed471d621d0c25b20a11bd778a1d0f81549552e2774811

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.273-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 819d710087154466a31b52435b94f016b9123825f564f8433c2e73812b0fd3fb
MD5 e13766e27900f4d0997cff460cb7e330
BLAKE2b-256 8fc4f7072f3a97c0a1c57d979731b20bb5b5596feed79ecdc3f4ef2daef6bc80

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.273-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7b491842f0cb1b40de63d5a9caa8e79cf14a7be15244eab0e474ee531a49b2fa
MD5 41aab4644b075b4c0d985978f546353b
BLAKE2b-256 cd9df5549814b48b72bb34053cb537d19d0ecc387384122133294414a8afe3e8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.273-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 5fff46c21b4135ab9c1f7a3fbbc07767f76a672a05f0d1d936727b8e49800fb8
MD5 edc17705bffc9284de3218bf6bdbecd8
BLAKE2b-256 9a82d256548b2f3857ccd8b59a8011605df383d9a132e7c347677822684a5493

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.273-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f4b9ffd616e5fc2ed1683c27a15cf171e1ea00a5e3470e02e1b37945893f7607
MD5 ebf9c057cdec007fdbb5f1c6e9110bc4
BLAKE2b-256 e7e03c4808e76f1f50ad3693b41c521230ca6444a2408aac1f049cf62ed2cdbe

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.273-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 13d930365e58eea3191008f4caf663b9b2859e3521a6770258687b2da76f2411
MD5 3a027277b9f75e9227e1336e7e97f992
BLAKE2b-256 1490a32f3a3e45d75d55ee5d9f48c1d4c18bc3222fcd5653271c745c252fb580

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