Skip to content

Comments

Refactor Jacobian assembly#339

Merged
pelesh merged 15 commits intodevelopfrom
kakeru/csr-jac
Feb 19, 2026
Merged

Refactor Jacobian assembly#339
pelesh merged 15 commits intodevelopfrom
kakeru/csr-jac

Conversation

@kakeueda
Copy link
Collaborator

@kakeueda kakeueda commented Feb 13, 2026

Description

Jacobian assembly currently uses a COO matrix, and we sort and rebuild CSR row pointers each step for IDA. The overhead from this process can become a bottleneck as nnz grows. This change keeps the system Jacobian in CSR and preserves a COO→CSR mapping for direct CSR updates.

Closes #301

cc @nkoukpaizan

Proposed changes

  • Store the system Jacobian in CSR format in PowerElectronicsModel.
  • Update allocate() to populate CSR entries and preserve the mapping.
  • Add CsrJac for the solver configuration (PhasorDynamics still uses the Jac function).

Currently PowerElectronics only.

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.
  • [N/A] 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.

@kakeueda kakeueda self-assigned this Feb 14, 2026
@kakeueda
Copy link
Collaborator Author

kakeueda commented Feb 16, 2026

Timed runSimulation(t_final) in the microgrid app. CSR assembly improved runtime, while the error remained unchanged.

Before
Screenshot 2026-02-16 083255

After
Screenshot 2026-02-16 083351

Copy link
Collaborator

@shakedregev shakedregev left a comment

Choose a reason for hiding this comment

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

Still need to test this. Looks good except for naming inconsistencies.

Copy link
Collaborator

@shakedregev shakedregev left a comment

Choose a reason for hiding this comment

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

Approved pending fixes to variable names

@shakedregev
Copy link
Collaborator

Timed runSimulation(t_final) in the microgrid app. CSR assembly improved runtime, while the error remained unchanged.

Before Screenshot 2026-02-16 083255

After Screenshot 2026-02-16 083351

@shakedregev shakedregev reopened this Feb 16, 2026
@shakedregev
Copy link
Collaborator

It's impressive that there are such substantial speed gains on even a small system. This means that for real systems it's probably astronomical. I wonder if we can test that.

Copy link
Collaborator

@pelesh pelesh left a comment

Choose a reason for hiding this comment

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

  • CSR matrix implementation should remain in the *.cpp file.
  • I would avoid using STL containers here because we want to prototype parallel implementations.
  • Do not use existing COO matrix implementation in GridKit. If needed, port COO matrix from Re::Solve.

I made some other (mostly nitpicking) comments about the code.

@pelesh pelesh marked this pull request as draft February 16, 2026 23:13
@pelesh pelesh marked this pull request as ready for review February 19, 2026 00:34
@pelesh pelesh marked this pull request as draft February 19, 2026 00:48
@pelesh pelesh marked this pull request as ready for review February 19, 2026 05:12
@pelesh pelesh requested a review from nkoukpaizan February 19, 2026 05:12
Copy link
Collaborator

@nkoukpaizan nkoukpaizan left a comment

Choose a reason for hiding this comment

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

Excellent work!

I only have a few minor comments.

One last thing is that there are some calls to sysmodel.getJacobian().printMatrix() in examples/PowerElectronics that will no longer be effective. It would be good to update to print the CSR matrix instead. We can always updated again when we remove the temporary getCsrJacobian method.

@pelesh pelesh added enhancement New feature or request help wanted Extra attention is needed examples labels Feb 19, 2026
@nkoukpaizan nkoukpaizan self-requested a review February 19, 2026 21:57
@pelesh pelesh merged commit 6830267 into develop Feb 19, 2026
6 checks passed
@kakeueda kakeueda deleted the kakeru/csr-jac branch February 20, 2026 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request examples help wanted Extra attention is needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement analysis in SystemModelPowerElectronics class to compute system Jacobian sparsity pattern

4 participants