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

Uploaded CPython 3.10Windows x86-64

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

Uploaded CPython 3.10macOS 11.0+ ARM64

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

Uploaded CPython 3.9Windows x86-64

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

Uploaded CPython 3.9macOS 11.0+ ARM64

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

Uploaded CPython 3.8Windows x86-64

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

Uploaded CPython 3.8macOS 11.0+ ARM64

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

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc950303905514-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 74d13786335cb10863adc4c3c2f7c9a6ebcafcfccd21e91d3c9b478119267b9b
MD5 dabfeed7758282ed3a2355f174258a15
BLAKE2b-256 6642fb6e96123e8c248506183366e5a892e82dfd3e97234a8d9b51558ae8020d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc950303905514-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 abc5f4936663875a7134a31609e7fbb2d43edd8583b9bbe4dc93da150f896453
MD5 0c9eb1ed5e07c2f5c415e808410859e6
BLAKE2b-256 1f13565a730a0d48f3a2fbf95011b4f64df52feacaf49b89457e1f4d1d0a21e5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc950303905514-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 84261ebaa0d79a4405c8746fce8d21cd28008ea7f7237d8324c86a192261236c
MD5 d812e3cdb2e4e58f3ef533f6fb402e19
BLAKE2b-256 1cf9efd4de8f320a514d9d38d2908cae79c327b0e2173d6fe3322924e3db1ecf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc950303905514-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ebf8f6dc344b63e5d5b1bad1a5ebda2c2e414c71c33256385b3264a2d657245f
MD5 82e981882d235afe0927d75b6dd2dd1a
BLAKE2b-256 0235799058348f302a0f8e66d8d7019f1603ba729aea0d1ec97243e0b38872d6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc950303905514-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 b055015206b73e9eeb07fe8c4da9d1f062e30eb279bdc6d689966aa2d9f545e3
MD5 a8332b3ec6242915fca3c7136b9a4693
BLAKE2b-256 46bd3b15c990f8f7ffebd58b5692337ba425e3aaa6c0676dc485156a590a10eb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc950303905514-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 ab1d72c562919508da3230c405652e9200ad9b3234cb65cfcce8017589279f8a
MD5 31ef3250bb0379f19015d6a66822dc43
BLAKE2b-256 3cda70251c845f2dfadca6e819599c953c3a19a1bb0908c268543060ee9ec231

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc950303905514-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 78c211e2c0387187478fd3701792ce8309a14cfc593a2f9789d65c4d6185642b
MD5 ff1783be9f54caded4e1441bc49f9722
BLAKE2b-256 468d17d24e1f0d2a850c52813cfffa372809af805cc2c1dedb6b331d1d6b34ce

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc950303905514-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 541e3e3d8be6fcded9f4a4ba8d242b77f693813f82df88367f98d839c41190dc
MD5 8054cfdd4346ead26f21b3f61e96e384
BLAKE2b-256 adbdb6160ee168d39b23e25b37a418ed78dee1a7f1733e4f6024af5b8670090a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc950303905514-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 926185278bd1342afa9733def8099db0b10da5f83a9e499067316c10c9a9c15f
MD5 6fdb5db1d85a680181916b8014040193
BLAKE2b-256 e87062d8cc199b884d2d74c8bad39f998806ffa1c49da3b68de92970d9244c9a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc950303905514-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 565ad543dc2ef161e6dc397ad8beea36a03c9c698427fa0a52489e0dd6bea6c1
MD5 5721077260bf2652765c6e2bbff81604
BLAKE2b-256 89c89e5098669f11d56aff1c096e6d4b4f8ad4055388b9d80024a5abf92edd9c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc950303905514-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 38850e1d0dc16f67c3a8bfd95f6084c7d8743475a6889e3487b2dcc9ac5d860d
MD5 940e48a1a306e4a6b325727869d10043
BLAKE2b-256 e314814ce2e4fe286f691cbb03cfbfb211afc4fd81eae7d2aee7ba83a21dfe27

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc950303905514-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7b03d9bbf74f035472c67ee26d03fbe6dc03388a21126f7656f9c0d57ec145cb
MD5 0ab56475063313c7017965a06f6315da
BLAKE2b-256 b1cccdfecff6f33be21455f78b7935c433f2c7c0f72f009aebabc02ac3756885

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc950303905514-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 3035fbba21139ce9f67ff5427aa47061e47d286eb6ab3952b232f91b83b99ca3
MD5 7102768b9d2db0a64f8e2f482b5cd082
BLAKE2b-256 86057569aa951ae7832f83ba054c860c3334bf92ce43c7fc733476f05c2f10e9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc950303905514-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e8198a1bbc899dfa63e3ea3d119481060043dbcc42cc9a93d5b1934f08f132f2
MD5 fe6f6c740dcfce6b67435238c690d88b
BLAKE2b-256 efa4f4be06a751d1e54f7a9e699d1f7cb50897aaaa37ad50c141f998cfafe29b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc950303905514-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 35e685f32f133e5c960073fd3358ff73e9372cc9b62e80a0eab0808e606e1427
MD5 9be36d0698bfa5f6d149bc5e173c8498
BLAKE2b-256 0a9fa535a335e81b9869cc5ae6bca84b6e01fc757a5c16dff1288f7ba00be813

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