Skip to content

Commit

Permalink
Spin-shuffle charge-hop model state lassis
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewRHermes committed Nov 1, 2023
1 parent c4fd19b commit 64f467e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
29 changes: 17 additions & 12 deletions my_pyscf/lassi/lassis.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,22 @@ def single_excitations_ci (lsi, las2, las1, ncharge=1, sa_heff=True, deactivate_
converged = True
log.info ("LASSIS electron hop spaces: %d-%d", las1.nroots, las2.nroots-1)
for i in range (las1.nroots, las2.nroots):
# spin shuffle escape
i_ssref = None
for i0 in range (las1.nroots, i):
if spaces[i].is_spin_shuffle_of (spaces[i0]):
i_ssref = i0
break
if i_ssref is not None:
spaces[i].ci = spaces[i].get_spin_shuffle_civecs (spaces[i_ssref])
log.info ("Electron hop space %d:", i)
spaces[i].table_printlog ()
log.info ("is a spin shuffle of space %d", i_ssref)
for k in range (nfrags):
ci[k][i] = spaces[i].ci[k]
t0 = log.timer ("Space {} excitations".format (i), *t0)
continue
# end spin shuffle escape
psref_ix = [j for j, space in enumerate (spaces[:las1.nroots])
if spaces[i].is_single_excitation_of (space)]
psref = [spaces[j] for j in psref_ix]
Expand Down Expand Up @@ -132,18 +148,7 @@ def single_excitations_ci (lsi, las2, las1, ncharge=1, sa_heff=True, deactivate_
elif spin_shuffle_ref:
# NOTE: This logic fails if the user does spin_shuffle -> lasci -> LASSIS
ci1[k] = np.asarray (ci1[k][0])
else:
ndeta, ndetb = space[i].get_ndet (k)
c = np.concatenate ([c.reshape (-1,ndeta*ndetb) for c in ci1[k]], axis=0)
w, v = linalg.eigh (c.conj () @ c.T)
print (w)
idx = w>1e-8
ci1[k] = (v[:,idx].T @ c).reshape (-1,ndeta,ndetb)
c = ci1[k].reshape (-1,ndeta*ndetb)
print (c.conj () @ c.T)
for k in range (nfrags):
if isinstance (ci1[k], list):
print (k, len (ci1[k]), np.asarray (ci1[k]).shape, type (ciref[k]), [c.shape for c in ciref[k]])
spaces[i].ci = ci1
if not conv: log.warn ("CI vectors for charge-separated rootspace %d not converged", i)
converged = converged and conv
for k in range (nfrags):
Expand Down
6 changes: 5 additions & 1 deletion my_pyscf/lassi/states.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,11 @@ def is_spin_shuffle_of (self, other):
if np.any (self.smults != other.smults): return False
return self.spins.sum () == other.spins.sum ()

def get_spin_shuffle_civecs (self, other):
assert (self.is_spin_shuffle_of (other) and other.has_ci ())
ci_sz = other.get_ci_szrot ()
return [ci_sz[ifrag][self.spins[ifrag]] for ifrag in range (self.nfrag)]

def excited_fragments (self, other):
dneleca = self.neleca - other.neleca
dnelecb = self.nelecb - other.nelecb
Expand All @@ -268,7 +273,6 @@ def get_lroots (self):
lroots.append (c.shape[0])
return lroots


def table_printlog (self, lroots=None):
if lroots is None: lroots = self.get_lroots ()
log = logger.new_logger (self, self.verbose)
Expand Down

0 comments on commit 64f467e

Please sign in to comment.