Skip to content
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

Refactor NewtonSolver #2521

Merged
merged 1 commit into from
Oct 3, 2024

Conversation

dweindl
Copy link
Member

@dweindl dweindl commented Sep 30, 2024

Use SUNLinSolWrapper. Get rid of subclasses. Simplify.

Closes #1164.

We should also be able to get rid of the remaining data members,
but that's for another time...

@dweindl dweindl changed the title Fix 1164 newton linsolwrapper Refactor NewtonSolver Sep 30, 2024
@dweindl dweindl self-assigned this Sep 30, 2024
@dweindl dweindl force-pushed the fix_1164_newton_linsolwrapper branch from 9a79289 to f7bd3f8 Compare September 30, 2024 18:20
Copy link

codecov bot commented Sep 30, 2024

Codecov Report

Attention: Patch coverage is 70.12987% with 23 lines in your changes missing coverage. Please review.

Project coverage is 77.75%. Comparing base (c199897) to head (39dfa38).
Report is 90 commits behind head on develop.

Files with missing lines Patch % Lines
src/newton_solver.cpp 73.07% 14 Missing ⚠️
src/sundials_linsol_wrapper.cpp 47.05% 9 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #2521      +/-   ##
===========================================
+ Coverage    77.67%   77.75%   +0.07%     
===========================================
  Files          324      323       -1     
  Lines        20951    20915      -36     
  Branches      1451     1446       -5     
===========================================
- Hits         16274    16262      -12     
+ Misses        4674     4650      -24     
  Partials         3        3              
Flag Coverage Δ
cpp 73.48% <70.12%> (+0.06%) ⬆️
cpp_python 34.13% <16.88%> (+0.02%) ⬆️
petab 36.66% <14.66%> (+0.04%) ⬆️
python 72.31% <62.33%> (+0.07%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
include/amici/steadystateproblem.h 100.00% <ø> (ø)
include/amici/sundials_linsol_wrapper.h 100.00% <ø> (ø)
src/steadystateproblem.cpp 83.92% <100.00%> (ø)
src/sundials_linsol_wrapper.cpp 22.31% <47.05%> (+5.64%) ⬆️
src/newton_solver.cpp 80.51% <73.07%> (+9.88%) ⬆️

@dweindl dweindl force-pushed the fix_1164_newton_linsolwrapper branch 2 times, most recently from ecc025e to 51ff7ce Compare October 1, 2024 11:41
@dweindl dweindl marked this pull request as ready for review October 1, 2024 12:17
@dweindl dweindl requested a review from a team as a code owner October 1, 2024 12:17
@dweindl dweindl mentioned this pull request Oct 3, 2024
Copy link
Member

@FFroehlich FFroehlich left a comment

Choose a reason for hiding this comment

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

neat!

void NewtonSolverDense::reinitialize() {
/* dense solver does not need reinitialization */
void NewtonSolver::reinitialize() {
// dense solver does not need reinitialization
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// dense solver does not need reinitialization
// direct solvers does not need reinitialization

what about iterative solvers?

Copy link
Member Author

Choose a reason for hiding this comment

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

They are already filtered out in the constructor:

switch (linsol_type) {
case LinearSolver::dense:
linsol_.reset(new SUNLinSolDense(x_));
break;
case LinearSolver::KLU:
linsol_.reset(new SUNLinSolKLU(x_, model.nnz, CSC_MAT));
break;
default:
throw NewtonFailure(
AMICI_NOT_IMPLEMENTED, "Unknown linear solver type"
);
}

Some methods will have to be updated when more solvers are to be supported.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added comment+exception regarding the need for updating those two functions to support additional solvers.

if (auto s = dynamic_cast<SUNLinSolKLU const*>(linsol_.get())) {
return s->is_singular();
}

// dense solver doesn't have any implementation for rcond/condest, so use
Copy link
Member

Choose a reason for hiding this comment

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

what about other direct/implicit solvers?

Copy link
Member Author

Choose a reason for hiding this comment

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

As above -- they haven't been supported before this PR, and they are still not supported yet. Although it would be pretty easy to extend that now....

@dweindl dweindl force-pushed the fix_1164_newton_linsolwrapper branch 3 times, most recently from cda7aac to 00602c8 Compare October 3, 2024 11:32
Use SUNLinSolWrapper. Get rid of subclasses. Simplify.

Closes AMICI-dev#1164.

We should also be able to get rid of the remaining data members,
but that's for another time...
@dweindl dweindl force-pushed the fix_1164_newton_linsolwrapper branch from 00602c8 to 39dfa38 Compare October 3, 2024 11:41
@dweindl dweindl merged commit f66f0b0 into AMICI-dev:develop Oct 3, 2024
19 of 20 checks passed
@dweindl dweindl deleted the fix_1164_newton_linsolwrapper branch October 3, 2024 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants