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

Uploaded CPython 3.10 Windows x86-64

power_grid_model-1.3.271-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.271-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (485.6 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

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

Uploaded CPython 3.9 Windows x86-64

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

Uploaded CPython 3.8 Windows x86-64

power_grid_model-1.3.271-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.271-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (486.3 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARM64

power_grid_model-1.3.271-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.271-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.271-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for power_grid_model-1.3.271-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 a64be3235cbea3ff7fc8585f87b58bae346042675f6be9d9fa8cf929d18a0d96
MD5 4dc9ebc096169fb3657a3990ccbbd705
BLAKE2b-256 79a762f09c17f6d694aaa24a3376d1b56868ad5fe1aed0d498963c712fc0b02e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.271-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 230e4c0da94d040d011f56688bc549ec1fdc5cf5d5c2a92495f06369f3c8231e
MD5 748ab12df9cf375bf94f04ef69a0e227
BLAKE2b-256 653a531a3377d864b2e847dddfef196fe1e871365a00333dbf397fbeaf35e5c3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.271-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 db20cc49a1c15adcfd2378f9cff25937a9c8d515d55cc090678e062a576baa7c
MD5 761bb196fecd3a1e441a28ccbfc0ed92
BLAKE2b-256 c5d7b9c994d0f96722f22aaa6cee0cdef7e500d5b492c181aa17f047805a850b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.271-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5a702860e1be1ddb0718c68f8ae796ddd7aa91c67ac3c63a422d1e3af0923deb
MD5 01a69eac2d4d13a1c9a8be032adc0134
BLAKE2b-256 365230f5749827b16890cb3fc4774493880400fa60475c997a269a5f16c8949f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.271-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 7ca8ea2250d3344798f9e8b51c979c9f25873d4605ad7515a036714284ba4156
MD5 61570618fa20a4bf89d471f5d4286e2f
BLAKE2b-256 4ef02454682d84bb6ec12b4afe958068e5def3ed1af2adc3a2983f569b664c9b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.271-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 0b7c4b9846adb64dca3dce0eebb28a579743963cc8372e2cf49f56335a2639e4
MD5 bcc15a997d486ef4e4e19fd6f2a1ff5a
BLAKE2b-256 e4e68e6d9de1e33568e43cdd0cd82b2b26fff312c7aebbc499d4863d99fb3f05

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.271-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 60884b9bf17c9dde604021cf5742a38ed13d0c4bc15215896d9164a51520963a
MD5 f23eab006327f9045f8e919c6f71bf6d
BLAKE2b-256 b0bd8188811dbdc8644d8ee35344eb22c18d04151994b04e663813accb91d1b2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.271-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 409cf5b9893b7f8ad7267de2ad4696b3708db4df1a3e0cc88dc27399ee2d2b3d
MD5 bf6d15386984483a0c2eb151a11b7f0e
BLAKE2b-256 cc01ada7b8cd5bb35a06dd18ca4d01426bb4952427850bd26aff90fb3a7b10a4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.271-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4210054208543cb0e85e53c9ba9b3759bc876a1e1be39a1655e9bae86c662126
MD5 837f2f99073018772d1991b7b83294e4
BLAKE2b-256 ec13b779ade308d66dbabdb6ce7345df1976cc3c2793c2ea8ce553d13917114b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.271-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 b232b297d598954c4cb2c5f962e291d113a9fde44d4b53a8a5c1ef3fe7ba888c
MD5 b9234fc0bf237729ed10ef89d3a339f6
BLAKE2b-256 34354c06cfd797cc030ea5c14eca427e95b544b22127893b0d160d72c5d6d2d0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.271-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 55cfe32a2225bca28b6be090a271c0ea003ce0f891d8fece0065c7d7897b01c8
MD5 88ee804030726c44b5b26f84155c5799
BLAKE2b-256 e91a2d3efffcbbcbd034479b897c89714e33473d6e582a000352da82390f0996

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.271-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2d00e6d9b7a8c5e05fd4d578022a9c1ec70bd3cdde5ba63a4a893b13b3d9e760
MD5 6e176046b3cbf41bcf1f65bbd2ca2015
BLAKE2b-256 cd0c2827e8608f4a55c492a260918d7a0ac063aa4684f3ab81f257ba09842afc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.271-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 907a9736e9e5174214e5dd25a750afda7bbc2ea22b62828e7812178c45f22a81
MD5 a9da25c504630b1f78a7cf3c8f2b369d
BLAKE2b-256 d61c6e2e9cde0d7b930336027212b10494aae228e33c9640cfdccfc603295bbc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.271-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9413de53607e26c8712008ea52e3d0dc93c8ec560be931fed4ce50d0a772e7b2
MD5 15b84f8550e3a4f5ac25c9722082b1f8
BLAKE2b-256 7f33175575c16487f4c89e3269be1f818a7095087223aaaca54eb5c953d62e4e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.271-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 f069bc74c8ecc3de44fdd9f7b8b34faba5080f1be1ce73e7f07d9c27569dd1fa
MD5 abd7ff86e9189ab9fa3ea7b891b17bf3
BLAKE2b-256 24ee036b5ab80bdb562984ebac25ac4696bb054b349c910eb502e7633ad06f75

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