fishjojo/pyscfad

Implement ROHF in pyscfad

Closed this issue · 7 comments

Feature request:

I was trying to use the different classes of scf and found out that only RHF and UHF are implemented in pyscfad. Since I wanted to use the automatic differentiation of pyscfad with ROHF, I was wondering if it would be possible to be implemented here too.

Yes, I can add it.

That is great to hear. My collaborator Nike Dattani (whom I cannot tag here for some reason) and I will be delighted to use that functionality.

@fishjojo we optimized the first 4 primitive exponents for the Li atom using UHF, and got:

E = -7.376925908376867

S-exponents:                         
3.4866918473739560e+01
5.1775711256586652e+00
1.0515665488904080e+00
4.7758303467345234e-02

This is lower than the published energy of -7.3769059.

We managed to get exactly the same energy as the published one, when we optimized the exponents using ROHF. Unfortunately we didn't have access to the derivative of the ROHF energy with respect to exponents, so we had to use a derivate-free optimization method, which requires far more iterations than most methods that use derivatives.

Also, is it possible to get the Hessian of the SCF energy with respect to exponents? This would allow us to speed-up the Newton-Raphson optimization of the exponents.

@ndattani the Hessian will need a little more work to implement, but I can take a look. ROHF will be ready to use soon.

Beautiful! The Hessian should improve our optimizations!

I'm currently getting this error:

  File "/localscratch/nike.62605116.0/ENV/lib/python3.10/site-packages/pyscfad/scf/rohf.py", line 4, in <module>
    from pyscf.lib import stop_grad
ImportError: cannot import name 'stop_grad' from 'pyscf.lib' (/localscratch/nike.62605116.0/ENV/lib/python3.10/site-packages/pyscf/lib/__init__.py)

This is because even the "ad" branch of PySCF doesn't have stop_grad. In hf.py we have from pyscfad.lib import stop_grad but in rohf.py we have from pyscf.lib import stop_grad.

So rohf.py should probably also have from pyscfad.lib import stop_grad.

@fishjojo did you test that the ROHF works? Or maybe your local version of PySCF is slightly different from the current "ad" branch on GitHub, and has stop_grad in it?

CC @vandan-revanur

Hi, @ndattani @vandan-revanur
This function is defined here in pyscf in the ad branch: https://github.com/fishjojo/pyscf/blob/4c3dcfb1226690a9013a0bdaffe08ef9113a3c77/pyscf/lib/misc.py#L1183-L1191
Please check if your pyscf is up to date.
The two versions of the stop_grad should both work, so you can use either one.
We are in the middle of transferring code from pyscfad to pyscf, so there may be some inconsistency.