Reactive power control loops #381
Draft
jd-lara wants to merge 14 commits into
Draft
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds discrete reactive-control support for AC power flow, centered on voltage-controlling tap transformers and switched shunts via an outer λ-continuation loop, while also including solver-performance and robustness refactors.
Changes:
- Adds
ControlledDeviceSet, controlled tap/shunt metadata extraction, continuation control, snapping/restoration, and public wiring through AC power-flow types andPowerFlowData. - Refactors AC/DC solver internals for lower allocation, including AC Jacobian structure caching, DC scratch typing, LM scratch buffers, and residual/Jacobian function-field removal.
- Updates robust homotopy, Cholesky, trust-region/Iwamoto logic, documentation, and regression tests.
Reviewed changes
Copilot reviewed 26 out of 26 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
src/discrete_control/controlled_devices.jl |
Defines controlled device types, parameter application, and discrete snapping. |
src/discrete_control/control_metadata.jl |
Builds controlled devices from PSY system metadata. |
src/discrete_control/control_continuation.jl |
Implements the outer λ-continuation, probing, stepping, snapping, and restore flow. |
src/definitions.jl |
Adds discrete-control constants. |
src/PowerFlows.jl |
Exports and includes the new discrete-control subsystem. |
src/PowerFlowData.jl |
Stores controlled device sets on power-flow data and wires construction. |
src/power_flow_types.jl |
Adds control_discrete_devices to AC formulations. |
src/solve_ac_power_flow.jl |
Routes AC solves through Q-limit or discrete-control paths. |
src/solve_dc_power_flow.jl |
Refactors DC scratch/cache usage and solve workers. |
src/ac_power_flow_residual.jl |
Removes stored residual function field. |
src/ac_power_flow_jacobian.jl |
Removes stored Jacobian function field and adds Jacobian structure caching. |
src/rectangular_ci_power_flow_residual.jl |
Removes stored residual function field and updates comments. |
src/rectangular_ci_power_flow_jacobian.jl |
Removes stored Jacobian function field. |
src/mixed_cpb_power_flow_residual.jl |
Removes stored residual function field. |
src/mixed_cpb_power_flow_jacobian.jl |
Removes stored Jacobian function field. |
src/power_flow_method.jl |
Updates trust-region dogleg scratch use and generalizes Iwamoto multiplier. |
src/levenberg-marquardt.jl |
Adds LM scratch buffers to reduce allocations. |
src/RobustHomotopy/homotopy_hessian.jl |
Optimizes homotopy Hessian/gradient assembly. |
src/RobustHomotopy/HessianSolver/cholesky_solver.jl |
Uses CHOLMOD success status for PD checks. |
docs/src/explanation/discrete_control.md |
Adds discrete-control explanation and metadata documentation. |
docs/make.jl |
Adds the new documentation page to the docs navigation. |
test/test_discrete_control.jl |
Adds discrete-control unit and integration coverage. |
test/test_utils/common.jl |
Adds test systems for tap/shunt control scenarios. |
test/test_iterative_methods.jl |
Adds/updates Iwamoto multiplier tests. |
test/test_homotopy_hessian.jl |
Adds intermediate-t homotopy Hessian regression coverage. |
test/test_ac_nr_allocations.jl |
Adds allocation regression tests for AC Jacobian and DC reuse paths. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+111
to
+114
| function apply_parameter!(d::ControlledSwitchedShunt, data, b::Float64, ts::Int) | ||
| data.bus_active_power_constant_impedance_withdrawals[d.bus_ix, ts] = d.g0 | ||
| data.bus_reactive_power_constant_impedance_withdrawals[d.bus_ix, ts] = -b | ||
| d.current = b |
Comment on lines
+116
to
+117
| The outer loop `_control_continuation!` runs up to | ||
| `MAX_CONTROL_OUTER_ITERATIONS = 20` passes. Each pass: |
Comment on lines
+126
to
+133
| **Under-relaxation.** The factor $\omega$ is chosen so the local iteration-map | ||
| slope magnitude is at most `CONTROL_CONTRACTION = 0.7`. The closed-loop slope | ||
| is bounded by $|h - \ell| \cdot S/4 \cdot |\partial|V|/\partial p|$ (the | ||
| maximum sigmoid derivative times the plant gain), giving | ||
|
|
||
| $$\omega \leq \frac{1 + \theta}{1 + |g'|}$$ | ||
|
|
||
| where $\theta = 0.7$ is the contraction target and $g'$ is the closed-loop |
Comment on lines
+64
to
+66
| else | ||
| apply_parameter!(d, data, reached, ts) | ||
| step /= 2.0 |
Comment on lines
+229
to
+230
| else | ||
| step /= 2.0 |
Comment on lines
+38
to
+40
| apply_parameter!(d, data, p0, ts) | ||
| ok2 = _solve_with_q_limits!(pf, data, ts; kwargs...) | ||
| reliable = ok1 && ok2 && h != 0.0 |
Comment on lines
+66
to
+70
| For `ControlledTap`, `apply_parameter!` rewrites four `nzval` entries of the | ||
| sparse Y-bus in place using cached linear offsets (`nz_offsets::NTuple{4,Int}`) | ||
| resolved once at device-set construction. The delta update | ||
| `nzval[k] += Y_new − Y_old` preserves any parallel-branch contributions already | ||
| in the shared slot; `d.current` (not the lossy `nzval`) is the authoritative |
Contributor
Performance ResultsPrecompile Time
Solve TimePolar AC
Rectangular CI
Mixed CPB
DC
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR implements the homotopy approach Agarwal's paper and also improvements to handle the outer loop reactive power limits check.