Module ml4opf.functional.ac

ACOPF Functional interface

Functions

def balance_residual_bus(pd_bus: torch.Tensor,
qd_bus: torch.Tensor,
pg_bus: torch.Tensor,
qg_bus: torch.Tensor,
vm: torch.Tensor,
pf_bus: torch.Tensor,
pt_bus: torch.Tensor,
qf_bus: torch.Tensor,
qt_bus: torch.Tensor,
gs_bus: torch.Tensor,
bs_bus: torch.Tensor) ‑> tuple[torch.Tensor, torch.Tensor]

Compute power balance residual.

\text{p_viol} = \text{pg_bus} - \text{pd_bus} - \text{pt_bus} - \text{pf_bus} - \text{gs_bus} \times \text{vm}^2 \text{q_viol} = \text{qg_bus} - \text{qd_bus} - \text{qt_bus} - \text{qf_bus} + \text{bs_bus} \times \text{vm}^2

Args

pd_bus : Tensor
Active power demand at each bus. (batch, n_bus)
qd_bus : Tensor
Reactive power demand at each bus. (batch, n_bus)
pg_bus : Tensor
Active power generation at each bus. (batch, n_bus)
qg_bus : Tensor
Reactive power generation at each bus. (batch, n_bus)
vm : Tensor
Voltage magnitude at each bus. (batch, n_bus)
pf_bus : Tensor
Active power flow from each bus. (batch, n_bus)
pt_bus : Tensor
Active power flow to each bus. (batch, n_bus)
qf_bus : Tensor
Reactive power flow from each bus. (batch, n_bus)
qt_bus : Tensor
Reactive power flow to each bus. (batch, n_bus)
gs_bus : Tensor
Shunt conductance at each bus. (batch, n_bus)
bs_bus : Tensor
Shunt susceptance at each bus. (batch, n_bus)

Returns

tuple[Tensor]
Active and reactive power balance violation \text{p_viol}, \text{q_viol} each of shape (batch, n_bus).
def flows_from_voltage(vm: torch.Tensor,
dva: torch.Tensor,
fbus: torch.Tensor,
tbus: torch.Tensor,
gff: torch.Tensor,
gft: torch.Tensor,
gtf: torch.Tensor,
gtt: torch.Tensor,
bff: torch.Tensor,
bft: torch.Tensor,
btf: torch.Tensor,
btt: torch.Tensor) ‑> tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor]
def flows_from_voltage_bus(vm: torch.Tensor,
va: torch.Tensor,
fbus: torch.Tensor,
tbus: torch.Tensor,
gff: torch.Tensor,
gft: torch.Tensor,
gtf: torch.Tensor,
gtt: torch.Tensor,
bff: torch.Tensor,
bft: torch.Tensor,
btf: torch.Tensor,
btt: torch.Tensor,
dva: torch.Tensor | None = None)

Compute power flows from voltage magnitude, angle, and branch info.

def objective(pg: torch.Tensor, c0: torch.Tensor, c1: torch.Tensor, c2: torch.Tensor) ‑> torch.Tensor

Compute ACOPF objective function.

Args

pg : Tensor
Active power generation. (batch, n_gen)
cost : Tensor
Cost coefficients. (n_gen, 3)

Returns

Tensor
Objective function value for each sample. (batch,)
def thermal_residual(pf: torch.Tensor,
pt: torch.Tensor,
qf: torch.Tensor,
qt: torch.Tensor,
smax: torch.Tensor) ‑> tuple[torch.Tensor, torch.Tensor]

Calculate the thermal residual for a set of flows.

\text{thrm}_1 = \text{pf}^2 + \text{qf}^2 - \text{smax}^2 \text{thrm}_2 = \text{pt}^2 + \text{qt}^2 - \text{smax}^2

Args

pf : Tensor
From power flow. (batch, n_branch)
pt : Tensor
To power flow. (batch, n_branch)
qf : Tensor
From reactive power flow. (batch, n_branch)
qt : Tensor
To reactive power flow. (batch, n_branch)
s1max : Tensor
From power flow limit. (n_branch,)
s2max : Tensor
To power flow limit. (n_branch,)

Returns

tuple[Tensor]
Thermal residuals (\text{thrm}_1, \text{thrm}_2) each of shape (batch, n_branch).