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

If you're not sure about the file name format, learn more about wheel file names.

power_grid_model-1.4.0rc947708991658-cp310-cp310-win_amd64.whl (393.8 kB view details)

Uploaded CPython 3.10Windows x86-64

power_grid_model-1.4.0rc947708991658-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (503.1 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

power_grid_model-1.4.0rc947708991658-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (483.1 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

power_grid_model-1.4.0rc947708991658-cp310-cp310-macosx_11_0_arm64.whl (403.5 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

power_grid_model-1.4.0rc947708991658-cp310-cp310-macosx_10_15_x86_64.whl (450.6 kB view details)

Uploaded CPython 3.10macOS 10.15+ x86-64

power_grid_model-1.4.0rc947708991658-cp39-cp39-win_amd64.whl (394.5 kB view details)

Uploaded CPython 3.9Windows x86-64

power_grid_model-1.4.0rc947708991658-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (504.1 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

power_grid_model-1.4.0rc947708991658-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (483.7 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ ARM64

power_grid_model-1.4.0rc947708991658-cp39-cp39-macosx_11_0_arm64.whl (403.4 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

power_grid_model-1.4.0rc947708991658-cp39-cp39-macosx_10_15_x86_64.whl (450.3 kB view details)

Uploaded CPython 3.9macOS 10.15+ x86-64

power_grid_model-1.4.0rc947708991658-cp38-cp38-win_amd64.whl (394.6 kB view details)

Uploaded CPython 3.8Windows x86-64

power_grid_model-1.4.0rc947708991658-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (505.4 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

power_grid_model-1.4.0rc947708991658-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (483.8 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ ARM64

power_grid_model-1.4.0rc947708991658-cp38-cp38-macosx_11_0_arm64.whl (403.5 kB view details)

Uploaded CPython 3.8macOS 11.0+ ARM64

power_grid_model-1.4.0rc947708991658-cp38-cp38-macosx_10_15_x86_64.whl (450.8 kB view details)

Uploaded CPython 3.8macOS 10.15+ x86-64

File details

Details for the file power_grid_model-1.4.0rc947708991658-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc947708991658-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 9ae189440a663d4899a50339156cc6e90f1e1d1a3052425eada95e5eda1cf1d0
MD5 eee4b6f2c929a769e4c9d453c9ab4e6d
BLAKE2b-256 0184d0a47716e619532ddd8b307e56e528763222492d7bc6f6e188de33acc98e

See more details on using hashes here.

File details

Details for the file power_grid_model-1.4.0rc947708991658-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc947708991658-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3f2393c50f8fe5a09844c099780ae90e2dd5e5a3a5482e62758682395ae6c79f
MD5 b05f1e054bfe9f11dea4365b64a19be0
BLAKE2b-256 f9e062cee28ad305f09527030bf7fa3786aabc14f540f3c747c8cbbcff9304e2

See more details on using hashes here.

File details

Details for the file power_grid_model-1.4.0rc947708991658-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc947708991658-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 7105672f07b5dccabb4152a97f2b582f0f8b80f0c5e1cc9c6c6e2b20d444822b
MD5 50ca81d37d85b2da01e170ed035ec507
BLAKE2b-256 135e53b575d3d35e77c9ab3b389ad245101063e95088b33bb3b2d480e5252bae

See more details on using hashes here.

File details

Details for the file power_grid_model-1.4.0rc947708991658-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc947708991658-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ca5002fa7d0ff05b02e15ca791472b0ac68266cfb113e1eb63d251f296c46bd5
MD5 359f0d9b8c72ef382b401d50133c6c47
BLAKE2b-256 b483429f6b1fca4b62bab0094698680ccbf539429f1b9c5ae254204c1cf58f7a

See more details on using hashes here.

File details

Details for the file power_grid_model-1.4.0rc947708991658-cp310-cp310-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc947708991658-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 27e71a1533e42b3cd1039d283d7ef7405a93839f51f8513ef8e1725c1c2fc490
MD5 3433fab4e40ce075925eb113e70be8a9
BLAKE2b-256 a4d6b309ff46520e6c664fa0f5d6192a6db6bb03e61934116b6a59f47b98c7cc

See more details on using hashes here.

File details

Details for the file power_grid_model-1.4.0rc947708991658-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc947708991658-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 52182f4beb2fc19d11c8f679b39f76f00aea910951cfd27fcbd816607bebe2c9
MD5 c5956f0612fe1f174c13a0ef303a102b
BLAKE2b-256 527cd90e336c95dd8e5fe9dea736d86fa29ce8588e8c8e1f4c97a9e745123fcc

See more details on using hashes here.

File details

Details for the file power_grid_model-1.4.0rc947708991658-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc947708991658-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9c98e4b37435b296081dab9fd9306c9751fdce716ec6de46afebf3034f30d821
MD5 06d71d35a785e394bd02fa57602b82c4
BLAKE2b-256 f0d544d1b505783254d31fa5cad554f54f74937f149cd72962f9c5e9e76ee271

See more details on using hashes here.

File details

Details for the file power_grid_model-1.4.0rc947708991658-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc947708991658-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 ba51442befb823f37e87ba0a40af6fdc221f6f3b50312a87ad989add74abe60d
MD5 b4f6020d9a9f08f78308bc029105b8c6
BLAKE2b-256 3f80a5c610cb89dd7e4cf90e7340c7cfb956cead211f64d51e3f56f8ae25761b

See more details on using hashes here.

File details

Details for the file power_grid_model-1.4.0rc947708991658-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc947708991658-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9281b76770330b9943b14b8c2fc497d5c16a5aed3f5b32deea09092265aa2353
MD5 67139f12c011a4307adb255567cc3773
BLAKE2b-256 58b2445f109188acdd3e38533e2d4dae0a3e9c7f0e5ac28c0b9332f4e8e6e3d1

See more details on using hashes here.

File details

Details for the file power_grid_model-1.4.0rc947708991658-cp39-cp39-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc947708991658-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 e193019191f40674e1690940580fe402aad3ce4601c0ff3f10d9f0733a8bf807
MD5 d8bc9d884efcddb3af02966a18002a49
BLAKE2b-256 3b3947d90553ada3eb276ed86533178674a87f5ecde06ca48877a88135b153d1

See more details on using hashes here.

File details

Details for the file power_grid_model-1.4.0rc947708991658-cp38-cp38-win_amd64.whl.

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc947708991658-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 a910d869c0a1e8200bf2b675b21e3ab0ab50bfcebb7b841c9529c423583e205d
MD5 f5897e42211b87576af33a6396bd6b01
BLAKE2b-256 8622df02eeb5b44ba7e90af998d7fdc55e21a1bc7033a4c4275905a091047bf0

See more details on using hashes here.

File details

Details for the file power_grid_model-1.4.0rc947708991658-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc947708991658-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ef2c170ad1264b49a7e06af1aaf94e1c553efa42eea5e06473446fbfc3d0074b
MD5 9bef482aa02a820a255f3a61474b5d54
BLAKE2b-256 c9c8ea084f91c40a1f75fe6dc8b903c431a7f1bcb066be2b88372a6f5e17ebf2

See more details on using hashes here.

File details

Details for the file power_grid_model-1.4.0rc947708991658-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc947708991658-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 1a5e34afa145ef6ed7f919f8433186bdfd5fce4cebd4c9f20ac5dbf69a98d144
MD5 1ad4926ced15525ed625134307df00c1
BLAKE2b-256 fe9ffa7f986e961d0b7fe507bed5be74cc6779b3ccf47fc286b4f004b077dda3

See more details on using hashes here.

File details

Details for the file power_grid_model-1.4.0rc947708991658-cp38-cp38-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc947708991658-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 57dda69e7c61e98a7b923f2c9415206e108e3d6ad2e25125f4f931625fd655b6
MD5 29878403bd1cd3378330ea4330c03103
BLAKE2b-256 afcf2a0f3e9c6ddd965b7b7dea885b72ee99bfb8cf595d97c504829a58f8d945

See more details on using hashes here.

File details

Details for the file power_grid_model-1.4.0rc947708991658-cp38-cp38-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc947708991658-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 c59a8d8022feeffdda92aa21dfd2185bac9de09e0a74cbf8a5f0d1af7ec8a324
MD5 3d7c2b8d5bd6b1b164f02f7d66422ae9
BLAKE2b-256 e346270083e4368b9a4445785ec0c00a54aafc83e33215f0c85771a7d06e4bc3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page