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

Uploaded CPython 3.10 Windows x86-64

power_grid_model-1.3.257-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (504.4 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

power_grid_model-1.3.257-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (484.1 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

power_grid_model-1.3.257-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.257-cp310-cp310-macosx_10_15_x86_64.whl (450.3 kB view details)

Uploaded CPython 3.10 macOS 10.15+ x86-64

power_grid_model-1.3.257-cp39-cp39-win_amd64.whl (394.0 kB view details)

Uploaded CPython 3.9 Windows x86-64

power_grid_model-1.3.257-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.257-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (483.2 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

power_grid_model-1.3.257-cp39-cp39-macosx_11_0_arm64.whl (403.0 kB view details)

Uploaded CPython 3.9 macOS 11.0+ ARM64

power_grid_model-1.3.257-cp39-cp39-macosx_10_15_x86_64.whl (449.8 kB view details)

Uploaded CPython 3.9 macOS 10.15+ x86-64

power_grid_model-1.3.257-cp38-cp38-win_amd64.whl (394.3 kB view details)

Uploaded CPython 3.8 Windows x86-64

power_grid_model-1.3.257-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (504.8 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

power_grid_model-1.3.257-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (483.9 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARM64

power_grid_model-1.3.257-cp38-cp38-macosx_11_0_arm64.whl (403.1 kB view details)

Uploaded CPython 3.8 macOS 11.0+ ARM64

power_grid_model-1.3.257-cp38-cp38-macosx_10_15_x86_64.whl (450.1 kB view details)

Uploaded CPython 3.8 macOS 10.15+ x86-64

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.257-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 3805537c7a7946343024aac3eddfd744cddc28b32dc49c2929cf7edfb6d12792
MD5 20c751b830cc1b62c1db600bc2db5db6
BLAKE2b-256 393f9a7bc7532a5e69b3af214e2467bf6e14f4982b324d72d226451bec9f56eb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.257-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a82987003ba8cfdc86d9b5517f85d76e66667140f72b937113a8e87e1384ae8d
MD5 13f55efadb6907f36c7757e2b9ceb7c5
BLAKE2b-256 fc3380dfe66a60fb6be556762fd63873aad7b6d68698cfc689b1fa50b4ca9117

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.257-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 224689d5b5d7683691d50de82ee39d9f8e33e43c32b98750ffed45021fe538f8
MD5 fc5b3ebbc7beaaadc0f85cc3e7959407
BLAKE2b-256 550d9eaa06e893f52e079a47c52815e9adc02747b16f36fd4c8ea6b5e9843bec

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.257-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 18a6bf292ae0e5e64bf3a85b5315ffcc170312f08446a3c39d43745b0ce4ed04
MD5 ff06a541175b452d51c29f2dfddb835b
BLAKE2b-256 a979e094a8ec671bd6c5ceb0c9a034d06a0b31eb176fecdca7b016f360103c4c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.257-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 ce0b572cb7713d4274f17f45d97a9a964608ece162b6c4965da01451c57a7190
MD5 2086df6689d5204c55ffe530b9d8958a
BLAKE2b-256 5e11be9f1b0b78d4199b39eccd608ed85efe70da7066ff313895937bf8f86447

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.257-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 e60ddccc190e154bd188da06ee1fb458501e1785f2f4e2fcbd0eaaf2693a4154
MD5 1aeaf2be14cecfdfad0245e1a8aaa65a
BLAKE2b-256 aaf1818e73c7c7d0781084ab061c6186a1af1867c78c0c430e544a018bbdaa4d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.257-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fd0c255afb2ea02496a9f8f8351f8914f6b0ac0dd7fd2682d3dfa3325f2a797d
MD5 7679f58d691f931a6ebbca671541e07d
BLAKE2b-256 e7fe39e6acc169f8272a098ec1a500fc5c8f5e02b42060da9c0932c87b4e8f80

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.257-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 6748f4fdbb45394b466f0cb71f927bcad35cdc43d5b3e52437a87735a1997d23
MD5 b01bcb77d83a24efaaa2e92dd03d7c93
BLAKE2b-256 21ea9c2526109645cf4a6ee55314638afa5e286cf769bfb6528f74f7847a7c05

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.257-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 533e705de0114c92ee3971db58ba599933875ffab1d3c48978494452f8e91f5a
MD5 34c42b2ae951a09ae0daf27f446b1408
BLAKE2b-256 bc975995c901886074fe6460593fc1033ae9c086708cc432771931a663c2fe01

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.257-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 586aba271b117d2cdb166fabe0690b828a82ff252cd27002ac66951d5a8323f9
MD5 3c53152a8471ac31bda16682daaddbb6
BLAKE2b-256 07f2715193a20d0c290df1b097e7f27d426ef396b9540593366fab5d12dd7dba

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.257-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 f9110f983ee02bd6515ea94c1879de3dd4ee88465c950a7757f0560e7da9a6b5
MD5 ed26209561811685d29cf348f55cf065
BLAKE2b-256 7cea6ab28dc309fa79206ea1589e2071d77bc83da63d7c4227aac959b851ab0a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.257-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 110df4dfb6104435c2dd1ccab63b96da2ac3534469bd5cf5acae70a89c112eb0
MD5 576eee6ce5e507fa8c1bd9a0c4426b42
BLAKE2b-256 9f0c2201033ccdc2d7f765bc1372767daa146fcc627fd6937eb23b49035a4d25

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.257-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 b23b84f8507f652275556f829934ac9805d49086239eb901c1ff136a2e934fb9
MD5 6f14204dad986f91f60c26ae916eec5d
BLAKE2b-256 274f5806063eb6e9dee9e7b576f4361172e08e845f0ad8e13830407a906496fc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.257-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d397dbbe709a9b7b67ec68820a88ac3ace7bf68dec0175e2332c5c5ae2eeb9f5
MD5 6ef90332a59f9c4de4cb6fd8f3aebdd3
BLAKE2b-256 3e404d5e17bad2a6d88c24b7dfe71380f24dc26825c64badf8ae1ab168b10218

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.257-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 d9db270610edca2f862768b2aded3b113a93b9717f7de072564c96e3cbafba71
MD5 f45af43c466990410c514ca81918f10e
BLAKE2b-256 52633dccab53c209001be84d6a04cef183e37f60127a4fdd23c428979ab5c20e

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