Skip to content

Commit b864680

Browse files
committed
Add a new eigh_method by setting eigh_method as 2. It can enhance the precision in computing smaller eigenvalues
1 parent 7c77176 commit b864680

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

deepks/model/reader.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def __init__(self, data_path, batch_size,
3535
phialpha_name="phialpha",gevdm_name="grad_evdm",
3636
h_base_name="h_base",h_ref_name="hamiltonian",
3737
read_overlap = False, overlap_name="overlap",
38+
eigh_method = 1,
3839
eg_name="eg_base", gveg_name="grad_veg",
3940
gldv_name="grad_ldv", conv_name="conv",
4041
atom_name="atom", **kwargs):
@@ -61,6 +62,7 @@ def __init__(self, data_path, batch_size,
6162
self.c_path = self.check_exist(conv_name+".npy")
6263
self.a_path = self.check_exist(atom_name+".npy")
6364
self.read_overlap = read_overlap
65+
self.eigh_method = eigh_method
6466
# load data
6567
self.load_meta()
6668
self.prepare()
@@ -184,8 +186,16 @@ def prepare(self):
184186
if self.read_overlap is True and self.overlap_path is not None:
185187
#print("use generalized eigh")
186188
overlap=torch.tensor(np.load(self.overlap_path))
187-
L=torch.linalg.cholesky(overlap)
188-
trans_matrix=torch.linalg.inv(L).mT
189+
# When overlap matrix is ill-conditioned, the eigenvalues (i.e. band) can suffer from significant roundoff errors.
190+
if self.eigh_method == 1:
191+
L=torch.linalg.cholesky(overlap)
192+
trans_matrix=torch.linalg.inv(L).mT
193+
# Substitute cholesky with eigen decomposition.
194+
# This modification effectively reorders the entries of symm_h, placing larger values towards the upper left-hand corner, thereby enhancing the precision in computing smaller eigenvalues
195+
elif self.eigh_method == 2:
196+
overlap_eigenvalue,overlap_eigenvector=torch.linalg.eigh(overlap)
197+
sigma_inv_sqrt = torch.diag_embed(1.0 / torch.sqrt(overlap_eigenvalue))
198+
trans_matrix=overlap_eigenvector @ sigma_inv_sqrt
189199
self.t_data["trans_matrix"]=trans_matrix\
190200
.reshape(raw_nframes, -1, self.nlocal, self.nlocal)[conv].clone()
191201
band_ref,phi_ref=generalized_eigh(h_ref,trans_matrix)

0 commit comments

Comments
 (0)