-
Notifications
You must be signed in to change notification settings - Fork 475
Move SCF-DIIS to Python #2298
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
Move SCF-DIIS to Python #2298
Conversation
loriab
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.
lgtm!
|
|
||
| if save_fock: | ||
| if not self.initialized_diis_manager_: | ||
| storage_policy = getattr(core.DIISManager.StoragePolicy, "InCore" if self.scf_type() == "DIRECT" else "OnDisk") |
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.
| storage_policy = getattr(core.DIISManager.StoragePolicy, "InCore" if self.scf_type() == "DIRECT" else "OnDisk") | |
| if self.scf_type() == "DIRECT": | |
| storage_policy = core.DIISManager.StoragePolicy.InCore | |
| else: | |
| storage_policy = core.DIISManager.StoragePolicy.OnDisk |
equivalent? I usually save getattr for when attribute only known in a variable. But that's my readability opinion. Your choice.
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.
Yes, equivalent. The right thing to do for readability is probably to import from core.DIISManager import StoragePolicy, RemovalPolicy. Then I can have a terse ternary without using getattr.
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.
that works. only other consideration is if you'd ever want to track which paths were tested with codecov.
|
|
||
| from psi4 import core | ||
|
|
||
| def _RHF_orbital_gradient(self, save_fock: bool, max_diis_vectors: int) -> float: |
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.
general info to readers: the Sphinx docs can now process type annotations, so they're not added in vain. the Sphinx docs now also hate the old Parameters\n verbose : int style in-docstring type annotation, so those're worth moving up into the signature.
|
On hold until #2296 gets approved, to see if we can reach a consensus on what pybind docstring format is now. |
e5fd818 to
e8ffabf
Compare
|
Force pushed to bring this branch up-to-date. Should be good to review again. |
jturney
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.
Looks good!
PeterKraus
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 only have a couple very minor style suggestions. I suggest @JonathonMisiewicz can decide whether to action them or merge straight away.
| return gradient.absmax() | ||
|
|
||
| core.RHF.compute_orbital_gradient = _RHF_orbital_gradient | ||
| core.UHF.compute_orbital_gradient = core.CUHF.compute_orbital_gradient = _UHF_orbital_gradient |
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'm not a terribly big fan of this triple-assignment.
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 looked strange to me at first as well, but I've made my peace with it. Putting these assignments on the same line makes it obvious that these two are intended to be the same function. I was a little surprised that CUHF didn't need custom logic here.
374a34f to
9a553de
Compare
Description
In preparation for some PRs adding EDIIS and ADIIS to Psi, this PR moves the
compute_orbital_gradientfunctions, which call DIIS, to the Python layer.There are multiple things going on:
libdiisto strongly typed enums. This means the enums have their own scope, which changes how other functions had to call them. Every change in occ, dfocc, dct, fisapt, and libdiis is solely due to this. This occupies commit one.diis_managerinto a property. Old code would callHF.diis_manager(), but now they callHF.diis_manager_. We're not bothering to deprecate the old way of calling it. I'm not aware if there's a way to still support the old syntax. It might work if we change the property name todiis_manager? I haven't tested this.set_error_vector_sizeandset_vector_sizeandadd_entrytype combination that Python might use. Sad, but necessary.And with that done, all four of the
compute_orbital_gradientfunctions could finally be moved to the Python layer.compute_orbital_gradientis kept as a virtual function, C++ side, to signal that Psi expects such a function to exist. My tests indicate that if the function is defined C++ side, it still works, so this won't break any SCF subclasses defined in plugins.Todos
HF.diis_manager()has changed toHF.diis_manager_HF.compute_orbital_gradientmoved to the Python layer. C-sidecompute_orbital_gradientis still supported, but not used by the core Psi.Questions
libdiisAPI change?Checklist
ctest -L scfpassesStatus