Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

API — AC OPF

PowerFlowOptimizationResult

Dataclass returned by AC OPF solvers.

FieldTypeDescription
successboolWhether solver converged
messagestrSolver status message
ybus_resultYBusResultY-bus matrix and node mapping
voltagenp.ndarrayComplex nodal voltages (V)
power_injectionnp.ndarrayComplex power injections (W + j·var)
iterationsintSolver iterations
initial_objectivefloatStarting objective value
final_objectivefloatConverged objective value

optimize_ac_power_flow

Low-level AC OPF solver accepting explicit power specifications.

def optimize_ac_power_flow(
    system: DistributionSystem,
    *,
    p_spec_w: dict[BusPhaseLabel, float] | None = None,
    q_spec_var: dict[BusPhaseLabel, float] | None = None,
    voltage_targets_v: dict[BusPhaseLabel, float] | None = None,
    voltage_limits_v: dict[BusPhaseLabel, tuple[float, float]] | None = None,
    slack_label: list[BusPhaseLabel] | None = None,
    vm_min_pu: float = 0.95,
    vm_max_pu: float = 1.05,
    voltage_reg_weight: float = 1e-3,
    voltage_target_weight: float = 1.0,
    mismatch_scale_floor_w: float = 1e3,
    max_nfev: int = 300,
    include_neutral: bool = False,
    include_shunt: bool = True,
) -> PowerFlowOptimizationResult:

Parameters:

ParameterDefaultDescription
p_spec_wNoneActive power spec per node (W, positive = generation)
q_spec_varNoneReactive power spec per node (var)
voltage_targets_vNoneRegulator voltage targets (V)
voltage_limits_vNoneRegulator voltage limits (min_v, max_v) per node
slack_labelNoneList of slack (bus, phase) labels
vm_min_pu0.95Lower voltage bound (per-unit)
vm_max_pu1.05Upper voltage bound (per-unit)
voltage_reg_weight1e-3Voltage regularization strength
voltage_target_weight1.0Regulator target penalty strength
mismatch_scale_floor_w1e3Minimum power mismatch normalization
max_nfev300Maximum function evaluations

optimize_ac_power_flow_from_components

High-level wrapper that extracts power specs from DistributionSystem components.

def optimize_ac_power_flow_from_components(
    system: DistributionSystem,
    *,
    include_loads: bool = True,
    include_solar: bool = True,
    include_capacitor: bool = True,
    include_battery: bool = True,
    include_regulator_targets: bool = True,
    include_regulator_limits: bool = True,
    **kwargs,
) -> PowerFlowOptimizationResult:

All **kwargs are forwarded to optimize_ac_power_flow.

Builder Functions

build_nodal_power_specs_from_components

def build_nodal_power_specs_from_components(
    system: DistributionSystem,
    *,
    include_loads: bool = True,
    include_solar: bool = True,
    include_capacitor: bool = True,
    include_battery: bool = True,
) -> tuple[dict[BusPhaseLabel, float], dict[BusPhaseLabel, float]]:

Returns (p_spec_w, q_spec_var) dictionaries from system components.

build_regulator_voltage_targets_from_components

def build_regulator_voltage_targets_from_components(
    system: DistributionSystem,
) -> dict[BusPhaseLabel, float]:

Returns voltage targets from DistributionRegulator components.

build_regulator_voltage_limits_from_components

def build_regulator_voltage_limits_from_components(
    system: DistributionSystem,
) -> dict[BusPhaseLabel, tuple[float, float]]:

Returns voltage limits (min_v, max_v) from regulator bandwidth settings.