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

Uploaded CPython 3.10Windows x86-64

power_grid_model-1.3.267-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (503.0 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

power_grid_model-1.3.267-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (483.0 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

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

Uploaded CPython 3.10macOS 11.0+ ARM64

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

Uploaded CPython 3.10macOS 10.15+ x86-64

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

Uploaded CPython 3.9Windows x86-64

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

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.9manylinux: glibc 2.17+ ARM64

power_grid_model-1.3.267-cp39-cp39-macosx_11_0_arm64.whl (403.2 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

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

Uploaded CPython 3.9macOS 10.15+ x86-64

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

Uploaded CPython 3.8Windows x86-64

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

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.8manylinux: glibc 2.17+ ARM64

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

Uploaded CPython 3.8macOS 11.0+ ARM64

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

Uploaded CPython 3.8macOS 10.15+ x86-64

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.267-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 a00e3c006e454d563312f696e5f0d74fe0f8d537613271513076154dac013c9d
MD5 da29cf5f88da642c78c97707873dadbf
BLAKE2b-256 9d4e39be57e0f1bf716b9ad8481b87429bab3eaf69a573bc13ca0b6cecbec45f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.267-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 648d7146f7b6587cbadf494232a64b28bf3dc60c89bad93152518444b9996314
MD5 9679cfe91e7b3a08ae0d464d773bf6cc
BLAKE2b-256 1e077fc2f9b931b900afcffa5f1649b668fcc29de05e378dd66e5f0b7762be47

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.267-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 477a802cf5ee06cb2af11e3c507f6fa139bd2e9f7efc463900a716f82901052a
MD5 280b64af27dcf51f6e4ba0ef31775ba1
BLAKE2b-256 01cfbaa663dba2d750c03575cefa9ad34cc25754544b43913442e782a3247717

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.267-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3f8965d6aec0badb051ac6a7e871b98cc147c5366aa794b2b4d75fbd09d59195
MD5 247a38e29137c6dfe13387dbf3fd06e7
BLAKE2b-256 6c6f13b700347e4b910beebb0b9e243443a3d8db08f9cc2844cf0c6e93cd7d01

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.267-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 e97c242c35fb59945d41ae03b8f7b6a35c762806f96eb31569ad9ea43b21b10f
MD5 4662207b27c01eff2b60c567669d5a7e
BLAKE2b-256 1740eb3ebdde7dcceb9e3d70f369fecaa7c384d25b99c26e0e0b13385bc06400

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.267-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 468f243b5a9cdc53d74a1c8ba5f923c38e7990fd142663e3823a8bf61abf3ee3
MD5 3e5db12ee522cd05d1719542cc687573
BLAKE2b-256 9a1b12f0d5498cc93ced10f3dc755d525f994c105ce271c3accd98fcdee5d7cf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.267-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 61eb6cb4caf6484751041ab458852f90b21193b3008dab307afc8f9d1881ce1e
MD5 113c8d6a851f7c963132996c9c1dfc8f
BLAKE2b-256 4b62b25c95191b4ca0158c53a4c2ed88105ce7f9b9b864bf8084be811c2e7b02

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.267-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 b1fd5e2eb6dee58c5784e8cdd92616534e98edbc86d82284f601349cf46c956d
MD5 107dd378ffb4e57628ad794ef9c46557
BLAKE2b-256 22562b993c0ad6926ec314bc30dfd0a9b5e51a6a5457fb4c708451e90c0146e0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.267-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ce667cccf4c618b1d822fcb004c9cf6eae064cd83f98d1d5c0aaba6fa13bb6a3
MD5 79a0b3ff5c5a5fe0735cf9f75f6ae883
BLAKE2b-256 e8373231f3d3b56d64298c140bcd888c920f90564422bf7055592217e3c85290

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.267-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 5f5d23fb5d62be8c0368aa6bed83d5f921bb472d95d4b12e417b53d560c1e059
MD5 2d02eebf3d94e099b11c77d95af9af68
BLAKE2b-256 fe2e5c026aace96b3d335586bdeb43cb2d294d1fa3b64bed71a7328c1f6c32ff

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.267-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 9f79fd8dae5987c569d106be09ae578fbcc38f02c5776e7e9bbd167091e164bb
MD5 15a4b0d9519e99ccc86f11f7ffbeac4d
BLAKE2b-256 44b6349dd5878f176c42da5da661412117a96138bfd5c4d45875d16c500e5b78

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.267-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e8589b98e2f808703065dd5f4888fb4b4aca2c2b9a358574d46c47b855367298
MD5 4a420678c08a1b94459618c26f9d5ee4
BLAKE2b-256 c1f862130b99ed8eecbb18350a69102c3d5681cd912bfa7755ff1b707f3e2d48

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.267-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 555f4ca7a47a5c3f7cb4277d2158d882675f78419b88f0e66dde1fd0ecbcdc68
MD5 ea6b5500d701621a623eb5fd90a151e9
BLAKE2b-256 c6e3a94f7a639cc6427457a86791f0b10dcef50d87732b325e7ba898fb1063a8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.267-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1a5565a5540a5a5e550375b0c0dbd33f9def705a64f48340d7643e1bc5c89a03
MD5 8a62c39ce1f70ee9ad82c3fbff8e98cf
BLAKE2b-256 a89d7d85a92f4ad55cdf2be9499242056d0b2effe3395c06347d1e39d6006cf2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.267-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 4fae1b62158e6fe7e427776727ecb798564e80aa37d87a088b68c0b5e919fa56
MD5 0809909092621a5df5560665677e0c1d
BLAKE2b-256 2cef5310df52b4f7ef8db4d1f0d90a55a5d1e6bdad28135b895e2f3aa1d60ada

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