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

Uploaded CPython 3.10 Windows x86-64

power_grid_model-1.3.264-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.264-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (483.0 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

power_grid_model-1.3.264-cp310-cp310-macosx_11_0_arm64.whl (403.3 kB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

power_grid_model-1.3.264-cp310-cp310-macosx_10_15_x86_64.whl (450.4 kB view details)

Uploaded CPython 3.10 macOS 10.15+ x86-64

power_grid_model-1.3.264-cp39-cp39-win_amd64.whl (394.4 kB view details)

Uploaded CPython 3.9 Windows x86-64

power_grid_model-1.3.264-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (503.9 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

power_grid_model-1.3.264-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (483.5 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

power_grid_model-1.3.264-cp39-cp39-macosx_11_0_arm64.whl (403.3 kB view details)

Uploaded CPython 3.9 macOS 11.0+ ARM64

power_grid_model-1.3.264-cp39-cp39-macosx_10_15_x86_64.whl (450.2 kB view details)

Uploaded CPython 3.9 macOS 10.15+ x86-64

power_grid_model-1.3.264-cp38-cp38-win_amd64.whl (394.4 kB view details)

Uploaded CPython 3.8 Windows x86-64

power_grid_model-1.3.264-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (505.3 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

power_grid_model-1.3.264-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (483.7 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARM64

power_grid_model-1.3.264-cp38-cp38-macosx_11_0_arm64.whl (403.4 kB view details)

Uploaded CPython 3.8 macOS 11.0+ ARM64

power_grid_model-1.3.264-cp38-cp38-macosx_10_15_x86_64.whl (450.6 kB view details)

Uploaded CPython 3.8 macOS 10.15+ x86-64

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.264-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 af4362227365736fc8534a95e1ee942beadd3d0a610062a09dfbf5a6832ab3c0
MD5 b44340ac54877d99066beb212966e994
BLAKE2b-256 7b6d70cc8cd576a75782e2872dfd129f35b6122a0bda731728b8bebd22fd559f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.264-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 607f48961fca0e994d162af84a09d24520cc75381ee8eb628971aadd171f41c4
MD5 2f97dcfc2d650cddc91965429f1e287b
BLAKE2b-256 b80dcd31d0115c5a2dfee68fa5e4593c168673244c52d6493ae11dfc7de319a2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.264-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 290e824a52ceb9727f7e527e8f238cde06594e2692f19ad8d47885795544fc09
MD5 1548d833ba05d584677d24059378a58c
BLAKE2b-256 2bc2c3899d616c6b42aec20bde4ce1efad0e5fa76e41a98884d51b7119be6ef7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.264-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0d2824315da604297d0d22324055ce099efb6a8fb7537f26911f91fca840a5c7
MD5 30e5c7f3bc35e35fa3c9b2cba8f3a0a1
BLAKE2b-256 8913281d37a9a031f55fbf7c358088293a06bc9a442ac421ba55adaf2b86eddc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.264-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 60c19e622ecbf7bb13f3b9d775ecd7c9d8d13c3c499c6cd1b266445b7f5f3a47
MD5 44e411e18b90a53ced1010a6926fc91e
BLAKE2b-256 cc7dfb08d57dc48e757f7e2ab47b466e52476c2ee1342ae8531eeb42249cc6ed

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.264-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 c86a4eaef7816e7c7d9ee4c44c10bb75895c75490217a1f753c727835cb28e34
MD5 af941de49acf21f2198287ee5c80fdad
BLAKE2b-256 0a9ea8067a804c71d3d8c76dadb5c55a451e51c5af7b7f4457e19a9f2f207fb3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.264-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cad729f9fdec4705cb76c710281b016f764cf9a4d52e004a7b50cfa67f866132
MD5 89d0a73ce664f3172bbf864081ccb0ab
BLAKE2b-256 ba8f4c1d0fe574bc316da1271feca73aa9f8def71677d5afff68c9d5d458ad93

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.264-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 4a973e9a83de29154e0861ba2c8ce7f6695c14fda7ec5027ad6ea84dc293d95e
MD5 7041c672e7a9d4813c6522ee72b5dffe
BLAKE2b-256 c0e197e48b89fd8550dff28b061fac96120370c53843f926b06400ef1c4bb35e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.264-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 59d318ef4acc4ae1e5f92de069806c5707acdd053187b36eec909b0eee513b09
MD5 78c310b532373cb6701701b7e59ddf8a
BLAKE2b-256 b8ae0b5341276c6d18d8c1661a5b68da9c54f3669c3423cb106d6d2549cc62df

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.264-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 f330a50199e974248da542665a91e1155639f4d88bfb0807ed860d71541e132f
MD5 ac2f1972c4433cae085b222d508f6f75
BLAKE2b-256 6331f6b98dab4800b350763605cdd18a0f82e6c3ccc5cb010001653500aa0be1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.264-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 57ff49da051bc24fe5968486f7247422ace274f6cd10b47d96a5de7463825c03
MD5 4f4e9c4601daa4ee53a1d515ece3a5f3
BLAKE2b-256 58ab06d209a1545449df49855f95f44422481ca40ef0211a3f6bfcdec75251c4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.264-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cb904a098fb40fdc8d97ebdfe5b8a05998eeafd7994bd0904eb94c44e5e52335
MD5 80e1a88eb835d298588354b770ccefcc
BLAKE2b-256 2cd2575f11b2219b96799f948e1e334e0979331b85f7bdb7aa3016f6d48b3285

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.264-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 b09595a2a7f11775a8bcc2fcf1e8f1abb52c3b1a2428ac5cca1893a294d7bd2b
MD5 39112b4e2227bdee97deb91d6272dddf
BLAKE2b-256 5f8da3d9c58790d89079197779cee7c840352e7bebbf8ad6d2a8c2b9ce571c82

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.264-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 13a4f598a1932c56e52afb031877a350cd274acd1249bae48df999675d4524ea
MD5 f155af469103b3b3a3ee65d0560c0f3c
BLAKE2b-256 5f48d79eb756626f401f6c762987e052a25eeadb02d35596914bd385daa10cb9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.264-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 c6d5d664225b0163fe3dfda11a2559acc60d0207baa3e7a47f7ecb80ddf5e29d
MD5 df0be8ed77ac168fc768b46ea61fdf6e
BLAKE2b-256 d3a202bd0f16a2cfd9b0aef79fa5b6466018cbd1d3cac3c86e7eed1960f83b69

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