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

Uploaded CPython 3.10 Windows x86-64

power_grid_model-1.3.266-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.266-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.266-cp310-cp310-macosx_11_0_arm64.whl (403.3 kB view details)

Uploaded CPython 3.10 macOS 11.0+ ARM64

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

Uploaded CPython 3.9 Windows x86-64

power_grid_model-1.3.266-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.266-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.266-cp39-cp39-macosx_11_0_arm64.whl (403.2 kB view details)

Uploaded CPython 3.9 macOS 11.0+ ARM64

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

Uploaded CPython 3.8 Windows x86-64

power_grid_model-1.3.266-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.266-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.266-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.266-cp38-cp38-macosx_10_15_x86_64.whl (450.6 kB view details)

Uploaded CPython 3.8 macOS 10.15+ x86-64

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.266-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 888d8719cbd8dafdc8d4eff3519a8922506922e0b3e80c9f45f82d0893b3740d
MD5 41b09b01821659040c0af97c84440251
BLAKE2b-256 a7816388ebbf8fab3c85c70ce89c3fe4d943b794fbe27235a553a5199f2fee87

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.266-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1b52b632d400ca4f135cac160731808884ea04fc37ace206d76e24fdd440621d
MD5 e9f9b885876f70d3c80ea85e331c5c99
BLAKE2b-256 c67e3a0c4a335b52574c26adac054fcbd1dffdb888e45d9ceee64678d049ee05

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.266-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 46519113a405a14e4c4260294a91fd1f10fe11ef57e6626db50a3afb871512bb
MD5 569c958e4b9ead3002e2c293780d1cac
BLAKE2b-256 f72e37eba53ad4a1803dcf6d4ae85b4d9c771804324bc936c6851c8d63c58b43

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.266-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 887bc1f19971168bac8fc70321f9f8a70fac567b73affcf76f72551cbe4d7467
MD5 d6e2f086e93ade87296e6647513571c8
BLAKE2b-256 194c8e8cb59b55a8ff8ba751218e5c84c93141149e8766e2aea57f325c9919cc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.266-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 29fa310901854a52432c710bdd98694c28f7f54d9a9fffe9e1769e6b8c36cc67
MD5 e886a3a636203ea61e8b0bc4042901f5
BLAKE2b-256 4b2258af44715dd7e57f600f47522cd4dc6c18c3e84d1426cdaab5a6055f6403

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.266-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 913ab0f547bf6eb28d1183937426280f0071c206938d9d269774a18ee41179d1
MD5 a97302a070c497b702bffd07413c7c20
BLAKE2b-256 372bb2cbb653755c8a2f108afa471dcda0dbaafdd9dba6cdb9cf8ea066ac3f9f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.266-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 29a7b067c82501525ae70a7125309984f0e6dab1d57f92625c775ca22ddf1ae7
MD5 a30cdb837d09d94a96ee7b3a66d88b65
BLAKE2b-256 8b6b502e866f81f20bd34112db4e7386318db5285178549ec9637d1211f64332

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.266-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 6ae216bc1ae87afc577b8253269ff3da53dcc9f4c545ddb7dd9da992cc94e78d
MD5 69c4ee69c00761374d657e7c9231021b
BLAKE2b-256 09017108fe714850758598ab5302795473f42cf6c257571c0784bd632df7203b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.266-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0a40284ad4b88f9e23f013efb0e2c154418353f226dab6260456da97b6aa611b
MD5 49cf76aa77b954580ef5a669bbff3d75
BLAKE2b-256 554e0a039b3d61b375b747645106f7dbc63007ccebd58d6f051826db6a8dd740

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.266-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 8f6dce403f76b949518026ba4b0452a126248724b876fb77ed5a7cfc42b29b0d
MD5 4af6af8cdf4570911a0dd0a98dfdda0f
BLAKE2b-256 810206a28f953af4a8eb3d0b40277ec85f45ffeb547605c23b56a94870c2c750

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.266-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 0bb35cde93b64c0c6f50a9c02fc6917e963af71a37533a55ccc024b89d4b3a7f
MD5 dd957c644e1f638a8c3955bfbed757a1
BLAKE2b-256 984056a981ebd093da0f75f6d7c6cbc92e467b48e4c4dda2d1da2b0f9ae204ae

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.266-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 49db8099ee86acae60777e8f6c33e38a3c2174c7adde0b91df3f6a6af22250b6
MD5 599e278e5617972e0b2d18b78dc10fda
BLAKE2b-256 703c761c49e73fc8d336e64aa6d1feecf285c8774768de4613f9b159e51acc6a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.266-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 ec575e586434194f009aa3afc31eee8867584617fe3cc77ff9b8b6f71d0a63e5
MD5 29e5cfd58be0b302f00b683f571d9697
BLAKE2b-256 2bc3a8e5b55aa7bb43c75154eef06844c76fdadb56a6b63c7a4374be4485b5d1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.266-cp38-cp38-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 046356a2dbc8fd05b9acc5e07fd5f85ca40b1d1a0484f76eeb72377f9de579af
MD5 b7d8bde346a2096c313b961198526f76
BLAKE2b-256 548ff61e6e4e0ba247dbc46145c2eed5e71ee4904daa12f1f46bb3a33bb1c62e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for power_grid_model-1.3.266-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 595be5fc30d09a191efc44dc947714304ccc76514a3cdb70c1921f010226535e
MD5 564986b5b1269ac73707aad834807f1c
BLAKE2b-256 0f895b57aabdcea242ed87192d23134490457cf7a4a1bc13e901963cb609f3ae

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