Skip to content

Commit e5ba7b6

Browse files
John-zzhzhouzehao.dbsv
andauthored
feat: TDDFT-ris store Tia Tij Tab in RAM (#461)
* store Tia Tij Tab in RAM * ris class API change: GS -> gram_schmidt * merge get_ab into new ris.py structure * self.X -> self.xy; merge zhichen's chkfile attr * print -> log.info * log info more attri; fancy indexing lower_inv_eri2c * converge TDA calculation in 5 iterations, enjoy it --------- Co-authored-by: zhouzehao.dbsv <zhouzehao.dbsv@bytedance.com>
1 parent 9e1e800 commit e5ba7b6

File tree

5 files changed

+676
-937
lines changed

5 files changed

+676
-937
lines changed

examples/42_ris_preconditioned_TDA.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Copyright 2021-2025 The PySCF Developers. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import gpu4pyscf.tdscf.ris as ris
16+
import pyscf
17+
18+
from gpu4pyscf import dft
19+
from gpu4pyscf.tdscf import _krylov_tools
20+
from pyscf.data.nist import HARTREE2EV
21+
22+
# this example shows how to use the TDA-rid (up to d orbitals) preconditioned TDA solver
23+
# converged the TDA calculation in 5 iterations
24+
25+
mol = pyscf.M(atom='Vitamin_C.xyz', basis='def2-svp', verbose=3)
26+
27+
mf = dft.RKS(mol, xc='pbe0')
28+
29+
mf=mf.to_gpu()
30+
mf.kernel()
31+
32+
33+
34+
td = mf.TDA()
35+
# construct the TDA matrix vector product function and the hdiag
36+
vind, hdiag = td.gen_vind(td._scf)
37+
38+
#construct the preconditioner, the TDA-ris matrix vector product function (and the hdiag)gi
39+
tda_ris = ris.TDA(mf, J_fit='spd')
40+
ris_mvp, _hdiag = tda_ris.gen_vind()
41+
42+
43+
# use the nested krylov solver, instead of the default krylov solver
44+
energies, X = _krylov_tools.nested_krylov_solver(matrix_vector_product=vind,hdiag=hdiag,
45+
problem_type='eigenvalue', n_states=5,
46+
init_mvp=ris_mvp, precond_mvp=ris_mvp)
47+
48+
print('energies', energies*HARTREE2EV)

gpu4pyscf/tdscf/_lr_eig.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import scipy.linalg
2424
import cupyx.scipy.linalg
2525
from gpu4pyscf.tdscf import math_helper
26-
import time
26+
from functools import partial
2727
from pyscf.lib.parameters import MAX_MEMORY
2828
from gpu4pyscf.lib import logger
2929
from pyscf.lib.linalg_helper import _sort_elast, _outprod_to_subspace
@@ -1119,7 +1119,7 @@ def Davidson(matrix_vector_product,
11191119
N_states=20,
11201120
conv_tol=1e-5,
11211121
max_iter=25,
1122-
GS=True,
1122+
gram_schmidt=True,
11231123
single=False,
11241124
verbose=logger.INFO):
11251125
'''
@@ -1144,7 +1144,7 @@ def Davidson(matrix_vector_product,
11441144
convergence tolerance
11451145
max_iter: int
11461146
maximum iterations
1147-
GS: bool
1147+
gram_schmidt: bool
11481148
use Gram-Schmidt orthogonalization
11491149
single: bool
11501150
use single precision
@@ -1196,9 +1196,9 @@ def Davidson(matrix_vector_product,
11961196
'''
11971197
V_holder = math_helper.TDA_diag_initial_guess(V_holder=V_holder, N_states=size_new, hdiag=hdiag)
11981198

1199-
if GS:
1199+
if gram_schmidt:
12001200
log.info('Using Gram-Schmidt orthogonalization')
1201-
fill_holder = math_helper.Gram_Schmidt_fill_holder
1201+
fill_holder = partial(math_helper.Gram_Schmidt_fill_holder, double=True)
12021202
else:
12031203
log.info('Using non-orthogonalized Krylov subspace (nKs) method.')
12041204

@@ -1247,7 +1247,7 @@ def Davidson(matrix_vector_product,
12471247
omega[:N_states] are smallest N_states eigenvalues
12481248
'''
12491249
t0 = log.init_timer()
1250-
if GS:
1250+
if gram_schmidt:
12511251
omega, x = cp.linalg.eigh(sub_A)
12521252
else:
12531253
s_holder = math_helper.gen_VW(s_holder, V_holder, V_holder, size_old, size_new, symmetry=False)
@@ -1320,7 +1320,7 @@ def Davidson_Casida(matrix_vector_product,
13201320
N_states=20,
13211321
conv_tol=1e-5,
13221322
max_iter=25,
1323-
GS=True,
1323+
gram_schmidt=True,
13241324
single=False,
13251325
verbose=logger.NOTE):
13261326
'''
@@ -1345,7 +1345,7 @@ def Davidson_Casida(matrix_vector_product,
13451345
convergence tolerance
13461346
max_iter: int
13471347
maximum number of iterations
1348-
GS: bool
1348+
gram_schmidt: bool
13491349
use Gram-Schmidt orthogonalization
13501350
single: bool
13511351
use single precision
@@ -1425,7 +1425,7 @@ def Davidson_Casida(matrix_vector_product,
14251425
N_states=size_new,
14261426
hdiag=hdiag)
14271427

1428-
if GS:
1428+
if gram_schmidt:
14291429
log.info('Using Gram-Schmidt orthogonalization')
14301430
fill_holder = math_helper.VW_Gram_Schmidt_fill_holder
14311431
else:
@@ -1527,7 +1527,7 @@ def Davidson_Casida(matrix_vector_product,
15271527
hdiag=hdiag)
15281528

15291529
'''
1530-
GS and symmetric orthonormalization
1530+
gram_schmidt and symmetric orthonormalization
15311531
'''
15321532
t0 = log.init_timer()
15331533
size_old = size_new

0 commit comments

Comments
 (0)