Skip to content

Manually constructing the grid can lead to failed calculations #62

@awvwgk

Description

@awvwgk

Since the grid needs to be constructed as unsorted grid for Skala-1.1, constructing the grid manually without specifying sort_grids=False can lead to failed calculations. We should either document this behavior explicitly or have a better way to intercept a sorted grid before it reaches the XC integrator and fails with an obscure error message.

Example:

In [1]: from pyscf import gto
   ...: from skala.gpu4pyscf import SkalaKS

In [2]: mol = gto.M(atom="H 0 0 0; H 0 0 1.1", basis="def2-svp")

In [3]: ks = SkalaKS(mol, xc="skala-1.1")

In [4]: ks.grids.build()  # Create sorted grid by default
Out[4]: <gpu4pyscf.dft.gen_grid.Grids at 0x7f658a242660>

In [5]: ks.kernel()
---------------------------------------------------------------------------
LinAlgError                               Traceback (most recent call last)
Cell In[5], line 1
----> 1 ks.kernel()

File $PREFIX/lib/python3.13/site-packages/gpu4pyscf/scf/hf.py:355, in scf(mf, dm0, **kwargs)
    350     dm0 = mf.make_rdm1()
    352 if mf.max_cycle > 0 or mf.mo_coeff is None:
    353     mf.converged, mf.e_tot, \
    354             mf.mo_energy, mf.mo_coeff, mf.mo_occ = \
--> 355             _kernel(mf, mf.conv_tol, mf.conv_tol_grad,
    356                     dm0=dm0, callback=mf.callback,
    357                     conv_check=mf.conv_check, **kwargs)
    358 else:
    359     # Avoid to update SCF orbitals in the non-SCF initialization
    360     # (issue #495).  But run regular SCF for initial guess if SCF was
    361     # not initialized.
    362     mf.e_tot = _kernel(mf, mf.conv_tol, mf.conv_tol_grad,
    363                         dm0=dm0, callback=mf.callback,
    364                         conv_check=mf.conv_check, **kwargs)[1]

File $PREFIX/lib/python3.13/site-packages/gpu4pyscf/scf/hf.py:260, in _kernel(mf, conv_tol, conv_tol_grad, dump_chk, dm0, callback, conv_check, **kwargs)
    257 dm_last = dm
    258 last_hf_e = e_tot
--> 260 fock = mf.get_fock(h1e, s1e, vhf, dm, cycle, mf_diis, fock_last=fock_last)
    261 t1 = log.timer_debug1('DIIS', *t0)
    262 mo_energy, mo_coeff = mf.eig(fock, s1e)

File $PREFIX/lib/python3.13/site-packages/gpu4pyscf/scf/hf.py:160, in get_fock(mf, h1e, s1e, vhf, dm, cycle, diis, diis_start_cycle, level_shift_factor, damp_factor, fock_last)
    158     f = damping(f, fock_last, damp_factor)
    159 if diis is not None and cycle >= diis_start_cycle:
--> 160     f = diis.update(s1e, dm, f)
    162 if level_shift_factor is None:
    163     level_shift_factor = mf.level_shift

File $PREFIX/lib/python3.13/site-packages/gpu4pyscf/scf/diis.py:67, in CDIIS.update(self, s, d, f, *args, **kwargs)
     65 errvec = pack_tril(errvec.reshape(-1,nmo,nmo))
     66 f_tril = pack_tril(f.reshape(-1,nao,nao))
---> 67 xnew = lib.diis.DIIS.update(self, f_tril, xerr=errvec)
     68 if self.rollback > 0 and len(self._bookkeep) == self.space:
     69     self._bookkeep = self._bookkeep[-self.rollback:]

File $PREFIX/lib/python3.13/site-packages/gpu4pyscf/lib/diis.py:211, in DIIS.update(self, x, xerr)
    208 dt = None
    210 if self._xprev is None:
--> 211     xnew = cupy.asarray(self.extrapolate(nd))
    212 else:
    213     self._xprev = None # release memory first

File $PREFIX/lib/python3.13/site-packages/gpu4pyscf/lib/diis.py:229, in DIIS.extrapolate(self, nd)
    226 g = np.zeros(nd+1, h.dtype)
    227 g[0] = 1
--> 229 w, v = np.linalg.eigh(h)
    230 if any(abs(w)<1e-14):
    231     logger.debug(self, 'Linear dependence found in DIIS error vectors.')

File $PREFIX/lib/python3.13/site-packages/numpy/linalg/_linalg.py:1677, in eigh(a, UPLO)
   1673 signature = 'D->dD' if isComplexType(t) else 'd->dd'
   1674 with errstate(call=_raise_linalgerror_eigenvalues_nonconvergence,
   1675               invalid='call', over='ignore', divide='ignore',
   1676               under='ignore'):
-> 1677     w, vt = gufunc(a, signature=signature)
   1678 w = w.astype(_realType(result_t), copy=False)
   1679 vt = vt.astype(result_t, copy=False)

File $PREFIX/lib/python3.13/site-packages/numpy/linalg/_linalg.py:169, in _raise_linalgerror_eigenvalues_nonconvergence(err, flag)
    168 def _raise_linalgerror_eigenvalues_nonconvergence(err, flag):
--> 169     raise LinAlgError("Eigenvalues did not converge")

LinAlgError: Eigenvalues did not converge

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdocumentationImprovements or additions to documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions