Optimization methods for voltage and congestion management in modern power distribution grids.
Project description
Grid Feedback Optimizer
Overview
Grid Feedback Optimizer is a Python package that uses feedback optimization to optimize generator and device setpoints in electrical distribution grids. It reads a JSON/EXCEL network description and iteratively computes optimal setpoints.
This package is designed for experimenting with voltage regulation and congestion management, providing a flexible framework for feedback-based grid optimization.
Features
- Load and simulate networks from JSON/EXCEL files.
- Iterative feedback optimization using:
- gradient projection (GP) algorithm,
- primal-dual (PD) algorithm.
- Structured input and output data.
- Modular design (
models,engine,utils) for extensions.
Repository Structure
grid_feedback_optimizer/
src/
grid_feedback_optimizer/
model/ # Loaders and I/O
engine/ # Power flow / optimization logic
utils/ # Helper functions
main.py
examples/ # Example JSON/EXCEL network files
tests/ # Tests
requirements.txt # Python dependencies
README.md
⚙️ Installation
Install from PyPI
pip install grid-feedback-optimizer
Usage
Python usage example:
from grid_feedback_optimizer.models.loader import load_network
from grid_feedback_optimizer.engine.solve import solve
from grid_feedback_optimizer.engine.powerflow import PowerFlowSolver
# Load network from example JSON
network = load_network("../examples/simple_example_with_transformer.json")
# Initialize and check power flow
power_flow_solver = PowerFlowSolver(network)
# Run optimization using the Gradient Projection (GP) algorithm
res_gp = solve(network, algorithm="gp")
# Display and store results
res_gp.print_summary()
res_gp.plot_iterations()
res_gp.save("gp_result.json")
Grid components
Follow power-grid-model for definition of buses (nodes), lines, transformers, and sources.
RenewGen
RenewGen models controllable generators and power-consuming devices.
- Generator:
p_max > 0andp_min >= 0 - Load:
p_max < 0andp_min <= 0 - Flexible device:
p_min < 0 < p_max(can generate or consume)
Key attributes:
index,bus: identifiersp_max,p_min: active power limitss_inv: apparent power ratingp_norm: normal active power (auto-computed if not set)q_norm: normal reactive power (0.0 if not set)c1_p: linear active power cost coefficientsc2_p: quadrtic active power cost coefficients for deviation fromp_normc1_q: linear reactive power cost coefficientsc2_q: quadrtic reactive power cost coefficients for deviation fromq_norm
Minimization cost function:
Cost = c1_p × p + c2_p × (p - p_norm)² + c1_q × q + c2_q × (q - q_norm)²
where p and q are the actual active and reactive power outputs.
p_norm is computed automatically:
- Generator →
p_norm = p_max - Load →
p_norm = p_min - Flexible →
p_norm = 0
Load
Load models non-controllable units, either a generator or a load.
- Load:
p_norm >= 0 - Generator:
p_norm < 0
Key attributes:
index,bus: identifiersp_norm,q_norm: active and reactive power
🧩 solve() Function Parameters
The solve() function performs the iterative feedback optimization between power flow calculation and control updates.
It supports both Gradient Projection (GP) and Primal-Dual (PD) algorithms.
solve(
network: Network,
max_iter: int = 1000,
tol: float = 1e-3,
delta_p: float = 1.0,
delta_q: float = 1.0,
algorithm: str = "gp",
alpha: float = 0.5,
alpha_v: float = 10.0,
alpha_l: float = 10.0,
alpha_t: float = 10.0,
record_iterates: bool = True,
solver: str = "CLARABEL",
loading_meas_side: str = "from",
rel_tol: float = 1E-4,
rel_tol_line: float = 1E-2,
**solver_kwargs
)
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
network |
Network |
— | Grid model object containing nodes, lines, transformers, loads, and generators (loaded via load_network or load_network_from_excel). |
max_iter |
int |
1000 |
Maximum number of optimization–power flow iterations. |
tol |
float |
1e-3 |
Convergence tolerance for generator setpoint changes between iterations. |
delta_p |
float |
1.0 |
Small perturbation (in W) used for computing active power sensitivities. |
delta_q |
float |
1.0 |
Small perturbation (in VAR) used for computing reactive power sensitivities. |
algorithm |
str |
"gp" |
Optimization algorithm to use: • "gp" → Gradient Projection • "pd" → Primal-Dual |
alpha |
float |
0.5 |
Step size (learning rate) for generator setpoint updates (used in both GP and PD). |
alpha_v |
float |
10.0 |
Voltage-related dual variable step size (only used in PD algorithm). |
alpha_l |
float |
10.0 |
Line-loading-related dual variable step size (only used in PD algorithm). |
alpha_t |
float |
10.0 |
Transformer-loading-related dual variable step size (only used in PD algorithm). |
record_iterates |
bool |
True |
If True, stores all intermediate iteration data (useful for analysis and plotting). |
solver |
str |
"CLARABEL" |
Convex optimization solver backend for subproblems (e.g., "CLARABEL", "OSQP", "SCS"). |
loading_meas_side |
str |
"from" |
Defines which end of the line or transformer is used for measuring loading: "from" or "to". |
rel_tol |
float |
"1E-4" |
Relative tolerance for sensitivity matrices other than dP_line_dq or dQ_line_dp. |
rel_tol_line |
float |
"1E-2" |
Relative tolerance for sensitivity matrices dP_line_dq and dQ_line_dp. |
**kwargs |
- | - | Optional solver parameters (e.g., "verbose", "BarHomogeneous"). |
Returns
| Output | Type | Description |
|---|---|---|
SolveResults |
dataclass |
Object containing: • final_output — final power flow results • final_gen_update — optimized generator setpoints • iterations — list of all recorded iteration states (if record_iterates=True) |
🌀 Conceptual workflow:
- Power flow calculation → compute voltages, line, and transformer loadings.
- Optimization step → update generator active/reactive power setpoints using feedback and sensitivities.
- Iterate until generator updates converge within
tol.
The process continues until steady-state optimal operation is achieved under the given constraints.
References
- Gradient Projection – V. Haberle, A. Hauswirth, L. Ortmann, S. Bolognani, and F. Dorfler, “Non-Convex Feedback Optimization with Input and Output Constraints,” IEEE Control Systems Letters, vol. 5, no. 1, pp. 343–348, 2021. DOI: 10.1109/LCSYS.2020.3002152
- Primal-Dual – E. Dall’Anese and A. Simonetto, “Optimal Power Flow Pursuit,” IEEE Transactions on Smart Grid, vol. 9, no. 2, 2018. DOI: 10.1109/TSG.2016.2571982
License
This project is licensed under the MIT License.
Author
Developed and maintained by Sen Zhan
📧 Email: sen.zhan@outlook.com
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 Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file grid_feedback_optimizer-0.1.5.tar.gz.
File metadata
- Download URL: grid_feedback_optimizer-0.1.5.tar.gz
- Upload date:
- Size: 23.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a5c81f26a55247f18e0d8771edf6a8e959f1be08b29674044ae886f929461ebb
|
|
| MD5 |
b77a363ab951da269cd6ac8c046f8b64
|
|
| BLAKE2b-256 |
0c7b4bb04c6061ea6d6ed9165a8bc4bea4d54eb93b627c6a69dd3a53413803ec
|
File details
Details for the file grid_feedback_optimizer-0.1.5-py3-none-any.whl.
File metadata
- Download URL: grid_feedback_optimizer-0.1.5-py3-none-any.whl
- Upload date:
- Size: 22.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
008a1d78fa69d52b37eecdd4f886bc8178bd9bff373544121d15238dc2009bb9
|
|
| MD5 |
9d5a89c3999209113d7d676dd3dfe999
|
|
| BLAKE2b-256 |
121320b3a17f89f50a6c32286c7ddd060d2adac539cb5607edd482e78477b703
|