Skip to main content

Python/C++ library for distribution power system analysis

Project description

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, 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.114-cp310-cp310-win_amd64.whl (392.1 kB view details)

Uploaded CPython 3.10 Windows x86-64

power_grid_model-1.3.114-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (527.4 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

power_grid_model-1.3.114-cp310-cp310-macosx_11_0_arm64.whl (388.8 kB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

power_grid_model-1.3.114-cp310-cp310-macosx_10_15_x86_64.whl (447.4 kB view details)

Uploaded CPython 3.10 macOS 10.15+ x86-64

power_grid_model-1.3.114-cp39-cp39-win_amd64.whl (391.8 kB view details)

Uploaded CPython 3.9 Windows x86-64

power_grid_model-1.3.114-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (527.1 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

power_grid_model-1.3.114-cp39-cp39-macosx_11_0_arm64.whl (388.3 kB view details)

Uploaded CPython 3.9 macOS 11.0+ ARM64

power_grid_model-1.3.114-cp39-cp39-macosx_10_15_x86_64.whl (447.0 kB view details)

Uploaded CPython 3.9 macOS 10.15+ x86-64

power_grid_model-1.3.114-cp38-cp38-win_amd64.whl (392.9 kB view details)

Uploaded CPython 3.8 Windows x86-64

power_grid_model-1.3.114-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (527.7 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

power_grid_model-1.3.114-cp38-cp38-macosx_11_0_arm64.whl (388.5 kB view details)

Uploaded CPython 3.8 macOS 11.0+ ARM64

power_grid_model-1.3.114-cp38-cp38-macosx_10_15_x86_64.whl (447.3 kB view details)

Uploaded CPython 3.8 macOS 10.15+ x86-64

File details

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

File metadata

  • Download URL: power_grid_model-1.3.114-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 392.1 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for power_grid_model-1.3.114-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 b6de4308ac984fd54fc13f3b27f017c7ea06a230dd3715a3875753d212a5d943
MD5 3b5ea1588c2a34541b6398ca21e2e070
BLAKE2b-256 b07d53c5b3d42d48b06a0009697249f44a9d306380a89a2f583a707db3b13240

See more details on using hashes here.

File details

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

File metadata

  • Download URL: power_grid_model-1.3.114-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 527.4 kB
  • Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for power_grid_model-1.3.114-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8055922096e1951eecdd607a32ecadfcaa7188568337f253adabfed9982dd027
MD5 d0bf9387be3d29e9913f279d76d7d405
BLAKE2b-256 158c4628a91d41ce5f46e8fd284658c30ef6a3cdab8a889ce22d3730a4db32ff

See more details on using hashes here.

File details

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

File metadata

  • Download URL: power_grid_model-1.3.114-cp310-cp310-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 388.8 kB
  • Tags: CPython 3.10, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for power_grid_model-1.3.114-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b1729de2ddd0e208772b8ad693368c74d1943dc36358648d1f98b8756e3e17b0
MD5 ef0299928a31c0aa53eba483ffc82032
BLAKE2b-256 a68df030e0782828630b71087b0d00a56e6e5cbf8a4014afda923f243366ccbe

See more details on using hashes here.

File details

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

File metadata

  • Download URL: power_grid_model-1.3.114-cp310-cp310-macosx_10_15_x86_64.whl
  • Upload date:
  • Size: 447.4 kB
  • Tags: CPython 3.10, macOS 10.15+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for power_grid_model-1.3.114-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 19beb3ea2263a83d4c73174aa2d0345a6835394dd9b2849b547377416ec96a51
MD5 d2d928d33bebee7885c9836de236ac83
BLAKE2b-256 51539f01db02e7eafe0160a633208098e28b5d0da10869bee8a646940403df14

See more details on using hashes here.

File details

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

File metadata

  • Download URL: power_grid_model-1.3.114-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 391.8 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for power_grid_model-1.3.114-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 476a7c1cd9fb5f5a50ff174e6ace8b6c423a7d163a3da624e2ff51281c44d69e
MD5 a37e95c698a882974b479d3f9113be95
BLAKE2b-256 f062672889f37b25cf01a6e0ffb200d7e9dfdaad6b6f74dbffb1a87d320a23fe

See more details on using hashes here.

File details

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

File metadata

  • Download URL: power_grid_model-1.3.114-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 527.1 kB
  • Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for power_grid_model-1.3.114-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4443baac14de2529f9f803439e42cdb314c1cb97d004daae1b0afdacd6cbcfe6
MD5 ea172dfcdf7e7568629194d9fbc3639c
BLAKE2b-256 95571c5240e8af241649f2b61c0773df997c558db33968f77fbb75e2c5c4916d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: power_grid_model-1.3.114-cp39-cp39-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 388.3 kB
  • Tags: CPython 3.9, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for power_grid_model-1.3.114-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b0d421bb0d9ae19428f00518c3176e131746cb1808050977631fabd18f08c342
MD5 ecbb41ec986021d846bdf7cb9eb07a46
BLAKE2b-256 14a7538eadaf87ff98a824dd1b0db07dc23a51dbe3dce42a225671869a526d3e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: power_grid_model-1.3.114-cp39-cp39-macosx_10_15_x86_64.whl
  • Upload date:
  • Size: 447.0 kB
  • Tags: CPython 3.9, macOS 10.15+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for power_grid_model-1.3.114-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 020a552b8e5d4249940450c1186dc1180ca28bf9ab4c195290b98d18463e5065
MD5 00f962257fff6febbc0f2dc9d418c843
BLAKE2b-256 c3e1257aff31d48400e6903d539014168783b22e142dbf37c803b812d856db20

See more details on using hashes here.

File details

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

File metadata

  • Download URL: power_grid_model-1.3.114-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 392.9 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for power_grid_model-1.3.114-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 3daf5131929d2c91481a4aad7e8d4e9e15918271f07c37a7a1ab2f8bf42f3726
MD5 ee682e7bccaba9d0b7a7ae734961393c
BLAKE2b-256 e92f8fad5f10dea5ac55ffea23cc4be31df7499a8b615f257bc2a6dcf0f8fa28

See more details on using hashes here.

File details

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

File metadata

  • Download URL: power_grid_model-1.3.114-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 527.7 kB
  • Tags: CPython 3.8, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for power_grid_model-1.3.114-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b4148075be9cd82306af9806bed867f81c374cc132a4035e958525d47e6ab1d6
MD5 f57cac872f00659edabe7a6f5a6955d8
BLAKE2b-256 cc0ae6c0759b3b02c992c53a9997cf717266806f49a7633913673d6f6e549e73

See more details on using hashes here.

File details

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

File metadata

  • Download URL: power_grid_model-1.3.114-cp38-cp38-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 388.5 kB
  • Tags: CPython 3.8, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for power_grid_model-1.3.114-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 abea11024710fcd7c546d342968f91fea39256a1667f719cce11d953a208c696
MD5 d6958d930e2f62eb8faf9e8d67c0149f
BLAKE2b-256 47a305f63cd72551bae8fa66fe7078ab40dd9ce5b691f5c3c72e099422e80960

See more details on using hashes here.

File details

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

File metadata

  • Download URL: power_grid_model-1.3.114-cp38-cp38-macosx_10_15_x86_64.whl
  • Upload date:
  • Size: 447.3 kB
  • Tags: CPython 3.8, macOS 10.15+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for power_grid_model-1.3.114-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 480966ef4d5b558cabbba98d7db9b3b75509b4ecb74cf3b29348e5d7530f3528
MD5 a82e194696f2aabec8a11a2bfde53af4
BLAKE2b-256 189e253e0aa673cf7898bd646b6839cd110cf62c15a6d475abe3239de2aeb372

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