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

Change internal fixed-point API to (x, info) = f(x, info) to simplify SCF metadata tracking #811

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

Conversation

epolack
Copy link
Collaborator

@epolack epolack commented Jan 12, 2023

PR from @niklasschmitz. Will fix the tests when CI completes.

@mfherbst
Copy link
Member

Since there are conflicts against master the CI will not run. @epolack @niklasschmitz You must first resolve the conflicts and/or rebase.

@epolack
Copy link
Collaborator Author

epolack commented Jan 13, 2023

@mfherbst, thanks.
Although I do not understand how Github did the PR. The branch is directly on DFTK.jl, so I cannot modify it. Should I close it and open a new one?

@mfherbst
Copy link
Member

Should I close it and open a new one?

If you want to continue the development I'd say that's the simplest.

You can already get an idea what's the issue right now from https://git.uni-paderborn.de/herbstm/DFTK.jl/-/jobs/123457 by the way.

@epolack epolack closed this Jan 18, 2023
@niklasschmitz
Copy link
Collaborator

Reopening now after pulling, let's see what the CI says

@niklasschmitz niklasschmitz reopened this Feb 15, 2023
@niklasschmitz niklasschmitz changed the title Modification of fixed-point API Change internal fixed-point API to (x, info) = f(x, info) to simplify SCF metadata tracking Feb 15, 2023
@niklasschmitz niklasschmitz marked this pull request as ready for review February 16, 2023 14:38
# Tolerance and maxiter are only dummy here: Convergence is flagged by is_converged
# inside the fixpoint_map.
solver(fixpoint_map, ρout, maxiter; tol=eps(T))

_, info = solver(fixpoint_map, ρ, info_init, maxiter; tol=eps(T)) # TODO ?? why dummy?
Copy link
Collaborator

Choose a reason for hiding this comment

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

On that TODO: I think I understand now the comment above for custom convergence flagging - I wonder whether we could move this to the fixed-point solvers API though? instead of specifying the tolerance, one could do something like solver(fixpoint_map, ρ, info_init, maxiter; is_converged_fn=is_converged_fn)?

Copy link
Member

Choose a reason for hiding this comment

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

Agree 100%. The is_converged should be executed in the solver. The thing with the converged flag has always been a hack to make NLSolve happy.

Copy link
Member

@mfherbst mfherbst left a comment

Choose a reason for hiding this comment

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

Very nice. Has the potential for quite some simplifications (e.g. unifying SCF routines in density and potential).

@@ -57,7 +60,7 @@ CROP-accelerated root-finding iteration for `f`, starting from `x0` and keeping
a history of `m` steps. Optionally `warming` specifies the number of non-accelerated
steps to perform for warming up the history.
"""
function CROP(f, x0, m::Int, max_iter::Int, tol::Real, warming=0)
function CROP(f, x0, info0, m::Int, max_iter::Int, tol::Real, warming=0)
Copy link
Member

Choose a reason for hiding this comment

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

@antoine-levitt Shall we just kill CROP ? It was an experiment anyway, which is not used or tested very much at all.

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 useful to have since it parallels the anderson implementation, and we might want to look at it again in 5 years. Why can't info be an optional arg (or kwarg) so that solvers don't have to bother with it?

Copy link
Member

Choose a reason for hiding this comment

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

If we want the solvers to be able to use the isconverged callback it somehow needs an info. But perhaps we can have a default-scfres function, which would be the default for the arg.

# Tolerance and maxiter are only dummy here: Convergence is flagged by is_converged
# inside the fixpoint_map.
solver(fixpoint_map, ρout, maxiter; tol=eps(T))

_, info = solver(fixpoint_map, ρ, info_init, maxiter; tol=eps(T)) # TODO ?? why dummy?
Copy link
Member

Choose a reason for hiding this comment

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

Agree 100%. The is_converged should be executed in the solver. The thing with the converged flag has always been a hack to make NLSolve happy.

@@ -11,12 +11,13 @@ Create a damped SCF solver updating the density as
`x = β * x_new + (1 - β) * x`
"""
function scf_damping_solver(β=0.2)
function fp_solver(f, x0, max_iter; tol=1e-6)
function fp_solver(f, x0, info0, max_iter; tol=1e-6)
Copy link
Member

Choose a reason for hiding this comment

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

While we are at this: Drop the tol flag from here (taken care of by the new is_converged kwarg and also make maxiter a kwarg (has always been bothering me that it's not).

Comment on lines 122 to 124
function scf_CROP_solver(m=10)
function crop_solver(f, x0, info0, max_iter; tol=1e-6)
function residual_f(x, info)
Copy link
Member

Choose a reason for hiding this comment

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

Puh ... that's not easy to process. I really feel like removing the CROP stuff.

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.

None yet

4 participants