Ultra fast power flow based in Laurent series expansion.
Project description
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:
- Example 1: The package comes with a preloaded network case of 34 nodes that can be solved by default.
- Example 2: Solve 10.000 PF for the default network case. The active power for the nodes is generated by sampling a Normal distribution.
- Example 3: The GridTensor class can generate a random grid using the
GridTensor.generate_from_graph()
method. The parametersnodes
andchild
, respectively, can control the number of nodes and branching per node. - 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:
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
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file tensorpowerflow-0.0.7.tar.gz
.
File metadata
- Download URL: tensorpowerflow-0.0.7.tar.gz
- Upload date:
- Size: 27.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f6ec888a61cd50c025e5f8bbb99460ccd0628886e1242acb1ba9aa0b30804ddf |
|
MD5 | c58697e68dc2c9cf8c89a381ded7da52 |
|
BLAKE2b-256 | 7c6db275bdbfe2ece3924bc35d863995ee54e550761ace83de0f2173dd21e087 |
File details
Details for the file tensorpowerflow-0.0.7-py3-none-any.whl
.
File metadata
- Download URL: tensorpowerflow-0.0.7-py3-none-any.whl
- Upload date:
- Size: 31.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2ffb3f1871588ca7b9a3125e4aa2f5db6902b0267aa5d75f32c324cc5cceb94d |
|
MD5 | acc3afb15aaac1c95fe75f8908159c8a |
|
BLAKE2b-256 | 215957d08e8c3f1d077f164d678f9f785b445a3495d5417ec3e1774a1cdf9892 |