Repository navigation
Description
With frozen=1, molecular UKS Casida TDDFT disagrees with the full-RPA formulation using the same SCF orbitals and numerical grid. Without frozen orbitals they agree. For LiH+/3-21g/BLYP, the first excitation is 8.96885810 eV rather than 9.00458160 eV.
Reproducer
import platform
import sys
import numpy as np
import scipy
import pyscf
from pyscf import dft, gto, lib, tdscf
lib.num_threads(2)
EV = 27.211386245988
mol = gto.M(atom="Li 0 0 0; H 0 0 1.6", basis="3-21g",
charge=1, spin=1, verbose=0)
mf = dft.UKS(mol)
mf.xc = "BLYP"
mf.grids.atom_grid = (99, 590)
mf.conv_tol = 1e-12
mf.kernel()
assert mf.converged
def matrix(td):
vind, hdiag = td.gen_vind()
return vind(np.eye(len(hdiag))).T
def energies(mat, squared=False):
w = np.linalg.eigvals(mat)
w = np.sort(w.real[(np.abs(w.imag) < 1e-8) & (w.real > 1e-8)])
return (np.sqrt(w) if squared else w)[:3] * EV
print("PySCF", pyscf.__version__, "Python", sys.version.split()[0],
"NumPy", np.__version__, "SciPy", scipy.__version__)
print(platform.platform())
for frozen in (None, 1):
td = mf.TDDFT(frozen=frozen)
stock = matrix(td)
# A second, equivalent TDDFT formulation using the same SCF orbitals/grid.
rpa = tdscf.uhf.TDHF(mf, frozen=frozen)
expected = energies(matrix(rpa))
# Diagnostic only: keep the frozen excitation space but use the full
# ground-state orbitals/occupations when constructing the XC kernel.
response = td.gen_response
electron_counts = []
def full_density(*args, **kwargs):
electron_counts.append(int(sum(np.sum(x) for x in args[1])))
return response(**kwargs)
td.gen_response = full_density
full = matrix(td)
observed = energies(stock, squared=True)
restored = energies(full, squared=True)
print("frozen =", frozen)
print(" stock Casida (eV): ", np.round(observed, 8))
print(" full-RPA expected (eV): ", np.round(expected, 8))
print(" full-density Casida: ", np.round(restored, 8))
print(" electrons passed to XC:", electron_counts[0],
"of", mol.nelectron)
print(" Casida matrix change: ", "%.6e" % np.max(abs(stock-full)))
assert np.max(abs(restored-expected)) < 1e-7
if frozen is None:
assert np.max(abs(observed-expected)) < 1e-7
else:
assert abs(observed[0]-expected[0]) > 0.01Output (PySCF 2.15.0)
PySCF 2.15.0 Python 3.14.4 NumPy 2.5.4 SciPy 1.18.1
Linux-7.0.0-38-generic-x86_64-with-glibc2.43
frozen = None
stock Casida (eV): [9.00395824 9.91146443 9.91146443]
full-RPA expected (eV): [9.00395824 9.91146443 9.91146443]
full-density Casida: [9.00395824 9.91146443 9.91146443]
electrons passed to XC: 3 of 3
Casida matrix change: 2.792905e-16
frozen = 1
stock Casida (eV): [8.9688581 9.81445551 9.81445551]
full-RPA expected (eV): [9.0045816 9.91178126 9.91178126]
full-density Casida: [9.0045816 9.91178126 9.91178126]
electrons passed to XC: 1 of 3
Casida matrix change: 5.098346e-03
Analysis and scope
At master 6037f7c86ae4afb9b9b02efbb3cbaab0b096ca78, pyscf/tdscf/uks.py:57–61 applies the frozen mask to mo_coeff and mo_occ; line 92 passes these sliced arrays to gen_response. The XC response therefore sees one electron rather than the three-electron SCF density in this example. Keeping the excitation space frozen but constructing the response from the full SCF orbitals restores agreement with full RPA. The matrix discrepancy is already present before iterative diagonalization.
The refuting control was agreement between the stock Casida matrix and the squared matrix constructed from get_ab() for the same frozen excitation space. It fails for UKS with a frozen occupied core: maximum element errors are BLYP 5.586e-3 Ha² and LDA,VWN 5.454e-3 Ha². Full-density Casida agrees within 9e-16 Ha². In 60 small-system matrix checks covering BLYP, LDA/VWN, B3LYP and HF, the corresponding RKS Casida, RKS/UKS TDA, full-RPA TDDFT and RHF/UHF TDHF paths agree with explicit A/B matrices to below 1e-14. No-freeze and frozen-virtual-only controls also agree.
Transition properties change with the incorrect eigenvectors, not through a separate frozen-orbital contraction error: for the BLYP level-4-grid control, the first transition-dipole norm is 0.25450773 au versus 0.24020145 au after restoring the full density; full-RPA gives 0.24020121 au. Direct AO-to-active-MO contraction reproduces the stock transition routine to 1.1e-16 au.
The two shipped nonhybrid UKS Casida tests (test_nohybrid_lda, test_nohybrid_b88p86) pass both stock and with the full-density response. The shipped examples/tddft/21-matrix_A_B.py also completes in both modes; its frozen UKS LDA/VWN branch exhibits the discrepancy. The relevant TDDFT and response source files are byte-identical in 2.15.0 and the stated master commit. The same minimal reproducer also fails in 2.14.0.
Environment
PySCF 2.15.0; Python 3.14.4; NumPy 2.5.4; SciPy 1.18.1; Linux x86_64, kernel 7.0.0-38-generic, glibc 2.43.
Activity