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

Uploaded CPython 3.10Windows x86-64

power_grid_model-1.4.0rc947104152050-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.0rc947104152050-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.0rc947104152050-cp310-cp310-macosx_11_0_arm64.whl (403.5 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

power_grid_model-1.4.0rc947104152050-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.0rc947104152050-cp39-cp39-win_amd64.whl (394.5 kB view details)

Uploaded CPython 3.9Windows x86-64

power_grid_model-1.4.0rc947104152050-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.0rc947104152050-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.0rc947104152050-cp39-cp39-macosx_11_0_arm64.whl (403.4 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

power_grid_model-1.4.0rc947104152050-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.0rc947104152050-cp38-cp38-win_amd64.whl (394.6 kB view details)

Uploaded CPython 3.8Windows x86-64

power_grid_model-1.4.0rc947104152050-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.0rc947104152050-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.0rc947104152050-cp38-cp38-macosx_11_0_arm64.whl (403.5 kB view details)

Uploaded CPython 3.8macOS 11.0+ ARM64

power_grid_model-1.4.0rc947104152050-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.0rc947104152050-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc947104152050-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 c6f3eab409ed931f526ea7f3e4eca7eed70b6e53108ae0c82f609329776a73a5
MD5 d8684aea68861f3a1a67fc123a2316b4
BLAKE2b-256 2a4df3d42f0536f2f1667c19392ffb56a6a99aa68faf2034886db6bae5a66d04

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc947104152050-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 92e32c5728f1defc6020dccf3004503097fcac4454ed9e24d6640a2809049e03
MD5 5dc683844b75136252b005bf1d789f66
BLAKE2b-256 e580d42c9a3a41677c3bd8d726da420dd4a929f7395b055b6babf468011853e8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc947104152050-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 73370e14670c69522680fb89639e10705f25d450fb2e70916d021325a8290267
MD5 a8b20bf093b041fa347144fd2b008b0c
BLAKE2b-256 e637c40f0676d1e62287fb446e6e19fd675d0b77600a23d7bd5041e40edba8ac

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc947104152050-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ca095d27ece9858e7007f03b627bc29aa66814db41204cbde45137d361b91324
MD5 6061e659ebe1b88baf217d9cdfac5a89
BLAKE2b-256 94d85a26c0ae263ada953e70098804f86cd0aef0dce39f5a29ce7713a0c05e03

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc947104152050-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 c4482ab0308ba99e970807adfa648936aad1fd2f1c01773eefa351244b07c6d6
MD5 5044b1e255561208185a372d054f9abe
BLAKE2b-256 d53484fbc329a76f2fbd0781a08d86409bb62e743c47248f7fc4c59a97a70d81

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc947104152050-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 de1cff6c37d08038a8128f69e95839fecdc82403ec7232a94578d3bcfa9467fe
MD5 2d7570561c67a619c4e1a38adc15e2c0
BLAKE2b-256 60897f95092bd8c08dc1bef14d3571c9f7035898ec72ba5eeed6851750ce6a32

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc947104152050-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b8644095de7c8bf35da4767f9d450b3bc5b2100d59ea9fbe7a77b54476109f43
MD5 0fae86a877a92d1feff33f5303b8be13
BLAKE2b-256 cc3179ffea4ced6e360915109ef75f650676c0445c25edef81357a4b6c66266c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc947104152050-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 7112ad2844123ff0d79e5fa98d0ea7cd667e84a2be3e7a8d02949ddc2b58c76e
MD5 8b11017e701104126edf38aa721d9b8a
BLAKE2b-256 d0d504e2a0f8c4e1c8738714993aa669506b0e70b635dd2e66b07d8ee3337f88

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc947104152050-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6211dc3b7a3cd4c9f24b50fdb848f05f114e897895f06041538ec7c42e9dd0f3
MD5 bc5edd45931b04849a28b7d6e5f1cff8
BLAKE2b-256 3a3de27fead319d49bbf4ea213a04ec9f28d4124898fa90340bc4049d6a3c5e2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc947104152050-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 5a2183b0040f319586d3a081616c0de2726de93f11cea8270e305d608c0de33c
MD5 f9e9f7cba667e97834589797ea1c155d
BLAKE2b-256 2f750f8b92daf99cc7173d8e793710f6610f23d376926694dcf76c47bcd7ee1c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc947104152050-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 9094252b02af3d2123e9a79b63118847c9c2c1c796c3cde72ebbeba746983d01
MD5 5cbb2db499ad98c0babe9a91815c97fc
BLAKE2b-256 33c9126900efb9df3ca4f750a4cd661c715e40998b37dda42e0e1380a984ee71

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc947104152050-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e89d5ed07ec9c5dec21a8543a078ad496352260133f2094a4f818c79af052242
MD5 6c79c258348285426338c68f06d878dc
BLAKE2b-256 435d06ad9ca0b1d99fad9530e82ce956df2657bc937cc8a9071366d75d8e5a09

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc947104152050-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 f58234eb594a08aa0662d4cd6a1249d0ecf326ea7c4d4ef3b50108fa265e0a5e
MD5 51f001451aa46b6b40a335b0cf85a3ef
BLAKE2b-256 bae2663aedcf15736eae10f75a8ea9d176515cac2acda6f08ff5f284da786b65

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc947104152050-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a505ea6d2a08bbd9c2d9baf403fc93a246bb416061aeb7f69d24db4ebd784a49
MD5 0c9c30bc52c6864b09df25fef4d1ec97
BLAKE2b-256 dec120dd95b6bdc6772c469c5d60a614c8d9b8d802cf8828ccf71857a7195ba1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc947104152050-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 4a315e6342259fb3d1158ac38bb5009c9b09f3dd2b1f0504fd11c5814618a3f1
MD5 43cdb2e62cda1209780e26df44fa9acd
BLAKE2b-256 2f8344331826afbefbe789272d4f4bb4209594845369cdccf6cea74d205088ab

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