BoothGroup / ebcc

Coupled cluster models for both purely electron and coupled electron-boson models, with a focus on generality and model extensibility.
https://boothgroup.github.io/ebcc/
MIT License
11 stars 2 forks source link

AttributeError: module 'pyscf.tblis_einsum' has no attribute 'tblis_dtype' #41

Closed vvp-nsk closed 8 months ago

vvp-nsk commented 8 months ago

Hej!

Please correct me if I am wrong, but EBCC might run faster if it utilizes the TBLIS library via PySCF's wrapper to it, right? I just locally installed TBLIS and pyscf-tblis but EBCC won’t work:

ccsd_sp.kernel()
  File "/home/rad/ebcc/ebcc/rebcc.py", line 364, in kernel
    e_cc = e_init = self.energy(amplitudes=amplitudes, eris=eris)
  File "/home/rad/ebcc/ebcc/rebcc.py", line 776, in energy
    return func(**kwargs)
  File "/home/rad/ebcc/ebcc/codegen/UCC2.py", line 10, in energy
    e_cc += einsum(t2.aaaa, (0, 1, 2, 3), v.aaaa.ovov, (0, 3, 1, 2), ()) * -1.0
  File "/home/rad/ebcc/ebcc/util.py", line 1108, in einsum
    out = _contract(subscript, *args, **kwargs)
  File "/home/rad/ebcc/ebcc/util.py", line 1041, in contract
    tblis_dtype = tblis_einsum.tblis_dtype[dtype]
AttributeError: module 'pyscf.tblis_einsum' has no attribute 'tblis_dtype

Do you know by chance what could be wrong with my local installation of TBLIS?

Thank you in advance!

With best regards, Victor

obackhouse commented 8 months ago

Should be fixed in #42, I'll merge once checks pass. Thanks, this is my oversight as my TBLIS is configured separately from PySCF. The ebcc.util code is a complete mess that I need to get round to cleaning up...

Indeed, I think that TBLIS has potential to improve speeds. Let me know how it goes.

vvp-nsk commented 8 months ago

Hej!

Thanks for the prompt fix. Now everything works out. The CC2 performs quite impressive, IMHO. I have a naive question. Does EBCC support the B-UCC2 (spin-unrestricted Brueckner CC2) ansatz?

With best regards, Victor

obackhouse commented 8 months ago

Hej!

Thanks for the prompt fix. Now everything works out. The CC2 performs quite impressive, IMHO. I have a naive question. Does EBCC support the B-UCC2 (spin-unrestricted Brueckner CC2) ansatz?

With best regards, Victor

Indeed it does, all methods that define a T2 amplitude can be run with Brueckner orbital self-consistency -- see example 5:

https://github.com/BoothGroup/ebcc/blob/4f01997caae06233adef6fbbf88fde8722c69300/examples/05-bccd.py#L1-L25

Just swap out the RHF for UHF and the ansatz="CCSD" for ansatz="CC2".

I just checked this using that example file, with CC2 instead of CCSD, and the convergence looks a little bit odd:

Solving for Brueckner orbitals.
Iter   Energy (corr.)  Converged        Δ(Energy)             |T1|
   0    -0.2127089116       True
   1    -0.2142051117       True        0.0014962        0.0031873
   2    -0.2140391594       True       5.8418e-05       0.00040664
   3    -0.2140535265       True        7.001e-06       9.3034e-06
   4    -0.2140506690       True        2.979e-06       8.8611e-06
   5    -0.2095300937       True        0.0045206         0.010745
   6     0.0000000000       True          0.20953                0
   7    -0.2140536823       True          0.21405       1.6012e-06
   8    -0.2140536949       True       6.7745e-10       1.1782e-06

I'm certainly no expert on Brueckner self-consistency, so not sure what's going on here, but it seems to converge no less. Let me know if you have any trouble with it for your application.

vvp-nsk commented 8 months ago

Hej!

I slightly modified your example to generate a real UHF open-shell reference case:

mport numpy as np
from pyscf import gto, scf

from ebcc import UEBCC

# Define the molecule using PySCF
mol = gto.Mole()
mol.atom = "H 0 0 0; F 0 0 1.1"
mol.basis = "cc-pvdz"
mol.charge = 1
mol.spin = 1
mol.build()

# Run a UHF calculation using PySCF
mf = scf.UHF(mol)
#mf = mf.density_fit()
mf.kernel()

# Run a CCSD calculation
ccsd = UEBCC(mf, ansatz="CC2")
ccsd.kernel()

# Run a Brueckner orbital calculation using the CCSD reference
ccsd.brueckner(e_tol=1e-6, t_tol=1e-5)

The input given above fails with the following error:

ebcc/ebcc/brueckner.py", line 410, in get_rotation_matrix
    a = diis.update(a, xerr=np.array([t1.aa, t1.bb]))
ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (2,) + inhomogeneous part.

Any help will be greatly appreciated!

With best regards, Victor

obackhouse commented 8 months ago

Hej!

I slightly modified your example to generate a real UHF open-shell reference case:

mport numpy as np
from pyscf import gto, scf

from ebcc import UEBCC

# Define the molecule using PySCF
mol = gto.Mole()
mol.atom = "H 0 0 0; F 0 0 1.1"
mol.basis = "cc-pvdz"
mol.charge = 1
mol.spin = 1
mol.build()

# Run a UHF calculation using PySCF
mf = scf.UHF(mol)
#mf = mf.density_fit()
mf.kernel()

# Run a CCSD calculation
ccsd = UEBCC(mf, ansatz="CC2")
ccsd.kernel()

# Run a Brueckner orbital calculation using the CCSD reference
ccsd.brueckner(e_tol=1e-6, t_tol=1e-5)

The input given above fails with the following error:

ebcc/ebcc/brueckner.py", line 410, in get_rotation_matrix
    a = diis.update(a, xerr=np.array([t1.aa, t1.bb]))
ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (2,) + inhomogeneous part.

Any help will be greatly appreciated!

With best regards, Victor

Ahh I see the issue, I've coded it up badly. This will take me a little longer, I'll try to get a fix later today. Sorry about all the bugs, I appreciate you identifying them though!

obackhouse commented 8 months ago

Should be fixed in #45. If you have any more problems, keep them coming :smile: