Skip to content

Commit 8d132c7

Browse files
John-zzhzhouzehao.dbsvsunqmwxj6000
authored
feature: TDDFT-ris (pyscf#367)
* TDDFT-ris with cupy speedup & nonorthonormal Krylov space methods * feat: implement RIS enhancements with file updates and tests * ris: syntax and test tolerance * einsum Ppq Cup Cvq now uses cupy_helper.contract; cp.zeros / cp.zeros_like -> cp.empty / cp.empty_like ; parameter docs ; remove prints ; * typo and logwarn * log timer; ris build; cholesky; magic number; eisum-> contract; TODO:test large systems * HARTREE2WAVENUMBER & bare except * Update GS flag in _lr_eig.py * example number --------- Co-authored-by: zhouzehao.dbsv <[email protected]> Co-authored-by: Qiming Sun <[email protected]> Co-authored-by: Xiaojie Wu <[email protected]>
1 parent 6c98f0f commit 8d132c7

File tree

8 files changed

+3427
-3
lines changed

8 files changed

+3427
-3
lines changed

examples/32-tddft_ris.py

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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+
16+
# Example of TDDFT-ris
17+
18+
19+
import pyscf
20+
from gpu4pyscf.dft import rks
21+
import gpu4pyscf.tdscf.ris as ris
22+
23+
atom ='''
24+
C -4.89126 3.29770 0.00029
25+
H -5.28213 3.05494 -1.01161
26+
O -3.49307 3.28429 -0.00328
27+
H -5.28213 2.58374 0.75736
28+
H -5.23998 4.31540 0.27138
29+
H -3.22959 2.35981 -0.24953
30+
'''
31+
32+
mol = pyscf.M(atom=atom, basis='def2-svp', verbose=4)
33+
mf = rks.RKS(mol, xc='wb97x').density_fit()
34+
35+
e_dft = mf.kernel()
36+
print(f"total energy = {e_dft}")
37+
38+
39+
40+
''' TDDFT-ris'''
41+
td = ris.TDDFT(mf=mf.to_gpu(), nstates=10, spectra=True)
42+
td.kernel()
43+
# energies, X, Y, oscillator_strength, rotatory_strength = td.kernel()
44+
45+
energies = td.energies
46+
# X = td.X
47+
# Y = td.Y
48+
oscillator_strength = td.oscillator_strength
49+
rotatory_strength = td.rotatory_strength
50+
51+
print("TDDFT-ris ex energies", energies)
52+
print("TDDFT-ris oscillator_strength", oscillator_strength)
53+
54+
''' TDA-ris'''
55+
td = ris.TDA(mf=mf.to_gpu(), nstates=10)
56+
td.kernel()
57+
# energies, X, oscillator_strength, rotatory_strength = td.kernel()
58+
59+
energies = td.energies
60+
# X = td.X
61+
oscillator_strength = td.oscillator_strength
62+
rotatory_strength = td.rotatory_strength
63+
64+
print("TDA-ris ex energies", energies)
65+
print("TDA-ris oscillator_strength", oscillator_strength)
66+
67+
68+

gpu4pyscf/lib/logger.py

+15
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,20 @@ def timer(rec, msg, cpu0=None, wall0=None, gpu0=None):
5959
flush(rec, ' CPU time for %s %9.2f sec' % (msg, t0-cpu0))
6060
return t0,
6161

62+
def timer_silent(rec, cpu0=None, wall0=None, gpu0=None):
63+
if gpu0:
64+
t0, w0, e0 = process_clock(), perf_counter(), cupy.cuda.Event()
65+
e0.record()
66+
e0.synchronize()
67+
return t0-cpu0, w0-wall0, cupy.cuda.get_elapsed_time(gpu0,e0)
68+
elif wall0:
69+
t0, w0 = process_clock(), perf_counter()
70+
return t0-cpu0, w0-wall0
71+
else:
72+
t0 = process_clock()
73+
return t0-cpu0,
74+
75+
6276
def _timer_debug1(rec, msg, cpu0=None, wall0=None, gpu0=None, sync=True):
6377
if rec.verbose >= DEBUG1:
6478
return timer(rec, msg, cpu0, wall0, gpu0)
@@ -103,6 +117,7 @@ def __init__(self, stdout=sys.stdout, verbose=NOTE):
103117
timer_debug2 = _timer_debug2
104118
timer = timer
105119
init_timer = init_timer
120+
timer_silent = timer_silent
106121

107122
def new_logger(rec=None, verbose=None):
108123
'''Create and return a :class:`Logger` object

0 commit comments

Comments
 (0)