From d56960a89adc64b26c8b22f55e54a117be8118e4 Mon Sep 17 00:00:00 2001 From: Atsushi Togo Date: Mon, 25 Nov 2024 13:40:01 +0900 Subject: [PATCH 1/3] Set version 3.8.0 --- doc/changelog.md | 6 ++++++ doc/conf.py | 4 ++-- doc/direct-solution.md | 7 ++++++- doc/install.md | 17 ++++++++++++++++- phono3py/conductivity/utils.py | 7 +++++++ phono3py/version.py | 2 +- pyproject.toml | 2 +- test/conductivity/test_kappa_LBTE.py | 27 ++++++++++++++++++++++++++- 8 files changed, 65 insertions(+), 7 deletions(-) diff --git a/doc/changelog.md b/doc/changelog.md index fea78c71..dd7516ef 100644 --- a/doc/changelog.md +++ b/doc/changelog.md @@ -2,6 +2,12 @@ # Change Log +## Nov-25-2024: Version 3.8.0 + +- Follow the change due to phonopy's refactoring of MLP interface. +- Experimental option (`BUILD_WITHOUT_LAPACKE=ON`) to compile phono3py without + LAPACKE in C + ## Nov-13-2024: Version 3.7.0 - Update to follow the change of phonopy's internal functions diff --git a/doc/conf.py b/doc/conf.py index e42ff2fa..8a8a5292 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -58,9 +58,9 @@ # built documents. # # The short X.Y version. -version = "3.7" +version = "3.8" # The full version, including alpha/beta/rc tags. -release = "3.7.0" +release = "3.8.0" # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/doc/direct-solution.md b/doc/direct-solution.md index a13c3fe1..2d716feb 100644 --- a/doc/direct-solution.md +++ b/doc/direct-solution.md @@ -307,7 +307,7 @@ 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: +Using `--pinv-solver NUMBER`, one of the following solver is chosen: 1. Lapacke `dsyev`: Smaller memory consumption than `dsyevd`, but slower. This is the default solver when MKL LAPACKE is integrated or scipy is not @@ -323,3 +323,8 @@ 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 04a10c1f..13c965f3 100644 --- a/doc/install.md +++ b/doc/install.md @@ -49,7 +49,7 @@ conda environment. Automatic search of required libraries and flags that are already on the system is performed by cmake. (install_with_cmake)= -### Build with automatic search of library configurations by cmake +### Building with automatic search of library configurations by cmake With installed cmake and required libraries on the system, cmake tries to find libraries to be linked and the compiler flags that are required during the build. @@ -61,6 +61,21 @@ 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. +### 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 diff --git a/phono3py/conductivity/utils.py b/phono3py/conductivity/utils.py index ea5797bc..ebdf67c6 100644 --- a/phono3py/conductivity/utils.py +++ b/phono3py/conductivity/utils.py @@ -686,6 +686,13 @@ def select_colmat_solver(pinv_solver): print("Phono3py C-routine is not compiled correctly.") default_solver = 4 + if not phono3c.include_lapacke(): + if pinv_solver in (1, 2, 6): + raise RuntimeError( + "Use pinv-solver 3, 4, or 5 because " + "phono3py is not compiled with LAPACKE." + ) + solver_numbers = (1, 2, 3, 4, 5, 6) solver = pinv_solver diff --git a/phono3py/version.py b/phono3py/version.py index 6dc2d7e2..23d47634 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.7.0" +__version__ = "3.8.0" diff --git a/pyproject.toml b/pyproject.toml index 50962076..5836dc48 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,7 +16,7 @@ dependencies = [ "matplotlib>=2.2.2", "h5py>=3.0", "spglib>=2.3", - "phonopy>=2.30,<2.31", + "phonopy>=2.31,<2.32", ] license = { file = "LICENSE" } diff --git a/test/conductivity/test_kappa_LBTE.py b/test/conductivity/test_kappa_LBTE.py index f494b0e0..1c7c9ab4 100644 --- a/test/conductivity/test_kappa_LBTE.py +++ b/test/conductivity/test_kappa_LBTE.py @@ -1,11 +1,17 @@ """Tests for direct solution of LBTE.""" import numpy as np +import pytest +import phono3py._phono3py as phono3c from phono3py.api_phono3py import Phono3py -def test_kappa_LBTE(si_pbesol: Phono3py): +@pytest.mark.skipif( + not phono3c.include_lapacke(), reason="test for phono3py compliled with lapacke" +) +@pytest.mark.parametrize("pinv_solver", [1, 2, 3, 4, 5]) +def test_kappa_LBTE(si_pbesol: Phono3py, pinv_solver: int): """Test for symmetry reduced collision matrix.""" if si_pbesol._make_r0_average: ref_kappa = [110.896, 110.896, 110.896, 0, 0, 0] @@ -18,11 +24,30 @@ def test_kappa_LBTE(si_pbesol: Phono3py): temperatures=[ 300, ], + pinv_solver=pinv_solver, ) kappa = si_pbesol.thermal_conductivity.kappa.ravel() np.testing.assert_allclose(ref_kappa, kappa, atol=0.3) +@pytest.mark.skipif( + phono3c.include_lapacke(), reason="test for phono3py compliled without lapacke" +) +@pytest.mark.parametrize("pinv_solver", [1, 2]) +def test_kappa_LBTE_witout_lapacke(si_pbesol: Phono3py, pinv_solver: int): + """Test for symmetry reduced collision matrix.""" + si_pbesol.mesh_numbers = [9, 9, 9] + si_pbesol.init_phph_interaction() + with pytest.raises(RuntimeError): + si_pbesol.run_thermal_conductivity( + is_LBTE=True, + temperatures=[ + 300, + ], + pinv_solver=pinv_solver, + ) + + def test_kappa_LBTE_full_colmat(si_pbesol: Phono3py): """Test for full collision matrix.""" if si_pbesol._make_r0_average: From 2b491d23271bb8df31ed97bff421d52791d37620 Mon Sep 17 00:00:00 2001 From: Atsushi Togo Date: Mon, 25 Nov 2024 14:16:00 +0900 Subject: [PATCH 2/3] Add test symmetrized LBTE over pinv-solvers --- test/conductivity/test_kappa_LBTE.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/test/conductivity/test_kappa_LBTE.py b/test/conductivity/test_kappa_LBTE.py index 1c7c9ab4..10326417 100644 --- a/test/conductivity/test_kappa_LBTE.py +++ b/test/conductivity/test_kappa_LBTE.py @@ -10,9 +10,19 @@ @pytest.mark.skipif( not phono3c.include_lapacke(), reason="test for phono3py compliled with lapacke" ) -@pytest.mark.parametrize("pinv_solver", [1, 2, 3, 4, 5]) -def test_kappa_LBTE(si_pbesol: Phono3py, pinv_solver: int): +@pytest.mark.parametrize("pinv_solver", [1, 2]) +def test_kappa_LBTE_12(si_pbesol: Phono3py, pinv_solver: int): + """Test for symmetry reduced collision matrix.""" + _test_kappa_LBTE(si_pbesol, pinv_solver) + + +@pytest.mark.parametrize("pinv_solver", [3, 4, 5]) +def test_kappa_LBTE_345(si_pbesol: Phono3py, pinv_solver: int): """Test for symmetry reduced collision matrix.""" + _test_kappa_LBTE(si_pbesol, pinv_solver) + + +def _test_kappa_LBTE(si_pbesol: Phono3py, pinv_solver: int): if si_pbesol._make_r0_average: ref_kappa = [110.896, 110.896, 110.896, 0, 0, 0] else: @@ -65,7 +75,7 @@ def test_kappa_LBTE_full_colmat(si_pbesol: Phono3py): is_reducible_collision_matrix=True, ) kappa = si_pbesol.thermal_conductivity.kappa.ravel() - np.testing.assert_allclose(ref_kappa, kappa, atol=0.3) + np.testing.assert_allclose(ref_kappa, kappa, atol=0.5) def test_kappa_LBTE_aln(aln_lda: Phono3py): From cf0ab00fc50c132d9cdfbec3ca2c10c3f529c7ed Mon Sep 17 00:00:00 2001 From: Atsushi Togo Date: Mon, 25 Nov 2024 14:26:33 +0900 Subject: [PATCH 3/3] Add comments in run_phonon_solver_c --- phono3py/phonon/solver.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/phono3py/phonon/solver.py b/phono3py/phonon/solver.py index 84b0dfd8..6c216a49 100644 --- a/phono3py/phonon/solver.py +++ b/phono3py/phonon/solver.py @@ -53,6 +53,14 @@ def run_phonon_solver_c( ): """Bulid and solve dynamical matrices on grid in C-API. + Note + ---- + When LAPACKE is linked in C, `phononcalc.phonons_at_gridpoints` constucts + and solves dynamical matrices on grid points. Otherwise, it only constructs + dynamical matrices and solves them in python. + + Parameters + ---------- dm : DynamicalMatrix DynamicalMatrix instance. frequencies, eigenvectors, phonon_done : @@ -65,8 +73,8 @@ def run_phonon_solver_c( QDinv : ndarray See BZGrid.QDinv. frequency_conversion_factor : float, optional - Frequency convertion factor that is multiplied with - sqrt or eigenvalue of dynamical matrix. Default is VaspToTHz. + Frequency convertion factor that is multiplied with sqrt or eigenvalue + of dynamical matrix. Default is VaspToTHz. nac_q_direction : array_like, optional See Interaction.nac_q_direction. Default is None. lapack_zheev_uplo : str, optional @@ -126,6 +134,9 @@ def run_phonon_solver_c( assert lapack_zheev_uplo in ("L", "U") if not phono3c.include_lapacke(): + # phonon_done is set even with phono3c.include_lapacke() == 0 for which + # dynamical matrices are not diagonalized in + # phononcalc.phonons_at_gridpoints. phonon_undone = np.where(phonon_done == 0)[0] fc_p2s, fc_s2p = _get_fc_elements_mapping(dm, fc) @@ -159,8 +170,12 @@ def run_phonon_solver_c( ) if not phono3c.include_lapacke(): + # The variable `eigenvectors` contains dynamical matrices. + # They are diagonalized in python as follows. for gp in phonon_undone: - frequencies[gp], eigenvectors[gp] = np.linalg.eigh(eigenvectors[gp]) + frequencies[gp], eigenvectors[gp] = np.linalg.eigh( + eigenvectors[gp], UPLO=lapack_zheev_uplo + ) frequencies[phonon_undone] = ( np.sign(frequencies[phonon_undone]) * np.sqrt(np.abs(frequencies[phonon_undone]))