pwrs.corex.mpoption#
- class pwrs.corex.mpoption.PfNrConfig(max_it: int = 10, lin_solver: str = '')[source]#
Bases:
DataclassDictMixin- Parameters:
max_it (int)
lin_solver (str)
- class pwrs.corex.mpoption.PfFdConfig(max_it: int = 30)[source]#
Bases:
DataclassDictMixin- Parameters:
max_it (int)
- class pwrs.corex.mpoption.PfGsConfig(max_it: int = 1000)[source]#
Bases:
DataclassDictMixin- Parameters:
max_it (int)
- class pwrs.corex.mpoption.PfRadialConfig(max_it: int = 20, vcorr: Literal[0, 1] = 0)[source]#
Bases:
DataclassDictMixin- Parameters:
max_it (int)
vcorr (Literal[0, 1])
- class pwrs.corex.mpoption.PfConfig(alg='NR', current_balance=0, v_cartesian=0, tol=1e-08, nr=<factory>, fd=<factory>, gs=<factory>, radial=<factory>, enforce_q_lims=0)[source]#
Bases:
DataclassDictMixinPower flow options.
- Parameters:
alg (PfAlg)
current_balance (PfCurrentBalance)
v_cartesian (PfVCartesian)
tol (float)
nr (PfNrConfig)
fd (PfFdConfig)
gs (PfGsConfig)
radial (PfRadialConfig)
enforce_q_lims (PfEnforceQLims)
- alg#
AC power flow algorithm. Default is
"NR". -"NR": Newton’s method (formulation depends oncurrent_balanceandv_cartesian) -"NR-SP": Newton’s method (power mismatch, polar) -"NR-SC": Newton’s method (power mismatch, cartesian) -"NR-SH": Newton’s method (power mismatch, hybrid) -"NR-IP": Newton’s method (current mismatch, polar) -"NR-IC": Newton’s method (current mismatch, cartesian) -"NR-IH": Newton’s method (current mismatch, hybrid) -"FDXB": Fast-Decoupled (XB version) -"FDBX": Fast-Decoupled (BX version) -"GS": Gauss-Seidel -"PQSUM": Power Summation method (radial networks only) -"ISUM": Current Summation method (radial networks only) -"YSUM": Admittance Summation method (radial networks only)- Type:
PfAlg
- current_balance#
Type of nodal balance equation. Default is
0. -0: use complex power balance equations -1: use complex current balance equations- Type:
PfCurrentBalance
- v_cartesian#
Voltage representation. Default is
0. -0: bus voltage variables represented in polar coordinates -1: bus voltage variables represented in cartesian coordinates -2: hybrid, polar updates computed via modified cartesian Jacobian- Type:
PfVCartesian
- tol#
Termination tolerance on per-unit P & Q mismatch. Default is
1e-8.- Type:
float
- nr#
Newton method options. -
max_it(int): maximum number of iterations for Newton’s method (default10) -lin_solver(str): linear solver passed to MPLINSOLVE for Newton update step (default"") -"": default to""for small systems,"LU3"for larger ones -"": built-in backslash operator -"LU": explicit default LU decomposition and back substitution -"LU3": 3-output LU, Gilbert-Peierls with AMD reordering -"LU4": 4-output LU, UMFPACK solver (same as"LU") -"LU5": 5-output LU, UMFPACK solver with row scaling- Type:
- fd#
Fast-decoupled method options. -
max_it(int): maximum number of iterations (default30)- Type:
- gs#
Gauss-Seidel method options. -
max_it(int): maximum number of iterations (default1000)- Type:
- radial#
Radial power flow method options. -
max_it(int): maximum number of iterations (default20) -vcorr(Literal[0, 1]): perform voltage correction procedure (default0) -0: do not perform voltage correction -1: perform voltage correction- Type:
- enforce_q_lims#
Enforce generator reactive power limits at expense of
|V|. Default is0. -0: do not enforce limits -1: enforce limits with simultaneous bus type conversion -2: enforce limits with one-at-a-time bus type conversion- Type:
PfEnforceQLims
- class pwrs.corex.mpoption.CpfPlotConfig(level: CpfPlotLevel = 0, bus: list[int] = <factory>)[source]#
Bases:
DataclassDictMixin- Parameters:
level (CpfPlotLevel)
bus (list[int])
- class pwrs.corex.mpoption.CpfConfig(parameterization=3, stop_at='NOSE', enforce_p_lims=0, enforce_q_lims=0, enforce_v_lims=0, enforce_flow_lims=0, step=0.05, adapt_step=0, step_min=0.0001, step_max=0.2, adapt_step_damping=0.7, adapt_step_tol=0.001, target_lam_tol=1e-05, nose_tol=1e-05, p_lims_tol=0.01, q_lims_tol=0.01, v_lims_tol=0.0001, flow_lims_tol=0.01, plot=<factory>, user_callback=None)[source]#
Bases:
DataclassDictMixinContinuation power flow options.
Attributes: parameterization (CpfParameterization): Choice of parameterization. Default is
3.1: natural2: arc length3: pseudo arc length
- stop_at (CpfStopAt): Determines stopping criterion. Default is
"NOSE". "NOSE": stop when nose point is reached"FULL": trace full nose curvefloat: stop upon reaching specified target lambda value
- enforce_p_lims (CpfBinaryFlag): Enforce generator active power limits. Default is
0. 0: do not enforce limits1: enforce limits, simultaneous bus type conversion
- enforce_q_lims (CpfBinaryFlag): Enforce generator reactive power limits at expense of
|V|. Default is0. 0: do not enforce limits1: enforce limits, simultaneous bus type conversion
- enforce_v_lims (CpfBinaryFlag): Enforce bus voltage magnitude limits. Default is
0. 0: do not enforce limits1: enforce limits, termination on detection
- enforce_flow_lims (CpfBinaryFlag): Enforce branch flow MVA limits. Default is
0. 0: do not enforce limits1: enforce limits, termination on detection
step (float): Continuation power flow step size. Default is
0.05. adapt_step (CpfBinaryFlag): Toggle adaptive step size feature. Default is0.0: adaptive step size disabled1: adaptive step size enabled
step_min (float): Minimum allowed step size. Default is
1e-4. step_max (float): Maximum allowed step size. Default is0.2. adapt_step_damping (float): Damping factor for adaptive step sizing. Default is0.7. adapt_step_tol (float): Tolerance for adaptive step sizing. Default is1e-3. target_lam_tol (float): Tolerance for target lambda detection. Default is1e-5. nose_tol (float): Tolerance for nose point detection in p.u. Default is1e-5. p_lims_tol (float): Tolerance for generator active power limit enforcement in MW. Default is0.01. q_lims_tol (float): Tolerance for generator reactive power limit enforcement in MVAR. Default is0.01. v_lims_tol (float): Tolerance for bus voltage magnitude enforcement in p.u. Default is1e-4. flow_lims_tol (float): Tolerance for line MVA flow enforcement in MVA. Default is0.01. plot (CpfPlotConfig): Nose curve plotting options.level(CpfPlotLevel): control plotting of nose curve (default0)0: do not plot nose curve1: plot when completed2: plot incrementally at each iteration3: same as2, with pause at each iterationbus(list[int]): index of bus whose voltage is to be plotted (default empty)
- user_callback (object | None): User callback specification. Default is
None. May be a function name string, a struct-like object with function name and optional priority and/or args, or a list of such entries.
- Parameters:
parameterization (CpfParameterization)
stop_at (CpfStopAt)
enforce_p_lims (CpfBinaryFlag)
enforce_q_lims (CpfBinaryFlag)
enforce_v_lims (CpfBinaryFlag)
enforce_flow_lims (CpfBinaryFlag)
step (float)
adapt_step (CpfBinaryFlag)
step_min (float)
step_max (float)
adapt_step_damping (float)
adapt_step_tol (float)
target_lam_tol (float)
nose_tol (float)
p_lims_tol (float)
q_lims_tol (float)
v_lims_tol (float)
flow_lims_tol (float)
plot (CpfPlotConfig)
user_callback (object | None)
- class pwrs.corex.mpoption.OpfAcConfig(solver: OpfAcSolver = 'DEFAULT')[source]#
Bases:
DataclassDictMixin- Parameters:
solver (OpfAcSolver)
- class pwrs.corex.mpoption.OpfDcConfig(solver: OpfDcSolver = 'DEFAULT')[source]#
Bases:
DataclassDictMixin- Parameters:
solver (OpfDcSolver)
- class pwrs.corex.mpoption.OpfSoftlimsConfig(default: OpfSoftlimsDefault = 1)[source]#
Bases:
DataclassDictMixin- Parameters:
default (OpfSoftlimsDefault)
- class pwrs.corex.mpoption.OpfPowerModelsConfig(formulation: PowerModelsFormulation = 'ACP', solver: PowerModelsSolver = 'DEFAULT', extensions: tuple[object, ...]=(), highs_options: dict[str, object]=<factory>, glpk_options: dict[str, object]=<factory>, clarabel_options: dict[str, object]=<factory>, scs_options: dict[str, object]=<factory>, mosek_options: dict[str, object]=<factory>)[source]#
Bases:
DataclassDictMixin- Parameters:
formulation (PowerModelsFormulation)
solver (PowerModelsSolver)
extensions (tuple[object, ...])
highs_options (dict[str, object])
glpk_options (dict[str, object])
clarabel_options (dict[str, object])
scs_options (dict[str, object])
mosek_options (dict[str, object])
- class pwrs.corex.mpoption.OpfConfig(backend='MATPOWER', power_models=<factory>, ac=<factory>, dc=<factory>, current_balance=0, v_cartesian=0, violation=5e-06, use_vg=0, flow_lim='S', ignore_angle_lim=0, softlims=<factory>, init_from_mpc=-1, start=0, return_raw_der=0)[source]#
Bases:
DataclassDictMixinOptimal power flow options.
Attributes: backend (OpfBackend): OPF implementation. Default is
"MATPOWER"."MATPOWER": use the MATPOWER-compatible OPF path"POWER_MODELS": use the PowerModels-compatible formulation path
- power_models (OpfPowerModelsConfig): PowerModels backend configuration.
formulation: network formulation,"ACP","ACR","ACT","SOCWR","DCP","DCMP","NFA","DCPLL","LPACC","BFA","SOCBF","IVR","QCRM","QCLS","SOCWRCONIC","SOCBFCONIC","SDPWRM", or"SPARSESDPWRM"solver:"DEFAULT"selects by model capability, preferring HiGHS for LP/QP models, GLPK for LP fallback, and Ipopt for nonlinear models. Explicit"HIGHS","GLPK", and"IPOPT"selections do not fall back. Default is"DEFAULT".extensions: callable model extensions applied after formulation construction and before solver selection. Default is empty.highs_optionsandglpk_options: native solver option mappings.
- ac (OpfAcConfig): AC OPF solver options.
solver(OpfAcSolver): AC optimal power flow solver. Default is"DEFAULT"."DEFAULT": choose pwrs default AC solver, currently"MIPS""MIPS": Pwrs Interior Point Solver"FMINCON": MATLAB Optimization Toolboxfmincon"IPOPT": IPOPT interface"KNITRO": Artelys Knitro interface"MINOPF": MINOS-based MINOPF package"PDIPM": TSPOPF primal/dual interior point solver"SDPOPF": semidefinite-relaxation OPF solver"TRALM": trust-region augmented Lagrangian method
- dc (OpfDcConfig): DC OPF solver options.
solver(OpfDcSolver): DC optimal power flow solver. Default is"DEFAULT"."DEFAULT": choose based on availability, preferring commercial/open-source LP/QP solvers before"MIPS""MIPS": Pwrs Interior Point Solver"BPMPD": BPMPD interface"CLP": COIN-OR LP solver"CPLEX": IBM CPLEX"GLPK": GNU Linear Programming Kit"GUROBI": Gurobi optimizer"IPOPT": IPOPT interface"MOSEK": MOSEK interface"OSQP": OSQP interface"OT": MATLAB Optimization Toolboxquadprog/linprog
- current_balance (OpfCurrentBalance): Type of nodal balance equations. Default is
0. 0: use complex power balance equations1: use complex current balance equations
- v_cartesian (OpfVCartesian): Voltage representation. Default is
0. 0: bus voltage variables represented in polar coordinates1: bus voltage variables represented in cartesian coordinates
violation (float): Constraint violation tolerance. Default is
5e-6. use_vg (float): How generator voltage setpoints affect bus voltage bounds. Default is0.0: use busVminandVmaxonly, ignore generatorVg1: replace busVminandVmaxwith corresponding generatorVgvalues between
0and1: use a weighted blend of the two behaviors
- flow_lim (OpfFlowLim): Quantity constrained by branch flow limits. Default is
"S". "S": apparent power flow, in MVA"P": active power flow, in MW"2": squared active power flow, corresponding to MW limits"I": current magnitude, in MVA at 1 p.u. voltage
- ignore_angle_lim (OpfIgnoreAngleLim): Whether to ignore branch angle difference limits. Default is
0. 0: include angle limits when specified1: ignore angle limits even if present
- softlims (OpfSoftlimsConfig): Soft limit behavior.
default(OpfSoftlimsDefault): handling for soft limits without explicit settings. Default is1.0: do not include unspecified soft limits1: include unspecified soft limits using default values
- init_from_mpc (OpfInitFromMpc): Deprecated; use
startinstead. Default is-1. Controls whether the current MATPOWER case state initializes the OPF. -
-1: let MATPOWER decide based on solver/algorithm -0: do not use current case state -1: use current case state- start (OpfStart): OPF initialization strategy. Default is
0. 0: default; MATPOWER chooses based on solver1: ignore current case state and use solver-specific interior initialization2: use current MATPOWER case state3: solve a power flow first and use that solution
- return_raw_der (OpfReturnRawDer): For AC OPF, include raw constraint and derivative data in
results.raw. Default is0. 0: do not return raw derivative info1: returng,dg,dfandd2finresults.raw
- Parameters:
backend (OpfBackend)
power_models (OpfPowerModelsConfig)
ac (OpfAcConfig)
dc (OpfDcConfig)
current_balance (OpfCurrentBalance)
v_cartesian (OpfVCartesian)
violation (float)
use_vg (float)
flow_lim (OpfFlowLim)
ignore_angle_lim (OpfIgnoreAngleLim)
softlims (OpfSoftlimsConfig)
init_from_mpc (OpfInitFromMpc)
start (OpfStart)
return_raw_der (OpfReturnRawDer)
- class pwrs.corex.mpoption.OutLimConfig(all: OutLimAll = -1, v: OutLimDetail = 1, line: OutLimDetail = 1, pg: OutLimDetail = 1, qg: OutLimDetail = 1)[source]#
Bases:
DataclassDictMixin- Parameters:
all (OutLimAll)
v (OutLimDetail)
line (OutLimDetail)
pg (OutLimDetail)
qg (OutLimDetail)
- class pwrs.corex.mpoption.OutConfig(all=-1, sys_sum=1, area_sum=0, bus=1, branch=1, gen=0, lim=<factory>, force=0, suppress_detail=-1)[source]#
Bases:
DataclassDictMixinOutput options.
Attributes: all: Controls pretty-printing of results. Default is
-1.- Options:
-1: Individual flags control what prints.0: Do not print anything. Overrides individual flags, except for output written to files specified explicitly.1: Print everything. Overrides individual flags.
- sys_sum: Print system summary. Default is
1. - Options:
0: Do not print.1: Print.
- area_sum: Print area summaries. Default is
0. - Options:
0: Do not print.1: Print.
- bus: Print bus detail. Default is
1. - Options:
0: Do not print.1: Print.
- branch: Print branch detail. Default is
1. - Options:
0: Do not print.1: Print.
- gen: Print generator detail. Default is
0. - Options:
0: Do not print.1: Print.
- lim: Constraint/limit output configuration. Default is an
OutLimConfig. - Includes options for:
all: Overall control for constraint info output.-1: Individual limit flags control what prints.0: Do not print constraint info.1: Print binding constraint info only.2: Print all constraint info.
v: Voltage limit info.0: Do not print.1: Print binding constraints only.2: Print all constraints.
line: Line flow limit info, using the same options asv.pg: Generator active power limit info, using the same options asv.qg: Generator reactive power limit info, using the same options asv.
- force: Print results even if the success flag is
0. Default is0. - Options:
0: Do not force printing.1: Force printing.
- suppress_detail: Suppress all output except the system summary. Default is
-1. - Options:
-1: Suppress details automatically for large systems (more than 500 buses).0: Do not suppress any output enabled by other flags.1: Suppress all output except the system summary. Overrides individual flags, but notall = 1.
- Parameters:
all (OutAll)
sys_sum (Literal[0, 1])
area_sum (Literal[0, 1])
bus (Literal[0, 1])
branch (Literal[0, 1])
gen (Literal[0, 1])
lim (OutLimConfig)
force (Literal[0, 1])
suppress_detail (OutBinaryOrAuto)
- class pwrs.corex.mpoption.MipsScConfig(red_it: int = 20)[source]#
Bases:
DataclassDictMixin- Parameters:
red_it (int)
- class pwrs.corex.mpoption.MipsConfig(step_control=0, feastol=0, gradtol=1e-06, comptol=1e-06, costtol=1e-06, max_it=150, sc=<factory>, verbose=None, linsolver=None, cost_mult=None, xi=None, sigma=None, z0=None, alpha_min=None, rho_min=None, rho_max=None, mu_threshold=None, max_stepsize=None)[source]#
Bases:
DataclassDictMixinMIPS solver options.
- Parameters:
step_control (Literal[0, 1])
feastol (float)
gradtol (float)
comptol (float)
costtol (float)
max_it (int)
sc (MipsScConfig)
verbose (int | None)
linsolver (MipsLinsolver | None)
cost_mult (float | None)
xi (float | None)
sigma (float | None)
z0 (float | None)
alpha_min (float | None)
rho_min (float | None)
rho_max (float | None)
mu_threshold (float | None)
max_stepsize (float | None)
- step_control#
Enable step-size control. Default is
0. -0: disabled -1: enabled- Type:
Literal[0, 1]
- linsolver#
Linear system solver. Default is
"". -""or"\": default SciPy solve -"LU3"variants or"SUPERLU": SciPy SuperLU -"LU","LU4"/"LU5"variants or"UMFPACK": SuiteSparse UMFPACK -"PARDISO": Intel MKL PARDISO via PyPardiso -"KLU": SuiteSparse KLU via nbklu Missing optional solvers emit a warning and fall back to SciPy SuperLU.- Type:
MipsLinsolver
- feastol#
Feasibility (equality) tolerance. Default is
0. If0, it is set fromopf.violation.- Type:
float
- gradtol#
Gradient tolerance. Default is
1e-6.- Type:
float
- comptol#
Complementarity (inequality) tolerance. Default is
1e-6.- Type:
float
- costtol#
Optimality tolerance. Default is
1e-6.- Type:
float
- max_it#
Maximum number of iterations. Default is
150.- Type:
int
- sc#
Step-control options. -
red_it(int): maximum number of reductions per iteration when step control is enabled (default20)- Type:
- xi#
Constant used in alpha updates. Default is
None- Type:
float | None
- sigma#
Centering parameter. Default is
None- Type:
float | None
- z0#
Initial slack variable value. Default is
None- Type:
float | None
- alpha_min#
Numerical-failure threshold for alpha parameters. Default is
None- Type:
float | None
- rho_min#
Lower bound on
rho_t. Default isNone- Type:
float | None
- rho_max#
Upper bound on
rho_t. Default isNone- Type:
float | None
- mu_threshold#
KT multipliers below this value for non-binding constraints are forced to zero. Default is
None- Type:
float | None
- max_stepsize#
Numerical-failure threshold for the 2-norm of the reduced Newton step. Default is
None- Type:
float | None
- class pwrs.corex.mpoption.IpoptConfig(opts: dict[str, object]=<factory>, opt_fname: str = '', opt: int = 0)[source]#
Bases:
DataclassDictMixin- Parameters:
opts (dict[str, object])
opt_fname (str)
opt (int)
- class pwrs.corex.mpoption.FminconConfig(alg: FminconAlg = 4, tol_x: float = 0.0001, tol_f: float = 0.0001, max_it: int = 0, opts: dict[str, object]=<factory>)[source]#
Bases:
DataclassDictMixin- Parameters:
alg (FminconAlg)
tol_x (float)
tol_f (float)
max_it (int)
opts (dict[str, object])
- class pwrs.corex.mpoption.KnitroConfig(tol_x: float = 0.0001, tol_f: float = 0.0001, maxit: int = 0, opts: dict[str, object]=<factory>, opt_fname: str = '', opt: int = 0)[source]#
Bases:
DataclassDictMixin- Parameters:
tol_x (float)
tol_f (float)
maxit (int)
opts (dict[str, object])
opt_fname (str)
opt (int)
- class pwrs.corex.mpoption.SysWideZipLoadsConfig(pw: tuple[float, float, float] | None = None, qw: tuple[float, float, float] | None = None)[source]#
Bases:
DataclassDictMixin- Parameters:
pw (tuple[float, float, float] | None)
qw (tuple[float, float, float] | None)
- class pwrs.corex.mpoption.ExpConfig(sys_wide_zip_loads: pwrs.corex.mpoption.SysWideZipLoadsConfig = <factory>)[source]#
Bases:
DataclassDictMixin- Parameters:
sys_wide_zip_loads (SysWideZipLoadsConfig)
- class pwrs.corex.mpoption.MatpowerConfig(v=21, model='AC', pf=<factory>, cpf=<factory>, opf=<factory>, verbose=1, out=<factory>, mips=<factory>, exp=<factory>, fmincon=<factory>, ipopt=<factory>, knitro=<factory>)[source]#
Bases:
DataclassDictMixinMATPOWER options struct.
- Parameters:
v (int)
model (ModelType)
pf (PfConfig)
cpf (CpfConfig)
opf (OpfConfig)
verbose (VerboseLevel)
out (OutConfig)
mips (MipsConfig)
exp (ExpConfig)
fmincon (FminconConfig)
ipopt (IpoptConfig | None)
knitro (KnitroConfig)
- v#
version number of MATPOWER options struct
- Type:
int
- verbose#
- Type:
VerboseLevel
- model#
AC vs. DC power flow model. Default is
AC. -AC: use nonlinear AC model & corresponding algorithms/options -DC: use linear DC model & corresponding algorithms/options- Type:
ModelType
- mips#
MIPS-specific options
- Type:
- fmincon#
options for MATLAB Optimization Toolbox
fmincon- Type:
- ipopt#
options for IPOPT solver, used when ‘opf.ac.solver’ or ‘opf.dc.solver’ is set to ‘IPOPT’
- Type:
- knitro#
options for the Artelys Knitro solver
- Type:
- pwrs.corex.mpoption.mpoption(*args)[source]#
Create or modify a MATPOWER options dict.
This function preserves the MATPOWER
mpoptioninterface, supporting default construction, overrides by name/value pairs, merging from an existing options dict, and conversion to or from the legacy numeric options vector form.However, for type safety, we recommend using the native Python interface by constructing and modifying a
MatpowerConfigdataclass directly. The legacy interface is still supported for compatibility, but it is more error-prone and less efficient than using the dataclass API.- Parameters:
*args (Any) – MATPOWER option inputs. To create a default options dict, call with no arguments:
mpoption(). To modify an existing options dict, use name/value pairs:mpoption(existing_opt, 'name', value, ...). The first argument may also be an existing options dict to merge with, or an old-style numeric options vector to convert from.- Returns:
The resulting MATPOWER options struct.
- Return type: