Skip to content

Commit

Permalink
finalize update_ham_pq
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewRHermes committed Nov 19, 2024
1 parent d6b0395 commit 1b02593
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions my_pyscf/lassi/excitations.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ def get_ham_pq (self, h0, h1, h2, ci_p):

def update_ham_pq (self, ham_pq, h0, h1, h2, ci, hci1_qspace, hci1_pspace_diag, tdm1s_f_1,
norb_f, nelec_f):
ref = self.get_ham_pq (h0, h1, h2, ci)
#ref = self.get_ham_pq (h0, h1, h2, ci)
t0 = lib.logger.process_clock (), lib.logger.perf_counter ()
#return ref
nfrags = len (ci)
Expand All @@ -322,7 +322,7 @@ def update_ham_pq (self, ham_pq, h0, h1, h2, ci, hci1_qspace, hci1_pspace_diag,
# q,q sector
ham_pq = np.zeros ((p+q,p+q), dtype=old_ham_pq.dtype)
ham_pq[-q:,-q:] = old_ham_pq[-q:,-q:]
assert (np.amax (np.abs (ham_pq[p:,p:] - ref[p:,p:])) < 1e-6)
#assert (np.amax (np.abs (ham_pq[p:,p:] - ref[p:,p:])) < 1e-6)

# p,q sector
h_pq = np.zeros ((lroots[1],lroots[0],q), dtype=ham_pq.dtype)
Expand All @@ -339,9 +339,9 @@ def update_ham_pq (self, ham_pq, h0, h1, h2, ci, hci1_qspace, hci1_pspace_diag,
)
h_pq = h_pq.reshape (lroots[1]*lroots[0],q)
ham_pq[:p,p:] = h_pq
assert (np.amax (np.abs (ham_pq[:p,p:] - ref[:p,p:])) < 1e-6)
#assert (np.amax (np.abs (ham_pq[:p,p:] - ref[:p,p:])) < 1e-6)
ham_pq[p:,:p] = h_pq.conj ().T
assert (np.amax (np.abs (ham_pq[p:,:p] - ref[p:,:p])) < 1e-6)
#assert (np.amax (np.abs (ham_pq[p:,:p] - ref[p:,:p])) < 1e-6)

# p,p sector - constant
h_pp = np.zeros ((p,p), dtype=ham_pq.dtype)
Expand Down Expand Up @@ -381,24 +381,24 @@ def update_ham_pq (self, ham_pq, h0, h1, h2, ci, hci1_qspace, hci1_pspace_diag,
h2[i:,:i,:i,i:])
h_pp += w.transpose (0,2,1,3)
ham_pq[:p,:p] = h_pp.reshape (lroots[1]*lroots[0], lroots[1]*lroots[0])
try:
assert (np.amax (np.abs (ham_pq[:p,:p] - ref[:p,:p])) < 1e-6), '{}-{}={}'.format (
lib.fp (ham_pq[:p,:p]), lib.fp (ref[:p,:p]), lib.fp (ham_pq[:p,:p])-lib.fp (ref[:p,:p]))
except AssertionError as err:
idx = np.argmax (np.abs (ham_pq[:p,:p]-ref[:p,:p]))
print (lroots, idx, ham_pq[:p,:p].flat[idx], ref[:p,:p].flat[idx], (ham_pq[:p,:p]-ref[:p,:p]).flat[idx])
raise (err)

try:
assert (np.amax (np.abs (ham_pq - ref)) < 1e-6), '{}-{}={}'.format (
lib.fp (ham_pq), lib.fp (ref), lib.fp (ham_pq)-lib.fp (ref))
except AssertionError as err:
idx = np.argmax (np.abs (ham_pq-ref))
print (lroots, idx, ham_pq.flat[idx], ref.flat[idx], ham_pq.flat[idx]-ref.flat[idx])
raise (err)
#try:
# assert (np.amax (np.abs (ham_pq[:p,:p] - ref[:p,:p])) < 1e-6), '{}-{}={}'.format (
# lib.fp (ham_pq[:p,:p]), lib.fp (ref[:p,:p]), lib.fp (ham_pq[:p,:p])-lib.fp (ref[:p,:p]))
#except AssertionError as err:
# idx = np.argmax (np.abs (ham_pq[:p,:p]-ref[:p,:p]))
# print (lroots, idx, ham_pq[:p,:p].flat[idx], ref[:p,:p].flat[idx], (ham_pq[:p,:p]-ref[:p,:p]).flat[idx])
# raise (err)

#try:
# assert (np.amax (np.abs (ham_pq - ref)) < 1e-6), '{}-{}={}'.format (
# lib.fp (ham_pq), lib.fp (ref), lib.fp (ham_pq)-lib.fp (ref))
#except AssertionError as err:
# idx = np.argmax (np.abs (ham_pq-ref))
# print (lroots, idx, ham_pq.flat[idx], ref.flat[idx], ham_pq.flat[idx]-ref.flat[idx])
# raise (err)

t1 = self.log.timer ('update_ham_pq', *t0)
return ref
return ham_pq

def op_ham_pq_ref (self, h1, h2, ci):
'''Act the Hamiltonian on the reference CI vectors and project onto the current
Expand Down

0 comments on commit 1b02593

Please sign in to comment.