Skip to content

Commit

Permalink
Save cycle count (pyscf#1351)
Browse files Browse the repository at this point in the history
* Add a class to save iteration information and apply it to CCSD.

Signed-off-by: Kazuhito Matsuda <[email protected]>

* Reflect comments.

Signed-off-by: Kazuhito Matsuda <[email protected]>

* Simplify the storage of iteration info in ccsd

---------

Signed-off-by: Kazuhito Matsuda <[email protected]>
Co-authored-by: Qiming Sun <[email protected]>
  • Loading branch information
kfyharukz and sunqm authored Aug 26, 2024
1 parent e678ddc commit b81f4ac
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
4 changes: 2 additions & 2 deletions pyscf/cc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
Saved results
converged : bool
CCSD converged or not
iterinfo : common.IterationInfo
Information about iteration (see pyscf.common.Iteration in detail)
e_tot : float
Total CCSD energy (HF + correlation)
t1, t2 :
Expand Down
17 changes: 11 additions & 6 deletions pyscf/cc/ccsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ def kernel(mycc, eris=None, t1=None, t2=None, max_cycle=50, tol=1e-8,
else:
adiis = None

conv = False
converged = False
mycc.cycles = 0
for istep in range(max_cycle):
t1new, t2new = mycc.update_amps(t1, t2, eris)
if callback is not None:
Expand All @@ -83,14 +84,15 @@ def kernel(mycc, eris=None, t1=None, t2=None, max_cycle=50, tol=1e-8,
t1new = t2new = None
t1, t2 = mycc.run_diis(t1, t2, istep, normt, eccsd-eold, adiis)
eold, eccsd = eccsd, mycc.energy(t1, t2, eris)
mycc.cycles = istep + 1
log.info('cycle = %d E_corr(%s) = %.15g dE = %.9g norm(t1,t2) = %.6g',
istep+1, name, eccsd, eccsd - eold, normt)
cput1 = log.timer(f'{name} iter', *cput1)
if abs(eccsd-eold) < tol and normt < tolnormt:
conv = True
converged = True
break
log.timer(name, *cput0)
return conv, eccsd, t1, t2
return converged, eccsd, t1, t2


def update_amps(mycc, t1, t2, eris):
Expand Down Expand Up @@ -891,10 +893,10 @@ class CCSDBase(lib.StreamObject):
callback function can access all local variables in the current
environment.
Saved results
Saved results:
converged : bool
CCSD converged or not
Whether the CCSD iteration converged
e_corr : float
CCSD correlation correction
e_tot : float
Expand All @@ -903,6 +905,8 @@ class CCSDBase(lib.StreamObject):
T amplitudes t1[i,a], t2[i,j,a,b] (i,j in occ, a,b in virt)
l1, l2 :
Lambda amplitudes l1[i,a], l2[i,j,a,b] (i,j in occ, a,b in virt)
cycles : int
The number of iteration cycles performed
'''

max_cycle = getattr(__config__, 'cc_ccsd_CCSD_max_cycle', 50)
Expand All @@ -929,7 +933,7 @@ class CCSDBase(lib.StreamObject):
'diis_start_cycle', 'diis_start_energy_diff', 'direct',
'async_io', 'incore_complete', 'cc2', 'callback',
'mol', 'verbose', 'stdout', 'frozen', 'level_shift',
'mo_coeff', 'mo_occ', 'converged', 'converged_lambda', 'emp2', 'e_hf',
'mo_coeff', 'mo_occ', 'cycles', 'converged_lambda', 'emp2', 'e_hf',
'e_corr', 't1', 't2', 'l1', 'l2', 'chkfile',
}

Expand Down Expand Up @@ -959,6 +963,7 @@ def __init__(self, mf, frozen=None, mo_coeff=None, mo_occ=None):
self.mo_coeff = mo_coeff
self.mo_occ = mo_occ
self.converged = False
self.cycles = None
self.converged_lambda = False
self.emp2 = None
self.e_hf = None
Expand Down

0 comments on commit b81f4ac

Please sign in to comment.