Skip to content

Experimental OPF Implementation - #594

Merged
nkoukpaizan merged 23 commits into
developfrom
lukel/OPF-NEW-dev
Oct 29, 2026
Merged

nkoukpaizan merged 23 commits into
developfrom
lukel/OPF-NEW-dev

Conversation

@lukelowry

@lukelowry lukelowry commented Sep 28, 2026 •

Copy link
Copy Markdown
Collaborator

Description

AC optimal power flow module (OptimalPowerFlow) solved with Ipopt using exact sparse derivatives from Enzyme. It follows the PhasorDynamics structure (OptimizationEvaluator -> Component -> SystemModel) and uses the same JSON case format. Scope is ACOPF only, coupling with PhasorDynamics will be a separate PR.

  • Components: Bus, Branch, Generator, Load (Cartesian voltages)
  • Solver: SteadyState::IpoptInterface
  • Example: EconomicDispatch, tested against PYPOWER costs for IEEE39, Hawaii, and ACTIVSg2000

Checklist

  • All tests pass.
  • Code compiles cleanly with flags -Wall -Wpedantic -Wconversion -Wextra.
  • The new code follows GridKit™ style guidelines.
  • There are unit tests for the new code.
  • The new code is documented.
  • The feature branch is rebased with respect to the target branch.
  • The CHANGELOG.md has been updated to reflect the changes. If this is a minor PR that is part of a larger fix already included in the file, state so.

Further comments

I can remove the large new OPF formatted cases if needed.

@pelesh

pelesh commented Sep 28, 2026

Copy link
Copy Markdown
Collaborator

A few comments:

  • If you have JSON input parser already available, I suggest you use that instead of MATPOWER format. I was thinking you could use some of the existing power flow implementation, but since you took a different route, I suggest you ditch MATPOWER and go straight to JSON.
  • I would have optimal power flow app in EconomicDispatch subdirectory in examples directory, at the same level as PhasorDynamics.
  • I would rename Optimization/OptimizationProblem.*pp files (and the class within) into Optimization/SteadyState.*pp. We will likely have Multiperiod and MixedInteger as new optimization modules in the future.

@pelesh
pelesh requested a review from abirchfield September 28, 2026 18:22
@lukelowry

lukelowry commented Sep 28, 2026 •

Copy link
Copy Markdown
Collaborator Author

@pelesh I changed it so it uses the PowerFlow parser with very few changes. I do believe its valuable to have that as the input format only because it makes validation easier and there is practically unlimited data in .m, and OPF data does not always come with dynamic case files.

I believed I addressed your other issues too. I am able to use the example app to change the objective/model, solve for new operating point, and start simulation in steady state at that new point!

@lukelowry
lukelowry force-pushed the lukel/OPF-NEW-dev branch 4 times, most recently from 95913b8 to 5c4fb92 Compare October 10, 2026 21:02

@pelesh pelesh left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very nice work. I suggest limiting the scope of this PR to providing ACOPF module only. Imho, the integration with dynamic simulations modules should be done after ACOPF is tested and input file format specified.

@superwhiskers superwhiskers left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tests pass on my end. i think it works quite well, but there are a few implementation questions we should sort out before this moves forward.

additionally, if we are to continue with matpower, are we intending to handle capability curves for generators or the convention of a dispatchable load as a generator with negative real-power injection? if they are outside the intended scope, could we reject them and document that limitation?

i think these conventions, particularly the latter, strengthen the argument for going with our own format, as using an existing format such as matpower requires us to adhere to its conventions, which may not be desirable.

Comment thread examples/OptimalPowerFlow/EconomicDispatch/EconomicDispatch.cpp Outdated
Comment thread GridKit/AutomaticDifferentiation/Enzyme/CooEntries.hpp Outdated
Comment thread GridKit/AutomaticDifferentiation/Enzyme/D2LDx2.hpp Outdated
Comment thread GridKit/AutomaticDifferentiation/Enzyme/D2LDx2.hpp Outdated
Comment thread GridKit/AutomaticDifferentiation/Enzyme/D2LDx2.hpp Outdated
Comment thread GridKit/AutomaticDifferentiation/Enzyme/LowerSparseStorage.hpp Outdated
Comment thread GridKit/Model/OptimalPowerFlow/Branch/Branch.hpp Outdated
Comment thread GridKit/Model/OptimalPowerFlow/Branch/Branch.hpp Outdated
Comment thread tests/UnitTests/OptimalPowerFlow/ComponentTests.hpp Outdated
Comment thread GridKit/Model/OptimalPowerFlow/SystemModelData.cpp Outdated

@nkoukpaizan nkoukpaizan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall nice work! The component implementations are clear and I like the consolidated ComponentModelImpl.hpp.

A few comments:

  • For Enzyme, can we re-use some of the existing boilerplate for LowerSparseStorage and use buffers instead of CooEntries wrapping std::vector)? Feel free to amend the wrappers.
  • Can we bind GridKit::LinearAlgebra::Vector at the component level instead of std::vector? This could be a follow-up PR.
  • Several methods, e.g., in OptimizationEvaluator* and SteadyState* don't have a Doxygen documentation.

Comment thread tests/UnitTests/OptimalPowerFlow/ComponentTests.hpp Outdated
Comment thread tests/UnitTests/CMakeLists.txt Outdated
Comment thread tests/UnitTests/OptimalPowerFlow/SystemTests.hpp Outdated
Comment thread GridKit/Model/OptimalPowerFlow/SystemModelData.cpp Outdated
Comment thread tests/UnitTests/OptimalPowerFlow/ComponentTests.hpp Outdated
Comment thread tests/UnitTests/OptimalPowerFlow/SystemTests.hpp Outdated
Comment thread GridKit/Model/PowerFlow/MatpowerParser.hpp

@pelesh pelesh left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks very good and has clean component model structure. Main issues that I would raise are:

  • Separating equality and inequality constraint evaluation methods.
  • Selection of coordinates polar vs. Cartesian.
  • Inheritance patterns should mirror PhasorDynamics module. If we want to change it, then the change should made be across the GridKit modules.

Comment thread GridKit/AutomaticDifferentiation/Enzyme/CooEntries.hpp Outdated
Comment thread GridKit/Model/OptimalPowerFlow/Branch/Branch.hpp
Comment thread GridKit/Model/OptimalPowerFlow/Branch/BranchImpl.hpp Outdated
Comment thread GridKit/Model/OptimalPowerFlow/ComponentModel.hpp Outdated
Comment thread GridKit/Model/OptimalPowerFlow/SystemModelImpl.hpp Outdated
Comment thread GridKit/Solver/Optimization/SteadyState.cpp Outdated
Comment thread GridKit/Solver/Optimization/SteadyState.hpp Outdated
Comment thread GridKit/Model/OptimalPowerFlow/Component.hpp Outdated
Comment thread GridKit/Model/OptimalPowerFlow/SystemModel.hpp Outdated
Comment thread GridKit/Model/OptimizationEvaluator.hpp Outdated
@lukelowry

Copy link
Copy Markdown
Collaborator Author

Thank you all for detailed review, I believe I have addressed all except a distinct few. I will go response by response soon, but the overall design is overall more consistent with PhasorDynamics except for the inheritance structure. I am considering removing the larger ACTIVSg2000 case until after this is merged, please let me know what you think.

@lukelowry
lukelowry requested a review from pelesh October 18, 2026 13:40

@superwhiskers superwhiskers left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some further changes since i looked a little closer at the ipopt interface code

Comment thread GridKit/AutomaticDifferentiation/Enzyme/LowerSparseStorage.hpp Outdated
Comment thread GridKit/Model/OptimalPowerFlow/Bus/BusData.hpp Outdated
Comment thread GridKit/Model/OptimalPowerFlow/SystemModelImpl.hpp
Comment thread GridKit/Model/OptimizationEvaluator.hpp
Comment thread GridKit/Solver/Optimization/IpoptInterface.cpp
Comment thread GridKit/Solver/Optimization/IpoptInterface.cpp Outdated
@lukelowry lukelowry changed the title Experimental OPF Implementation using MATPOWER Input Experimental OPF Implementation Oct 20, 2026
@read-the-docs-community

read-the-docs-community Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Documentation build overview

📚 GridKit | 🛠️ Build #35486724 | 📁 Comparing dafe4e8 against latest (4315301)

  🔍 Preview build  

190 files changed · + 102 added · ± 77 modified · - 11 deleted

+ Added

± Modified

- Deleted

@lukelowry

Copy link
Copy Markdown
Collaborator Author

I have adjusted so that OPF now follows same inheritance of PhasorDynamics. Once again, thank you for the invaluable feedback. I have taken great care to touch existing files very little! Nearly ready.

@lukelowry
lukelowry force-pushed the lukel/OPF-NEW-dev branch 3 times, most recently from 86a079b to 0b5b3a4 Compare October 26, 2026 15:27
@lukelowry

Copy link
Copy Markdown
Collaborator Author

Addressed!

@nkoukpaizan nkoukpaizan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! I'll wait for a rebase before merging to make sure there's no interference from #632.

@lukelowry

Copy link
Copy Markdown
Collaborator Author

Rebased! thanks so much

@lukelowry

Copy link
Copy Markdown
Collaborator Author

Is it in play to get this merged today?

@nkoukpaizan
nkoukpaizan merged commit 94c9766 into develop Oct 29, 2026
7 checks passed
@superwhiskers
superwhiskers deleted the lukel/OPF-NEW-dev branch October 29, 2026 19:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants