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

Uploaded CPython 3.10 Windows x86-64

power_grid_model-1.3.258-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.258-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.258-cp310-cp310-macosx_11_0_arm64.whl (403.4 kB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

power_grid_model-1.3.258-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.258-cp39-cp39-win_amd64.whl (394.4 kB view details)

Uploaded CPython 3.9 Windows x86-64

power_grid_model-1.3.258-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.258-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.258-cp39-cp39-macosx_11_0_arm64.whl (403.3 kB view details)

Uploaded CPython 3.9 macOS 11.0+ ARM64

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

Uploaded CPython 3.8 Windows x86-64

power_grid_model-1.3.258-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.258-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.258-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.258-cp38-cp38-macosx_10_15_x86_64.whl (450.7 kB view details)

Uploaded CPython 3.8 macOS 10.15+ x86-64

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.258-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 61581784e67805ca65c32e43a4d950fa8f566d71b53c9b18f3d6c935ecdf77ef
MD5 94656eca00476a13102aa06e6ceb0cc7
BLAKE2b-256 c329f3d2b4e4e5ff0b204aca0851556a26d5adccce51cc451eef84824de33dcf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.258-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f57a94238b7c01b149ee85382788e61ad191ecaea7f290b04621b692c07fee62
MD5 f11b6ca1be8a7011c7f5db0c74600f29
BLAKE2b-256 d4090a26d263491c1f4b157d8776d6e631e0bdcdeaab80a6d0fcb30adef7f079

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.258-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 d8044608cea02c115c7927973b4248376db4483aa0629406001744a66859536f
MD5 5287227eaa6c858fd1e5726b3a555fe3
BLAKE2b-256 b1fa7d7f3504e33d10f210b394a6961251be869dc2389fb3c9f62456c53c6e21

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.258-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cdf6cf85fbad0219293d71dba63fc5cfe7b6bdebb5664beeff68e31c5633ad4c
MD5 750c3b65dad20d25d751d3be6438c2d7
BLAKE2b-256 6cbc56477ba774456067f1808661a6797b6c29b384ef901005b83d8e3589c16e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.258-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 4406f3c9857c56075a1b7441159f1a362311479ea3b57510f7c93f96faae2ec4
MD5 72c8894aa0aad4a1210f9d56bbfbcfb8
BLAKE2b-256 fe8a04db0d701a9c68eac044fa7b2109da1690d68f9ce9bea7433e828cb958b2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.258-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 0885b96afc4a0ea2f56d383f55f16c9ea171807c9985d5906b8b0eabbc458fa7
MD5 67cc13b88629c3629aada5269fb7f6ba
BLAKE2b-256 4c0d6789ed12fecc587b4b5ad130426f3d0299a55f1c18951abc705261196387

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.258-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 96664cdb02c05ce6705854b214d61ee400884eeba73068efb843c89c214ca2a1
MD5 3b153f75a893dab793a17fa906410dfc
BLAKE2b-256 3c18354a205cf20d2b3efb81aaf1c1460afab956496fcccc8171545801b08c0a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.258-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 d08856340724f4a6e4e7facd3425857ecb8eb7313b242b605ccf010c59f68432
MD5 0689e9d4f704465b5b61f48c1dbe8b53
BLAKE2b-256 87a5a70f120965cd49ab391e28d4f3c8dac4c601bda8b2ed9e08aa7c8f7057cd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.258-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a99e105cce354817b3c987eb1e2298431b348b14c79d5ff778658a010eed0754
MD5 2e620bedf5afe7cc778345fbd369d7fd
BLAKE2b-256 8e4d09ee981be82a48b8fae8affe923d8ecc6e7723eb986f6deb7c5136e8c028

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.258-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 741b40c8a00e669e0f60ac79ee0d6bedbc13bb06899092dafd62cc92fb0711f1
MD5 d090befea6ff552f2a19753bb5084f50
BLAKE2b-256 82e6df355e91c5f40536c567be2b4aa5a062fa39c7e5da3e19ce43b660e84e69

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.258-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 21a53f4a3137d45e0c3e486a19c1a2ec2f95cca787231cb3f927051f6f4eb6ac
MD5 286c140f7c169bd95bd49dbb88dd7a48
BLAKE2b-256 ada62642efbb361150b0786c262b1afaa9d2ef335d753e674fab867adae8d26a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.258-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b87b62d2e0e03caae2f1d6a9b754fb25a89c0dcd7eb2132033a985c3616a8c0d
MD5 e3a3cab2374d5bb1623f5c22852bafbb
BLAKE2b-256 d9e277a4f64782d806751ac9b6ef8b3d5d02fce5e43942644c75cfb7d6598094

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.258-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 a6911cc97d2507beb2daa761f2e63fe6121270ddf456d893b6d0a477a04deecf
MD5 063600bc4119990930d23ae45ed0cf49
BLAKE2b-256 2e68103a961e70bfa8718923919bc063fc278399f3773b9de9431e7072c947e4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.258-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6109b5615b61c077bd4c67d77566ca1267d5117d83e023b4ce386d08fed96ee7
MD5 cecb70ab4849c4f8be159775fd5b7041
BLAKE2b-256 43b0ae71d9f94ac30e0f6e28b060b77b40e154f6ad83972779388654bfaa0619

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.258-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 88198442b9b301304d41ce1d9d7fa60e59609e3bf868f081b3ef6956d0c9ea24
MD5 63a47154f34e53e0a3afb0db11119db6
BLAKE2b-256 dd2ca9d1a8d5d16cb9bf0c072c600510d51b465019e4ce70db5f701e7a260e06

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