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

Add debug logger for solvers #1620

Merged
merged 9 commits into from
Jul 5, 2024
Merged

Add debug logger for solvers #1620

merged 9 commits into from
Jul 5, 2024

Conversation

upsj
Copy link
Member

@upsj upsj commented May 31, 2024

This debug logger prints out the value of all scalars inside the solver after each iteration:

Here we see the output of the simple-solver example with the logger running

gko::solver::Cg<double>::apply(0x124f04b60,0x124f04f00) of dimensions (19, 19) and 1 rhs
       Iteration           alpha            beta        prev_rho             rho
               0               0               0               1              19
               1               0             765       5.3109419              19
               2               0       151.51792       5.3109419       2.1541599
               3               0       56.610294      0.96997901       2.1541599
               4               0        22.91651      0.96997901      0.55031615
               5               0       13.637587      0.26380868      0.55031615
               6               0       5.8524907      0.26380868      0.14758275
               7               0       3.2949066      0.10013392      0.14758275
               8               0       2.3026212      0.10013392     0.051851311
               9               0       1.1447493     0.029006197     0.051851311
              10               0      0.64935163     0.029006197    0.0094813452
              11               0      0.22821574    0.0038048001    0.0094813452
              12               0     0.075631164    0.0038048001    0.0020622776
              13               0     0.047698364     0.001020997    0.0020622776
              14               0     0.023026955     0.001020997   0.00026116441
              15               0    0.0072957469   4.3166892e-05   0.00026116441
              16               0   0.00078229883   4.3166892e-05   6.9889839e-06
              17               0   0.00017981764   7.3755266e-07   6.9889839e-06
              18               0   1.9199351e-05   7.3755266e-07   8.2060081e-08
              19               0   1.9866215e-06   8.9249994e-28   8.2060081e-08

Should be useful for debugging #1563

@upsj upsj added the 1:ST:ready-for-review This PR is ready for review label May 31, 2024
@upsj upsj requested a review from a team May 31, 2024 13:05
@upsj upsj self-assigned this May 31, 2024
@ginkgo-bot ginkgo-bot added reg:build This is related to the build system. reg:testing This is related to testing. mod:core This is related to the core module. labels May 31, 2024
@upsj
Copy link
Member Author

upsj commented May 31, 2024

Also relevant for investigating #1026 (which is where this idea came up originally)

@upsj
Copy link
Member Author

upsj commented May 31, 2024

Wondering about the name here - it might make sense to also have a version that stores all scalars and intermediate vectors in files - should it be SolverDebugPrint or similar?

Copy link
Member

@tcojean tcojean left a comment

Choose a reason for hiding this comment

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

Some comments.

Also, to clarify, this would not give very helpful output with Gmres right, due to the nature of its "scalars" (in relation with krylov_dim most of the time)?

I think in general, having a version that stores output to files/json/wherever, in particular for vector cases would be really helpful as a general solution.

include/ginkgo/core/log/solver_debug.hpp Outdated Show resolved Hide resolved
core/log/solver_debug.cpp Outdated Show resolved Hide resolved
@upsj
Copy link
Member Author

upsj commented Jun 7, 2024

@tcojean There is now a printing and a storing variant + tests

Copy link
Member

@MarcelKoch MarcelKoch left a comment

Choose a reason for hiding this comment

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

I think the naming needs to be updated, and the internal dispatch in the scalar printer.

include/ginkgo/core/log/solver_debug.hpp Outdated Show resolved Hide resolved
* solver after each iteration. If the solver is applied to multiple right-hand
* sides, only the first right-hand side gets printed.
*/
class SolverDebug : public Logger {
Copy link
Member

Choose a reason for hiding this comment

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

I think the name is not great. Maybe SolverStatePrinter, but that is also not great. I'm struggling a bit to find a more suitable name.

Copy link
Member

Choose a reason for hiding this comment

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

Pinging this again, I'm still unhappy with the name. It's rather non-descriptive, so users will have no idea what this is doing just from the name.

Copy link
Member Author

Choose a reason for hiding this comment

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

How would you describe what this logger is used for? My first thought was "It's for debugging solvers", so the name made sense. But from a user perspective, it's maybe slightly unintuitive. OTOH, will users need to use this regularly?

Copy link
Member

Choose a reason for hiding this comment

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

It's for debugging solvers in a very specific sense, by printing the internal state after every iteration. That can be reflected in the name. Just 'debug' can mean anything and nothing.
Regarding usage: it could also be used to achieve the same thing as in #1517, so perhaps users will use it for that.

Copy link
Member Author

Choose a reason for hiding this comment

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

How about SolverProgress?

Copy link
Member

Choose a reason for hiding this comment

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

TBH, I kinda warmed up to my first suggestion. SolverProgress could easily be understood to mean just the residual norm, so I think referencing the state might be useful.

include/ginkgo/core/log/solver_debug.hpp Outdated Show resolved Hide resolved
core/log/solver_debug.cpp Outdated Show resolved Hide resolved
core/log/solver_debug.cpp Outdated Show resolved Hide resolved
core/test/log/solver_debug.cpp Outdated Show resolved Hide resolved
Copy link
Collaborator

@fritzgoebel fritzgoebel left a comment

Choose a reason for hiding this comment

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

This looks very useful!
LGTM

include/ginkgo/core/log/solver_debug.hpp Outdated Show resolved Hide resolved
@upsj upsj force-pushed the solver_debug_logger branch 3 times, most recently from a1dd3da to 88bbd77 Compare July 4, 2024 11:33
@upsj upsj requested a review from MarcelKoch July 4, 2024 11:37
Copy link
Member

@MarcelKoch MarcelKoch left a comment

Choose a reason for hiding this comment

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

LGTM, except the name.

core/log/solver_debug.cpp Outdated Show resolved Hide resolved
* solver after each iteration. If the solver is applied to multiple right-hand
* sides, only the first right-hand side gets printed.
*/
class SolverDebug : public Logger {
Copy link
Member

Choose a reason for hiding this comment

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

Pinging this again, I'm still unhappy with the name. It's rather non-descriptive, so users will have no idea what this is doing just from the name.

@thoasm
Copy link
Member

thoasm commented Jul 4, 2024

Here are some alternative suggestions:

  • SolverIntricaciesLogger
  • SolverDetailsLogger
  • SolverNuancesLogger
  • SolverBreakdownLogger

@upsj upsj added 1:ST:ready-to-merge This PR is ready to merge. and removed 1:ST:ready-for-review This PR is ready for review labels Jul 5, 2024
@upsj upsj merged commit 89a9c0e into develop Jul 5, 2024
12 of 14 checks passed
@upsj upsj deleted the solver_debug_logger branch July 5, 2024 16:29
Copy link

sonarcloud bot commented Jul 5, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1:ST:ready-to-merge This PR is ready to merge. mod:core This is related to the core module. reg:build This is related to the build system. reg:testing This is related to testing.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants