-
Notifications
You must be signed in to change notification settings - Fork 97
direct_minimization with Manopt.jl as a weak dependency
#1105
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
base: master
Are you sure you want to change the base?
direct_minimization with Manopt.jl as a weak dependency
#1105
Conversation
though not yet fully correcet on the stopping criterion.
|
I had a meeting that was shorter than I thought, so here is a small snippet that somewhat works on this branch already (thanks to @elorannug for the setup) It still requires a bit of careful default parameter tuning, since the default (Armijo) line search currently uses the QR retraction instead of the default we prescribe and such. But a very first small generic interface does work. |
|
While I did not yet address the points above, I spent this evening debugging the code, now it is relatively easy to
Every now and then it seems the gradient is not so correct because the step size collapses after a few iterations, I have to check that (or the example is too simple so it finishes after < 4 steps anyways). 6 is nearly done, just requires a bit of tolerance on the gradient descent side in manopt; |
|
I worked a bit mainly on a bit of testing (as far as my knowledge reaches), naming and documentation. This should work for now, with the small caveat that for Questions on the code(also written within the code in the corresponding places)
Questions in general
...and beyondI had a discussion with @jonas-pueschel to also include his CG approache; that however would first mean, that in severa places, especially in Armijo and Wolfe, the inner product with the gradient has to ne replaced an evaluation of the differentia, see JuliaManifolds/Manopt.jl#482. Then we can probably either update the cost/grad here or provide a second alternative. |
direct_minimization with Manopt.jldirect_minimization with Manopt.jl
mfherbst
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left a few high-level comments. Maybe we should have a zoom to discuss a few details, that I don't get yet.
|
Yes a zoom is probably the best, in Text it might take a few iterations too much. edit: one that could easily be resolved I already resolved – and added a few notes to the comments, maybe also just for me to remember to discuss this :) |
# Conflicts: # Project.toml
|
@mfherbst I think I have finished everything we discussed and I was able to do. Here is a few remaining things I am unsure about
I think this is how far I can provide code here. For a next step I would probably need help. Feedback on the code is of course also welcome. |
direct_minimization with Manopt.jldirect_minimization with Manopt.jl as a weak dependency
|
This is a careful bump after 2 months without any reaction on my last post with questions and/or a review. If this is too much work or too much of a change to ask, we can also not do this. |
|
Thanks for the reminder and sorry for the delay. I'll try to follow up in the next days. |
If it's just a small energetic glitch as you mention it, I would not be too worried. But if fails means it crashes, then I am.
We can, but not extremely important from my point of view. If you have it handy, it does not hurt, though.
If it's clear now feel free to do it. If not, I'll do a cleanup pass and then I can take a look.
I don't know about the extensions. Basically what we do is that we re-use the examples also as documentation. Is that your confusion ? It may also be that the literate step causes trouble ? |
mfherbst
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's converging. Take a look what you can fix with the additional information from my end, else I'd suggest we have a call to clean things up and then I can take over the rest whatever is needed. Things we should clarify:
- How does the printing look like
- Anything else to be discussed on docs building ?
- Source code formatting: We try to keep line length around 92 (see the scarce style guide https://docs.dftk.org/stable/developer/style_guide/)
| using DFTK | ||
| using LinearAlgebra | ||
| using PseudoPotentialData | ||
| using Manopt, Manifolds, RecursiveArrayTools |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a little weird that one needs to using all there three packages explicitly. Can we somehow avoid that ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really.
- Manopt is needed to load the solver(s) we use
- Manifolds is needed for Grassmann and the Product manifold
- The product manifold is basically a dummy until RecursiveArrayTools are loaded end the extension (in Manifolds) provides the efficient product manifold functions (baes on
ArrayPartition)
so all 3 are needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, but that's quite inconvenient for a potential user. Could we avoid that by making a metapackage that depends on all three of them (like DFTKManopt.jl) ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uff. I would have no clue how to do that?
I also do not agree that that is inconvenient, it is what the extensions now bring – more modular packages without direct dependencies:
One can use Manopt with an own manifold (nand then not load Manifolds)
One can use Manifolds with an own implementation for the product structure (and then not load RecursiveArrayTools)
What would that package look like? Something with the Reexport all package? I am not sure what to do here.
| * `maxiter=1000`: The maximum number of iterations for the optimization. If you set the `stopping_criterion=` directly, this keyword has no effect. | ||
| * `ψ=nothing`: The initial guess for the wave functions. If not provided, random orbitals will be generated. | ||
| * `ρ=guess_density(basis), # would be consistent with other scf solvers | ||
| * `tol=1e-6`: stop when the change in the density is less than this tolerance. If you set the `stopping_criterion=` directly, this keyword has no effect. | ||
| * `manifold=`[`Stiefel`](@extref `Manifolds.Stiefel`): the manifold the optimisation is running on. | ||
| The current default cost function allows to also use ∞`Grassmann`](@extref `Manifolds.Grassmann`), | ||
| both in their complex form. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to avoid duplicating info between here and the low-level function below?
Perhaps we only provide docs here and the in the low-level version we don't document it, referring to this version instead ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, these two variants allow for a slightly different level of settings.
This is the version that is meant for ease of use and follow a bit closer the DFTK scheme. That limits a bit what one can set up.
The other (maybe considered a bit more internal) already requires to pass a Manopt state, but then provides more access to “Manopt-stuff”. Sure we can leave that one undocumented, but then I will have forgotten half of what I wrote in about a year and would not be able to help (or help easily) if someone comes along with a problem.
That would not be my preferred way to go.
|
To answer a few already:
to me it looks like small glitches.
Mainly a matter of time, and I fear it would take me quite some time.
to me this is to 0% clear.
Well. To be precise: The new doc strings are defined in the extension. |
…DFTK.jl into kellertuer/direct-min-manopt
If you could make more precise what you mean here?
As written in the post above, currently 0 documentation of extensions seems to be in the documentation.
Been there, done that. |
…ich introduced this.
|
Since we released |
|
I tried at least illustrating the documentation of things in the extension
When trying to do 3 I usually check which signatures fail to add them on that page – otherwise it is a bit hard to specify that by hand. However, I can not render the docs locally, the Error I get is (starting snippet) I would assume that is unlrelated to this PR? However, the last commit is hence only a first step towards documenting the extension. I checked the other extensions, and only one has a one-line (more-like-dummy) doc string. So maybe for other extensions this is not necessary. For the one here, I am unsure how to continue – also not for the other open points. Let me know what best to do then. |
ok, good then.
then let's not
Ok then I do it. Is it ok if I push to your branch directly ?
How do the output look like when running the direct minimisation with ManOpt.
Ok, but then all it takes is to add the
I would think so. Are you on a windows machine ? Because Wannier90 does not compile on windows (hence no binary in Yggdrasil). |
Thanks for your understanding.
Sure, feel free to change on this branch what is necessary or what ever you like :)
Its
And loading the packages before, the ? get_extension` only returns extensions that are loaded already.
No I am on a Mac (macOS Tahoe 26.0, just updated yesterday) |
|
It's been a while again. Anything I can help with? I think the one thing missing is still the Besides that
This was not yet answered. I am happy to provide show methods, but I can not just guess what is the usual thing one want the printing to look like?
Same here: Currently 0% of extension documentation is rendered, since extensions are not included in the modules list of the documentation. If that is how it should be, then all things for the docs have been discussed. and finally (and fourth) the issue that now 3 packages have to be loaded. I do not have a good solution for that. If that is too annoying, then we should maybe discontinue this and stick to the old scheme of using optim, that is also fine with me, then just close this PR. |
As I said, I'll look into it, but my coding time is limited, unfortunately. But it's still on my list.
I meant quite naively, what does the printed output look like if I run the code. But I can check when I look at the first point .
I thought you suggested this can be changed, which sounded very reasonable to me. You also mentioned cross-referencing documentation. These are things which would be nice to have and I just wondered if we are all set on this or if more things need to be discussed.
Yeah, I think that will be too annoying. But I think we can work around that by making a small DFTKManopt package, which then hard-depends on all there dependencies. If this exposes (@rexports maybe) |
Yes, but to me it was unclear whether that is wanted - and currently I can not do that since I can not get the docs to render locally, see the problem with
But ok, then I know now, that I currently can not help any further, but I am of course available if there are things that need to be clarified further, so I will keep myself subscribed here, but put it aside (no more reminders) now then. |
Sounds good. I'll |
Following the discussion in #1102, here is a work in progress on moving
direct_minimizationto an extension and to useManopt.jl.Due to the discussions in the linked issue I feel a bit unsure how and whether to continue. Currently left to do
direct_minimizationinsrc/scf/that it requiresManoptandManifoldsto workManoptPreconditionerto maybe something more reasonable. It basically wraps a DFTK preconditionedCostGradFunctor!should get a nicer name and could maybe also become the fixed energy/gradient computation but also maybe stay a keyword argumentCostGradFunctor![ ] 5 clarify what the use of(removed it)alphaguessis and what else than `nothing it can/should be.infoor in other words what to return from that function.Points 1-4 and 8 are merely to work though as soon as I find time
On 5 and 7 I need some help and feedback
7 is maybe a bit tricky to get right in general.
For now this function (and its helpers) are a bit work in progress – I open this a bit early, since I am not sure the philosophies of the packages agree well enough that this approach is useful. in the issue above it sounds currently like the idea here is that the philosophy is too different and that it might not fit.