From 61712ee520ce37d1fbfc7bfe99571709b0ab43c7 Mon Sep 17 00:00:00 2001 From: Atsushi Togo Date: Tue, 24 Dec 2024 13:30:05 +0900 Subject: [PATCH 1/3] Made D_diag's dtype=long --- phono3py/phonon/grid.py | 1 + 1 file changed, 1 insertion(+) diff --git a/phono3py/phonon/grid.py b/phono3py/phonon/grid.py index c34bcc9f..5997de66 100644 --- a/phono3py/phonon/grid.py +++ b/phono3py/phonon/grid.py @@ -684,6 +684,7 @@ def _set_mesh_numbers( self._D_diag = length2mesh( length, self._lattice, rotations=symmetry_dataset.rotations ) + self._D_diag = np.array(self._D_diag, dtype="long") if num_values == 9: self._run_grg( symmetry_dataset, From b12248f384017d6ad81e9801576f6f8e19aac37b Mon Sep 17 00:00:00 2001 From: Atsushi Togo Date: Tue, 24 Dec 2024 15:37:41 +0900 Subject: [PATCH 2/3] Show diagonalization information --- phono3py/conductivity/direct_solution.py | 47 ++++++++++++++++-------- phono3py/conductivity/utils.py | 2 +- 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/phono3py/conductivity/direct_solution.py b/phono3py/conductivity/direct_solution.py index 8e3ec348..52f60c9b 100644 --- a/phono3py/conductivity/direct_solution.py +++ b/phono3py/conductivity/direct_solution.py @@ -177,10 +177,21 @@ def set_collision_matrix(self, collision_matrix): ) self.collision_matrix = collision_matrix - def get_collision_eigenvalues(self): + @property + def collision_eigenvalues(self): """Return eigenvalues of collision matrix.""" return self._collision_eigenvalues + def get_collision_eigenvalues(self): + """Return eigenvalues of collision matrix.""" + warnings.warn( + "Use attribute, Conductivity_LBTE.collision_eigenvalues " + "instead of Conductivity_LBTE.get_collision_eigenvalues().", + DeprecationWarning, + stacklevel=2, + ) + return self.collision_eigenvalues + def get_frequencies_all(self): """Return phonon frequencies on GR-grid.""" return self._frequencies[self._pp.bz_grid.grg2bzg] @@ -690,12 +701,12 @@ def _symmetrize_collision_matrix(self): import phono3py._phono3py as phono3c if self._log_level: - sys.stdout.write("- Making collision matrix symmetric " "(built-in) ") + sys.stdout.write("- Making collision matrix symmetric (built-in) ") sys.stdout.flush() phono3c.symmetrize_collision_matrix(self._collision_matrix) except ImportError: if self._log_level: - sys.stdout.write("- Making collision matrix symmetric " "(numpy) ") + sys.stdout.write("- Making collision matrix symmetric (numpy) ") sys.stdout.flush() if self._is_reducible_collision_matrix: @@ -819,14 +830,18 @@ def _get_Y(self, i_sigma, i_temp, weights, X): start = time.time() - if self._pinv_method == 0: - eig_str = "abs(eig)" - else: - eig_str = "eig" - print( - f"Calculating pseudo-inv by ignoring {eig_str}<{self._pinv_cutoff:<.1e}", - end="", - ) + if self._log_level: + if self._pinv_method == 0: + eig_str = "abs(eig)" + else: + eig_str = "eig" + w = self._collision_eigenvalues[i_sigma, i_temp] + null_space = (np.abs(w) < self._pinv_cutoff).sum() + print( + f"Pseudo-inv by ignoring {null_space}/{len(w)} dims " + f"under {eig_str}<{self._pinv_cutoff:<.1e}", + end="", + ) if solver in [0, 1, 2, 3, 4, 5]: if self._log_level: print(" (np.dot) ", end="") @@ -1866,13 +1881,14 @@ def diagonalize_collision_matrix( assert size == shape[1] solver = select_colmat_solver(pinv_solver) + trace = np.trace(collision_matrices[i_sigma, i_temp].reshape(size, size)) # [1] dsyev: safer and slower than dsyevd and smallest memory usage # [2] dsyevd: faster than dsyev and largest memory usage if solver in [1, 2]: if log_level: routine = ["dsyev", "dsyevd"][solver - 1] - sys.stdout.write("Diagonalizing by lapacke %s... " % routine) + sys.stdout.write("Diagonalizing by lapacke %s ... " % routine) sys.stdout.flush() import phono3py._phono3py as phono3c @@ -1890,14 +1906,14 @@ def diagonalize_collision_matrix( ) # only diagonalization elif solver == 3: # np.linalg.eigh depends on dsyevd. if log_level: - sys.stdout.write("Diagonalizing by np.linalg.eigh... ") + sys.stdout.write("Diagonalizing by np.linalg.eigh ... ") sys.stdout.flush() col_mat = collision_matrices[i_sigma, i_temp].reshape(size, size) w, col_mat[:] = np.linalg.eigh(col_mat) elif solver == 4: # fully scipy dsyev if log_level: - sys.stdout.write("Diagonalizing by " "scipy.linalg.lapack.dsyev... ") + sys.stdout.write("Diagonalizing by " "scipy.linalg.lapack.dsyev ... ") sys.stdout.flush() import scipy.linalg @@ -1905,7 +1921,7 @@ def diagonalize_collision_matrix( w, _, info = scipy.linalg.lapack.dsyev(col_mat.T, overwrite_a=1) elif solver == 5: # fully scipy dsyevd if log_level: - sys.stdout.write("Diagonalizing by " "scipy.linalg.lapack.dsyevd... ") + sys.stdout.write("Diagonalizing by " "scipy.linalg.lapack.dsyevd ... ") sys.stdout.flush() import scipy.linalg @@ -1913,6 +1929,7 @@ def diagonalize_collision_matrix( w, _, info = scipy.linalg.lapack.dsyevd(col_mat.T, overwrite_a=1) if log_level: + print(f"delta={trace - w.sum():<.1e} ", end="") print("[%.3fs]" % (time.time() - start)) sys.stdout.flush() diff --git a/phono3py/conductivity/utils.py b/phono3py/conductivity/utils.py index ebdf67c6..1b70ce99 100644 --- a/phono3py/conductivity/utils.py +++ b/phono3py/conductivity/utils.py @@ -550,7 +550,7 @@ def write_kappa( mfp = lbte.get_mean_free_path() boundary_mfp = lbte.boundary_mfp - coleigs = lbte.get_collision_eigenvalues() + coleigs = lbte.collision_eigenvalues # After kappa calculation, the variable is overwritten by unitary matrix unitary_matrix = lbte.collision_matrix From 47aaab55d31482f9e0f5299bc9c74e79a3429ffe Mon Sep 17 00:00:00 2001 From: Atsushi Togo Date: Tue, 24 Dec 2024 15:59:36 +0900 Subject: [PATCH 3/3] Show also trace in diagonalization of colmat --- phono3py/conductivity/direct_solution.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/phono3py/conductivity/direct_solution.py b/phono3py/conductivity/direct_solution.py index 52f60c9b..8bca4a8b 100644 --- a/phono3py/conductivity/direct_solution.py +++ b/phono3py/conductivity/direct_solution.py @@ -838,7 +838,7 @@ def _get_Y(self, i_sigma, i_temp, weights, X): w = self._collision_eigenvalues[i_sigma, i_temp] null_space = (np.abs(w) < self._pinv_cutoff).sum() print( - f"Pseudo-inv by ignoring {null_space}/{len(w)} dims " + f"Pinv by ignoring {null_space}/{len(w)} dims " f"under {eig_str}<{self._pinv_cutoff:<.1e}", end="", ) @@ -1906,14 +1906,14 @@ def diagonalize_collision_matrix( ) # only diagonalization elif solver == 3: # np.linalg.eigh depends on dsyevd. if log_level: - sys.stdout.write("Diagonalizing by np.linalg.eigh ... ") + sys.stdout.write("Diagonalize by np.linalg.eigh ") sys.stdout.flush() col_mat = collision_matrices[i_sigma, i_temp].reshape(size, size) w, col_mat[:] = np.linalg.eigh(col_mat) elif solver == 4: # fully scipy dsyev if log_level: - sys.stdout.write("Diagonalizing by " "scipy.linalg.lapack.dsyev ... ") + sys.stdout.write("Diagonalize by scipy.linalg.lapack.dsyev ") sys.stdout.flush() import scipy.linalg @@ -1921,7 +1921,7 @@ def diagonalize_collision_matrix( w, _, info = scipy.linalg.lapack.dsyev(col_mat.T, overwrite_a=1) elif solver == 5: # fully scipy dsyevd if log_level: - sys.stdout.write("Diagonalizing by " "scipy.linalg.lapack.dsyevd ... ") + sys.stdout.write("Diagnalize by scipy.linalg.lapack.dsyevd ") sys.stdout.flush() import scipy.linalg @@ -1929,7 +1929,7 @@ def diagonalize_collision_matrix( w, _, info = scipy.linalg.lapack.dsyevd(col_mat.T, overwrite_a=1) if log_level: - print(f"delta={trace - w.sum():<.1e} ", end="") + print(f"sum={w.sum():<.1e} d={trace - w.sum():<.1e} ", end="") print("[%.3fs]" % (time.time() - start)) sys.stdout.flush()