From 24b6b06a4f50dce897dfafe981dc551b034c5406 Mon Sep 17 00:00:00 2001 From: Atsushi Togo Date: Sun, 21 Apr 2024 14:00:21 +0900 Subject: [PATCH 1/5] Fix --v2 option --- phono3py/cui/phono3py_argparse.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phono3py/cui/phono3py_argparse.py b/phono3py/cui/phono3py_argparse.py index c15677d2..6c5d2e74 100644 --- a/phono3py/cui/phono3py_argparse.py +++ b/phono3py/cui/phono3py_argparse.py @@ -284,8 +284,8 @@ def get_parser(fc_symmetry=False, is_nac=False, load_phono3py_yaml=False): parser.add_argument( "--v2", dest="is_fc3_r0_average", - action="store_true", - default=False, + action="store_false", + default=True, help="Take average in fc3-r2q transformation around three atoms", ) parser.add_argument( From 9156ff1bca84741add79a25221735602b5698b45 Mon Sep 17 00:00:00 2001 From: Atsushi Togo Date: Sun, 21 Apr 2024 14:01:09 +0900 Subject: [PATCH 2/5] Update github workflows and add multithreaded blas test for phph-calc --- .../phono3py-pytest-conda-mkl-phphmtblas.yml | 46 +++++++++++++++++++ .../phono3py-pytest-conda-mkl-v2.yml | 10 +--- .../workflows/phono3py-pytest-conda-mkl.yml | 10 +--- .../phono3py-pytest-conda-phphmtblas.yml | 46 +++++++++++++++++++ .github/workflows/phono3py-pytest-conda.yml | 10 +--- 5 files changed, 98 insertions(+), 24 deletions(-) create mode 100644 .github/workflows/phono3py-pytest-conda-mkl-phphmtblas.yml create mode 100644 .github/workflows/phono3py-pytest-conda-phphmtblas.yml diff --git a/.github/workflows/phono3py-pytest-conda-mkl-phphmtblas.yml b/.github/workflows/phono3py-pytest-conda-mkl-phphmtblas.yml new file mode 100644 index 00000000..eff7c597 --- /dev/null +++ b/.github/workflows/phono3py-pytest-conda-mkl-phphmtblas.yml @@ -0,0 +1,46 @@ +name: Pytest with mkl sing BLAS for phph-calc + +on: + pull_request: + branches: [ develop ] + +jobs: + build-linux: + runs-on: ubuntu-latest + defaults: + run: + shell: bash -l {0} + strategy: + matrix: + python-version: ["3.12"] + + steps: + - uses: actions/checkout@v3 + # Use conda-incubator/setup-miniconda for precise control of conda infrastructure + - uses: conda-incubator/setup-miniconda@v2 + with: + miniforge-version: latest + - name: Install dependent packages + run: | + conda activate test + conda install --yes python=${{ matrix.python-version }} + #conda install --yes matplotlib-base pyyaml "libblas=*=*openblas" openblas h5py scipy pytest codecov pytest-cov spglib alm cmake c-compiler + conda install --yes matplotlib-base pyyaml "libblas=*=*mkl" mkl-include h5py scipy pytest codecov pytest-cov spglib alm cmake c-compiler + - name: Install phonopy develop branch + run: | + conda activate test + git clone --depth 1 https://github.com/phonopy/phonopy.git + cd phonopy + PHONOPY_USE_OPENMP=true pip install -e . -vvv + cd .. + - name: Install phono3py + run: | + conda activate test + PHPHCALC_USE_MTBLAS=true pip install -e . -vvv + - name: Run pytest + run: | + pytest -v --cov=./ --cov-report=xml test + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v3 + with: + verbose: true diff --git a/.github/workflows/phono3py-pytest-conda-mkl-v2.yml b/.github/workflows/phono3py-pytest-conda-mkl-v2.yml index a6219859..1b80bb99 100644 --- a/.github/workflows/phono3py-pytest-conda-mkl-v2.yml +++ b/.github/workflows/phono3py-pytest-conda-mkl-v2.yml @@ -3,12 +3,6 @@ name: Pytest with mkl and --v2 option on: pull_request: branches: [ develop ] - push: - branches-ignore: - - publish-gh-pages - - develop - - master - - rc jobs: build-linux: @@ -18,7 +12,7 @@ jobs: shell: bash -l {0} strategy: matrix: - python-version: ["3.11"] + python-version: ["3.12"] steps: - uses: actions/checkout@v3 @@ -37,7 +31,7 @@ jobs: conda activate test git clone --depth 1 https://github.com/phonopy/phonopy.git cd phonopy - pip install -e . -vvv + PHONOPY_USE_OPENMP=true pip install -e . -vvv cd .. - name: Install phono3py run: | diff --git a/.github/workflows/phono3py-pytest-conda-mkl.yml b/.github/workflows/phono3py-pytest-conda-mkl.yml index 0ebabd9b..e436e7f5 100644 --- a/.github/workflows/phono3py-pytest-conda-mkl.yml +++ b/.github/workflows/phono3py-pytest-conda-mkl.yml @@ -3,12 +3,6 @@ name: Pytest with mkl on: pull_request: branches: [ develop ] - push: - branches-ignore: - - publish-gh-pages - - develop - - master - - rc jobs: build-linux: @@ -18,7 +12,7 @@ jobs: shell: bash -l {0} strategy: matrix: - python-version: ["3.11"] + python-version: ["3.12"] steps: - uses: actions/checkout@v3 @@ -37,7 +31,7 @@ jobs: conda activate test git clone --depth 1 https://github.com/phonopy/phonopy.git cd phonopy - pip install -e . -vvv + PHONOPY_USE_OPENMP=true pip install -e . -vvv cd .. - name: Install phono3py run: | diff --git a/.github/workflows/phono3py-pytest-conda-phphmtblas.yml b/.github/workflows/phono3py-pytest-conda-phphmtblas.yml new file mode 100644 index 00000000..c427aaeb --- /dev/null +++ b/.github/workflows/phono3py-pytest-conda-phphmtblas.yml @@ -0,0 +1,46 @@ +name: Pytest with openblas using BLAS for phph-calc + +on: + pull_request: + branches: [ develop ] + +jobs: + build-linux: + runs-on: ubuntu-latest + defaults: + run: + shell: bash -l {0} + strategy: + matrix: + python-version: ["3.12"] + + steps: + - uses: actions/checkout@v3 + # Use conda-incubator/setup-miniconda for precise control of conda infrastructure + - uses: conda-incubator/setup-miniconda@v2 + with: + miniforge-version: latest + - name: Install dependent packages + run: | + conda activate test + conda install --yes python=${{ matrix.python-version }} + conda install --yes matplotlib-base pyyaml "libblas=*=*openblas" openblas h5py scipy pytest codecov pytest-cov spglib alm cmake c-compiler + #conda install --yes matplotlib-base pyyaml "libblas=*=*mkl" mkl-include h5py scipy pytest codecov pytest-cov spglib alm cmake c-compiler + - name: Install phonopy develop branch + run: | + conda activate test + git clone --depth 1 https://github.com/phonopy/phonopy.git + cd phonopy + PHONOPY_USE_OPENMP=true pip install -e . -vvv + cd .. + - name: Install phono3py + run: | + conda activate test + PHPHCALC_USE_MTBLAS=true pip install -e . -vvv + - name: Run pytest + run: | + pytest -v --cov=./ --cov-report=xml test + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v3 + with: + verbose: true diff --git a/.github/workflows/phono3py-pytest-conda.yml b/.github/workflows/phono3py-pytest-conda.yml index 5ec01320..979c8401 100644 --- a/.github/workflows/phono3py-pytest-conda.yml +++ b/.github/workflows/phono3py-pytest-conda.yml @@ -3,12 +3,6 @@ name: Pytest with openblas on: pull_request: branches: [ develop ] - push: - branches-ignore: - - publish-gh-pages - - develop - - master - - rc jobs: build-linux: @@ -18,7 +12,7 @@ jobs: shell: bash -l {0} strategy: matrix: - python-version: ["3.8", "3.9", "3.10", "3.11"] + python-version: ["3.9", "3.10", "3.11", "3.12"] steps: - uses: actions/checkout@v3 @@ -37,7 +31,7 @@ jobs: conda activate test git clone --depth 1 https://github.com/phonopy/phonopy.git cd phonopy - pip install -e . -vvv + PHONOPY_USE_OPENMP=true pip install -e . -vvv cd .. - name: Install phono3py run: | From d2ed4b1beca97f086971969f9f77fe3099907bba Mon Sep 17 00:00:00 2001 From: Atsushi Togo Date: Sun, 21 Apr 2024 14:02:09 +0900 Subject: [PATCH 3/5] Add PHPHCALC_USE_MTBLAS option to build it --- CMakeLists.txt | 57 +++++++++++++++++++++++++++++++++++++------------- setup.py | 8 ++++++- 2 files changed, 50 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9cafbd19..23c842eb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,11 +1,12 @@ cmake_minimum_required(VERSION 3.15) project(phono3py C) -option(PHONO3PY "Option to build phono3py module" OFF) +option(PHPHCALC "Option to build phph calculation module" OFF) option(PHONONCALC "Option to build phonon calculation module" OFF) option(GRIDSYS "Option to build gridsys module" OFF) option(WITH_Fortran "enable fortran interface" OFF) -option(USE_OpenMP "Option to search OpenMP library" ON) +option(PHONO3PY_USE_OMP "Option to search OpenMP library" ON) +option(PHPHCALC_USE_MTBLAS "Use multithread BLAS is it exists" OFF) option(WITH_TESTS "build unit tests" OFF) option(BUILD_SHARED_LIBRARIES "Option to build shared library" OFF) if(WITH_Fortran) @@ -51,7 +52,7 @@ else() set(MY_INCLUDES ${PROJECT_SOURCE_DIR}/c) endif() -if(USE_OpenMP) +if(PHONO3PY_USE_OMP) message(STATUS "Find OpenMP library") find_package(OpenMP) @@ -61,7 +62,7 @@ if(USE_OpenMP) endif() endif() -if(PHONO3PY OR PHONONCALC) +if(PHPHCALC OR PHONONCALC) find_package(BLAS REQUIRED) # set BLAS_LIBRARIES if(BLAS_FOUND) @@ -77,22 +78,30 @@ if(PHONO3PY OR PHONONCALC) endif() endif() -if(PHONO3PY OR PHONONCALC) +if(PHPHCALC OR PHONONCALC) if(BLAS_LIBRARIES MATCHES "libmkl") message(STATUS "MKL detected: Set C-macros MKL_LAPACKE MULTITHREADED_BLAS") + message(STATUS "Use multithreaded BLAS for phonon calculation.") + if(PHPHCALC_USE_MTBLAS) + message(STATUS "Use multithreaded BLAS for ph-ph calculation.") + endif() endif() if(BLAS_LIBRARIES MATCHES "libopenblas") message(STATUS "OpenBLAS detected: Set C-macro MULTITHREADED_BLAS") + message(STATUS "Use multithreaded BLAS for phonon calculation.") + if(PHPHCALC_USE_MTBLAS) + message(STATUS "Use multithreaded BLAS for ph-ph calculation.") + endif() endif() endif() # ############################################################################## # phono3py # # ############################################################################## -if(PHONO3PY) +if(PHPHCALC) # Source code - set(SOURCES_PHONO3PY + set(SOURCES_PHPHCALC ${PROJECT_SOURCE_DIR}/c/bzgrid.c ${PROJECT_SOURCE_DIR}/c/collision_matrix.c ${PROJECT_SOURCE_DIR}/c/fc3.c @@ -116,18 +125,28 @@ if(PHONO3PY) if(BUILD_SHARED_LIBRARIES) # Shared library - add_library(ph3py SHARED ${SOURCES_PHONO3PY}) + add_library(ph3py SHARED ${SOURCES_PHPHCALC}) target_link_libraries(ph3py m ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES} ${OpenMP_C_LIBRARIES}) target_include_directories(ph3py PRIVATE ${MY_INCLUDES}) target_compile_options(ph3py PRIVATE ${OpenMP_C_FLAGS}) if(BLAS_LIBRARIES MATCHES "libmkl") - target_compile_definitions(ph3py PRIVATE MKL_LAPACKE THM_EPSILON=1e-10) + if(PHPHCALC_USE_MTBLAS) + target_compile_definitions(ph3py PRIVATE MKL_LAPACKE MULTITHREADED_BLAS + THM_EPSILON=1e-10) + else() + target_compile_definitions(ph3py PRIVATE MKL_LAPACKE THM_EPSILON=1e-10) + endif() endif() if(BLAS_LIBRARIES MATCHES "libopenblas") - target_compile_definitions(ph3py PRIVATE THM_EPSILON=1e-10) + if(PHPHCALC_USE_MTBLAS) + target_compile_definitions(ph3py PRIVATE MULTITHREADED_BLAS + THM_EPSILON=1e-10) + else() + target_compile_definitions(ph3py PRIVATE THM_EPSILON=1e-10) + endif() endif() set_property(TARGET ph3py PROPERTY VERSION ${SERIAL}) @@ -136,19 +155,29 @@ if(PHONO3PY) endif() # Static link library - add_library(ph3py_static STATIC ${SOURCES_PHONO3PY}) + add_library(ph3py_static STATIC ${SOURCES_PHPHCALC}) target_link_libraries(ph3py_static m ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES} ${OpenMP_C_LIBRARIES}) target_include_directories(ph3py_static PRIVATE ${MY_INCLUDES}) target_compile_options(ph3py_static PRIVATE ${OpenMP_C_FLAGS}) if(BLAS_LIBRARIES MATCHES "libmkl") - target_compile_definitions(ph3py_static PRIVATE MKL_LAPACKE - THM_EPSILON=1e-10) + if(PHPHCALC_USE_MTBLAS) + target_compile_definitions( + ph3py_static PRIVATE MKL_LAPACKE MULTITHREADED_BLAS THM_EPSILON=1e-10) + else() + target_compile_definitions(ph3py_static PRIVATE MKL_LAPACKE + THM_EPSILON=1e-10) + endif() endif() if(BLAS_LIBRARIES MATCHES "libopenblas") - target_compile_definitions(ph3py_static PRIVATE THM_EPSILON=1e-10) + if(PHPHCALC_USE_MTBLAS) + target_compile_definitions(ph3py_static PRIVATE MULTITHREADED_BLAS + THM_EPSILON=1e-10) + else() + target_compile_definitions(ph3py_static PRIVATE THM_EPSILON=1e-10) + endif() endif() set_property(TARGET ph3py_static PROPERTY VERSION ${SERIAL}) diff --git a/setup.py b/setup.py index d221f990..2f0cbba5 100644 --- a/setup.py +++ b/setup.py @@ -34,9 +34,15 @@ def _run_cmake(build_dir): "-B", "_build", "-DPHONONCALC=on", - "-DPHONO3PY=on", + "-DPHPHCALC=on", "-DCMAKE_INSTALL_PREFIX=.", ] + if ( + "PHPHCALC_USE_MTBLAS" in os.environ + and os.environ["PHPHCALC_USE_MTBLAS"].lower() == "true" + ): + args.append("-DPHPHCALC_USE_MTBLAS=on") + # if "CONDA_PREFIX" in os.environ: # args.append("-DUSE_CONDA_PATH=on") # if "CC" in os.environ: From e6dacb4d18e374989e2acd812921f59835824273 Mon Sep 17 00:00:00 2001 From: Atsushi Togo Date: Sun, 21 Apr 2024 14:02:28 +0900 Subject: [PATCH 4/5] Minor refactoring --- c/reciprocal_to_normal.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/c/reciprocal_to_normal.c b/c/reciprocal_to_normal.c index f3a275ce..d061999c 100644 --- a/c/reciprocal_to_normal.c +++ b/c/reciprocal_to_normal.c @@ -34,11 +34,13 @@ #include "reciprocal_to_normal.h" +#ifdef MULTITHREADED_BLAS #if defined(MKL_LAPACKE) || defined(SCIPY_MKL_H) #include #else #include #endif +#endif #include #include #include @@ -55,11 +57,13 @@ static double get_fc3_sum(const lapack_complex_double *e0, const lapack_complex_double *e2, const lapack_complex_double *fc3_reciprocal, const long num_band); +#ifdef MULTITHREADED_BLAS static double get_fc3_sum_blas(const lapack_complex_double *e0, const lapack_complex_double *e1, const lapack_complex_double *e2, const lapack_complex_double *fc3_reciprocal, const long num_band); +#endif static double get_fc3_sum_blas_like(const lapack_complex_double *e0, const lapack_complex_double *e1, const lapack_complex_double *e2, @@ -153,6 +157,7 @@ void reciprocal_to_normal_squared( if (freqs0[band_indices[g_pos[i][0]]] > cutoff_frequency && freqs1[g_pos[i][1]] > cutoff_frequency && freqs2[g_pos[i][2]] > cutoff_frequency) { +#ifdef MULTITHREADED_BLAS if (use_multithreaded_blas) { fc3_normal_squared[g_pos[i][3]] = get_fc3_sum_blas(e0 + band_indices[g_pos[i][0]] * num_band, @@ -162,6 +167,7 @@ void reciprocal_to_normal_squared( (freqs0[band_indices[g_pos[i][0]]] * freqs1[g_pos[i][1]] * freqs2[g_pos[i][2]]); } else { +#endif fc3_normal_squared[g_pos[i][3]] = get_fc3_sum_blas_like( e0 + band_indices[g_pos[i][0]] * num_band, @@ -169,7 +175,9 @@ void reciprocal_to_normal_squared( e2 + g_pos[i][2] * num_band, fc3_reciprocal, num_band) / (freqs0[band_indices[g_pos[i][0]]] * freqs1[g_pos[i][1]] * freqs2[g_pos[i][2]]); +#ifdef MULTITHREADED_BLAS } +#endif } else { fc3_normal_squared[g_pos[i][3]] = 0; } @@ -224,6 +232,7 @@ static double get_fc3_sum(const lapack_complex_double *e0, return (sum_real * sum_real + sum_imag * sum_imag); } +#ifdef MULTITHREADED_BLAS static double get_fc3_sum_blas(const lapack_complex_double *e0, const lapack_complex_double *e1, const lapack_complex_double *e2, @@ -259,6 +268,7 @@ static double get_fc3_sum_blas(const lapack_complex_double *e0, lapack_complex_double_imag(retval) * lapack_complex_double_imag(retval); } +#endif static double get_fc3_sum_blas_like(const lapack_complex_double *e0, const lapack_complex_double *e1, From 7ae85c093fdc27f712182a8636768fa169520168 Mon Sep 17 00:00:00 2001 From: Atsushi Togo Date: Sun, 21 Apr 2024 14:02:37 +0900 Subject: [PATCH 5/5] Set version 3.0.2 --- doc/changelog.md | 11 +++++++++-- doc/conf.py | 2 +- phono3py/version.py | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/doc/changelog.md b/doc/changelog.md index 16055e0f..20942849 100644 --- a/doc/changelog.md +++ b/doc/changelog.md @@ -2,6 +2,11 @@ # Change Log +## Apr-21-2024: Version 3.0.2 + +- New way of ph-ph interaction calculation (see {ref}`changelog_v290`) is used as + default. In versions 3.0.0 and 3.0.1, it was not the default by mistake. + ## Apr-20-2024: Version 3.0.1 - Minor fix to build phono3py C-library on conda-forge. @@ -11,8 +16,8 @@ This is a major version release. There are backward-incompatible changes. - Calculation method to transform supercell third-order force constants fc3 in - real to reciprocal space was changed as described at Version 2.9.0 changelog - below. This results in the change of results with respect to those obtained by + real to reciprocal space was changed as described at {ref}`changelog_v290`. + This results in the change of results with respect to those obtained by phono3py version 2. To emulate v2 behaviour, use `--v2` option in phono3py command line script. For `Phono3py` class , `make_r0_average=True` (default) when instantiating it, and similarly for `phono3py.load` function. @@ -36,6 +41,8 @@ This is a major version release. There are backward-incompatible changes. - Release to build conda-forge package. +(changelog_v290)= + ## Dec-25-2023: Version 2.9.0 - Pre-release of version 3.0. diff --git a/doc/conf.py b/doc/conf.py index d3134c9e..2d38dbd6 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -60,7 +60,7 @@ # The short X.Y version. version = "3.0" # The full version, including alpha/beta/rc tags. -release = "3.0.1" +release = "3.0.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 ba1bb35c..c2305594 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.0.1" +__version__ = "3.0.2"