Skip to content

Reuse CSR pattern in PhasorDynamics system Jacobian#342

Merged
pelesh merged 11 commits intodevelopfrom
nicholson/phasor-dynamics-save-csr
Feb 24, 2026
Merged

Reuse CSR pattern in PhasorDynamics system Jacobian#342
pelesh merged 11 commits intodevelopfrom
nicholson/phasor-dynamics-save-csr

Conversation

@nkoukpaizan
Copy link
Collaborator

@nkoukpaizan nkoukpaizan commented Feb 23, 2026

Description

This adapts the approach to reuse system Jacobian CSR pattern, introduced in #339 for PowerElectronics, to PhasorDynamics.

Proposed changes

  • Updated the PhasorDynamics system model to reuse the CSR Jacobian pattern.
  • Updated IDA interface to remove the temporary CsrJac function.

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 only touches the system-level Jacobians. I'll follow up with a PR that changes the component-level Jacobians.

@nkoukpaizan nkoukpaizan requested a review from pelesh February 23, 2026 21:47
@nkoukpaizan nkoukpaizan self-assigned this Feb 23, 2026
@nkoukpaizan nkoukpaizan added the enhancement New feature or request label Feb 23, 2026
@nkoukpaizan nkoukpaizan requested a review from kakeueda February 23, 2026 21:48
@nkoukpaizan nkoukpaizan marked this pull request as ready for review February 23, 2026 21:48
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.

The code executes correctly. On my machine I get Hawaii case to run in 6.8s compared to 8.4s before, so we are going in the right direction.

I made a couple of nitpicking comments, but I think this is ready to be merged.

Comment on lines +327 to +328
printf("%lu : %e \n", i, fres[i]);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider using iostream here:

Suggested change
printf("%lu : %e \n", i, fres[i]);
}
std::cout << i << " : " << << std::scientifi << fres[i] << "\n";
}

Comment on lines 6 to 10
#include <GridKit/LinearAlgebra/SparseMatrix/COO_Matrix.hpp>
#include <GridKit/LinearAlgebra/SparseMatrix/CooMatrix.hpp>
#include <GridKit/LinearAlgebra/SparseMatrix/CsrMatrix.hpp>
#include <GridKit/Model/VariableMonitor.hpp>
#include <GridKit/ScalarTraits.hpp>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need to include matrix header here? Could we use forward declarations instead?

Suggested change
#include <GridKit/LinearAlgebra/SparseMatrix/COO_Matrix.hpp>
#include <GridKit/LinearAlgebra/SparseMatrix/CooMatrix.hpp>
#include <GridKit/LinearAlgebra/SparseMatrix/CsrMatrix.hpp>
#include <GridKit/Model/VariableMonitor.hpp>
#include <GridKit/ScalarTraits.hpp>
#include <GridKit/LinearAlgebra/SparseMatrix/COO_Matrix.hpp>
#include <GridKit/Model/VariableMonitor.hpp>
#include <GridKit/ScalarTraits.hpp>
namespace GridKit
{
namespace LinearAlgebra
{
template <typename RealT, typename IdxT>
class CsrMatrix<RealT, IdxT>;
template <typename RealT, typename IdxT>
class CooMatrix<RealT, IdxT>;
}
}

@pelesh
Copy link
Collaborator

pelesh commented Feb 23, 2026

CC @lukelowry @abirchfield

Copy link
Collaborator

@kakeueda kakeueda left a comment

Choose a reason for hiding this comment

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

Enzyme isn't enabled on my machine yet so I haven't evaluated speedup, but it looks good to me.

@pelesh pelesh merged commit d8128ce into develop Feb 24, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants