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

[documentation] Improve the docstring of SimpleStats #917

Merged
merged 3 commits into from
Oct 30, 2024
Merged

Conversation

amontoison
Copy link
Member

@amontoison amontoison commented Oct 29, 2024

src/krylov_stats.jl Outdated Show resolved Hide resolved
Copy link
Contributor

github-actions bot commented Oct 29, 2024

Package name latest stable
CaNNOLeS.jl
DCISolver.jl
FletcherPenaltySolver.jl
JSOSolvers.jl
LLSModels.jl
LinearSolve.jl
Percival.jl
RipQP.jl

Copy link

codecov bot commented Oct 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.70%. Comparing base (d1215ab) to head (a7614ae).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #917      +/-   ##
==========================================
+ Coverage   94.17%   94.70%   +0.53%     
==========================================
  Files          45       45              
  Lines        8219     8027     -192     
==========================================
- Hits         7740     7602     -138     
+ Misses        479      425      -54     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

@gdalle gdalle left a comment

Choose a reason for hiding this comment

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

Thanks for documenting this! I made a few suggestions, mostly to refer to SimpleStats in the more complicated stats docstrings and to only document the fields that don't appear in the simple version

Type for storing statistics returned by the majority of Krylov solvers.
The fields are as follows:
- `niter`: The total number of iterations completed by the solver;
- `solved`: Indicates whether the solver successfully reached convergence (`true` if solved, ``false` otherwise);
Copy link

Choose a reason for hiding this comment

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

Suggested change
- `solved`: Indicates whether the solver successfully reached convergence (`true` if solved, ``false` otherwise);
- `solved`: Indicates whether the solver successfully reached convergence (`true` if solved, `false` otherwise);

Copy link

Choose a reason for hiding this comment

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

Also, convergence according to which criterion? A tolerance I assume?

Copy link
Member Author

@amontoison amontoison Oct 29, 2024

Choose a reason for hiding this comment

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

The answer is quite complex. It depends which shopping condition is triggered.
It could be also related to the callback.

I need to document that since a long time too: #552

- `solved`: Indicates whether the solver successfully reached convergence (`true` if solved, ``false` otherwise);
- `inconsistent`: Flags whether the system was detected as inconsistent (i.e., when `b` is not in the range of `A`);
- `residuals`: A vector containing the residual norms at each iteration;
- `Aresiduals`: A vector of `Aᴴ`-residual norms at each iteration;
Copy link

Choose a reason for hiding this comment

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

What is Aᴴ?

Copy link
Member Author

@amontoison amontoison Oct 29, 2024

Choose a reason for hiding this comment

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

The adjoint of A Guillaume.
A^T is the transpose and A^H the conjugate hermitian.
In the real case A^H are A^T are the same matrices.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link

Choose a reason for hiding this comment

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

My bad, I'm more used to A' or A* for the adjoint, hence my surprise

Copy link
Member Author

Choose a reason for hiding this comment

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

I will use A'. I probably expected users to know too many concepts of linear algebra (A^H, consistent, indefinite, singular, singular, dual, etc...).

Copy link

Choose a reason for hiding this comment

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

Some of those were probably explained elsewhere in the docs, like A^H, but yeah the point of all my review comments was getting some clarification in the stats docstring itself.

- `Aresiduals`: A vector of `Aᴴ`-residual norms at each iteration;
- `Acond`: An estimate of the condition number of matrix `A`.
- `timer`: The elapsed time (in seconds) taken by the solver to complete all iterations;
- `status`: A string indicating the outcome of the solve, providing additional details beyond `solved`.
Copy link

Choose a reason for hiding this comment

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

Can you give an example? What are its possible values?

@@ -47,7 +48,8 @@ function copyto!(dest :: SimpleStats, src :: SimpleStats)
end

"""
Type for statistics returned by LSMR. The attributes are:
Type for storing statistics returned by LSMR.
The fields are as follows:
Copy link

Choose a reason for hiding this comment

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

Suggested change
The fields are as follows:
The fields are as follows (see [`Krylov.SimpleStats`](@ref)):

Copy link

Choose a reason for hiding this comment

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

Same for the other more sophisticated stats, so that you don't need to document every field again

Copy link

Choose a reason for hiding this comment

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

What is xNorm here?

Copy link
Member Author

Choose a reason for hiding this comment

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

The norm of the solution x.
You can compute it cheaply for many methods because the Krylov basis is orthonormal.

Copy link

Choose a reason for hiding this comment

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

okay, we should probably explain it here then

@@ -96,7 +98,8 @@ function copyto!(dest :: LsmrStats, src :: LsmrStats)
end

"""
Type for statistics returned by CG-LANCZOS, the attributes are:
Type for storing statistics returned by CG-LANCZOS.
The fields are as follows:
Copy link

Choose a reason for hiding this comment

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

Suggested change
The fields are as follows:
The fields are as follows (see [`Krylov.SimpleStats`](@ref)):

Copy link

Choose a reason for hiding this comment

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

What is indefinite here?

Copy link
Member Author

@amontoison amontoison Oct 29, 2024

Choose a reason for hiding this comment

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

It means that the matrix is indefinite.
A matrix is indefinite if it has positive and negative eigenvalues.

Copy link

Choose a reason for hiding this comment

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

okay, we should probably explain it here or in a high-level preamble

@@ -134,7 +137,8 @@ function copyto!(dest :: LanczosStats, src :: LanczosStats)
end

"""
Type for statistics returned by CG-LANCZOS with shifts, the attributes are:
Type for storing statistics returned by CG-LANCZOS-SHIFT and CGLS-LANCZOS-SHIFT.
The fields are as follows:
Copy link

Choose a reason for hiding this comment

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

Suggested change
The fields are as follows:
The fields are as follows (see [`Krylov.SimpleStats`](@ref)):

Copy link

Choose a reason for hiding this comment

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

What is indefinite here?

@@ -174,7 +178,8 @@ function copyto!(dest :: LanczosShiftStats, src :: LanczosShiftStats)
end

"""
Type for statistics returned by SYMMLQ, the attributes are:
Type for storing statistics returned by SYMMLQ.
The fields are as follows:
Copy link

Choose a reason for hiding this comment

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

Suggested change
The fields are as follows:
The fields are as follows (see [`Krylov.SimpleStats`](@ref)):

Copy link

Choose a reason for hiding this comment

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

What are residualscg, errors and errorscg here?

@@ -221,7 +226,8 @@ function copyto!(dest :: SymmlqStats, src :: SymmlqStats)
end

"""
Type for statistics returned by adjoint systems solvers BiLQR and TriLQR, the attributes are:
Type for storing statistics returned by adjoint systems solvers BiLQR and TriLQR.
The fields are as follows:
Copy link

Choose a reason for hiding this comment

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

Suggested change
The fields are as follows:
The fields are as follows (see [`Krylov.SimpleStats`](@ref)):

Copy link

Choose a reason for hiding this comment

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

What do the primal and dual suffixes mean here?

Copy link
Member Author

Choose a reason for hiding this comment

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

You solve two systems here Ax = b and A'y = c. The primal refers to the first system while the dual refers to the second one.

Copy link

Choose a reason for hiding this comment

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

maybe this docstring could link to an explanation of the algorithm itself for these details

Copy link
Member Author

Choose a reason for hiding this comment

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

It's just that you checked the docstring in the wrong way.
I don't think any user wants to understand how to use a result before knowing how to obtain it. 😉

Nobody will ever use AdjointStats without previously calling bilqr and trilqr, which explain everything and that gives a pointer to this structure: https://jso.dev/Krylov.jl/dev/solvers/as/

Copy link

Choose a reason for hiding this comment

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

fair enough

@@ -258,7 +264,8 @@ end


"""
Type for statistics returned by the LNLQ method, the attributes are:
Type for storing statistics returned by the LNLQ method.
The fields are as follows:
Copy link

Choose a reason for hiding this comment

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

Suggested change
The fields are as follows:
The fields are as follows (see [`Krylov.SimpleStats`](@ref)):

Copy link

Choose a reason for hiding this comment

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

What do the error_ fields mean here?

@@ -298,7 +305,8 @@ function copyto!(dest :: LNLQStats, src :: LNLQStats)
end

"""
Type for statistics returned by the LSLQ method, the attributes are:
Type for storing statistics returned by the LSLQ method.
The fields are as follows:
Copy link

Choose a reason for hiding this comment

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

Suggested change
The fields are as follows:
The fields are as follows (see [`Krylov.SimpleStats`](@ref)):

Copy link

Choose a reason for hiding this comment

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

What are the new fields here?

@amontoison
Copy link
Member Author

@gdalle I agree with you on many point but for specific statistics like LsmrStats, LnlqStats, AdjointStats, etc...
Many details are explained in the docstring of the Krylov method itself.
I don't think that any user will need to understand LnlqStats if he is not using the method that returned this structure.

Note also that the title of the PR is Improve the docstring of SimpleStats.
By lack of time I didn't do the other stuctures yet, so you review of what you don't understand is meningful but not related to the PR.

src/krylov_stats.jl Outdated Show resolved Hide resolved
@amontoison amontoison merged commit 83db3f3 into main Oct 30, 2024
29 of 30 checks passed
@amontoison amontoison deleted the doc_stats branch October 30, 2024 19:46
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