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

Uploaded CPython 3.10 Windows x86-64

power_grid_model-1.3.179-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (517.6 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

power_grid_model-1.3.179-cp310-cp310-macosx_11_0_arm64.whl (388.9 kB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

power_grid_model-1.3.179-cp310-cp310-macosx_10_15_x86_64.whl (447.8 kB view details)

Uploaded CPython 3.10 macOS 10.15+ x86-64

power_grid_model-1.3.179-cp39-cp39-win_amd64.whl (392.0 kB view details)

Uploaded CPython 3.9 Windows x86-64

power_grid_model-1.3.179-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (517.5 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

power_grid_model-1.3.179-cp39-cp39-macosx_11_0_arm64.whl (388.5 kB view details)

Uploaded CPython 3.9 macOS 11.0+ ARM64

power_grid_model-1.3.179-cp39-cp39-macosx_10_15_x86_64.whl (447.4 kB view details)

Uploaded CPython 3.9 macOS 10.15+ x86-64

power_grid_model-1.3.179-cp38-cp38-win_amd64.whl (393.1 kB view details)

Uploaded CPython 3.8 Windows x86-64

power_grid_model-1.3.179-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (518.1 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

power_grid_model-1.3.179-cp38-cp38-macosx_11_0_arm64.whl (388.6 kB view details)

Uploaded CPython 3.8 macOS 11.0+ ARM64

power_grid_model-1.3.179-cp38-cp38-macosx_10_15_x86_64.whl (447.8 kB view details)

Uploaded CPython 3.8 macOS 10.15+ x86-64

File details

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

File metadata

  • Download URL: power_grid_model-1.3.179-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 392.2 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for power_grid_model-1.3.179-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 c1d57686d310010f6f13b31d105087931a2ec198ffaa8024127c00a6658fac70
MD5 23eea9c3288fa0678f80dbd7c64d3900
BLAKE2b-256 305614f36363e52214bdfbbc4848a156b061b6275e2d2e44900e317962d7f6ff

See more details on using hashes here.

File details

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

File metadata

  • Download URL: power_grid_model-1.3.179-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 517.6 kB
  • Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for power_grid_model-1.3.179-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0f452d2e6d30f59ffb529220e3613d40463f1b267866346559cc99e87f5609ec
MD5 8866d794b4f024134356a489b19d0536
BLAKE2b-256 dd86d0c0b631520cdfc1c211c9a789a59161209ac95f2b2dc910c8c78ab704eb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: power_grid_model-1.3.179-cp310-cp310-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 388.9 kB
  • Tags: CPython 3.10, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for power_grid_model-1.3.179-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4fa9db4ca57cd73084e1f5f838497ab5255386ce91e316594bbf29e837d43c5f
MD5 ce3935b42182e14bfeb7f3a93cce54d6
BLAKE2b-256 0337064afa8af6604a725b74c8b13bc9b5ba88e99b6022ed10b9ab309f2d7441

See more details on using hashes here.

File details

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

File metadata

  • Download URL: power_grid_model-1.3.179-cp310-cp310-macosx_10_15_x86_64.whl
  • Upload date:
  • Size: 447.8 kB
  • Tags: CPython 3.10, macOS 10.15+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for power_grid_model-1.3.179-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 ca76fa29a595deaeb3ccb6606122752f23cefdcdda677fdf0b84bdcaffefb37a
MD5 d3d3a56c28e0adfd2147aa2d64c6421e
BLAKE2b-256 d72796f7f310b466bd14e38c53eb741571f57a471044b7e8d2194437c4664e39

See more details on using hashes here.

File details

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

File metadata

  • Download URL: power_grid_model-1.3.179-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 392.0 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for power_grid_model-1.3.179-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 e1a769986933982ad755fa026e18a4ebea6b2764670067a6b5207f941ac40a32
MD5 9dd88ee1df43fd7afcb67b28372e39d8
BLAKE2b-256 ca82b56a277080696609c6b298a8e0e94905882d5260f572fca2d6c7ec6c806c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: power_grid_model-1.3.179-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 517.5 kB
  • Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for power_grid_model-1.3.179-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 25d77a32025ff5a6b92422956c7231be5e942a6fe2a49e23281f4668070998ad
MD5 b01ad8072e87e97f554855bdc8f13eab
BLAKE2b-256 da7c9cd3130a68e682e55b17b731f678eab9f8588d43dd53906a77ba50472571

See more details on using hashes here.

File details

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

File metadata

  • Download URL: power_grid_model-1.3.179-cp39-cp39-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 388.5 kB
  • Tags: CPython 3.9, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for power_grid_model-1.3.179-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6f4cc3b9227590f97a9976396cef426ece11629ec39eea16b80da8558d77534f
MD5 fceccb1926c88c5f7a743fa61cbc244c
BLAKE2b-256 5642f341c67f1f07c58dcceb85357dde1abe6fe43f2d407031fda15bed7aa389

See more details on using hashes here.

File details

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

File metadata

  • Download URL: power_grid_model-1.3.179-cp39-cp39-macosx_10_15_x86_64.whl
  • Upload date:
  • Size: 447.4 kB
  • Tags: CPython 3.9, macOS 10.15+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for power_grid_model-1.3.179-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 d88598487c59fb3ee8ca8546683ca49293eceec8f96588a7295b586862493b4d
MD5 67fed24ce01c0bd3f5bac0134db41399
BLAKE2b-256 b128c3265209de64567dfa8375c42403cef552039ddab295a991a2efc36772d4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: power_grid_model-1.3.179-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 393.1 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for power_grid_model-1.3.179-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 d816597060f501d3cd0ee8ca311da7c2e075af3dbc38ed6603035717becb3e73
MD5 2d9f0ad8f2767129da0c043206b07fe9
BLAKE2b-256 77437a6783e3a42e07808ecd6fd758c86c932456c0dec65e5d232c587aa1d8b8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: power_grid_model-1.3.179-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 518.1 kB
  • Tags: CPython 3.8, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for power_grid_model-1.3.179-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7f7d7165d6f1a4e37cd2108af75dc09e3f8e7731824d033de90fa3348d6ba83c
MD5 909c7be9339fb0bb1a37e64b0380d118
BLAKE2b-256 0d609f66582db34766c00675cefb4c8f6daeefefd24dd1b4c92a5197a592bbe7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: power_grid_model-1.3.179-cp38-cp38-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 388.6 kB
  • Tags: CPython 3.8, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for power_grid_model-1.3.179-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 26866fe16dcef0d9fd0971685dcb76a0f76cfc4577fa8e29d86b43fc18bbf256
MD5 8a4941dc29879487bf9c1eb21687e6eb
BLAKE2b-256 074eb5a23aeded1db7bf5ad288a4b8212a04752fdaec56e8ce768955e91d3584

See more details on using hashes here.

File details

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

File metadata

  • Download URL: power_grid_model-1.3.179-cp38-cp38-macosx_10_15_x86_64.whl
  • Upload date:
  • Size: 447.8 kB
  • Tags: CPython 3.8, macOS 10.15+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for power_grid_model-1.3.179-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 a2297f9bd8f44dfbea2c0585545986e7f19680b3463715dd8a984e945aa80dda
MD5 8487e501cb578e0b8ec7e1878be0487e
BLAKE2b-256 20f7363985c61ee6fc47279468920e47aade7e934a9984f1f4ac8dabe55e8e48

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