Skip to content

SUNDIALS updates#105

Merged
pelesh merged 15 commits intodevelopfrom
sundials-updates
May 22, 2025
Merged

SUNDIALS updates#105
pelesh merged 15 commits intodevelopfrom
sundials-updates

Conversation

@Steven-Roberts
Copy link
Copy Markdown
Collaborator

@Steven-Roberts Steven-Roberts commented May 9, 2025

Description

Replaces some deprecated SUNDIALS calls, adds a missing N_VDestroy, fixes uninitialized member variables that could cause issues when freed, and simplifies some of the code in the Ida and Kinsol classes. There's also some TODOs I left with questions @pelesh

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.

@pelesh pelesh added the enhancement New feature or request label May 9, 2025
Comment thread src/Solver/Dynamic/Ida.hpp
Comment thread src/Solver/Dynamic/Ida.cpp Outdated
Comment thread src/Solver/Dynamic/Ida.hpp Outdated
Comment thread src/Solver/SteadyState/Kinsol.cpp Outdated
Comment thread src/Solver/SteadyState/Kinsol.hpp
Comment thread src/Solver/Dynamic/Ida.cpp Outdated
@pelesh
Copy link
Copy Markdown
Collaborator

pelesh commented May 21, 2025

@nkoukpaizan, we need to set SUNDIALS version in CI to develop branch > 07d21c2.

Comment thread .github/workflows/spack_default_build.yaml
@pelesh
Copy link
Copy Markdown
Collaborator

pelesh commented May 21, 2025

The prior segfaults have been fixed with using SUNDIALS from develop branch. However, recent commits to the sundials-updates branch have introduced segfaults I have not seen before. The failing tests are all Ipopt related:

The following tests FAILED:
         14 - DynamicConOpt (SEGFAULT)
         15 - GenConstLoad (SEGFAULT)
         16 - GenInfiniteBus (SEGFAULT)
         17 - ParameterEst (SEGFAULT)

It seems there is an issue with getting data array pointer from the N_Vector. Full backtrace is available below:

Details Process 42256 launched: '/Users/55y/src/gridkit/build-gcc/examples/Experimental/DynamicConstrainedOpt/dynconopt' (x86_64)

This program contains Ipopt, a library for large-scale nonlinear optimization.
Ipopt is released as open source code under the Eclipse Public License (EPL).
For more information visit https://github.com/coin-or/Ipopt


Process 42256 stopped

  • thread Working Example of Solving RLCircuit and Microgrid with Jacobians #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=EXC_I386_GPFLT)
    frame #0: 0x00000001000e46d4 libsundials_core.7.dylib`N_VGetArrayPointer(v=0x00007fe3fb909ae0) at sundials_nvector.c:338:13
    335
    336 sunrealtype* N_VGetArrayPointer(N_Vector v)
    337 {
    -> 338 if (v->ops->nvgetarraypointer)
    339 {
    340 return (sunrealtype*)v->ops->nvgetarraypointer(v);
    341 }
    Target 0: (dynconopt) stopped.
    (lldb) bt
  • thread Working Example of Solving RLCircuit and Microgrid with Jacobians #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=EXC_I386_GPFLT)
    • frame #0: 0x00000001000e46d4 libsundials_core.7.dylibN_VGetArrayPointer(v=0x00007fe3fb909ae0) at sundials_nvector.c:338:13 frame #1: 0x00000001000a285b libgridkit_solvers_dyn.0.dylibAnalysisManager::Sundials::Ida<double, unsigned long>::initializeBackwardSimulation(double) [inlined] AnalysisManager::Sundials::Ida<double, unsigned long>::copyVec(x=size=2, y=0x00007fe3fb909ae0) at Ida.cpp:631:42
      frame Bus Parameters of Generator #2: 0x00000001000a2856 libgridkit_solvers_dyn.0.dylibAnalysisManager::Sundials::Ida<double, unsigned long>::initializeBackwardSimulation(this=0x00007fe3fb906110, tf=20) at Ida.cpp:378:14 frame #3: 0x000000010004af24 libgridkit_solvers_opt.0.dylibAnalysisManager::IpoptInterface::DynamicObjective<double, unsigned long>::eval_grad_f(this=0x00007fe3fb93da40, n=, x=0x00007fe3fb93fe00, new_x=, grad_f=0x00007fe3fb804fe0) at DynamicObjective.cpp:120:48
      frame Fix max number of backward steps in IDA solver. #4: 0x00000001004fc94d libipopt.3.dylibIpopt::OrigIpoptNLP::grad_f(Ipopt::Vector const&) + 173 frame #5: 0x00000001004c41c7 libipopt.3.dylibIpopt::IpoptCalculatedQuantities::curr_grad_f() + 359
      frame Formatting Fix Composer-Dev #6: 0x00000001004d143d libipopt.3.dylibIpopt::IpoptCalculatedQuantities::curr_grad_lag_x() + 685 frame #7: 0x00000001004d2066 libipopt.3.dylibIpopt::IpoptCalculatedQuantities::curr_dual_infeasibility(Ipopt::ENormType) + 998
      frame Create an interface target to add debug symbols #8: 0x00000001004f197e libipopt.3.dylibIpopt::OptimalityErrorConvergenceCheck::CheckConvergence(bool) + 78 frame #9: 0x00000001004b9f60 libipopt.3.dylibIpopt::IpoptAlgorithm::Optimize(bool) + 272
      frame Scalable Microgrid #10: 0x0000000100550592 libipopt.3.dylibIpopt::IpoptApplication::call_optimize() + 1858 frame #11: 0x00000001005524be libipopt.3.dylibIpopt::IpoptApplication::OptimizeNLP(Ipopt::SmartPtrIpopt::NLP const&, Ipopt::SmartPtrIpopt::AlgorithmBuilder&) + 398
      frame Organize component models by model family #12: 0x000000010054e466 libipopt.3.dylibIpopt::IpoptApplication::OptimizeNLP(Ipopt::SmartPtr<Ipopt::NLP> const&) + 54 frame #13: 0x0000000100006491 dynconoptmain at DynamicConstrainedOpt.cpp:96:34
      (lldb)

Comment thread src/Solver/Dynamic/Ida.cpp
Comment thread src/Solver/Dynamic/Ida.cpp Outdated
Copy link
Copy Markdown
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.

Good to merge. Consider merging #111 to sundials-updates before that.

* Minor suggestions to SUNDIALS interface

- Create "symmetric" functions for creating and deleting SUNDIALS objects.
- Modify RL example to test Ida destructor.


---------

Co-authored-by: pelesh <pelesh@users.noreply.github.com>
@pelesh pelesh merged commit ae31acb into develop May 22, 2025
3 checks passed
@pelesh pelesh deleted the sundials-updates branch June 10, 2025 18:02
@Steven-Roberts Steven-Roberts mentioned this pull request Jun 27, 2025
6 tasks
WiktoriaZielinskaORNL pushed a commit that referenced this pull request Jul 23, 2025
* Improvements for IDA and KINSOL

* Remove N_VGetArrayPointer_Serial calls

* Resolve t_init_ issue

* Add missing N_VDestroy

* Apply pre-commmit fixes

* Fix some adjoint memory leaks

* Remove unused function

* Minor suggestions to SUNDIALS interface (#111)

- Create "symmetric" functions for creating and deleting SUNDIALS objects.
- Modify RL example to test Ida destructor.


---------

Co-authored-by: pelesh <pelesh@users.noreply.github.com>

---------

Co-authored-by: Steven-Roberts <Steven-Roberts@users.noreply.github.com>
Co-authored-by: pelesh <peless@ornl.gov>
Co-authored-by: Nicholson Koukpaizan <koukpaizannk@ornl.gov>
Co-authored-by: pelesh <pelesh@users.noreply.github.com>
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