OptiQ / api /routes /baseline.py
AhmedSamir1598's picture
first baseline for project OptiQ. Contains research resources, first baseline using GNNs + QC, and benchmarks against current industry standards, while addressing the challenges that prevents better practices to be used in industry.
55e3496
"""
Baseline endpoint — Returns default power flow for a given IEEE test system.
"""
from __future__ import annotations
from fastapi import APIRouter, HTTPException
from src.grid.loader import load_network, get_network_summary, get_line_info, get_bus_data, get_topology_data
from src.grid.power_flow import get_baseline
router = APIRouter()
@router.get("/baseline/{system}")
def baseline(system: str = "case33bw"):
"""Run AC power flow on the default (unoptimized) network configuration.
Parameters
----------
system : str
``"case33bw"`` or ``"case118"``.
"""
try:
net = load_network(system)
except ValueError as exc:
raise HTTPException(status_code=400, detail=str(exc))
summary = get_network_summary(net)
line_info = get_line_info(net)
results = get_baseline(net)
if not results.get("converged", False):
raise HTTPException(status_code=500, detail="Baseline power flow did not converge.")
return {
"system": system,
"network": summary,
"topology": {
"total_lines": len(line_info["all"]),
"in_service": len(line_info["in_service"]),
"tie_lines": len(line_info["out_of_service"]),
"open_line_indices": line_info["out_of_service"],
},
"power_flow": results,
"buses": get_bus_data(net),
"lines": get_topology_data(net),
}