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

Uploaded CPython 3.10 Windows x86-64

power_grid_model-1.3.245-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (523.7 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

power_grid_model-1.3.245-cp310-cp310-macosx_11_0_arm64.whl (380.4 kB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

power_grid_model-1.3.245-cp310-cp310-macosx_10_15_x86_64.whl (426.2 kB view details)

Uploaded CPython 3.10 macOS 10.15+ x86-64

power_grid_model-1.3.245-cp39-cp39-win_amd64.whl (394.6 kB view details)

Uploaded CPython 3.9 Windows x86-64

power_grid_model-1.3.245-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (523.6 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

power_grid_model-1.3.245-cp39-cp39-macosx_11_0_arm64.whl (380.0 kB view details)

Uploaded CPython 3.9 macOS 11.0+ ARM64

power_grid_model-1.3.245-cp39-cp39-macosx_10_15_x86_64.whl (425.9 kB view details)

Uploaded CPython 3.9 macOS 10.15+ x86-64

power_grid_model-1.3.245-cp38-cp38-win_amd64.whl (394.9 kB view details)

Uploaded CPython 3.8 Windows x86-64

power_grid_model-1.3.245-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (524.6 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

power_grid_model-1.3.245-cp38-cp38-macosx_11_0_arm64.whl (379.9 kB view details)

Uploaded CPython 3.8 macOS 11.0+ ARM64

power_grid_model-1.3.245-cp38-cp38-macosx_10_15_x86_64.whl (426.2 kB view details)

Uploaded CPython 3.8 macOS 10.15+ x86-64

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.245-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 0c47b91a7a2d7e3daa8e15d4cd6d8d0eb90d21c5410583d38a5d21584041cbd3
MD5 81020692db58bcbd122d7b9ebf763f01
BLAKE2b-256 e11a5e2be32e3e528f47aa995e4118e20c80cbcf59a4d3634440a386fc858d60

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.245-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9afb991c7db3e4792b01c4190348a01ee1e51753257613f5cb451738be4e28ed
MD5 abb7938ba978ce9e07d81333e8ae8167
BLAKE2b-256 d485d705fa4b87278b20c824f373886074367e3f604c0159c1152314a7f349c4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.245-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 644254505304917688c3d89a951fe4be2ade2e11427c9f8acd497352ce08ae38
MD5 11b5089f7a4b03084f40ae8438fcb09a
BLAKE2b-256 b9565518785f42104b697a459d5a861f459baa1b0ffeeca7f9e1f8a63d277702

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.245-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 d604023d887c1768e085012438690f823dd214217335e91d63f75abd15dbf868
MD5 ed92ec2fdc97c890d662c96a4bea77ae
BLAKE2b-256 11b6189f7c5e01568d8e8806d5bc3a9fd2ef602ea14d112e34852ddcf3937cae

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.245-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 9c8e7f5c54a3b508547edee98f5e45428d6ffbffc22e26a02a28d9fbc1d988e2
MD5 5a619cf4fa193dd8f40c36f07963f9a9
BLAKE2b-256 07e8bb05767346a0ce20e80301e3537e5363c4f933a014cbedfad11966f21055

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.245-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b435c2bfdcc2a8b09a533b15bab56905c710284a4fce8b1a835e0059cd4842b2
MD5 deca949654321b7d2343d3e9ea0bee59
BLAKE2b-256 aba6dcd2a3e366432b2166d680cd32f8090ecdbacb0bda48c6f35638081fc598

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.245-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b517af80c89c342d74d774a68b605d72f4d10f3c6507912ae188cf970f9d8a0d
MD5 17bb334e424899f37c3bfd8c53f5b52e
BLAKE2b-256 3ab135793186218e8b1ea68e51bef2f4563845430fc324a7c30738493ac7369a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.245-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 8f0c6bcfbc56883c6b9a9227c89d55ed55981fded2897906ae560cf5f403446b
MD5 00bdabe1c9e0d83c34baa3f54453a232
BLAKE2b-256 cb5a757144fadd34162cbba27e53137b457a4b98be0674bd99e0b5ce4d2c2fd4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.245-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 5f7af5e6c3d65b73451a125e74f6079a247c193a8bf25572ea8d2fd2856f068c
MD5 c607532119412f556efda9fc7c2180bc
BLAKE2b-256 3fbd5a946555a8252e57d21bae81c5418f411daa40f3ec4e7040e6d42ad455e9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.245-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4e754c44f64f5c87e77a74c50a34f6f4f283eb464dc626d37efe50c201259a97
MD5 9d2992630f364342639f63cd4caf0dfe
BLAKE2b-256 4d3577efa74a295d095294d3df7dc7e16802fec9061813ab709d3a0801a53fc6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.245-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b8b33de9162cb4b12249f10f0f81a0d852cc9459d4e2aef16c5575b9839f4232
MD5 5b443a5cc0e59a4f37e78f84ed67756a
BLAKE2b-256 d880ab1e38ad53bf226eb880d4c355184fd1fa962e92b730d1a4f4f023d74f51

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.245-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 5492506fa232eaa7b7e48879c041b15287bf9c1f0df5a93c5e1894db20e96bfb
MD5 0922d0fd6883b0ef682c53b31835c595
BLAKE2b-256 43ac2489ada9970b834e6a03d7c226c2b23f2e074323046e6c70c0f291d225ec

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