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

If you're not sure about the file name format, learn more about wheel file names.

power_grid_model-1.4.0rc950607194166-cp310-cp310-win_amd64.whl (399.6 kB view details)

Uploaded CPython 3.10Windows x86-64

power_grid_model-1.4.0rc950607194166-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (514.0 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

power_grid_model-1.4.0rc950607194166-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (495.3 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

power_grid_model-1.4.0rc950607194166-cp310-cp310-macosx_11_0_arm64.whl (412.1 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

power_grid_model-1.4.0rc950607194166-cp310-cp310-macosx_10_15_x86_64.whl (460.9 kB view details)

Uploaded CPython 3.10macOS 10.15+ x86-64

power_grid_model-1.4.0rc950607194166-cp39-cp39-win_amd64.whl (400.0 kB view details)

Uploaded CPython 3.9Windows x86-64

power_grid_model-1.4.0rc950607194166-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (514.1 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

power_grid_model-1.4.0rc950607194166-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (497.0 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ ARM64

power_grid_model-1.4.0rc950607194166-cp39-cp39-macosx_11_0_arm64.whl (412.0 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

power_grid_model-1.4.0rc950607194166-cp39-cp39-macosx_10_15_x86_64.whl (460.7 kB view details)

Uploaded CPython 3.9macOS 10.15+ x86-64

power_grid_model-1.4.0rc950607194166-cp38-cp38-win_amd64.whl (400.2 kB view details)

Uploaded CPython 3.8Windows x86-64

power_grid_model-1.4.0rc950607194166-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (514.6 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

power_grid_model-1.4.0rc950607194166-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (496.8 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ ARM64

power_grid_model-1.4.0rc950607194166-cp38-cp38-macosx_11_0_arm64.whl (412.1 kB view details)

Uploaded CPython 3.8macOS 11.0+ ARM64

power_grid_model-1.4.0rc950607194166-cp38-cp38-macosx_10_15_x86_64.whl (461.1 kB view details)

Uploaded CPython 3.8macOS 10.15+ x86-64

File details

Details for the file power_grid_model-1.4.0rc950607194166-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc950607194166-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 355ea00d9bd14cab7835564eac39bf881330faefdd11284df506f25eeb73705b
MD5 a4fe64f486bf1e415f920af5a3744573
BLAKE2b-256 7327f99f73e385ffb6061fb1b33227b0012dec3e8a5b79cfcadaac5c5adc2b12

See more details on using hashes here.

File details

Details for the file power_grid_model-1.4.0rc950607194166-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc950607194166-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 db180f61e077770809fa1f5db9191f9400e7fa403e2dfc46d4c07dafa7a52f7a
MD5 871ee463415326257af65a502400eedc
BLAKE2b-256 be2a22e2f03c11936025d171960c60389fc2745bb8f9fa3873a5fb08c7d9a581

See more details on using hashes here.

File details

Details for the file power_grid_model-1.4.0rc950607194166-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc950607194166-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 6f9e91292ab353a921e2a7eacd8deb07ab15be453947d0341cc031d7958ba97f
MD5 4c319f79f1478b7ff5d9d9e2d45af2bf
BLAKE2b-256 8682cded97fa5d89b0713c9fc519f5af81b2ff9b6af6bf1a89559e96a7bb231a

See more details on using hashes here.

File details

Details for the file power_grid_model-1.4.0rc950607194166-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc950607194166-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6e14c3719f80841c0795d4b37c67b030397fdb0b9034a6def06672b98db637d0
MD5 ebfc10f1232e740e3a7b03ab14087d2c
BLAKE2b-256 93385fda43540dd83f4c71bd21a411da0008ed75faea83c6a4a47d56525a9d12

See more details on using hashes here.

File details

Details for the file power_grid_model-1.4.0rc950607194166-cp310-cp310-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc950607194166-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 f928dc79eb8b2357c686723a9a8096a3a938e3e7cab621ac5cb4c71329289d00
MD5 60a6b4ad27b7149a95d9e13c0298c62c
BLAKE2b-256 f6e1d1c9445d7e3d7fb0577b202abc05d0e82073be62c8edd3ef4172a4fc18ca

See more details on using hashes here.

File details

Details for the file power_grid_model-1.4.0rc950607194166-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc950607194166-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 a58e1e669fe9d9eb3ef7ea05e460ad6012199342852dab168ea5456b25560321
MD5 9295441e6b0e4f9f6cb196548fe1e038
BLAKE2b-256 eb803859eb82e5cc57099f71f391b68e2ef8581d9a631b7f9e616bab7eed0e9a

See more details on using hashes here.

File details

Details for the file power_grid_model-1.4.0rc950607194166-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc950607194166-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a4f3c2816ae3d515aaafaab3cbd146076ecb35a9fe42817e960351d27951d4f2
MD5 be212c4b8435911619ba4c5ef2042da4
BLAKE2b-256 7b0b8890757c823e03dd7b196ff5a28efbf0e079c4956a4db26fbf127379db60

See more details on using hashes here.

File details

Details for the file power_grid_model-1.4.0rc950607194166-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc950607194166-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 dd225eb77065ff25effbe054310eeeeda9b11158ac4d047a660096071320babd
MD5 a7268e50cc967bf68486e509652e19bb
BLAKE2b-256 db2a234bc7bea8fc7867098ebe4e3071d88c47c70c4c28f3a122c3d969bf842c

See more details on using hashes here.

File details

Details for the file power_grid_model-1.4.0rc950607194166-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc950607194166-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 89ad63d6d760eda9af9660ddc7a318360e36607e033f01f599d7799eba1d71e4
MD5 10c6ae0731f2c27338f51fcf524d99b4
BLAKE2b-256 22e64b428a7b63c100a90db1412ada411b9e99cf20b095fce5ee0d4896384071

See more details on using hashes here.

File details

Details for the file power_grid_model-1.4.0rc950607194166-cp39-cp39-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc950607194166-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 3bed291d8891be910dd65fc61f9581a9b8e86db24e9f3674b582e49c21a734c0
MD5 3c41c48b263d3533b455c34ef046678b
BLAKE2b-256 660389a062080062dbed7cb15b802ce6aa6d98aeffb5c342240f5d67b73d54fd

See more details on using hashes here.

File details

Details for the file power_grid_model-1.4.0rc950607194166-cp38-cp38-win_amd64.whl.

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc950607194166-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 5a06e794227d654f37930203a4174bc667aa9e6d5058c321aa9ac4dacdecc2ab
MD5 676c81fb3f739d1c55dbbb281060b605
BLAKE2b-256 5011833c1e075f0c1ae75d0de35f80308322f96592d35c6ebe8b5859438d1330

See more details on using hashes here.

File details

Details for the file power_grid_model-1.4.0rc950607194166-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc950607194166-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5a4b0eff0ece1901407aaaddcdce2d51f675c0fe7fde041d99cad7fb55f4b66c
MD5 d537642cbe2d387a3ca2c63226339cc2
BLAKE2b-256 923bcc46f379af134c78263547f4684f62b7f2a180f25e038364e5eae478d9af

See more details on using hashes here.

File details

Details for the file power_grid_model-1.4.0rc950607194166-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc950607194166-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 139680a34f7cef627f9b46298a56a1805f704c0408db38d8221a5519546ef5dd
MD5 4c036d5eebf34473b57d68ace7e72cb7
BLAKE2b-256 bf378340314a696b187cb03f6ee2855783d3ea645d714d5b7c67a85670a87b17

See more details on using hashes here.

File details

Details for the file power_grid_model-1.4.0rc950607194166-cp38-cp38-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc950607194166-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8ca305fc28020d1e7c3cb6b298cc8cbe9ee8dcae705a573bcc02e71eb708eadb
MD5 8c63c78cd9926e5d8e33a0d129f257c0
BLAKE2b-256 04f540ed8781bfd8025b58ba100fff2d968e2a32843161f7b9894fe52ef21bc3

See more details on using hashes here.

File details

Details for the file power_grid_model-1.4.0rc950607194166-cp38-cp38-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for power_grid_model-1.4.0rc950607194166-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 5fec63bb040ee7853d1ab27ab6f5a86d5f982f9a72185df2fcafef9c71578a7f
MD5 79c731c035c8978e0a94671707240b36
BLAKE2b-256 50d876d625529121015314078e10dc5378b9caa50d017ab8829cd2a5779fb455

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page