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

Uploaded CPython 3.10 Windows x86-64

power_grid_model-1.3.260-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.260-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.260-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.260-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.260-cp39-cp39-win_amd64.whl (394.3 kB view details)

Uploaded CPython 3.9 Windows x86-64

power_grid_model-1.3.260-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.260-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.260-cp39-cp39-macosx_11_0_arm64.whl (403.2 kB view details)

Uploaded CPython 3.9 macOS 11.0+ ARM64

power_grid_model-1.3.260-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.260-cp38-cp38-win_amd64.whl (394.4 kB view details)

Uploaded CPython 3.8 Windows x86-64

power_grid_model-1.3.260-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.260-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.260-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.260-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.260-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for power_grid_model-1.3.260-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 4e5cb2cb04972c751c2f235b861bda38aa242bb62d72a19de325a8fcf6046a92
MD5 3ca17c2e61a5aa9d3e79983e51d243d9
BLAKE2b-256 54bf5ff898e0c63b311d97786fdce72f3fe0d1b47150aaeae01c489bf98782fd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.260-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9a8237a62456192fb398ee8e93077dddbc9d7ab18a2fad9090856ec0c9edbb18
MD5 280d52fcd2274d93e6c582c141a2444b
BLAKE2b-256 42b00d392cad1ff0f5475a4c57a30029e8df1839581eb26253439722bb3ea614

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.260-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 d73e6fc28f554fdf859f700f8b51b0415f7451226f0ebe0fb626eec093b053e8
MD5 0e3fa06c429227635bef689a1630df93
BLAKE2b-256 2973d60ccd7f3c2a91eb751be2d69584548cf19cfa4aca2ddbd1e4f9e85f701e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.260-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2b08766dfbcc66199b89ba6776cacbe420844520d2413b2756d0fd1d46bcbc38
MD5 9cd95ad30d78db6fa5aa2d9edd6ff61a
BLAKE2b-256 100fc3601374151e7279733db6cce92ab391ec6ef4b4e2253a1c2edaa583c5ac

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.260-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 129fdbf15ff4d96dd908a07f713a038f0f643247905cd757f986a830abc22c52
MD5 3136c814782da648b3b8202035f05cf8
BLAKE2b-256 69462c370dbaa3ac208c33053ca37976ffe06878a1de76d8f38ee98be8da7d3b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.260-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 7a8946dce82caf7ce0cd34f17ec7f20c88198ad913a9bb7cbb7c67c6009f9e7c
MD5 b9b5f9119c6085ad2b2e1809fd94c29a
BLAKE2b-256 2165a125342f0a0067daf3bc1dc7c0a1a18ad88d53330ac28a7ed19783190dd2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.260-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 81636374f21547f6bb4dd2909011d74deaa88e77d8012f3aa7f4eb6ad6da5abb
MD5 705699ca4f5f1a6a035a3dbebc95d2b5
BLAKE2b-256 1ec96957bf925cf39b416fb74e973ee8cc0443f82400f6018a2d66ea5c8b6225

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.260-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 430f9a417c5356f7d3aa4d24100a81aaa3e497ce79e973aea6d06575cd0ec056
MD5 8d7ad755ef8ca812b15649aeccea95f1
BLAKE2b-256 6d2d851e526fba7d37775f7249fa39fcd57a0f7f8518ce3e641fc08ff884fc89

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.260-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3f46bf7b1bbdad77062e9e87bf1b256d4842e1061fbf33b6ff2d09e708381b93
MD5 25bbf1b7f5b964308965710a56a70d42
BLAKE2b-256 45d14cf6b270193ff4f34b285376ad80467d52de7e8d282a91bb67dbdbcd58c2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.260-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 6ad4058ab078f1acfdd8698c78cef29a6ad48b3ab7ce8c64ee7eb5df465df0a2
MD5 788d5e6e3d298bb3db5698e459568f25
BLAKE2b-256 5238f45f85ac5c0842859ce67a7c18b5b3353a5f853346efb2857807e8dd20aa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.260-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 ca4c812e5ffde1527164b6bd57fe58d400175642ae03aac400799ab435101167
MD5 8808db103dfc91b00df24b7877f93b0a
BLAKE2b-256 b7e4ac81dbdbed564d9ad8b75a6bac223b32eb65bfce200bbcdf7e02834f26d4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.260-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 dbff7bd9207a7ed8f8dbfdbe02c30af766cc6328b35e27f6c8b26408426594fb
MD5 5dd90852e5719cdc67f05deab46a3b02
BLAKE2b-256 5698ee6f26bd1ca87f9703a0a0ee7e8f91eb81511435b53d6f61020660202d21

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.260-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 7759e402c6f822896795f437771305618fc822d2ecdf44ca8833294224df4a94
MD5 ce51f879a5b4e018ec4dbd939dba9d51
BLAKE2b-256 fc77ed10eccc5016201274a682401ba031d92ec1e195aca91a4dcd8708c8fd55

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.260-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 18389f3548b659e2a225de2f5f7e60a602ec9cbeb4a72247d7fadde1b683f47f
MD5 7fe0c97441fac8d2bb0ff08e03b25867
BLAKE2b-256 164f646317bcb71d3a19f10acb85ef484ed7721e3bcccaae5afb5a79e8fca00a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.260-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 5683421832dd76f945f5c0fe098555c004625aead497b4dbcbefa508009e8148
MD5 ef0f60e15a64e163b446e633c057af9e
BLAKE2b-256 30bec3f1d15565e41c74f3f1d60a18c439f3df72ad06b9da747271caf62eb5ea

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