Skip to content

Verify Branch and Load Jacobians computed with Sparse::Variable #89

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from

Conversation

nkoukpaizan
Copy link
Collaborator

@nkoukpaizan nkoukpaizan commented Apr 22, 2025

Description

This adds tests for Branch and Load Jacobians.

Proposed changes

Added a Jacobian test for BranchTest and LoadTest. Using Gridkit::Sparse::Variable, we track model residual dependencies and compute the values of the Jacobian. The result is compared to the analytical Jacobian in std::map format. The Jacobians are constant matrices in these cases.

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.

@nkoukpaizan nkoukpaizan self-assigned this Apr 22, 2025
@nkoukpaizan nkoukpaizan force-pushed the nicholson/variable-type-test branch from c6bfc25 to 9a46d05 Compare April 22, 2025 18:20
@nkoukpaizan nkoukpaizan force-pushed the nicholson/variable-type-test branch from 1de6f41 to 8265e7a Compare April 22, 2025 18:25
@nkoukpaizan nkoukpaizan added development Features/Tools related to development of GridKit, rather than use as a library. testing automatic differentiation labels Apr 22, 2025
@nkoukpaizan nkoukpaizan force-pushed the nicholson/variable-type-test branch from 3531a77 to 16cad59 Compare April 22, 2025 18:43
Copy link
Collaborator

@alexander-novo alexander-novo left a comment

Choose a reason for hiding this comment

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

Maybe I'm misunderstanding, but wasn't the point of Sparse::Variable that we wouldn't have to write these analyticalJacobian functions manually, and would be able to call e.g. LoadTests<Sparse::Variable>::residual() to compute the same thing?

@nkoukpaizan
Copy link
Collaborator Author

Maybe I'm misunderstanding, but wasn't the point of Sparse::Variable that we wouldn't have to write these analyticalJacobian functions manually, and would be able to call e.g. LoadTests<Sparse::Variable>::residual() to compute the same thing?

This is exactly what is being done here. See for example, load.evaluateResidual(). The point of the analytical Jacobian is to verify the answer we are getting. For a unit test, we need a reference.

@alexander-novo alexander-novo self-requested a review April 28, 2025 20:33
@shakedregev
Copy link
Collaborator

48%] Building CXX object examples/MatPowerTesting/CMakeFiles/test_parse_gen_row.dir/test_parse_gen_row.cpp.o
In file included from /Users/szb/GridKit_dir/GridKit/examples/MatPowerTesting/test_parse_gen_row.cpp:5:
/Users/szb/GridKit_dir/GridKit/src/Utilities/Testing.hpp:235:30: error: no template named 'map' in namespace 'std'; did you mean 'max'?
  235 |     inline bool isEqual(std::map<IdxT, RealT> a,
      |                         ~~~~~^~~
      |                              max
/opt/homebrew/Cellar/llvm/19.1.7/bin/../include/c++/v1/__algorithm/max.h:29:1: note: 'max' declared here
   29 | max(_LIBCPP_LIFETIMEBOUND const _Tp& __a, _LIBCPP_LIFETIMEBOUND const _Tp& __b, _Compare __comp) {
      | ^
In file included from /Users/szb/GridKit_dir/GridKit/examples/MatPowerTesting/test_parse_gen_row.cpp:5:
/Users/szb/GridKit_dir/GridKit/src/Utilities/Testing.hpp:235:17: error: redefinition of 'isEqual' as different kind of symbol
  235 |     inline bool isEqual(std::map<IdxT, RealT> a,
      |                 ^
/Users/szb/GridKit_dir/GridKit/src/Utilities/Testing.hpp:207:17: note: previous definition is here
  207 |     inline bool isEqual(PowerSystemData::SystemModelData<RealT, IdxT> a,
      |                 ^
/Users/szb/GridKit_dir/GridKit/src/Utilities/Testing.hpp:235:47: error: expected ')'
  235 |     inline bool isEqual(std::map<IdxT, RealT> a,
      |                                               ^
/Users/szb/GridKit_dir/GridKit/src/Utilities/Testing.hpp:235:24: note: to match this '('
  235 |     inline bool isEqual(std::map<IdxT, RealT> a,
      |                        ^
/Users/szb/GridKit_dir/GridKit/src/Utilities/Testing.hpp:237:91: error: expected ';' after top level declarator
  237 |                         const RealT           tol = std::numeric_limits<RealT>::epsilon())
      |                                                                                           ^
      |                                                                                           ;
4 errors generated.

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.

I cannot build this code. Details above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automatic differentiation development Features/Tools related to development of GridKit, rather than use as a library. testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants