Skip to content

Conversation

@nkoukpaizan
Copy link
Collaborator

@nkoukpaizan nkoukpaizan commented Nov 24, 2025

Description

This adds the ability to run PhasorDynamics examples with sparse Jacobian. The component Jacobians are obtained with Enzyme and assembled into the system Jacobian.

cc @lukelowry @abirchfield

Proposed changes

  • Added missing Jacobian block terms such as $\partial f/\partial y'$, $\partial h/\partial y$ and $\partial f/\partial w_b$
  • Added verification in the unit tests for the $\partial f/\partial y'$ terms
  • Multiple bug fixes

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.
  • I have updated CHANGELOG.md to reflect the changes in this PR. If this is a minor PR that is part of a larger fix already included in the file, state so.

Further comments

This is still using COO_Matrix. I suggest we merge #307 and re-use Jacobian assembly.

Comparison plots between current (sparse Jacobians) and reference (dense Jacobians computed by IDA with finite differences)

ThreeBus_Basic
Example_ThreeBus_Basic_results

ThreeBus_Classical
Example_ThreeBus_Classical_results

TenGenGenrou
TenGenGenrou_Results

TenGenGenClassical
TenGenClassical_results

@nkoukpaizan nkoukpaizan self-assigned this Nov 24, 2025
@nkoukpaizan nkoukpaizan force-pushed the nicholson/sim-with-sparse-jac branch 2 times, most recently from f80e836 to 8a6ddd0 Compare December 18, 2025 21:48
@nkoukpaizan nkoukpaizan force-pushed the nicholson/sim-with-sparse-jac branch 4 times, most recently from 05e2ddb to 3285026 Compare December 22, 2025 16:46
@nkoukpaizan nkoukpaizan marked this pull request as ready for review December 22, 2025 18:47
Comment on lines +181 to +182
sys.evaluateResidual();
sys.evaluateJacobian();
Copy link
Collaborator

Choose a reason for hiding this comment

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

These calls should not be made here. Evaluating residual and Jacobian should be done by the numerical integrator only, not a user code.

Suggested change
sys.evaluateResidual();
sys.evaluateJacobian();

Comment on lines +99 to +101
sys.initialize();
sys.evaluateResidual();
sys.evaluateJacobian();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since this is a workaround we should either hide these lines in SystemModel or comment them as temporary.

Comment on lines +79 to +81
sys.initialize();
sys.evaluateResidual();
sys.evaluateJacobian();
Copy link
Collaborator

Choose a reason for hiding this comment

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

See earlier comments. Allocating and initializing system here is ok but evaluating residual and Jacobian may be confusing for the user.

@nkoukpaizan nkoukpaizan force-pushed the nicholson/sim-with-sparse-jac branch from 0a47f42 to ad67082 Compare January 8, 2026 22:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: IDA::initializeSimulation errors if t0 is too close to 0.1 and findConsistent is set to true

3 participants