Skip to main content

Power Grid Model in C++

Project description

Build and Test C++ and Python Format Code REUSE Compliance Check

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.

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

Uploaded CPython 3.10 Windows x86-64

power_grid_model-1.3.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (550.6 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

power_grid_model-1.3.3-cp310-cp310-macosx_10_15_x86_64.whl (461.4 kB view details)

Uploaded CPython 3.10 macOS 10.15+ x86-64

power_grid_model-1.3.3-cp39-cp39-win_amd64.whl (406.8 kB view details)

Uploaded CPython 3.9 Windows x86-64

power_grid_model-1.3.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (550.6 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

power_grid_model-1.3.3-cp39-cp39-macosx_10_15_x86_64.whl (461.4 kB view details)

Uploaded CPython 3.9 macOS 10.15+ x86-64

power_grid_model-1.3.3-cp38-cp38-win_amd64.whl (406.9 kB view details)

Uploaded CPython 3.8 Windows x86-64

power_grid_model-1.3.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (550.5 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

power_grid_model-1.3.3-cp38-cp38-macosx_10_14_x86_64.whl (461.2 kB view details)

Uploaded CPython 3.8 macOS 10.14+ x86-64

File details

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

File metadata

  • Download URL: power_grid_model-1.3.3-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 406.9 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.2

File hashes

Hashes for power_grid_model-1.3.3-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 27fc66f86eaf2d978d204d2208c300eca2e17d89b536f4fefb759233f8d0f21c
MD5 837c8987c3e3fdb5a8b02325a664a622
BLAKE2b-256 98c79e1a1bdbb3fdcdc18a930017cd8f4b48b5533abb1a18f1919bc7009323fd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 98d746dadb4b8399dc61af89b74821acf63ef589dff7c74eb582962e9ffbf694
MD5 2813c28aa9cc8d64aaf26eed2c01aa0d
BLAKE2b-256 26c62c746b6dfb5986876927499b4054ebf5b433f533d42936adc3b67309f6e3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: power_grid_model-1.3.3-cp310-cp310-macosx_10_15_x86_64.whl
  • Upload date:
  • Size: 461.4 kB
  • Tags: CPython 3.10, macOS 10.15+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.2

File hashes

Hashes for power_grid_model-1.3.3-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 2a5cfad101aec831264548f60e538ad93196d0887a8e453b92f5b6485769420d
MD5 616e6e1dbe2e5966271c091e699082ac
BLAKE2b-256 f59067de4553da2fa693e136e21049ef6dc2a5e82bd26faa45cc0f4f0dedb2a9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: power_grid_model-1.3.3-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 406.8 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for power_grid_model-1.3.3-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 e9ba44dc3c2ec954ad6797fb92518d0120dab6608c56dbb3887dd0809f1f58e7
MD5 07b90319779befa1e688ad61a9524bac
BLAKE2b-256 df452011b5460dc3b65e3c54a1e2350a0fd98d637beb54f7c3f5d7080b5ef7c2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2526b40ee2920a54395325dee73289454cdbb54265303376542a149a6b898038
MD5 2fa4e02570bc53dd3ae800033d76a74a
BLAKE2b-256 72be66e08aa6f74002cb6cb3bf994319379793167d600e29dc50dd30cb08884b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: power_grid_model-1.3.3-cp39-cp39-macosx_10_15_x86_64.whl
  • Upload date:
  • Size: 461.4 kB
  • Tags: CPython 3.9, macOS 10.15+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.10

File hashes

Hashes for power_grid_model-1.3.3-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 1ffce7bd15e6d54b9e7611b73b068f28ed303f1291b031a11312c646dab01120
MD5 c750a1b8672c8a0aeb10d6d918aa4f36
BLAKE2b-256 108554f930f77a8e39707f36ecf41d42fc81892e380b807e814ae52b825ea794

See more details on using hashes here.

File details

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

File metadata

  • Download URL: power_grid_model-1.3.3-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 406.9 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for power_grid_model-1.3.3-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 21182f0c4716d36d54b23b093e5210dd61e2f92e07d675e458de23ec0ad41a49
MD5 7122ff31c49103876720ed6b104ef168
BLAKE2b-256 eb66d8184ca39c7090e64841c36ab5b2df020b25307a2037fd38fdaf956aed56

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e55c3f79c29cedacd74500c9af3527a5047b00ea99485aa6771f3a9f65cb2d48
MD5 b6b1feab63c28833b5a7d9031b4c2e6e
BLAKE2b-256 a258cd982e4855b16c0180a553bf4b7d50a73a81193cadbf562edf44f4b56d11

See more details on using hashes here.

File details

Details for the file power_grid_model-1.3.3-cp38-cp38-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: power_grid_model-1.3.3-cp38-cp38-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 461.2 kB
  • Tags: CPython 3.8, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for power_grid_model-1.3.3-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 c6c9207ae5ed2095fc352a177c5d42dc1213eb2ed821331885453e65ef6b4c67
MD5 cb0c00e20c3cd1e476538f2ae7bdebf3
BLAKE2b-256 1b95665b692b3d2ce27bd1e105f2b81a0fea90d67d3cef45ce4b78563b4647d3

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