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

Logging #131

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open

Logging #131

wants to merge 16 commits into from

Conversation

shivupa
Copy link
Contributor

@shivupa shivupa commented Oct 5, 2021

This implements a virtual Logging class which can be implemented by the user to log each iteration. This implements the proposed implementation "A" on #103.

The added tests are very simple and demonstrate an example of the derived logging class.

Closes #103

@codecov-commenter
Copy link

codecov-commenter commented Oct 5, 2021

Codecov Report

Attention: Patch coverage is 96.96970% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 92.4%. Comparing base (3af5641) to head (a91f594).

Current head a91f594 differs from pull request most recent head 88c3b30

Please upload reports for the commit 88c3b30 to get more accurate results.

Files Patch % Lines
include/Spectra/JDSymEigsBase.h 88.8% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           master    #131     +/-   ##
========================================
- Coverage    93.2%   92.4%   -0.9%     
========================================
  Files          45      46      +1     
  Lines        2400    2253    -147     
========================================
- Hits         2239    2082    -157     
- Misses        161     171     +10     

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

@@ -39,8 +39,8 @@ class DavidsonSymEigsSolver : public JDSymEigsBase<DavidsonSymEigsSolver<OpType>
Vector m_diagonal;

public:
DavidsonSymEigsSolver(OpType& op, Index nev, Index nvec_init, Index nvec_max) :
JDSymEigsBase<DavidsonSymEigsSolver<OpType>, OpType>(op, nev, nvec_init, nvec_max)
DavidsonSymEigsSolver(OpType& op, Index nev, Index nvec_init, Index nvec_max, std::unique_ptr<LoggerBase<Scalar, Vector>> logger = nullptr) :
Copy link
Contributor

Choose a reason for hiding this comment

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

I do not prefer default arguments instead just have two constructors. The reason for it is that if we eve change the interface or add a second default argument it will all break down in user code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had it implemented this way at first, but I wanted to reduce code duplication so I went with default args. I will change it back since I agree with your assessment.

Comment on lines 353 to 354
if (logger)
m_logger = std::move(logger);
Copy link
Contributor

Choose a reason for hiding this comment

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

I prefer brackets around one line if statements, but it is a nitpick

Copy link
Contributor

Choose a reason for hiding this comment

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

and the rest of the codebase does not do it so. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I prefer it as well but I will leave it since the code base doesn't do that

Comment on lines 444 to 445
if (m_logger)
m_logger->iteration_log(i, nconv, m_ncv, m_ritz_val.head(m_nev), m_resid, m_ritz_conv);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be nicer to have an iteration_data structure because if we want to log more things this function signature would have to change everywhere, of course then we would maybe have to take copies.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure this makes sense. I will push some commits with this change. Even if we make copies, the size of the objects shouldn't be overly large so this will probably be ok.

Copy link
Contributor

Choose a reason for hiding this comment

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

you can also take references in the constructor. So you could have a datastructure that just returns const references as well

@@ -51,6 +54,7 @@ class JDSymEigsBase

private:
CompInfo m_info = CompInfo::NotComputed; // status of the computation
std::unique_ptr<LoggerBase<Scalar, Vector>> m_logger;
Copy link
Contributor

Choose a reason for hiding this comment

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

thing is this makes the class non copyable, what do we do about that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could use shared_ptr? There is no need for this to be unique_ptr

Copy link
Contributor

Choose a reason for hiding this comment

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

the other option would be to just have a * and have the user of the library manage the lifetime of the logger

///
/// Virtual logging function
///
virtual void iteration_log(const Index& iteration, const Index& number_of_converged, const Index& subspace_size, const Vector& current_eigenvalues, const Vector& residues, const BoolArray& current_eig_converged);
Copy link
Contributor

Choose a reason for hiding this comment

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

as said I think we should add a Datastructure here, maybe even an abstract baseclass so we can use this also for the other solvers. @yixuan would this be worth extending to the other solvers?

Copy link
Contributor

@JensWehner JensWehner 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 implementing it, what a nice PR. I added some comments which I think can make it even more long term stable. Would be nice for the other solvers to adapt sth. similiar.

Great work!

@shivupa
Copy link
Contributor Author

shivupa commented Oct 6, 2021

Thanks for the quick review and the advice!

@shivupa
Copy link
Contributor Author

shivupa commented Oct 8, 2021

@JensWehner If you could take another pass I'd appreciate it!


private:
BoolArray m_ritz_conv; // indicator of the convergence of Ritz values
CompInfo m_info; // status of the computation
std::shared_ptr<LoggerBase<Scalar, ComplexVector>> m_logger;
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure if a shared_ptr is a good idea, because I copy would habe interesting problems then, because we would only have a shallow copy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah sorry I wanted to try to use something safer than a raw pointer, but I realize now I would have to rewrite the copy constructor. That is still an option, but I switched to raw ptrs for now.

Copy link
Contributor

@JensWehner JensWehner left a comment

Choose a reason for hiding this comment

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

Small nitpicks otherwise I like the addition, but let us see what @yixuan says.

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.

Adding a Logger functionality for Spectra
3 participants