SKILL.md
AC Branch Pi-Model + Transformer Handling
Implement the exact branch power flow equations in acopf-math-model.md using MATPOWER branch data:
[F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, TAP, SHIFT, BR_STATUS, ANGMIN, ANGMAX]
Quick start
- Use
scripts/branch_flows.pyto compute per-unit branch flows. - Treat the results as power leaving the “from” bus and power leaving the “to” bus (i.e., compute both directions explicitly).
Example:
import json
import numpy as np
from scripts.branch_flows import compute_branch_flows_pu, build_bus_id_to_idx
data = json.load(open("/root/network.json"))
baseMVA = float(data["baseMVA"])
buses = np.array(data["bus"], dtype=float)
branches = np.array(data["branch"], dtype=float)
bus_id_to_idx = build_bus_id_to_idx(buses)
Vm = buses[:, 7] # initial guess VM
Va = np.deg2rad(buses[:, 8]) # initial guess VA
br = branches[0]
P_ij, Q_ij, P_ji, Q_ji = compute_branch_flows_pu(Vm, Va, br, bus_id_to_idx)
S_ij_MVA = (P_ij**2 + Q_ij**2) ** 0.5 * baseMVA
S_ji_MVA = (P_ji**2 + Q_ji**2) ** 0.5 * baseMVA
print(S_ij_MVA, S_ji_MVA)
Model details (match the task formulation)
Per-unit conventions
- Work in per-unit internally.
- Convert with
baseMVA:- (P_{pu} = P_{MW} / baseMVA)
- (Q_{pu} = Q_{MVAr} / baseMVA)
- (|S|{MVA} = |S|{pu} \cdot baseMVA)
Transformer handling (MATPOWER TAP + SHIFT)
- Use (T_{ij} = tap \cdot e^{j \cdot shift}).
- Implementation shortcut (real tap + phase shift):
