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 more convergence history to scfres #1049

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

Conversation

ClementineBarat
Copy link
Contributor

This PR adds history_εF to scfres and the possibility to save the convergence history of other data by passing a dictionary of functions that are evaluated and saved at each scf iteration.

@antoine-levitt
Copy link
Member

Hm, the API feels a bit ad hoc, and self_consistent_field already has lots of stuff in it. Can we somehow merge this with the callback API? Ie the callback would add stuff to info, and we'd (optionally) save the result of all callbacks or something?

@Technici4n
Copy link
Contributor

A bit ugly, but something like this might also work?

history_extra = []
callback = info -> push!(history_extra, info.<what needs to be saved>)`
self_consistent_field(...; callback)

@ClementineBarat ClementineBarat marked this pull request as draft January 20, 2025 08:01
@ClementineBarat
Copy link
Contributor Author

I added a specific callback that takes care of filling an history_extra dictionary.

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.

I'm ok to include the εF if you need it @ClementineBarat, but about the ScfSaveHistory struct I am not sure. What is the advantage of this struct over just writing a bunch of callbacks directly ?

Just to be clear: My problem is that you inevitably have to make some decisions when designing such a struct (e.g. you choose to call functions as fun(; info...)) which work very well in the use case you have in mind, but which may not work well for others. Then others anyway have to write some bloat code to connect the SCF to their callback function.

@ClementineBarat
Copy link
Contributor Author

Yes that make sense, no need to add my custom callback to DFTK. I removed all changes except for adding the history_εF but i can do without if it is just for me.

@mfherbst
Copy link
Member

I think it can be useful also for occupation functions, but @antoine-levitt may have an opinion here.

@antoine-levitt If you are ok, I'd say we merge.

Comment on lines 189 to 190
info_next = merge(info_next, (; energies, history_Etot, history_Δρ, history_εF,
n_matvec))
Copy link
Member

Choose a reason for hiding this comment

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

Here the indention is weird, I'd do

Suggested change
info_next = merge(info_next, (; energies, history_Etot, history_Δρ, history_εF,
n_matvec))
info_next = merge(info_next, (; energies, history_Etot, history_Δρ, history_εF,
n_matvec))

@@ -202,8 +206,7 @@ Overview of parameters:

info_init = (; ρin=ρ, ψ=ψ, occupation=nothing, eigenvalues=nothing, εF=nothing,
n_iter=0, n_matvec=0, timedout=false, converged=false,
history_Etot=T[], history_Δρ=T[])

Copy link
Member

Choose a reason for hiding this comment

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

Here you're killing an empty line, which I think would help the structure of the code.

@mfherbst mfherbst marked this pull request as ready for review January 27, 2025 12:21
@antoine-levitt
Copy link
Member

scfres already has quite a lot of stuff, maybe we can have a convergence_history field and move all the convergence logging stuff to there?

@mfherbst
Copy link
Member

mfherbst commented Jan 27, 2025

maybe we can have a convergence_history field and move all the convergence logging stuff to there?

Ok for me, sounds reasonable, although I'd just name it history (like scfres.history.εF feels very natural)

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.

4 participants