diff --git a/.github/workflows/publish-to-test-pypi.yml b/.github/workflows/publish-to-test-pypi.yml index 64a45448..65606fbe 100644 --- a/.github/workflows/publish-to-test-pypi.yml +++ b/.github/workflows/publish-to-test-pypi.yml @@ -9,30 +9,21 @@ on: jobs: build-linux: runs-on: ubuntu-latest - defaults: - run: - shell: bash -l {0} strategy: matrix: - python-version: ["3.10", ] + python-version: [3.12, ] steps: - uses: actions/checkout@v4 - # Use conda-incubator/setup-miniconda for precise control of conda infrastructure - - uses: conda-incubator/setup-miniconda@v3 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 with: - auto-update-conda: true - channels: conda-forge - channel-priority: strict python-version: ${{ matrix.python-version }} - name: Make sdist run: | - conda activate test - conda install --yes python=${{ matrix.python-version }} - conda install --yes "libblas=*=*openblas" openblas cmake c-compiler numpy - ./get_nanoversion.sh - cat __nanoversion__.txt - python setup.py sdist + git tag v`grep __version__ phono3py/version.py|awk -F'"' '{print($2)}'` + pip install build + python -m build --sdist - name: Publish package to TestPyPI if: github.event_name == 'push' && startsWith(github.ref, 'refs/heads/rc') uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/CMakeLists.txt b/CMakeLists.txt index 29413b8a..fc372955 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,27 +1,27 @@ cmake_minimum_required(VERSION 3.20) -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(BUILD_PHPHCALC_LIB "Option to build phph calculation module" OFF) +option(BUILD_PHONONCALC_LIB "Option to build phonon calculation module" OFF) +option(BUILD_GRIDSYS_LIB "Option to build gridsys module" OFF) +option(PHONO3PY_WITH_Fortran "enable fortran interface" OFF) 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(PHONO3PY_USE_MTBLAS "Use multithread BLAS if it exists" ON) +option(PHONO3PY_WITH_TESTS "build unit tests" OFF) option(BUILD_SHARED_LIBS "Option to build shared library" OFF) -if(WITH_Fortran) +if(PHONO3PY_WITH_Fortran) enable_language(Fortran) - set(GRIDSYS ON) + set(BUILD_GRIDSYS_LIB ON) endif() -if(WITH_TESTS) +if(PHONO3PY_WITH_TESTS) set(BUILD_SHARED_LIBS ON) - set(GRIDSYS ON) + set(BUILD_GRIDSYS_LIB ON) endif() -if((NOT PHPHCALC) - AND (NOT PHONONCALC) - AND (NOT GRIDSYS)) +if((NOT BUILD_PHPHCALC_LIB) + AND (NOT BUILD_PHONONCALC_LIB) + AND (NOT BUILD_GRIDSYS_LIB)) set(BUILD_NANOBIND_MODULE ON) message(STATUS "Build nanobind module of ${SKBUILD_PROJECT_NAME}") else() @@ -86,8 +86,8 @@ else() set(OpenMP_FOUND OFF) # cmake-lint: disable=C0103 endif() -if(PHPHCALC - OR PHONONCALC +if(BUILD_PHPHCALC_LIB + OR BUILD_PHONONCALC_LIB OR BUILD_NANOBIND_MODULE) find_package(BLAS REQUIRED) # set BLAS_LIBRARIES @@ -104,20 +104,22 @@ if(PHPHCALC endif() if(BLAS_LIBRARIES MATCHES "libmkl") - message(STATUS "MKL detected: Set C-macros MKL_LAPACKE MULTITHREADED_BLAS") - message(STATUS "Use multithreaded BLAS for phonon calculation.") + message(STATUS "MKL detected: Set C-macro MKL_LAPACKE.") - if(PHPHCALC_USE_MTBLAS) - message(STATUS "Use multithreaded BLAS for ph-ph calculation.") + if(PHONO3PY_USE_MTBLAS) + message( + STATUS "Set C-macro MULTITHREADED_BLAS to avoid nested OpenMP calls." + ) endif() endif() if(BLAS_LIBRARIES MATCHES "libopenblas") - message(STATUS "OpenBLAS detected: Set C-macro MULTITHREADED_BLAS") - message(STATUS "Use multithreaded BLAS for phonon calculation.") + message(STATUS "OpenBLAS detected.") - if(PHPHCALC_USE_MTBLAS) - message(STATUS "Use multithreaded BLAS for ph-ph calculation.") + if(PHONO3PY_USE_MTBLAS) + message( + STATUS "Set C-macro MULTITHREADED_BLAS to avoid nested OpenMP calls." + ) endif() endif() endif() @@ -125,7 +127,7 @@ endif() # ################################################################################### # Build phphcalc module # # ################################################################################### -if(PHPHCALC OR BUILD_NANOBIND_MODULE) +if(BUILD_PHPHCALC_LIB OR BUILD_NANOBIND_MODULE) # Source code set(SOURCES_PHPHCALC ${PROJECT_SOURCE_DIR}/c/bzgrid.c @@ -163,7 +165,7 @@ if(PHPHCALC OR BUILD_NANOBIND_MODULE) target_include_directories(phphcalc_lib PRIVATE ${MY_INCLUDES}) if(BLAS_LIBRARIES MATCHES "libmkl") - if(PHPHCALC_USE_MTBLAS) + if(PHONO3PY_USE_MTBLAS) target_compile_definitions( phphcalc_lib PRIVATE MKL_LAPACKE MULTITHREADED_BLAS THM_EPSILON=1e-10) @@ -174,7 +176,7 @@ if(PHPHCALC OR BUILD_NANOBIND_MODULE) endif() if(BLAS_LIBRARIES MATCHES "libopenblas") - if(PHPHCALC_USE_MTBLAS) + if(PHONO3PY_USE_MTBLAS) target_compile_definitions(phphcalc_lib PRIVATE MULTITHREADED_BLAS THM_EPSILON=1e-10) else() @@ -195,7 +197,7 @@ if(PHPHCALC OR BUILD_NANOBIND_MODULE) target_include_directories(phphcalc_lib PRIVATE ${MY_INCLUDES}) if(BLAS_LIBRARIES MATCHES "libmkl") - if(PHPHCALC_USE_MTBLAS) + if(PHONO3PY_USE_MTBLAS) target_compile_definitions( phphcalc_lib PRIVATE MKL_LAPACKE MULTITHREADED_BLAS THM_EPSILON=1e-10) @@ -206,7 +208,7 @@ if(PHPHCALC OR BUILD_NANOBIND_MODULE) endif() if(BLAS_LIBRARIES MATCHES "libopenblas") - if(PHPHCALC_USE_MTBLAS) + if(PHONO3PY_USE_MTBLAS) target_compile_definitions(phphcalc_lib PRIVATE MULTITHREADED_BLAS THM_EPSILON=1e-10) else() @@ -236,7 +238,7 @@ endif() # ################################################################################### # phononcalc # # ################################################################################### -if(PHONONCALC OR BUILD_NANOBIND_MODULE) +if(BUILD_PHONONCALC_LIB OR BUILD_NANOBIND_MODULE) # Source code set(SOURCES_PHONONCALC ${PROJECT_SOURCE_DIR}/c/dynmat.c ${PROJECT_SOURCE_DIR}/c/lapack_wrapper.c @@ -311,7 +313,7 @@ endif() # ################################################################################### # grid # # ################################################################################### -if(GRIDSYS) +if(BUILD_GRIDSYS_LIB) # Source code set(SOURCES_GRIDSYS ${PROJECT_SOURCE_DIR}/c/bzgrid.c @@ -360,12 +362,12 @@ if(GRIDSYS) DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) endif() -if(WITH_Fortran) +if(PHONO3PY_WITH_Fortran) add_subdirectory(fortran) endif() -if(WITH_TESTS) - if(WITH_Fortran) +if(PHONO3PY_WITH_TESTS) + if(PHONO3PY_WITH_Fortran) set(LIB_MOD_DIR ${CMAKE_CURRENT_BINARY_DIR}/fortran) endif() diff --git a/doc/changelog.md b/doc/changelog.md index 9fba0f68..77c32354 100644 --- a/doc/changelog.md +++ b/doc/changelog.md @@ -2,6 +2,12 @@ # Change Log +## Jul-8-2024: Version 3.3.0 + +- Build system of phono3py was renewed. Now nanobind, cmake, and + scikit-build-core are used for the building, and the receipt is written in + `CMakeLists.txt` and `pyproject.toml`. + ## Jun-29-2024: Version 3.2.0 - `--rd` and `--rd-fc2` options for generating random directional displacements. diff --git a/doc/conf.py b/doc/conf.py index ef0f8f99..ab73c002 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -58,9 +58,9 @@ # built documents. # # The short X.Y version. -version = "3.2" +version = "3.3" # The full version, including alpha/beta/rc tags. -release = "3.2.0" +release = "3.3.0" # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/doc/install.md b/doc/install.md index 16d64e77..f3103668 100644 --- a/doc/install.md +++ b/doc/install.md @@ -30,18 +30,23 @@ All dependent packages should be installed. (install_from_source_code)= ## Installation from source code -When installing phono3py using `setup.py` from the source code, a few libraries -are required before running `setup.py` script. +When installing phono3py from the source code, a few libraries are required +before running `pip install`. + +Note that at version 3.3.0, the build system of phono3py was modernized. +Nanobind, cmake, and scikit-build-core are used for the building. The receipt is +written in `CMakeLists.txt` and `pyproject.toml`. The old `setup.py` was +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. 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 -already on the system is performed by cmake. If cmake is installed on the -system, this automatic search is invoked as default. For the installation with -custom configurations without using cmake, the environment variable -`PHONO3PY_USE_CMAKE=false` has to be set. +already on the system is performed by cmake. (install_with_cmake)= ### Build with automatic search of library configurations by cmake @@ -56,57 +61,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_custom)= -### Build with custom library configurations by `site.cfg` file - -Custom installation is achieved by creating `site.cfg` file on the same -directory as `setup.py`. Users will write configurations of compiler flags and -linked libraries in `site.cfg`. If `setup.py` finds `site.cfg`, the -configurations are used as the default configurations. If cmake is found in the -system, cmake tries to find required libraries and found configurations are -appended. To deactivate cmake's library search, the environment variable -`PHONO3PY_USE_CMAKE=false` has to be set before running the phono3py build: -``` -% export PHONO3PY_USE_CMAKE=false -``` -In previous versions, `site.cfg` was processed by numpy, -but from version 2.4.0, it is processed by script in `setup.py`. -`extra_link_args`, `extra_compile_args`, `extra_objects`, and `include_dirs` can -be specified. How they used is found at [setuptools web -site](https://setuptools.pypa.io/en/latest/userguide/ext_modules.html#extension-api-reference). - -In most cases, users want to enable multithreading support with OpenMP. Its -minimum setting with gcc as the compiler is: - -``` -extra_compile_args = -fopenmp -``` - -Additional configuration can be necessary. It is recommended first starting only -with `extra_compile_args = -fopenmp` and run `setup.py`, then check if phono3py -works properly or not without error or warning. When phono3py doesn't work with -the above setting, add another configuration one by one to test compilation. -Some examples are given below. - -For MKL (for gcc and clang), `site.cfg` - -``` -extra_compile_args = -fopenmp -``` - -For openblas and clang - -``` -extra_compile_args = -fopenmp -``` - -For openblas and gcc - -``` -extra_compile_args = -fopenmp -extra_link_args = -lgomp -``` - (install_an_example)= ## Installation instruction of latest development version of phono3py @@ -117,7 +71,8 @@ wrong python libraries can be imported. 1. Download miniforge Miniforge is downloaded at https://github.com/conda-forge/miniforge. The - detailed installation instruction is found in the same page. If usual conda or miniconda is used, the following `~/.condarc` setting is recommended: + detailed installation instruction is found in the same page. If usual conda + or miniconda is used, the following `~/.condarc` setting is recommended: ``` channel_priority: strict @@ -148,7 +103,7 @@ wrong python libraries can be imported. For x86-64 system: ```bash - % conda install numpy scipy h5py pyyaml matplotlib-base c-compiler "libblas=*=*mkl" spglib mkl-include cmake + % conda install numpy scipy h5py pyyaml matplotlib-base c-compiler cxx-compiler "libblas=*=*mkl" spglib mkl-include cmake ``` A libblas library can be chosen among `[openblas, mkl, blis, netlib]`. If @@ -161,7 +116,7 @@ wrong python libraries can be imported. For macOS ARM64 system, currently only openblas can be chosen: ```bash - % conda install numpy scipy h5py pyyaml matplotlib-base c-compiler spglib cmake openblas + % conda install numpy scipy h5py pyyaml matplotlib-base c-compiler cxx-compiler spglib cmake openblas ``` Note that using hdf5 files on NFS mounted file system, you may have to disable @@ -179,10 +134,8 @@ wrong python libraries can be imported. % git clone https://github.com/phonopy/phonopy.git % git clone https://github.com/phonopy/phono3py.git % cd phonopy - % git checkout develop % pip install -e . -vvv % cd ../phono3py - % git checkout develop % pip install -e . -vvv ``` @@ -215,23 +168,6 @@ Ubuntu package manager (`liblapacke` and `liblapacke-dev`): % sudo apt-get install liblapack-dev liblapacke-dev ``` -### Compiling Netlib LAPACKE - -The compilation procedure is found at the LAPACKE web site. After creating the -LAPACKE library, `liblapacke.a` (or the dynamic link library), `setup.py` must -be properly modified to link it. As an example, the procedure of compiling -LAPACKE is shown below. - -```bash -% tar xvfz lapack-3.6.0.tgz -% cd lapack-3.6.0 -% cp make.inc.example make.inc -% make lapackelib -``` - -BLAS, LAPACK, and LAPACKE, these all may have to be compiled with `-fPIC` option -to use it with python. - (install_openmp)= ## Multithreading and its controlling by C macro diff --git a/phono3py/scripts/phono3py-coleigplot b/phono3py/scripts/phono3py_coleigplot.py similarity index 98% rename from phono3py/scripts/phono3py-coleigplot rename to phono3py/scripts/phono3py_coleigplot.py index 22d1894b..6f829860 100755 --- a/phono3py/scripts/phono3py-coleigplot +++ b/phono3py/scripts/phono3py_coleigplot.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - import argparse import os import sys @@ -139,5 +137,6 @@ def main(args: argparse.Namespace): plot(args) -if __name__ == "__main__": +def run(): + """Run phono3py-coleigplot script.""" main(get_options()) diff --git a/phono3py/scripts/phono3py-kaccum b/phono3py/scripts/phono3py_kaccum.py similarity index 97% rename from phono3py/scripts/phono3py-kaccum rename to phono3py/scripts/phono3py_kaccum.py index 0129ba8a..2ccd37fa 100755 --- a/phono3py/scripts/phono3py-kaccum +++ b/phono3py/scripts/phono3py_kaccum.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - # Copyright (C) 2021 Atsushi Togo # All rights reserved. # @@ -36,5 +34,7 @@ from phono3py.cui.kaccum_script import main -if __name__ == "__main__": + +def run(): + """Run phono3py-kaccum script.""" main() diff --git a/phono3py/scripts/phono3py-kdeplot b/phono3py/scripts/phono3py_kdeplot.py similarity index 99% rename from phono3py/scripts/phono3py-kdeplot rename to phono3py/scripts/phono3py_kdeplot.py index 184bbc88..d1913272 100755 --- a/phono3py/scripts/phono3py-kdeplot +++ b/phono3py/scripts/phono3py_kdeplot.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python - import argparse import os import sys @@ -350,5 +348,6 @@ def main(args): plt.close(fig) -if __name__ == "__main__": +def run(): + """Run phono3py-kdeplot script.""" main(get_options()) diff --git a/phono3py/version.py b/phono3py/version.py index a490a3d8..87c2d2f1 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.2.0" +__version__ = "3.3.0" diff --git a/pyproject.toml b/pyproject.toml index c9fa2f64..6447ea50 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,9 +26,15 @@ Repository = "https://github.com/phonopy/phono3py" [project.scripts] phono3py = "phono3py.scripts.phono3py:run" -phono3py-load = "phonopy.scripts.phono3py_load:run" +phono3py-load = "phono3py.scripts.phono3py_load:run" +phono3py-coleigplot = "phono3py.scripts.phono3py_coleigplot:run" +phono3py-kaccum = "phono3py.scripts.phono3py_kaccum:run" +phono3py-kdeplot = "phono3py.scripts.phono3py_kdeplot:run" + [tool.scikit-build] +cmake.verbose = true +logging.level = "INFO" metadata.version.provider = "scikit_build_core.metadata.setuptools_scm" sdist.exclude = ["*"] sdist.include = [ @@ -43,7 +49,7 @@ sdist.include = [ ] [tool.scikit-build.cmake.define] -PHPHCALC_USE_MTBLAS = {env="PHPHCALC_USE_MTBLAS", default="OFF"} +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"} diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 146789f8..00000000 --- a/requirements.txt +++ /dev/null @@ -1,5 +0,0 @@ -numpy >= 1.17.0 -PyYAML >= 5.3 -matplotlib >= 2.2.2 -h5py >= 3.0 -phonopy >=2.25,<2.26