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

Uploaded CPython 3.10 Windows x86-64

power_grid_model-1.3.238-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (518.0 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

power_grid_model-1.3.238-cp310-cp310-macosx_11_0_arm64.whl (389.1 kB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

power_grid_model-1.3.238-cp310-cp310-macosx_10_15_x86_64.whl (448.2 kB view details)

Uploaded CPython 3.10 macOS 10.15+ x86-64

power_grid_model-1.3.238-cp39-cp39-win_amd64.whl (385.5 kB view details)

Uploaded CPython 3.9 Windows x86-64

power_grid_model-1.3.238-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (517.7 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

power_grid_model-1.3.238-cp39-cp39-macosx_11_0_arm64.whl (388.6 kB view details)

Uploaded CPython 3.9 macOS 11.0+ ARM64

power_grid_model-1.3.238-cp39-cp39-macosx_10_15_x86_64.whl (447.8 kB view details)

Uploaded CPython 3.9 macOS 10.15+ x86-64

power_grid_model-1.3.238-cp38-cp38-win_amd64.whl (385.8 kB view details)

Uploaded CPython 3.8 Windows x86-64

power_grid_model-1.3.238-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (518.4 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

power_grid_model-1.3.238-cp38-cp38-macosx_11_0_arm64.whl (388.8 kB view details)

Uploaded CPython 3.8 macOS 11.0+ ARM64

power_grid_model-1.3.238-cp38-cp38-macosx_10_15_x86_64.whl (448.1 kB view details)

Uploaded CPython 3.8 macOS 10.15+ x86-64

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.238-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 b8fd087308603409fce296470aee1c0d11a9ce095cb3e803bd52290f634daad3
MD5 99dc5981bde4dc2b51ad97110103d894
BLAKE2b-256 d943fba5813f35167ef9c2520c35c9a8881853c919d538adc1f31ec63fcb3a21

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.238-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ee027b560c4257d1896a51fd92b453635d94659bc09d167291a766ba62513b49
MD5 5b111dcd4865453ad9e075576613e183
BLAKE2b-256 90f46a9451d6804d3b0b1885776f742afe0cc072d6ed3af6dac6387bcd6dbb74

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.238-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3454be58d040f7c844ccb6d4f3e6c52e04c5f80a7831abb746e3bc0b23c941ca
MD5 e6d010a1e770d36c8750c0c5aa37d004
BLAKE2b-256 e30326e70e7d59c3ba6d988b9fa09483bbf990a6e5497c74dc4af1d6286eddaa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.238-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 9485c2e6f3a731a1b4dd4ac34aa491ee6309a65b17935dbf2fc2c236a115e0fb
MD5 2016adf0ef3d8a2ba0d2e00a4b4798d3
BLAKE2b-256 109ba078da6c5873b394e017a92d013c020af8fb6ff7792f73dc7ff4a0358109

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.238-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 e2733081bc1402aa3d85da159cc2265fbe50400c862b34ce400baecd5e8590ca
MD5 fd3e7094e16501c42b814bb58958705d
BLAKE2b-256 d76c686c4acc5c56b39eef2cece2930b14596e8389f23e7c40f6995d66da1f98

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.238-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 822ff26b6fadda1b392619cd9fd631ed5e98ad1b437b019599b4bb0b349d56d3
MD5 f7edaf293fc1e622d409f508705fd488
BLAKE2b-256 167e8fce68af5e35c8539b0aca068710c017e3b5ab40a1610e28aad10dbed76a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.238-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cd5535442a3ea7ea29f15b8fb77088bddc04b1ba83ebfb35fa4fa7fa3133adef
MD5 05e9c1a3507ab6bbf3ae39e32898f64d
BLAKE2b-256 a8fffae62bdb1c85245837fc63a5c861f694277b6cd02889c170d00d5bf308d5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.238-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 213e1dad299874b7aff8f75a9dd63b964cb00745e3689a38455c28085280ba49
MD5 4ab7db737c497cd62167939d3521066a
BLAKE2b-256 9d507acedc693134e45af23fc117607734e6160a03e0ef445c0b3cb19dfef075

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.238-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 bfebf2a030e348a6babf462c224feaf1bde87b398adec78be51ea1055739e4b4
MD5 4dabd7a9db16c00654e05c87f400a67d
BLAKE2b-256 be4203a9fab8f041c001a89772d759ad726cf580ab1be5ffaee06c97138af390

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.238-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a9de17071f4700858b2dd14748fb5382ecfb16996a05626783514b19eacc7833
MD5 154a1ee598d80ffae2fdeb059ba62aaf
BLAKE2b-256 3062b0e8e24c655fcdf8d2caad9e023a51e4929a1ab7c2ddf593ae0d031441ac

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.238-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 33a84f360a6ec33ed09c6547a04f689e2119a93d59a58cad8bda9fab23d63aa9
MD5 3dc633bb6265e9953d1ea18fc5426754
BLAKE2b-256 ae2e94ed1ca9d5d192df413d27d4e6a1aacaaf334c8520beae871894ef4ad8f0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.238-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 f1a3d6b32b48eca448fa3057750565ada1688e830ed3ebeab87751c583ab766f
MD5 343f17c3704b79be63696c8a828534e8
BLAKE2b-256 3953e525c2093795d62fdabe34833ed473c76242130eea227c76ebde84efabae

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