Skip to content

Molecular DF (.density_fit()) fails in cart2sph for lanthanide basis sets with g functions (auxbasis reaches l=8) — molecular analogue of #761 #811

Description

@rhjvanworkum

Describe the bug

Molecular density-fitted SCF (.density_fit()) crashes with RuntimeError: failed in cart2sph kernel for lanthanide elements whose orbital basis contains g functions (l=4) — e.g. Eu with def2-TZVP. The auto-generated DF auxiliary basis for such a system reaches l=8, and the molecular DF path (gpu4pyscf/df/int3c2e.py) calls cart2sph(..., ang=lk) with that high angular momentum, which the cart2sph CUDA kernel cannot handle.

This appears to be the molecular-path analogue of #761, which fixed the same "lanthanide g-shells → auxbasis reaches l=8" problem for the periodic path by raising L_AUX_MAX. The molecular DF path seems not to have received an equivalent fix, and instead of a graceful assert it fails inside the CUDA kernel.

  • CPU PySCF runs the identical system fine.
  • GPU without density fitting (direct SCF) also gets past this point (no cart2sph error) — so the gap is specific to the DF integral transform, consistent with the core DFT path supporting high l (up to i, Support I orbital in DFT #340).

Minimal reproducer

import re
import basis_set_exchange as bse
from pyscf import gto
from gpu4pyscf.dft import rks

# PySCF's built-in library has no Eu def2-TZVP, so fetch it (basis + ECP) from BSE.
nw = bse.get_basis("def2-tzvp", elements=["Eu"], fmt="nwchem", header=False)
m = re.search(r"(?im)^\s*ECP\s*$", nw)
basis = {"Eu": gto.basis.parse(nw[: m.start()])}
ecp = {"Eu": gto.basis.parse_ecp(nw[m.start():])}

mol = gto.M(atom="Eu 0 0 0", basis=basis, ecp=ecp, spin=7, verbose=4)
# orbital lmax = 4 (g); auto DF aux lmax = 8
mf = rks.RKS(mol, xc="pbe").density_fit()
mf.kernel()   # -> RuntimeError: failed in cart2sph kernel

(The same failure occurs for a real Eu coordination complex at wB97M-V/def2-TZVPD — that was the original context; the single atom is the minimal trigger.)

Traceback

File ".../gpu4pyscf/df/df.py", line 282, in cholesky_eri_gpu
File ".../gpu4pyscf/df/df.py", line 339, in _cderi_task
File ".../gpu4pyscf/df/int3c2e.py", line 1527, in get_int3c2e_slice
    int3c_blk = cart2sph(int3c_blk, axis=0, ang=lk, out=out)
File ".../gpu4pyscf/lib/cupy_helper.py", line 615, in cart2sph
    raise RuntimeError('failed in cart2sph kernel')
RuntimeError: failed in cart2sph kernel

Diagnostics

For the reproducer:

  • orbital basis lmax = 4 (g functions on Eu; all lighter atoms are ≤ f)
  • auto DF auxiliary basis lmax = 8 (via pyscf.df.addons.make_auxmol) — the ang=lk passed into cart2sph reaches this value
  • CPU PySCF: builds and runs (this system has 762 basis functions, matching the reference)
  • GPU direct SCF (no .density_fit()): does not hit the cart2sph error

Expected behavior

Density-fitted SCF should support auxiliary-basis angular momenta produced by lanthanide (g-function) orbital bases — i.e. the molecular DF cart2sph should handle ang up to at least 8, mirroring the L_AUX_MAX fix in #761 for the periodic path (or fall back gracefully).

Environment

  • gpu4pyscf-cuda12x 1.7.4
  • pyscf 2.13.1
  • cupy-cuda12x 14.1.1
  • CUDA 12.8, NVIDIA L4 (24 GB)
  • Python 3.13, Linux

Related

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions