ExaModelsPower.CASE_START — Constant
CASE_STARTThe starting points opf_args(file; start = :case) uses: the case file's bus voltages (va, vm, and vr, vim from them) and generator dispatch (pg, qg). The branch flows keep their default.
ExaModelsPower.MPOPF_DEFAULT_CURVE — Constant
MPOPF_DEFAULT_CURVEThe load curve behind mpopf_args_default: [1.0, 0.9, 0.8, 0.95, 1.0].
A compiled multi-period library needs a ONE-argument, package-owned function to call — the generated app resolves it by name from another process, so a closure over a curve cannot be reached. The curve and horizon are compile-time facts of such a library anyway, so the default lives here as a constant; a different curve means defining your own one-argument wrapper over mpopf_args in your own package.
ExaModelsPower.DC — Type
The DC linearization: va only, flows per branch, no reactive half.
ExaModelsPower.OPFForm — Type
ExaModelsPower.Polar — Type
Polar-voltage AC: variables va, vm.
ExaModelsPower.Rect — Type
Rectangular-voltage AC: variables vr, vim, plus the voltage-magnitude rows.
ExaModelsPower._precompile_workload — Method
_precompile_workload(backend; T = nothing)Build and evaluate the OPF models on backend, with the keyword combinations that ac_opf_model and opf_model are usually called with, and use their results as a solver's caller does (write_matpower_solution, opf_violations, case_start). T is passed only when given (Metal needs Float32).
ExaModelsPower.case_start — Method
case_start(case_file, model) -> VectorThe starting point of model, a static model built by opf_model (Polar(), Rect() or DC(); not a multi-period model), with the bus voltages and generator dispatch taken from case_file, as CASE_START defines them: model's own x0 with those blocks replaced. A Vector on the host, also for a model on a GPU. case_file must be the case model was built from, or one with the same buses and generators in the same order, such as its solution written by write_matpower_solution; only the numbers of buses and generators are checked.
ExaModelsPower.goc3_commitment — Method
goc3_commitment(uc_filename, static) -> NamedTupleThe unit commitment in the GOC3 solution file uc_filename, as matrices by position and interval: device on, startup and shutdown status (rows by j_prcs), AC line and transformer on status, and shunt steps. Rows are joined to the problem static (from goc3_static) by uid. An element the problem has and the file lacks is refused: skipping it would shift every later row onto the wrong element.
ExaModelsPower.goc3_static — Method
goc3_static(filename) -> NamedTupleThe time-invariant tables of the GOC3 problem in filename, indexed the way the model reads them:
bus:i, the bus position, and its voltage bounds.acl_branchandacx_branch: AC lines (j_ln) and transformers (j_xf) with their end buses, series admittance, charging, terminal shunts and ratings;vpd,fpd,vwr,fwrsplit the transformers by variable or fixed phase shift and winding ratio.dc_branch(j_dc) andshunt(j_sh).prodandcons: one row per device,j_prcsits position among all devices andj_pr(j_cs) among the producers (consumers), with its bus and initial active power;devicesholds PowerIO's device records, whose time series the model reads byj_prcs.- The reserve zones and, per zone, the devices at its buses;
outaged, the uids each contingency takes out of service;dt, the interval durations; and the violation costs. uids: the uid at each position of each table, for the solution writer.
ExaModelsPower.mpopf_args — Method
mpopf_args(filename, curve; N, T, backend, corrective_action_ratio) -> (data,)The arguments that close mpopf_recipe: the parsed case with the load curve already applied, plus everything the recipe cannot compute from a placeholder.
N and the curve are NOT arguments to a compiled library — they are baked into the recipe. The body slices genarray[:, 2:N] and expands bounds with repeat(v, 1, N), neither of which has a symbolic form, so a compiled multi-period library is per-(N, curve) and the case file is the one value that crosses the boundary.
The N-expanded bounds are grouped under rep rather than spread across the top level: there are fifteen of them, and map over a NamedTuple stops inferring elementwise past 31 fields, which would leave the whole argument tuple with concrete names and no value types.
ExaModelsPower.mpopf_args_default — Method
mpopf_args_default(filename) -> (data,)mpopf_args at MPOPF_DEFAULT_CURVE — the spelling a compiled library can call. Define your own one-argument wrapper in your package for a different curve.
ExaModelsPower.mpopf_model — Method
mpopf_model(filename, curve; kwargs...)
mpopf_model(filename, active_power_data, reactive_power_data; kwargs...)
mpopf_model(filename, curve, discharge_func::Function; kwargs...)
mpopf_model(filename, active_power_data, reactive_power_data, discharge_func::Function; kwargs...)Construct a multi-period AC optimal power flow (MPOPF) model using different formats of load input data.
Arguments
filename::String: Path to the network data file (e.g., MATPOWER).curve::AbstractVector: A time series of demand multiplier values.active_power_data::String: Path to a matrix of active power loads (Pd) per bus and time.reactive_power_data::String: Path to a matrix of reactive power loads (Qd).discharge_func::Function: (Optional) A function specifying battery discharge losses.
Keyword Arguments
N::Int: Number of time periods (inferred if not provided).corrective_action_ratio::Float64: Ratio of corrective power action allowed (default = 0.1).backend: Optimization solver backend (deault = nothing).form::OPFForm: the formulation —Polar()(default),Rect()orDC().T::Type: Floating-point type for numeric variables (default =Float64).storage_complementarity_constraint::Bool: Whether to enforce complementarity for storage (only for some methods, default = false).user_callback: User function that extends the modelkwargs...: Additional arguments passed to the solver or builder.
Returns
A vector (model::ExaModel object, variables::NamedTuple of variables, constraints::NamedTuple of constraints) representing the MPOPF model.
Method Variants
This function is overloaded for different combinations of input:
mpopf_model(filename, curve)mpopf_model(filename, active_power_data, reactive_power_data)mpopf_model(filename, curve, discharge_func)mpopf_model(filename, active_power_data, reactive_power_data, discharge_func)
ExaModelsPower.mpopf_recipe — Method
mpopf_recipe(; N, form, has_storage, backend, T, user_callback)The multi-period recipe. N, the load curve and whether the case has storage are BUILD-time facts — the body slices genarray[:, 2:N] and storage changes how many variable blocks there are — so a compiled library is per-(N, curve, storage-shape). The network size is NOT: the bus axis is the extent of the data, so one recipe instantiates any case. Close it with mpopf_args.
ExaModelsPower.opf_args — Method
opf_args(filename; T = Float64, backend = nothing, start = (;))
-> (data,)Return the argument tuple that closes opf_recipe — the parsed case together with everything the recipe cannot compute from a placeholder.
start overrides any of the starting points va, vm, vr, vim, pg, qg, p, q. Each entry may be a scalar, a vector, a Base.Generator, or a function of the parsed data (d -> d.vm0 to warm-start from the case's own operating point). start = :case takes the bus voltages and generator dispatch from the case file (CASE_START); for a solved case, that is a warm start from its solution. Defaults are a flat 1.0 voltage magnitude and zero elsewhere, which is what this model used before the recipe split.
Example
args = opf_args("pglib_opf_case118_ieee.m"; start = (vm = d -> d.vm0, va = d -> d.va0))
model = ExaModel(ac_opf_recipe()[1], args...)ExaModelsPower.opf_model — Method
ac_opf_model(filename; backend, T, form, user_callback, start, kwargs...)Return ExaModel, variables, and constraints for a static AC Optimal Power Flow (ACOPF) problem from the given file.
Defined as opf_recipe instantiated at opf_args, so the model solved here and the model compiled by ExaModelsC are built from one definition rather than two.
Arguments
filename::String: Path to the data file.backend: The solver backend to use. Default if nothing.T: The numeric type to use (default isFloat64).form: the formulation, anOPFForminstance —Polar()(default),Rect()orDC().user_callback: User function that extends the modelstart: Starting-point overrides; seeopf_args.kwargs...: Additional keyword arguments passed to the model builder.
Returns
A vector (model, variables, constraints):
model: AnExaModelobject.variables: NamedTuple of model variables.constraints: NamedTuple of model constraints.
ExaModelsPower.opf_recipe — Method
ac_opf_recipe(; backend, T, form, user_callback) -> (core, variables, constraints)Return the AC OPF recipe — an ExaCore holding the model's structure with its data left open — together with the variable and constraint handles.
Close it with opf_args:
core, vars, cons = ac_opf_recipe()
model = ExaModel(core, opf_args("pglib_opf_case118_ieee.m")...)The same recipe instantiates at any case; it is not consumed by the first use.
Arguments
backend: the array backend to build against. Defaultnothing(CPU).T: the numeric type (defaultFloat64).form: the formulation, anOPFForminstance —Polar()(default),Rect()orDC().user_callback: user function that extends the model.
ExaModelsPower.opf_start — Method
opf_start(value, n, T)Materialize a user-supplied starting point into a length-n Vector{T}.
value may be
- a scalar — the flat start, e.g.
one(T)for voltage magnitude; - an
AbstractVectorof lengthn; - a
Base.Generator, e.g.Base.Generator(f, 1:n)— note thatfshould be a named function rather than an anonymous one, so that the type survives ahead-of-time compilation and reads intelligibly in errors.
Generators and vectors are collected here, in opf_args, rather than being referred to from the recipe: only data crosses into an instantiated model, so resolving them at this point is what lets the same start work for an in-Julia model and for a compiled library.
ExaModelsPower.opf_violations — Method
opf_violations(model, x)The largest absolute violation of each group of constraints and bounds of model, an OPF model built by opf_model (any form, on any backend), at the point x, as a NamedTuple of Float64s in the model's units (per unit, radians):
power_balance: active and reactive power balance at each bus;power_flow: the branch flow equations (Ohm's law inDC()) and the reference angle;branch_flow: the branch flow limits,p² + q² ≤ rate²and the flow bounds;angle_difference: the phase angle difference limits;voltage: the voltage magnitude bounds (a variable bound inPolar(), a constraint inRect(); none inDC());generation: the active and reactive generation bounds.
The violation of l ≤ v ≤ u is max(l - v, v - u, 0); a group a formulation does not have is 0. Constraint values are evaluated at x.
ExaModelsPower.parse_sc_data — Method
parse_sc_data(static, uc) -> (sc_time_data, lengths)The time-indexed arrays of the GOC3 model for the problem static (from goc3_static) at the commitment uc (from goc3_commitment), and the sizes of its index sets.
ExaModelsPower.save_go3_solution — Method
save_go3_solution(uc_filename, solution_name, result, vars, lengths, uids)Write the solution result of a model goc3_model(filename, uc_filename) into the GOC3 solution file uc_filename, and save it as solution_name. vars and lengths are what goc3_model returned, and uids the uids field of the sc_data_array it returned, which names the element at every position.
Device dispatch and reserves, transformer taps and phase shifts, DC line flows, and bus voltages are written; AC line flows follow from the voltages, and the commitment is kept as it was.
ExaModelsPower.write_case_start — Method
write_case_start(out, case_file, model, x, y, zl, zu; objective = NaN, status = "")Write case_start(case_file, model) to out, one number per line. The signature of a solution writer, so that a compiled library carries it (P_write_start; see compile_all): a program using the library reads the file back as the starting point. x, the multipliers, objective and status are not used, but a C caller of P_write_start must still pass valid arrays of the model's sizes (zeros will do): the library copies them before calling the writer.
ExaModelsPower.write_matpower_solution — Method
write_matpower_solution(out, case_file, model, x, y, zl, zu; objective = NaN, status = "")The same, for a model built by opf_model: the variable and constraint handles and the formulation are read from the model. This is the form a compiled library carries; see compile_all.
ExaModelsPower.write_matpower_solution — Method
write_matpower_solution(out, case_file, vars, cons, x, y, zl, zu;
form = Polar(), objective = NaN, status = "")Write the OPF solution x of the model opf_model(case_file; form) as a solved MATPOWER case to out (a path or an IO), for form = Polar(), Rect() or DC().
vars and cons are the variable and constraint handles opf_model returns, y the constraint multipliers, and zl, zu the lower and upper bound multipliers, with Ipopt's signs (L = f + yᵀg, zl, zu ≥ 0).
The output is case_file with, in MATPOWER's units and column order:
bus:VM,VA(degrees) updated;LAM_P,LAM_Q(/MWh, /MVArh per hour of objective),MU_VMAX,MU_VMIN(per p.u.) appended;gen:PG,QG(MW, MVAr) andVGupdated;MU_PMAX,MU_PMIN,MU_QMAX,MU_QMIN(per MW, per MVAr) appended;branch:PF,QF,PT,QT(MW, MVAr),MU_SF,MU_ST(per MVA),MU_ANGMIN,MU_ANGMAX(per degree) appended.
For DC(), as in MATPOWER's DC OPF, VM is 1, the reactive quantities and their multipliers are 0, PT = -PF, and MU_SF, MU_ST are the multipliers of the flow limit in the from-to and to-from direction.
Out-of-service generators and branches get zeros, as in MATPOWER. Everything else in the file is kept as it was, and objective and status go into a comment at the top.
ExaModelsPower.write_violations — Method
write_violations(out, case_file, model, x, y, zl, zu; objective = NaN, status = "")Write opf_violations(model, x) to out as CSV, one group,violation row per group. The signature of a solution writer, so that a compiled library carries it; see compile_all. case_file, the multipliers, objective and status are not used.