From be5d2dd30c9ee249ba11be32679f9eabe95821e7 Mon Sep 17 00:00:00 2001 From: Atsushi Togo Date: Mon, 23 Dec 2024 14:17:06 +0900 Subject: [PATCH 01/12] Set BUILD_WITHOUT_LAPACKE=ON as default --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index c178490f..3b2ad2ac 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -52,7 +52,7 @@ sdist.include = [ PHONO3PY_USE_MTBLAS = {env="PHONO3PY_USE_MTBLAS", default="ON"} USE_CONDA_PATH = {env="USE_CONDA_PATH", default="ON"} PHONO3PY_USE_OMP = {env="PHONO3PY_USE_OMP", default="ON"} -BUILD_WITHOUT_LAPACKE = {env="BUILD_WITHOUT_LAPACKE", default="OFF"} +BUILD_WITHOUT_LAPACKE = {env="BUILD_WITHOUT_LAPACKE", default="ON"} [tool.setuptools_scm] write_to = "phono3py/_version.py" From eb1ebe0cf29f5efbb91edeae32e7893fa6169d2a Mon Sep 17 00:00:00 2001 From: Atsushi Togo Date: Mon, 23 Dec 2024 14:43:32 +0900 Subject: [PATCH 02/12] Update CMakeLists.txt --- CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 11dc20d1..0e46d3fa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,7 +66,9 @@ endif() message(STATUS "Build type: ${CMAKE_BUILD_TYPE}") message(STATUS "CMAKE_SYSTEM_PREFIX_PATH: ${CMAKE_SYSTEM_PREFIX_PATH}") -if(USE_CONDA_PATH AND DEFINED ENV{CONDA_PREFIX}) +if((NOT BUILD_WITHOUT_LAPACKE) + AND USE_CONDA_PATH + AND DEFINED ENV{CONDA_PREFIX}) message(STATUS "$ENV{CONDA_PREFIX}") set(CMAKE_MODULE_PATH $ENV{CONDA_PREFIX}) set(MY_INCLUDES $ENV{CONDA_PREFIX}/include ${PROJECT_SOURCE_DIR}/c) From 7b8f7a8d841de8634d583e670ad151a8a1b957a0 Mon Sep 17 00:00:00 2001 From: Atsushi Togo Date: Mon, 23 Dec 2024 15:20:16 +0900 Subject: [PATCH 03/12] Define complex for VC --- c/lapack_wrapper.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/c/lapack_wrapper.h b/c/lapack_wrapper.h index b18db54a..a2e30008 100644 --- a/c/lapack_wrapper.h +++ b/c/lapack_wrapper.h @@ -36,6 +36,20 @@ #define __lapack_wrapper_H__ #ifdef NO_INCLUDE_LAPACKE +#if defined(_MSC_VER) +typedef struct { + double real; + double imag; +} lapack_complex_double; +lapack_complex_double lapack_make_complex_double(double re, double im) { + lapack_complex_double c; + c.real = re; + c.imag = im; + return c; +} +#define lapack_complex_double_real(z) ((z).real) +#define lapack_complex_double_imag(z) ((z).imag) +#else #include #define lapack_complex_double double _Complex #ifdef CMPLX @@ -46,6 +60,7 @@ #define lapack_complex_double_real(z) (creal(z)) #define lapack_complex_double_imag(z) (cimag(z)) #endif +#endif #if defined(MKL_BLAS) || defined(SCIPY_MKL_H) #include From 71dcf8410835fd57a453290cfaa156e2d331374d Mon Sep 17 00:00:00 2001 From: Atsushi Togo Date: Mon, 23 Dec 2024 15:45:51 +0900 Subject: [PATCH 04/12] Define complex for VC --- c/lapack_wrapper.c | 5 +++-- c/lapack_wrapper.h | 28 ++++++++++------------------ 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/c/lapack_wrapper.c b/c/lapack_wrapper.c index 166e2000..f8838cb1 100644 --- a/c/lapack_wrapper.c +++ b/c/lapack_wrapper.c @@ -38,7 +38,7 @@ #define min(a, b) ((a) > (b) ? (b) : (a)) -#if (defined(MKL_BLAS) || defined(SCIPY_MKL_H)) && !defined(NO_INCLUDE_LAPACKE) +#if defined(_MSC_VER) || defined(MKL_BLAS) || defined(SCIPY_MKL_H) lapack_complex_double lapack_make_complex_double(double re, double im) { lapack_complex_double z; z.real = re; @@ -47,7 +47,8 @@ lapack_complex_double lapack_make_complex_double(double re, double im) { } #endif -#if defined(MKL_BLAS) || defined(SCIPY_MKL_H) || defined(NO_INCLUDE_LAPACKE) +#if defined(_MSC_VER) || defined(MKL_BLAS) || defined(SCIPY_MKL_H) || \ + defined(NO_INCLUDE_LAPACKE) #ifndef LAPACKE_malloc #define LAPACKE_malloc(size) malloc(size) #endif diff --git a/c/lapack_wrapper.h b/c/lapack_wrapper.h index a2e30008..2c4178a4 100644 --- a/c/lapack_wrapper.h +++ b/c/lapack_wrapper.h @@ -35,21 +35,21 @@ #ifndef __lapack_wrapper_H__ #define __lapack_wrapper_H__ -#ifdef NO_INCLUDE_LAPACKE +#if defined(_MSC_VER) || defined(MKL_BLAS) || defined(SCIPY_MKL_H) #if defined(_MSC_VER) typedef struct { double real; double imag; } lapack_complex_double; -lapack_complex_double lapack_make_complex_double(double re, double im) { - lapack_complex_double c; - c.real = re; - c.imag = im; - return c; -} +#else +#include +#define lapack_complex_double MKL_Complex16 +#endif +lapack_complex_double lapack_make_complex_double(double re, double im); #define lapack_complex_double_real(z) ((z).real) #define lapack_complex_double_imag(z) ((z).imag) #else +#if defined(NO_INCLUDE_LAPACKE) #include #define lapack_complex_double double _Complex #ifdef CMPLX @@ -59,19 +59,11 @@ lapack_complex_double lapack_make_complex_double(double re, double im) { #endif #define lapack_complex_double_real(z) (creal(z)) #define lapack_complex_double_imag(z) (cimag(z)) +#else +#if !defined(MKL_BLAS) && !defined(SCIPY_MKL_H) +#include #endif #endif - -#if defined(MKL_BLAS) || defined(SCIPY_MKL_H) -#include -#define lapack_complex_double MKL_Complex16 -MKL_Complex16 lapack_make_complex_double(double re, double im); -#define lapack_complex_double_real(z) ((z).real) -#define lapack_complex_double_imag(z) ((z).imag) -#endif - -#if !defined(MKL_BLAS) && !defined(SCIPY_MKL_H) && !defined(NO_INCLUDE_LAPACKE) -#include #endif lapack_complex_double phonoc_complex_prod(const lapack_complex_double a, From 0b677509b9969ee29a39213a6a6eb5f906b66aaa Mon Sep 17 00:00:00 2001 From: Atsushi Togo Date: Mon, 23 Dec 2024 16:04:55 +0900 Subject: [PATCH 05/12] Remove unnecessary functions from _phono3py.cpp and phono3py.h --- c/_phono3py.cpp | 162 ------------------------------------------------ c/phono3py.h | 31 --------- 2 files changed, 193 deletions(-) diff --git a/c/_phono3py.cpp b/c/_phono3py.cpp index a7017d66..52e7ff14 100644 --- a/c/_phono3py.cpp +++ b/c/_phono3py.cpp @@ -887,168 +887,6 @@ void py_get_triplets_integration_weights_with_sigma( num_triplets, frequencies, num_band, num_iw); } -long py_get_grid_index_from_address(nb::ndarray<> py_address, - nb::ndarray<> py_D_diag) { - long *address; - long *D_diag; - long gp; - - address = (long *)py_address.data(); - D_diag = (long *)py_D_diag.data(); - - gp = ph3py_get_grid_index_from_address(address, D_diag); - - return gp; -} - -long py_get_ir_grid_map(nb::ndarray<> py_grid_mapping_table, - nb::ndarray<> py_D_diag, nb::ndarray<> py_is_shift, - nb::ndarray<> py_rotations) { - long *D_diag; - long *is_shift; - long(*rot)[3][3]; - long num_rot; - - long *grid_mapping_table; - long num_ir; - - D_diag = (long *)py_D_diag.data(); - is_shift = (long *)py_is_shift.data(); - rot = (long(*)[3][3])py_rotations.data(); - num_rot = (long)py_rotations.shape(0); - grid_mapping_table = (long *)py_grid_mapping_table.data(); - - num_ir = ph3py_get_ir_grid_map(grid_mapping_table, D_diag, is_shift, rot, - num_rot); - return num_ir; -} - -void py_get_gr_grid_addresses(nb::ndarray<> py_gr_grid_addresses, - nb::ndarray<> py_D_diag) { - long(*gr_grid_addresses)[3]; - long *D_diag; - - gr_grid_addresses = (long(*)[3])py_gr_grid_addresses.data(); - D_diag = (long *)py_D_diag.data(); - - ph3py_get_gr_grid_addresses(gr_grid_addresses, D_diag); -} - -long py_get_reciprocal_rotations(nb::ndarray<> py_rec_rotations, - nb::ndarray<> py_rotations, - long is_time_reversal) { - long(*rec_rotations)[3][3]; - long(*rotations)[3][3]; - long num_rot, num_rec_rot; - - rec_rotations = (long(*)[3][3])py_rec_rotations.data(); - rotations = (long(*)[3][3])py_rotations.data(); - num_rot = (long)py_rotations.shape(0); - - num_rec_rot = ph3py_get_reciprocal_rotations(rec_rotations, rotations, - num_rot, is_time_reversal); - - return num_rec_rot; -} - -bool py_transform_rotations(nb::ndarray<> py_transformed_rotations, - nb::ndarray<> py_rotations, nb::ndarray<> py_D_diag, - nb::ndarray<> py_Q) { - long(*transformed_rotations)[3][3]; - long(*rotations)[3][3]; - long *D_diag; - long(*Q)[3]; - long num_rot, succeeded; - - transformed_rotations = (long(*)[3][3])py_transformed_rotations.data(); - rotations = (long(*)[3][3])py_rotations.data(); - D_diag = (long *)py_D_diag.data(); - Q = (long(*)[3])py_Q.data(); - num_rot = (long)py_transformed_rotations.shape(0); - - succeeded = ph3py_transform_rotations(transformed_rotations, rotations, - num_rot, D_diag, Q); - if (succeeded) { - return true; - } else { - return false; - } -} - -bool py_get_snf3x3(nb::ndarray<> py_D_diag, nb::ndarray<> py_P, - nb::ndarray<> py_Q, nb::ndarray<> py_A) { - long *D_diag; - long(*P)[3]; - long(*Q)[3]; - long(*A)[3]; - long succeeded; - - D_diag = (long *)py_D_diag.data(); - P = (long(*)[3])py_P.data(); - Q = (long(*)[3])py_Q.data(); - A = (long(*)[3])py_A.data(); - - succeeded = ph3py_get_snf3x3(D_diag, P, Q, A); - if (succeeded) { - return true; - } else { - return false; - } -} - -long py_get_bz_grid_addresses(nb::ndarray<> py_bz_grid_addresses, - nb::ndarray<> py_bz_map, nb::ndarray<> py_bzg2grg, - nb::ndarray<> py_D_diag, nb::ndarray<> py_Q, - nb::ndarray<> py_PS, - nb::ndarray<> py_reciprocal_lattice, long type) { - long(*bz_grid_addresses)[3]; - long *bz_map; - long *bzg2grg; - long *D_diag; - long(*Q)[3]; - long *PS; - double(*reciprocal_lattice)[3]; - long num_total_gp; - - bz_grid_addresses = (long(*)[3])py_bz_grid_addresses.data(); - bz_map = (long *)py_bz_map.data(); - bzg2grg = (long *)py_bzg2grg.data(); - D_diag = (long *)py_D_diag.data(); - Q = (long(*)[3])py_Q.data(); - PS = (long *)py_PS.data(); - reciprocal_lattice = (double(*)[3])py_reciprocal_lattice.data(); - - num_total_gp = - ph3py_get_bz_grid_addresses(bz_grid_addresses, bz_map, bzg2grg, D_diag, - Q, PS, reciprocal_lattice, type); - - return num_total_gp; -} - -long py_rotate_bz_grid_addresses(long bz_grid_index, nb::ndarray<> py_rotation, - nb::ndarray<> py_bz_grid_addresses, - nb::ndarray<> py_bz_map, - nb::ndarray<> py_D_diag, nb::ndarray<> py_PS, - long type) { - long(*bz_grid_addresses)[3]; - long(*rotation)[3]; - long *bz_map; - long *D_diag; - long *PS; - long ret_bz_gp; - - bz_grid_addresses = (long(*)[3])py_bz_grid_addresses.data(); - rotation = (long(*)[3])py_rotation.data(); - bz_map = (long *)py_bz_map.data(); - D_diag = (long *)py_D_diag.data(); - PS = (long *)py_PS.data(); - - ret_bz_gp = ph3py_rotate_bz_grid_index( - bz_grid_index, rotation, bz_grid_addresses, bz_map, D_diag, PS, type); - - return ret_bz_gp; -} - long py_get_default_colmat_solver() { #if defined(MKL_BLAS) || defined(SCIPY_MKL_H) || !defined(NO_INCLUDE_LAPACKE) return (long)1; diff --git a/c/phono3py.h b/c/phono3py.h index 54247e24..351a7c3f 100644 --- a/c/phono3py.h +++ b/c/phono3py.h @@ -176,37 +176,6 @@ void ph3py_get_integration_weight_with_sigma( const double *frequency_points, const long num_band0, const long (*triplets)[3], const long num_triplets, const double *frequencies, const long num_band, const long tp_type); -long ph3py_get_grid_index_from_address(const long address[3], - const long mesh[3]); -void ph3py_get_gr_grid_addresses(long gr_grid_addresses[][3], - const long D_diag[3]); -long ph3py_get_reciprocal_rotations(long rec_rotations[48][3][3], - const long (*rotations)[3][3], - const long num_rot, - const long is_time_reversal); -long ph3py_transform_rotations(long (*transformed_rots)[3][3], - const long (*rotations)[3][3], - const long num_rot, const long D_diag[3], - const long Q[3][3]); -long ph3py_get_snf3x3(long D_diag[3], long P[3][3], long Q[3][3], - const long A[3][3]); -long ph3py_transform_rotations(long (*transformed_rots)[3][3], - const long (*rotations)[3][3], - const long num_rot, const long D_diag[3], - const long Q[3][3]); -long ph3py_get_ir_grid_map(long *ir_grid_map, const long D_diag[3], - const long PS[3], const long (*grg_rotations)[3][3], - const long num_rot); -long ph3py_get_bz_grid_addresses(long (*bz_grid_addresses)[3], long *bz_map, - long *bzg2grg, const long D_diag[3], - const long Q[3][3], const long PS[3], - const double rec_lattice[3][3], - const long type); -long ph3py_rotate_bz_grid_index(const long bz_grid_index, - const long rotation[3][3], - const long (*bz_grid_addresses)[3], - const long *bz_map, const long D_diag[3], - const long PS[3], const long bz_grid_type); void ph3py_symmetrize_collision_matrix(double *collision_matrix, const long num_column, const long num_temp, From cd1e1e9407ef3b41f641e9f33e5661fac1f9c67c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 24 Dec 2024 00:07:42 +0000 Subject: [PATCH 06/12] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.8.3 → v0.8.4](https://github.com/astral-sh/ruff-pre-commit/compare/v0.8.3...v0.8.4) --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ea69ffe6..69500ebe 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -11,7 +11,7 @@ repos: exclude: ^example/AlN-LDA/ - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.8.3 + rev: v0.8.4 hooks: - id: ruff args: [ "--fix", "--show-fixes" ] From 61712ee520ce37d1fbfc7bfe99571709b0ab43c7 Mon Sep 17 00:00:00 2001 From: Atsushi Togo Date: Tue, 24 Dec 2024 13:30:05 +0900 Subject: [PATCH 07/12] 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 08/12] 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 09/12] 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() From fb7f2bbe8f9d83e6389b4be032bbef7fe053ff54 Mon Sep 17 00:00:00 2001 From: Atsushi Togo Date: Thu, 26 Dec 2024 10:02:00 +0900 Subject: [PATCH 10/12] Update github workflows for no-lapacke as default --- .../phono3py-pytest-conda-mkl-phphmtblas.yml | 2 +- .../phono3py-pytest-conda-mkl-v2.yml | 2 +- .../workflows/phono3py-pytest-conda-mkl.yml | 2 +- .../phono3py-pytest-conda-phphmtblas.yml | 2 +- ...=> phono3py-pytest-conda-with-lapacke.yml} | 4 +- .github/workflows/phono3py-pytest-conda.yml | 4 +- doc/direct-solution.md | 36 ++++++--------- doc/install.md | 46 ++++++++++--------- 8 files changed, 48 insertions(+), 50 deletions(-) rename .github/workflows/{phono3py-pytest-conda-nolapacke.yml => phono3py-pytest-conda-with-lapacke.yml} (86%) diff --git a/.github/workflows/phono3py-pytest-conda-mkl-phphmtblas.yml b/.github/workflows/phono3py-pytest-conda-mkl-phphmtblas.yml index 49e60dd4..2c149f50 100644 --- a/.github/workflows/phono3py-pytest-conda-mkl-phphmtblas.yml +++ b/.github/workflows/phono3py-pytest-conda-mkl-phphmtblas.yml @@ -42,7 +42,7 @@ jobs: - name: Install phono3py run: | conda activate test - PHPHCALC_USE_MTBLAS=ON pip install -e . -vvv + BUILD_WITHOUT_LAPACKE=OFF PHPHCALC_USE_MTBLAS=ON pip install -e . -vvv - name: Run pytest run: | conda activate test diff --git a/.github/workflows/phono3py-pytest-conda-mkl-v2.yml b/.github/workflows/phono3py-pytest-conda-mkl-v2.yml index c1e95df6..2ff17580 100644 --- a/.github/workflows/phono3py-pytest-conda-mkl-v2.yml +++ b/.github/workflows/phono3py-pytest-conda-mkl-v2.yml @@ -42,7 +42,7 @@ jobs: - name: Install phono3py run: | conda activate test - pip install -e . -vvv + BUILD_WITHOUT_LAPACKE=OFF pip install -e . -vvv - name: Run pytest run: | conda activate test diff --git a/.github/workflows/phono3py-pytest-conda-mkl.yml b/.github/workflows/phono3py-pytest-conda-mkl.yml index c1ae62de..15df9803 100644 --- a/.github/workflows/phono3py-pytest-conda-mkl.yml +++ b/.github/workflows/phono3py-pytest-conda-mkl.yml @@ -46,7 +46,7 @@ jobs: - name: Run pytest run: | conda activate test - pytest -v --cov=./ --cov-report=xml test + BUILD_WITHOUT_LAPACKE=OFF pytest -v --cov=./ --cov-report=xml test - name: Upload coverage to Codecov uses: codecov/codecov-action@v3 with: diff --git a/.github/workflows/phono3py-pytest-conda-phphmtblas.yml b/.github/workflows/phono3py-pytest-conda-phphmtblas.yml index cd4d625e..d7fde199 100644 --- a/.github/workflows/phono3py-pytest-conda-phphmtblas.yml +++ b/.github/workflows/phono3py-pytest-conda-phphmtblas.yml @@ -42,7 +42,7 @@ jobs: - name: Install phono3py run: | conda activate test - PHPHCALC_USE_MTBLAS=ON pip install -e . -vvv + BUILD_WITHOUT_LAPACKE=OFF PHPHCALC_USE_MTBLAS=ON pip install -e . -vvv - name: Run pytest run: | conda activate test diff --git a/.github/workflows/phono3py-pytest-conda-nolapacke.yml b/.github/workflows/phono3py-pytest-conda-with-lapacke.yml similarity index 86% rename from .github/workflows/phono3py-pytest-conda-nolapacke.yml rename to .github/workflows/phono3py-pytest-conda-with-lapacke.yml index a114f4e4..ba6ea604 100644 --- a/.github/workflows/phono3py-pytest-conda-nolapacke.yml +++ b/.github/workflows/phono3py-pytest-conda-with-lapacke.yml @@ -24,7 +24,7 @@ jobs: run: | conda activate test conda install --yes python=${{ matrix.python-version }} - conda install --yes matplotlib-base pyyaml h5py scipy pytest spglib cmake c-compiler cxx-compiler + conda install --yes matplotlib-base pyyaml "libblas=*=*openblas" openblas h5py scipy pytest spglib cmake c-compiler cxx-compiler - name: Install symfc develop branch run: | conda activate test @@ -42,7 +42,7 @@ jobs: - name: Install phono3py run: | conda activate test - BUILD_WITHOUT_LAPACKE=ON pip install -e . -vvv + BUILD_WITHOUT_LAPACKE=OFF pip install -e . -vvv - name: Run pytest run: | conda activate test diff --git a/.github/workflows/phono3py-pytest-conda.yml b/.github/workflows/phono3py-pytest-conda.yml index 99b0a596..ac42faa9 100644 --- a/.github/workflows/phono3py-pytest-conda.yml +++ b/.github/workflows/phono3py-pytest-conda.yml @@ -25,13 +25,13 @@ jobs: run: | conda activate test conda install --yes python=${{ matrix.python-version }} - conda install --yes matplotlib-base pyyaml "libblas=*=*openblas" openblas h5py "numpy>=2.1" scipy pytest spglib alm cmake c-compiler cxx-compiler pypolymlp + conda install --yes matplotlib-base pyyaml h5py "numpy>=2.1" scipy pytest spglib alm cmake c-compiler cxx-compiler pypolymlp - name: Install dependent packages for python == 3.9 if: ${{ matrix.python-version == 3.9 }} run: | conda activate test conda install --yes python=${{ matrix.python-version }} - conda install --yes matplotlib-base pyyaml "libblas=*=*openblas" openblas h5py scipy pytest spglib alm cmake c-compiler cxx-compiler + conda install --yes matplotlib-base pyyaml h5py scipy pytest spglib alm cmake c-compiler cxx-compiler - name: Install symfc develop branch run: | conda activate test diff --git a/doc/direct-solution.md b/doc/direct-solution.md index 2d716feb..54c8edf7 100644 --- a/doc/direct-solution.md +++ b/doc/direct-solution.md @@ -295,24 +295,23 @@ language implementation through the python C-API. ## Solver choice for diagonalization -For larger systems, diagonalization of collision matrix takes longest time and -requires large memory space. Phono3py relies on LAPACK for the diagonalization -and so the performance is dependent on the choice of the diagonalization solver. - -Using multithreaded BLAS with many-core computing node, computing time may be -well reduced and the calculation can finish in a realistic time. Currently -scipy, numpy and LAPACKE can be used as the LAPACK wrapper in phono3py. Scipy -and numpy distributed by anaconda are MKL linked, therefore MKL multithread BLAS -is used through them. Multithreaded OpenBLAS is installed by conda and can be -used via LAPACKE in phono3py. MKL LAPACK and BLAS are also able to be used via -LAPACKE in phono3py with appropriate setting in `setup.py`. - -Using `--pinv-solver NUMBER`, one of the following solver is chosen: - -1. Lapacke `dsyev`: Smaller memory consumption than `dsyevd`, but slower. This +Diagonalizing the collision matrix for larger systems is the most time-consuming +step and requires significant memory. Phono3py uses LAPACK for diagonalization, +making performance highly dependent on the solver choice. Utilizing +multithreaded BLAS on many-core nodes can significantly reduce computation time, +allowing calculations to complete within practical limits. Currently, Phono3py +supports diagonalization via scipy, numpy, and LAPACKE as LAPACK wrappers. + +The default choice of the diagonalization solver is `scipy.linalg.lapack.dsyev` +(`--pinv-solver=4`). Using `--pinv-solver NUMBER`, one of the following solvers +is specified: + +1. (Only available when {ref}`compiling with LAPACKE `) + Lapacke `dsyev`: Smaller memory consumption than `dsyevd`, but slower. This is the default solver when MKL LAPACKE is integrated or scipy is not installed. -2. Lapacke `dsyevd`: Larger memory consumption than `dsyev`, but faster. This is +2. (Only available when {ref}`compiling with LAPACKE `) + Lapacke `dsyevd`: Larger memory consumption than `dsyev`, but faster. This is not considered as stable as `dsyev` but can be significantly faster than `dsyev` for solving large collision matrix. It is recommended to compare the result with that by `dsyev` solver using smaller collision matrix (e.g., @@ -323,8 +322,3 @@ Using `--pinv-solver NUMBER`, one of the following solver is chosen: LAPACKE is not integrated. 5. Scipy's `dsyevd`: Similar to solver (2), this solver should be used carefully. - -```{note} -`pinv-solver` =3, 4, and 5 are only available when phono3py is compiled -without LAPACKE. -``` diff --git a/doc/install.md b/doc/install.md index 6ff25900..17b6de30 100644 --- a/doc/install.md +++ b/doc/install.md @@ -41,8 +41,9 @@ removed. If phono3py is compiled with a special compiler or special options, manual modification of `CMakeLists.txt` may be needed. -- {ref}`Linear algebra library `: BLAS, LAPACK, and LAPACKE - {ref}`OpenMP library `: For the multithreding support. +- {ref}`Linear algebra library `: BLAS, LAPACK, and LAPACKE + (optional, see {ref}`install_with_lapacke`) These packages may be installed by the package manager of OS (e.g. `apt`) or conda environment. Automatic search of required libraries and flags that are @@ -61,24 +62,6 @@ See an example at {ref}`install_an_example`. In the standard output, flags and libraries found by cmake are shown. Please carefully check if those configurations are expected ones or not. -(install_without_lapacke)= -### Building without linking LAPACKE - -**Experimental** - -To compile phono3py without linking LAPACKE in C, use the following command: - -``` -% BUILD_WITHOUT_LAPACKE=ON pip install -e . -vvv -``` - -When this option is enabled, linking to BLAS and LAPACKE libraries is not -required, so installing these libraries for C compilation may not be necessary. -However, since numpy and scipy rely on BLAS and LAPACK libraries, their runtime -versions are still required. - -(install_an_example)= - ## Installation instruction of latest development version of phono3py When using conda, `PYTHONPATH` should not be set if possible because potentially @@ -122,7 +105,7 @@ wrong python libraries can be imported. % conda install numpy scipy h5py pyyaml matplotlib-base c-compiler cxx-compiler cmake spglib ``` - Unless {ref}`install_without_lapacke`, the following packages will be + Unless {ref}`install_with_lapacke`, the following packages will be necessary to compile phono3py: ```bash @@ -142,7 +125,7 @@ wrong python libraries can be imported. % conda install numpy scipy h5py pyyaml matplotlib-base c-compiler cxx-compiler spglib cmake ``` - Unless {ref}`install_without_lapacke`, the following package will be + Unless {ref}`install_with_lapacke`, the following package will be necessary to compile phono3py: ```bash @@ -185,6 +168,27 @@ LAPACK*E* is the C-wrapper of LAPACK and LAPACK relies on BLAS. Both single-thread or multithread BLAS can be used in phono3py. In the following, multiple different ways of installation of LAPACKE are explained. +(install_with_lapacke)= +#### Building with linking LAPACKE + +Phono3py can operate without linking to LAPACKE, which is the default +compilation setting. However, it is also possible to compile Phono3py with +LAPACKE support. When compiled this way, the diagonalization of the dynamical +matrix is handled by LAPACK routines within the C code of Phono3py. +Additionally, LAPACK is used for the diagonalization of the collision matrix +in the direct solution. + +To compile phono3py with linking LAPACKE in C, use the following command: + +``` +% BUILD_WITHOUT_LAPACKE=OFF pip install -e . -vvv +``` + +For this, BLAS and LAPACKE libraries are required. + +(install_an_example)= + + #### OpenBLAS provided by conda The installation of LAPACKE is easy by conda. It is: From 1184cc00c4da32597662c65ff0aa087f7988fdd4 Mon Sep 17 00:00:00 2001 From: Atsushi Togo Date: Thu, 26 Dec 2024 10:11:06 +0900 Subject: [PATCH 11/12] Fix titles of github workflows --- .github/workflows/phono3py-pytest-conda-mkl-phphmtblas.yml | 2 +- .github/workflows/phono3py-pytest-conda-with-lapacke.yml | 2 +- .github/workflows/phono3py-pytest-conda.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/phono3py-pytest-conda-mkl-phphmtblas.yml b/.github/workflows/phono3py-pytest-conda-mkl-phphmtblas.yml index 2c149f50..7a276266 100644 --- a/.github/workflows/phono3py-pytest-conda-mkl-phphmtblas.yml +++ b/.github/workflows/phono3py-pytest-conda-mkl-phphmtblas.yml @@ -1,4 +1,4 @@ -name: Pytest with mkl sing BLAS for phph-calc +name: Pytest with mkl using BLAS for phph-calc on: pull_request: diff --git a/.github/workflows/phono3py-pytest-conda-with-lapacke.yml b/.github/workflows/phono3py-pytest-conda-with-lapacke.yml index ba6ea604..09e41605 100644 --- a/.github/workflows/phono3py-pytest-conda-with-lapacke.yml +++ b/.github/workflows/phono3py-pytest-conda-with-lapacke.yml @@ -1,4 +1,4 @@ -name: Pytest without linking BLAS and LAPACK in C +name: Pytest with linking BLAS and LAPACK in C on: pull_request: diff --git a/.github/workflows/phono3py-pytest-conda.yml b/.github/workflows/phono3py-pytest-conda.yml index ac42faa9..bc6e8e8d 100644 --- a/.github/workflows/phono3py-pytest-conda.yml +++ b/.github/workflows/phono3py-pytest-conda.yml @@ -1,4 +1,4 @@ -name: Pytest with openblas +name: Pytest without using LAPACKE on: pull_request: From 3a7458b207f1c28f29acf98f0c9dafbc69c54735 Mon Sep 17 00:00:00 2001 From: Atsushi Togo Date: Thu, 26 Dec 2024 10:17:52 +0900 Subject: [PATCH 12/12] Set version 3.10.2 --- doc/changelog.md | 4 ++++ doc/conf.py | 2 +- phono3py/version.py | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/doc/changelog.md b/doc/changelog.md index 85cc3446..3d22fee3 100644 --- a/doc/changelog.md +++ b/doc/changelog.md @@ -2,6 +2,10 @@ # Change Log +## Dec-26-2024: Version 3.10.2 + +- `BUILD_WITHOUT_LAPACKE=ON` was made as the default compilation choice. + ## Dec-23-2024: Version 3.10.1 - Replace `dtype="int_"` by `dtype="long"`. diff --git a/doc/conf.py b/doc/conf.py index 319c91eb..3682b15e 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -60,7 +60,7 @@ # The short X.Y version. version = "3.10" # The full version, including alpha/beta/rc tags. -release = "3.10.1" +release = "3.10.2" # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/phono3py/version.py b/phono3py/version.py index 97046b22..a589b5d7 100644 --- a/phono3py/version.py +++ b/phono3py/version.py @@ -34,4 +34,4 @@ # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -__version__ = "3.10.1" +__version__ = "3.10.2"