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.0rc949500771945-cp310-cp310-win_amd64.whl (399.6 kB view details)

Uploaded CPython 3.10Windows x86-64

power_grid_model-1.4.0rc949500771945-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (514.0 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

power_grid_model-1.4.0rc949500771945-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (495.3 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

power_grid_model-1.4.0rc949500771945-cp310-cp310-macosx_11_0_arm64.whl (412.1 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

power_grid_model-1.4.0rc949500771945-cp310-cp310-macosx_10_15_x86_64.whl (460.9 kB view details)

Uploaded CPython 3.10macOS 10.15+ x86-64

power_grid_model-1.4.0rc949500771945-cp39-cp39-win_amd64.whl (400.0 kB view details)

Uploaded CPython 3.9Windows x86-64

power_grid_model-1.4.0rc949500771945-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (514.1 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

power_grid_model-1.4.0rc949500771945-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (497.0 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ ARM64

power_grid_model-1.4.0rc949500771945-cp39-cp39-macosx_11_0_arm64.whl (412.0 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

power_grid_model-1.4.0rc949500771945-cp39-cp39-macosx_10_15_x86_64.whl (460.7 kB view details)

Uploaded CPython 3.9macOS 10.15+ x86-64

power_grid_model-1.4.0rc949500771945-cp38-cp38-win_amd64.whl (400.2 kB view details)

Uploaded CPython 3.8Windows x86-64

power_grid_model-1.4.0rc949500771945-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (514.6 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

power_grid_model-1.4.0rc949500771945-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (496.8 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ ARM64

power_grid_model-1.4.0rc949500771945-cp38-cp38-macosx_11_0_arm64.whl (412.1 kB view details)

Uploaded CPython 3.8macOS 11.0+ ARM64

power_grid_model-1.4.0rc949500771945-cp38-cp38-macosx_10_15_x86_64.whl (461.1 kB view details)

Uploaded CPython 3.8macOS 10.15+ x86-64

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc949500771945-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 5558cef6a340de4b03ee27bf67f134e0ea5c2164c02cebd3afedeefdae1ea3bc
MD5 149dc0d50a2fc3321c86e1a842ff5037
BLAKE2b-256 154ee311325e301a6955a22397e55ae6405390a379e30d950c00f5070819010a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc949500771945-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 47239c8af675ab79575e6ee6480a10dc83cad20b6ac11207fa404a5ea517dd71
MD5 735fe2093dffa45460fb22f2b6e92209
BLAKE2b-256 e488b7a5d19d924c1983118dd42ca9864fd2d72e866b2636ee42e0dafec2187b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc949500771945-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 3561aec9eb8440c73373089e3478fc2e6ae34ec32443029204599a64f7950102
MD5 4f11afe74a292cb38b5ee0d9cde2e290
BLAKE2b-256 04ad91c6ede7eebd1c59b7503dcd0a0bbef5ffa85095738f9eb3b2f882ecdd47

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc949500771945-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b8be7a14805379cd5aca8c8221ed04709ab934bd991629f67a1befff5468b3f6
MD5 d1c90bd3c80d0ab00816af21d4e091c5
BLAKE2b-256 8695fb58361398e4f62279dc0463cdf40ccee993d2e9304aaeb80705b4cf1830

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc949500771945-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 f2ca0781d0a63e5bd231e84c4c56eb9b0697355d14ed8f937c8109ce1e54e85a
MD5 f39a4b2f916431da5501512fbe4258d1
BLAKE2b-256 617e6866473623dea6dea44dd2529c21692e0b51d11adaf83ce5158d8dfdc375

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc949500771945-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 15cd3a785d1881cf420a9bdb372a8a8862c4239ba3f8a402900ec7902c6257b3
MD5 5a94f3c0a0d554c97fc75476816bef81
BLAKE2b-256 67eda1765fd287b7c5d668cc0057cbcfdc5ea2ddcb7341c1170b148776251726

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc949500771945-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2713ba3616034f3da43fe52dd2c997c7e5e732be656057d56fbcd3a8e580f864
MD5 dfdd5056bd04c5c996ed7e9c2c8bccc7
BLAKE2b-256 f3518035b478352857a10178b2dc7bdaed28cf496bfe8c11b862e76808ec6698

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc949500771945-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 07ba9f9a0a227fd40efc41fca7ab4f07cd1232ea85ca1b5cfb11860fdaface33
MD5 f9ba6067bffa8e84029ad1e8d6615e8f
BLAKE2b-256 bcd35280970b8e0f982c985d1a54b196d909973975684dd97af862d55ec734ca

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc949500771945-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cdc39b00fabafd8324b3b872bc5258ebc4d49eee11ec9a5bc84eee0ab556916d
MD5 67c429ea2d0a010cec3af94847001d0a
BLAKE2b-256 4d61253b5f47cf22ef790c206f0079bc9bdf073c17b56594c04705a2f55fd154

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc949500771945-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 75711c949dda9cbf0200db52e4f84224bf46d43d7b79ec7a8fc459eca012f2c5
MD5 88f9408ea9b35cf461a8ec4e0afe260a
BLAKE2b-256 9455abe266d0222a83249af143f75946d703d433dca8f4012b0b34d8581f6085

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc949500771945-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 569f31b9c85c0a4d61defb7ca23c18084cf47b579963674c724f661154e9ba6d
MD5 56ce7e22f063622ce3dff158444288b2
BLAKE2b-256 5d0595712138b96d0e3fc67e101f2855df881c75b283732969b04e43635e0813

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc949500771945-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 47649d8e0ac0488bff08b34b91917472517efaf964b5e7a4cb88d4d5876dec69
MD5 951315efc4a7b9cc86e681fe6d1a6955
BLAKE2b-256 58e67704db0868f35ba9e24b6ee15223999dbcf0a1de1f1c9cbbee1212e1a841

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc949500771945-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 e25449c152ac4bb9d63582cea832ee529382c21b13c709beffdc55d1ee8520a4
MD5 344aee9d68190633cf35bb76d46361b6
BLAKE2b-256 1b57c281406fbe530fc742baeafbce19314556dccb6adb3e271614d6bb9a34bc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc949500771945-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 74be95c400124f88b49a6cc97a576841960ae6539d2ced20dedf34d2213acc17
MD5 5ee5fab9c55f99af334becbb5cafc75e
BLAKE2b-256 03a1058813ad9437c346b001847cdc20432ae665d26fb77042752e6c015a32e0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc949500771945-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 13dac46c77f645de3122609ec9f46ea4fc9de9b812f6d6c9125db949cde5888a
MD5 47c62af72701f1b85faa23268457ab3b
BLAKE2b-256 21cadbbfe7945d4747c25ead17f6eb33c70b0346298c929a432932b6d893b1a2

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