← Back to Skills Marketplace
wu-uk

ac-branch-pi-model

by wu-uk · GitHub ↗ · v0.1.0 · MIT-0
cross-platform ✓ Security Clean
80
Downloads
0
Stars
0
Active Installs
1
Versions
Install in OpenClaw
/install energy-ac-optimal-power-flow-ac-branch-pi-model
Description
AC branch pi-model power flow equations (P/Q and |S|) with transformer tap ratio and phase shift, matching `acopf-math-model.md` and MATPOWER branch fields....
README (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.py to 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):
    • If abs(TAP) \x3C 1e-12, treat tap = 1.0 (no transformer).
    • Convert SHIFT from degrees to radians.
    • Use the angle shift by modifying the angle difference:
      • (\delta_{ij} = heta_i - heta_j - shift)
      • (\delta_{ji} = heta_j - heta_i + shift)

Series admittance

Given BR_R = r, BR_X = x:

  • If r == 0 and x == 0, set g = 0, b = 0 (avoid divide-by-zero).
  • Else:
    • (y = 1/(r + jx) = g + jb)
    • (g = r/(r^2 + x^2))
    • (b = -x/(r^2 + x^2))

Line charging susceptance

  • BR_B is the total line charging susceptance (b_c) (per unit).
  • Each end gets (b_c/2) in the standard pi model.

Power flow equations (use these exactly)

Let:

  • (V_i = |V_i| e^{j heta_i}), (V_j = |V_j| e^{j heta_j})
  • tap is real, shift is radians
  • inv_t = 1/tap, inv_t2 = inv_t^2

Then the real/reactive power flow from i→j is:

  • (P_{ij} = g |V_i|^2 inv_t2 - |V_i||V_j| inv_t (g\cos\delta_{ij} + b\sin\delta_{ij}))
  • (Q_{ij} = -(b + b_c/2)|V_i|^2 inv_t2 - |V_i||V_j| inv_t (g\sin\delta_{ij} - b\cos\delta_{ij}))

And from j→i is:

  • (P_{ji} = g |V_j|^2 - |V_i||V_j| inv_t (g\cos\delta_{ji} + b\sin\delta_{ji}))
  • (Q_{ji} = -(b + b_c/2)|V_j|^2 - |V_i||V_j| inv_t (g\sin\delta_{ji} - b\cos\delta_{ji}))

Compute apparent power:

  • (|S_{ij}| = \sqrt{P_{ij}^2 + Q_{ij}^2})
  • (|S_{ji}| = \sqrt{P_{ji}^2 + Q_{ji}^2})

Common uses

Enforce MVA limits (rateA)

  • RATE_A is an MVA limit (may be 0 meaning “no limit”).
  • Enforce in both directions:
    • (|S_{ij}| \le RATE_A)
    • (|S_{ji}| \le RATE_A)

Compute branch loading %

For reporting “most loaded branches”:

  • loading_pct = 100 * max(|S_ij|, |S_ji|) / RATE_A if RATE_A > 0, else 0.

Aggregate bus injections for nodal balance

To build the branch flow sum for each bus (i):

  • Add (P_{ij}, Q_{ij}) to bus i
  • Add (P_{ji}, Q_{ji}) to bus j

This yields arrays P_out[i], Q_out[i] such that the nodal balance can be written as:

  • (P^g - P^d - G^s|V|^2 = P_{out})
  • (Q^g - Q^d + B^s|V|^2 = Q_{out})

Sanity checks (fast debug)

  • With SHIFT=0 and TAP=1, if (V_i = V_j) and ( heta_i= heta_j), then (P_{ij}\approx 0) and (P_{ji}\approx 0) (lossless only if r=0).
  • For a pure transformer (r=x=0) you should not get meaningful flows; treat as g=b=0 (no series element).
Usage Guidance
This skill appears to do exactly what it claims (compute AC branch flows). Before running: ensure you execute it in a Python environment with numpy installed, review and replace the example's /root/network.json path with a safe/test dataset (to avoid the agent reading host files), and run it in a sandbox if you don't trust the source. The only real coherence issues are: (1) numpy is required but not declared, and (2) the example references an absolute host path — neither is evidence of malice, but both are worth correcting.
Capability Analysis
Type: OpenClaw Skill Name: energy-ac-optimal-power-flow-ac-branch-pi-model Version: 0.1.0 The skill bundle provides a standard mathematical implementation of AC branch pi-model power flow equations used in electrical engineering. The Python script `scripts/branch_flows.py` and the instructions in `SKILL.md` are strictly focused on power system calculations and do not contain any malicious logic, data exfiltration, or prompt injection attempts.
Capability Assessment
Purpose & Capability
The SKILL.md, name, description, and the included Python implementation all align: the code computes per-unit branch flows for MATPOWER-style branch rows and matches the documented equations. There are no unrelated requirements (no cloud creds, no unusual binaries).
Instruction Scope
The runtime instructions and example focus only on local numeric computation and using the provided script. The example shows opening /root/network.json (an absolute host path) which could cause an agent to read a sensitive host file if followed verbatim — the SKILL.md doesn't otherwise instruct broad file access or external network calls. The code expects numpy arrays shaped like MATPOWER data.
Install Mechanism
There is no install spec (instruction-only), which minimizes risk. However, the included Python file imports numpy (and uses Python) but the skill metadata does not declare this dependency or an install step to ensure numpy is available — a minor coherence gap.
Credentials
No environment variables, credentials, or config paths are requested. The skill does not attempt to access external services or secrets.
Persistence & Privilege
always is false and the skill does not request or modify persistent agent/system settings. It does not write installers or change other skills' configs.
How to Use
  1. Make sure OpenClaw is installed (local or Docker)
  2. Run the install command in chat: /install energy-ac-optimal-power-flow-ac-branch-pi-model
  3. After installation, invoke the skill by name or use /energy-ac-optimal-power-flow-ac-branch-pi-model
  4. Provide required inputs per the skill's parameter spec and get structured output
Version History
v0.1.0
Bulk publish from all-task-skills-dedup
Metadata
Slug energy-ac-optimal-power-flow-ac-branch-pi-model
Version 0.1.0
License MIT-0
All-time Installs 0
Active Installs 0
Total Versions 1
Frequently Asked Questions

What is ac-branch-pi-model?

AC branch pi-model power flow equations (P/Q and |S|) with transformer tap ratio and phase shift, matching `acopf-math-model.md` and MATPOWER branch fields.... It is an AI Agent Skill for Claude Code / OpenClaw, with 80 downloads so far.

How do I install ac-branch-pi-model?

Run "/install energy-ac-optimal-power-flow-ac-branch-pi-model" in the OpenClaw or Claude Code chat to install it in one step — no extra setup required.

Is ac-branch-pi-model free?

Yes, ac-branch-pi-model is completely free, licensed under MIT-0. You can download, install and use it at no cost.

Which platforms does ac-branch-pi-model support?

ac-branch-pi-model is cross-platform and runs anywhere OpenClaw / Claude Code is available (cross-platform).

Who created ac-branch-pi-model?

It is built and maintained by wu-uk (@wu-uk); the current version is v0.1.0.

💬 Comments