Skip to main content

Binder MIT License Python versions supported Downloads per month GitHub code size in bytes PyPI - Version GitHub Actions Workflow Status

TensorPowerFlow

What is TensorPowerFlow?

An ultra-fast power flow based on a fixed-point iteration algorithm. The power flow is intended for applications requiring massive amounts of power flow computations. e.g., electrical load time series, metaheuristics, and electrical grid environments for reinforcement learning.

How to install

The package can be installed via pip using:

pip install tensorpowerflow

Example:

Here we show four examples of what can be done with the packages:

  1. Example 1: The package comes with a preloaded network case of 34 nodes that can be solved by default.
  2. Example 2: Solve 10.000 PF for the default network case. The active power for the nodes is generated by sampling a Normal distribution.
  3. Example 3: The GridTensor class can generate a random grid using the GridTensor.generate_from_graph() method. The parameters nodes and child, respectively, can control the number of nodes and branching per node.
  4. Example 4: We test the grid with a tensor of 3 dimensions. The first dimension is the number of scenarios (10 in the example). The second dimension is the number of time steps (8.760 to simulate a 30-minute resolution consumption for one year). The third dimension is the number of PQ nodes in the grid (33 PQ nodes for the base grid case).
from tensorpowerflow import GridTensor
import numpy as np
from time import perf_counter

#%% Example 1: Solve base case (34 node bus)
network = GridTensor(gpu_mode=False)
solution = network.run_pf()
print(solution["v"])

#%% Example 2: Solve 10_000 power flows on the 34 node bus network case.
network_size = network.nb - 1 # Size of the network without the slack bus.
active_ns = np.random.normal(50, scale=1, size=(10_000, network_size)) # Power in kW
reactive_ns = active_ns * 0.1  # kVAr
solution_tensor = network.run_pf(active_power=active_ns, reactive_power=reactive_ns)
print(solution_tensor["v"])

#%% Example 3: Generate a random radial network of 100 nodes and a maximum of 1 to 3 branches per node.
network_rnd = GridTensor.generate_from_graph(nodes=100, child=3, plot_graph=True)
solution_rnd = network_rnd.run_pf()
print(solution_rnd["v"])

#%% Example 4: Solve a tensor power flow. For 10 scenarios, 8_760 time steps (one year - 1 hr res) for the 33 PQ nodes.
# Meaning that the dimensions of the tensor are (10, 8_760, 33)

network = GridTensor(numba=True)  # Loads the basic 34 bus node network.
active_ns = np.random.normal(50,  # Power in kW
                             scale=10,
                             size=(10, 8_760, 33)).round(3)  # Assume 1 slack variable
reactive_ns = (active_ns * .1).round(3)  # Constant PF of 0.1

start_tensor_dense = perf_counter()
solution = network.run_pf(active_power=active_ns, reactive_power=reactive_ns, algorithm="tensor")
t_tensor_dense = perf_counter() - start_tensor_dense
assert solution["convergence"], "Algorithm did not converge."
assert solution["v"].shape == active_ns.shape
print(f"Time tensor dense: {t_tensor_dense:.3f} sec.")

More examples can be found in the examples folder (under development). Also, you can try the package via Jupyter lab by clicking on the binder icon:

Binder

Reading and citations:

The mathematical formulation of the power flow can be found at:

"Tensor Power Flow Formulations for Multidimensional Analyses in Distribution Systems." E.M. Salazar Duque, Juan S. Giraldo, Pedro P. Vergara, Phuong H. Nguyen, and Han (J.G.) Slootweg. arXiv:2403.04578 (2024).

How to contact us

For any questions, suggestions or collaborations, contact Juan S. Giraldo at jnse@ieee.org

Release files for tensorpowerflow 0.0.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tensorpowerflow 0.0.7
File Size Uploaded
tensorpowerflow-0.0.7.tar.gz 27.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tensorpowerflow 0.0.7
File Interpreter ABI Platform
tensorpowerflow-0.0.7-py3-none-any.whl Python 3 none any Details

Total release size: 59.0 kB

Release files / tensorpowerflow-0.0.7.tar.gz

Download URL tensorpowerflow-0.0.7.tar.gz
Size 27.8 kB
Tags Source
SHA-256 checksum
How to use checksums
f6ec888a61cd50c025e5f8bbb99460ccd0628886e1242acb1ba9aa0b30804ddf
BLAKE2b-256 checksum
How to use checksums
7c6db275bdbfe2ece3924bc35d863995ee54e550761ace83de0f2173dd21e087
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.2

Release files / tensorpowerflow-0.0.7-py3-none-any.whl

Download URL tensorpowerflow-0.0.7-py3-none-any.whl
Size 31.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2ffb3f1871588ca7b9a3125e4aa2f5db6902b0267aa5d75f32c324cc5cceb94d
BLAKE2b-256 checksum
How to use checksums
215957d08e8c3f1d077f164d678f9f785b445a3495d5417ec3e1774a1cdf9892
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.2

Release history Release notifications | RSS feed

This release

0.0.7 This release

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page