Initial attempt to migrate to nanobind

This commit is contained in:
Atsushi Togo 2024-07-07 10:55:19 +09:00
parent 3e01240a56
commit 2b5b6f6d0b
13 changed files with 409 additions and 297 deletions

View File

@ -1,5 +1,4 @@
cmake_minimum_required(VERSION 3.15)
project(phono3py C)
cmake_minimum_required(VERSION 3.20)
option(PHPHCALC "Option to build phph calculation module" OFF)
option(PHONONCALC "Option to build phonon calculation module" OFF)
@ -8,297 +7,364 @@ option(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(BUILD_SHARED_LIBRARIES "Option to build shared library" OFF)
option(BUILD_SHARED_LIBS "Option to build shared library" OFF)
if(WITH_Fortran)
enable_language(Fortran)
set(GRIDSYS ON)
enable_language(Fortran)
set(GRIDSYS ON)
endif()
if(WITH_TESTS)
set(BUILD_SHARED_LIBRARIES ON)
set(GRIDSYS ON)
set(BUILD_SHARED_LIBS ON)
set(GRIDSYS ON)
endif()
set(CMAKE_MACOSX_RPATH 1)
set(CMAKE_C_FLAGS_RELEASE "-Wall -O2")
set(CMAKE_C_FLAGS_DEBUG "-g -DLAGWARNING -DTHMWARNING")
if((NOT PHPHCALC)
AND (NOT PHONONCALC)
AND (NOT GRIDSYS))
set(BUILD_NANOBIND_MODULE ON)
message(STATUS "Build nanobind module of ${SKBUILD_PROJECT_NAME}")
else()
set(BUILD_NANOBIND_MODULE OFF)
endif()
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif(NOT CMAKE_BUILD_TYPE)
if(BUILD_NANOBIND_MODULE)
project(${SKBUILD_PROJECT_NAME})
set(DEV_MODULE Development.Module)
find_package(
Python 3.8 REQUIRED
COMPONENTS Interpreter ${DEV_MODULE}
OPTIONAL_COMPONENTS Development.SABIModule)
else()
project(phono3py C)
set(CMAKE_MACOSX_RPATH 1)
set(CMAKE_C_FLAGS_RELEASE "-Wall -O2")
set(CMAKE_C_FLAGS_DEBUG "-g -DLAGWARNING -DTHMWARNING")
# Version numbers
file(READ ${PROJECT_SOURCE_DIR}/phono3py/version.py version_file)
string(REGEX MATCH "__version__.*([0-9]+)[.]([0-9]+)[.]([0-9]+)"
phono3py_version ${version_file})
set(MAJOR_VERSION ${CMAKE_MATCH_1})
set(MINOR_VERSION ${CMAKE_MATCH_2})
set(MICRO_VERSION ${CMAKE_MATCH_3})
set(SERIAL "${MAJOR_VERSION}.${MINOR_VERSION}.${MICRO_VERSION}")
set(SOSERIAL "1")
include(GNUInstallDirs)
endif()
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE
Release
CACHE STRING "Choose the type of build." FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
"MinSizeRel" "RelWithDebInfo")
endif()
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
message(STATUS "CMAKE_SYSTEM_PREFIX_PATH: ${CMAKE_SYSTEM_PREFIX_PATH}")
include(GNUInstallDirs)
# set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# Version numbers
file(READ ${PROJECT_SOURCE_DIR}/phono3py/version.py version_file)
string(REGEX MATCH "__version__.*([0-9]+)[.]([0-9]+)[.]([0-9]+)"
phono3py_version ${version_file})
set(MAJOR_VERSION ${CMAKE_MATCH_1})
set(MINOR_VERSION ${CMAKE_MATCH_2})
set(MICRO_VERSION ${CMAKE_MATCH_3})
set(SERIAL "${MAJOR_VERSION}.${MINOR_VERSION}.${MICRO_VERSION}")
set(SOSERIAL "1")
if(USE_CONDA_PATH)
message(STATUS "$ENV{CONDA_PREFIX}")
set(CMAKE_MODULE_PATH $ENV{CONDA_PREFIX})
set(MY_INCLUDES $ENV{CONDA_PREFIX}/include ${PROJECT_SOURCE_DIR}/c)
link_directories($ENV{CONDA_PREFIX}/lib)
message(STATUS "$ENV{CONDA_PREFIX}")
set(CMAKE_MODULE_PATH $ENV{CONDA_PREFIX})
set(MY_INCLUDES $ENV{CONDA_PREFIX}/include ${PROJECT_SOURCE_DIR}/c)
link_directories($ENV{CONDA_PREFIX}/lib)
else()
set(MY_INCLUDES ${PROJECT_SOURCE_DIR}/c)
set(MY_INCLUDES ${PROJECT_SOURCE_DIR}/c)
endif()
if(PHONO3PY_USE_OMP)
message(STATUS "Find OpenMP library")
find_package(OpenMP)
message(STATUS "Find OpenMP library")
find_package(OpenMP)
if(OpenMP_FOUND)
message(STATUS "OpenMP libs: ${OpenMP_C_LIBRARIES}")
message(STATUS "OpenMP flags: ${OpenMP_C_FLAGS}")
endif()
endif()
if(PHPHCALC OR PHONONCALC)
find_package(BLAS REQUIRED) # set BLAS_LIBRARIES
if(BLAS_FOUND)
message(STATUS "BLAS libs: ${BLAS_LIBRARIES}")
message(STATUS "BLAS flags: ${BLAS_LINKER_FLAGS}")
endif()
find_package(LAPACK REQUIRED) # set LAPACK_LIBRARIES
if(LAPACK_FOUND)
message(STATUS "LAPACK libs: ${LAPACK_LIBRARIES}")
message(STATUS "LAPACK flags: ${LAPACK_LINKER_FLAGS}")
endif()
endif()
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.")
if(OpenMP_FOUND)
message(STATUS "OpenMP libs: ${OpenMP_C_LIBRARIES}")
message(STATUS "OpenMP flags: ${OpenMP_C_FLAGS}")
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(PHPHCALC)
# Source code
set(SOURCES_PHPHCALC
${PROJECT_SOURCE_DIR}/c/bzgrid.c
${PROJECT_SOURCE_DIR}/c/collision_matrix.c
${PROJECT_SOURCE_DIR}/c/fc3.c
${PROJECT_SOURCE_DIR}/c/grgrid.c
${PROJECT_SOURCE_DIR}/c/imag_self_energy_with_g.c
${PROJECT_SOURCE_DIR}/c/interaction.c
${PROJECT_SOURCE_DIR}/c/isotope.c
${PROJECT_SOURCE_DIR}/c/lagrid.c
${PROJECT_SOURCE_DIR}/c/lapack_wrapper.c
${PROJECT_SOURCE_DIR}/c/phono3py.c
${PROJECT_SOURCE_DIR}/c/phonoc_utils.c
${PROJECT_SOURCE_DIR}/c/pp_collision.c
${PROJECT_SOURCE_DIR}/c/real_self_energy.c
${PROJECT_SOURCE_DIR}/c/real_to_reciprocal.c
${PROJECT_SOURCE_DIR}/c/reciprocal_to_normal.c
${PROJECT_SOURCE_DIR}/c/snf3x3.c
${PROJECT_SOURCE_DIR}/c/tetrahedron_method.c
${PROJECT_SOURCE_DIR}/c/triplet.c
${PROJECT_SOURCE_DIR}/c/triplet_grid.c
${PROJECT_SOURCE_DIR}/c/triplet_iw.c)
if(PHPHCALC
OR PHONONCALC
OR BUILD_NANOBIND_MODULE)
find_package(BLAS REQUIRED) # set BLAS_LIBRARIES
if(BUILD_SHARED_LIBRARIES)
# Shared library
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_FOUND)
message(STATUS "BLAS libs: ${BLAS_LIBRARIES}")
message(STATUS "BLAS flags: ${BLAS_LINKER_FLAGS}")
endif()
find_package(LAPACK REQUIRED) # set LAPACK_LIBRARIES
if(LAPACK_FOUND)
message(STATUS "LAPACK libs: ${LAPACK_LIBRARIES}")
message(STATUS "LAPACK flags: ${LAPACK_LINKER_FLAGS}")
endif()
if(BLAS_LIBRARIES MATCHES "libmkl")
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()
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")
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()
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()
set_property(TARGET ph3py PROPERTY VERSION ${SERIAL})
set_property(TARGET ph3py PROPERTY SOVERSION ${SOSERIAL})
install(TARGETS ph3py LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()
# Static link library
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")
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")
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})
set_property(TARGET ph3py_static PROPERTY SOVERSION ${SOSERIAL})
set_property(TARGET ph3py_static PROPERTY OUTPUT_NAME ph3py)
install(TARGETS ph3py_static ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
# Header file
install(FILES ${PROJECT_SOURCE_DIR}/c/phono3py.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
endif()
# ##############################################################################
# ###################################################################################
# Build phphcalc module #
# ###################################################################################
if(PHPHCALC OR BUILD_NANOBIND_MODULE)
# Source code
set(SOURCES_PHPHCALC
${PROJECT_SOURCE_DIR}/c/bzgrid.c
${PROJECT_SOURCE_DIR}/c/collision_matrix.c
${PROJECT_SOURCE_DIR}/c/fc3.c
${PROJECT_SOURCE_DIR}/c/grgrid.c
${PROJECT_SOURCE_DIR}/c/imag_self_energy_with_g.c
${PROJECT_SOURCE_DIR}/c/interaction.c
${PROJECT_SOURCE_DIR}/c/isotope.c
${PROJECT_SOURCE_DIR}/c/lagrid.c
${PROJECT_SOURCE_DIR}/c/lapack_wrapper.c
${PROJECT_SOURCE_DIR}/c/phono3py.c
${PROJECT_SOURCE_DIR}/c/phonoc_utils.c
${PROJECT_SOURCE_DIR}/c/pp_collision.c
${PROJECT_SOURCE_DIR}/c/real_self_energy.c
${PROJECT_SOURCE_DIR}/c/real_to_reciprocal.c
${PROJECT_SOURCE_DIR}/c/reciprocal_to_normal.c
${PROJECT_SOURCE_DIR}/c/snf3x3.c
${PROJECT_SOURCE_DIR}/c/tetrahedron_method.c
${PROJECT_SOURCE_DIR}/c/triplet.c
${PROJECT_SOURCE_DIR}/c/triplet_grid.c
${PROJECT_SOURCE_DIR}/c/triplet_iw.c)
if(BUILD_SHARED_LIBS)
# Shared library
add_library(phphcalc_lib SHARED ${SOURCES_PHPHCALC})
target_link_libraries(phphcalc_lib m ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES}
${OpenMP_C_LIBRARIES})
target_include_directories(phphcalc_lib PRIVATE ${MY_INCLUDES})
target_compile_options(phphcalc_lib PRIVATE ${OpenMP_C_FLAGS})
if(BLAS_LIBRARIES MATCHES "libmkl")
if(PHPHCALC_USE_MTBLAS)
target_compile_definitions(
phphcalc_lib PRIVATE MKL_LAPACKE MULTITHREADED_BLAS
THM_EPSILON=1e-10)
else()
target_compile_definitions(phphcalc_lib PRIVATE MKL_LAPACKE
THM_EPSILON=1e-10)
endif()
endif()
if(BLAS_LIBRARIES MATCHES "libopenblas")
if(PHPHCALC_USE_MTBLAS)
target_compile_definitions(phphcalc_lib PRIVATE MULTITHREADED_BLAS
THM_EPSILON=1e-10)
else()
target_compile_definitions(phphcalc_lib PRIVATE THM_EPSILON=1e-10)
endif()
endif()
else()
# Static link library
add_library(phphcalc_lib STATIC ${SOURCES_PHPHCALC})
target_link_libraries(phphcalc_lib m ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES}
${OpenMP_C_LIBRARIES})
target_include_directories(phphcalc_lib PRIVATE ${MY_INCLUDES})
target_compile_options(phphcalc_lib PRIVATE ${OpenMP_C_FLAGS})
if(BLAS_LIBRARIES MATCHES "libmkl")
if(PHPHCALC_USE_MTBLAS)
target_compile_definitions(
phphcalc_lib PRIVATE MKL_LAPACKE MULTITHREADED_BLAS
THM_EPSILON=1e-10)
else()
target_compile_definitions(phphcalc_lib PRIVATE MKL_LAPACKE
THM_EPSILON=1e-10)
endif()
endif()
if(BLAS_LIBRARIES MATCHES "libopenblas")
if(PHPHCALC_USE_MTBLAS)
target_compile_definitions(phphcalc_lib PRIVATE MULTITHREADED_BLAS
THM_EPSILON=1e-10)
else()
target_compile_definitions(phphcalc_lib PRIVATE THM_EPSILON=1e-10)
endif()
endif()
endif()
if(NOT BUILD_NANOBIND_MODULE)
if(BUILD_SHARED_LIBS)
set_property(TARGET phphcalc_lib PROPERTY VERSION ${SERIAL})
set_property(TARGET phphcalc_lib PROPERTY SOVERSION ${SOSERIAL})
install(TARGETS phphcalc_lib LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
else()
set_property(TARGET phphcalc_lib PROPERTY VERSION ${SERIAL})
set_property(TARGET phphcalc_lib PROPERTY SOVERSION ${SOSERIAL})
set_property(TARGET phphcalc_lib PROPERTY OUTPUT_NAME phphcalc_lib)
install(TARGETS phphcalc_lib ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()
# Header file
install(FILES ${PROJECT_SOURCE_DIR}/c/phono3py.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
endif()
endif()
# ###################################################################################
# phononcalc #
# ##############################################################################
if(PHONONCALC)
# Source code
set(SOURCES_PHONONCALC
${PROJECT_SOURCE_DIR}/c/dynmat.c ${PROJECT_SOURCE_DIR}/c/lapack_wrapper.c
${PROJECT_SOURCE_DIR}/c/phonon.c ${PROJECT_SOURCE_DIR}/c/phononcalc.c)
# ###################################################################################
if(PHONONCALC OR BUILD_NANOBIND_MODULE)
# Source code
set(SOURCES_PHONONCALC
${PROJECT_SOURCE_DIR}/c/dynmat.c ${PROJECT_SOURCE_DIR}/c/lapack_wrapper.c
${PROJECT_SOURCE_DIR}/c/phonon.c ${PROJECT_SOURCE_DIR}/c/phononcalc.c)
if(BUILD_SHARED_LIBRARIES)
# Shared library
add_library(phcalc SHARED ${SOURCES_PHONONCALC})
target_link_libraries(phcalc m ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES}
${OpenMP_C_LIBRARIES})
target_include_directories(phcalc PRIVATE ${MY_INCLUDES})
target_compile_options(phcalc PRIVATE ${OpenMP_C_FLAGS})
if(BUILD_SHARED_LIBS)
# Shared library
add_library(phononcalc_lib SHARED ${SOURCES_PHONONCALC})
target_link_libraries(phononcalc_lib m ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES}
${OpenMP_C_LIBRARIES})
target_include_directories(phononcalc_lib PRIVATE ${MY_INCLUDES})
target_compile_options(phononcalc_lib PRIVATE ${OpenMP_C_FLAGS})
if(BLAS_LIBRARIES MATCHES "libmkl")
target_compile_definitions(phcalc PRIVATE MKL_LAPACKE MULTITHREADED_BLAS)
if(BLAS_LIBRARIES MATCHES "libmkl")
target_compile_definitions(phononcalc_lib PRIVATE MKL_LAPACKE
MULTITHREADED_BLAS)
endif()
if(BLAS_LIBRARIES MATCHES "libopenblas")
target_compile_definitions(phononcalc_lib PRIVATE MULTITHREADED_BLAS)
endif()
else()
# Static link library
add_library(phononcalc_lib STATIC ${SOURCES_PHONONCALC})
target_link_libraries(phononcalc_lib m ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES}
${OpenMP_C_LIBRARIES})
target_include_directories(phononcalc_lib PRIVATE ${MY_INCLUDES})
target_compile_options(phononcalc_lib PRIVATE ${OpenMP_C_FLAGS})
if(BLAS_LIBRARIES MATCHES "libmkl")
target_compile_definitions(phononcalc_lib PRIVATE MKL_LAPACKE
MULTITHREADED_BLAS)
endif()
if(BLAS_LIBRARIES MATCHES "libopenblas")
target_compile_definitions(phononcalc_lib PRIVATE MULTITHREADED_BLAS)
endif()
endif()
if(BLAS_LIBRARIES MATCHES "libopenblas")
target_compile_definitions(phcalc PRIVATE MULTITHREADED_BLAS)
if(NOT BUILD_NANOBIND_MODULE)
if(BUILD_SHARED_LIBS)
set_property(TARGET phononcalc_lib PROPERTY VERSION ${SERIAL})
set_property(TARGET phononcalc_lib PROPERTY SOVERSION ${SOSERIAL})
install(TARGETS phononcalc_lib
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
else()
set_property(TARGET phononcalc_lib PROPERTY VERSION ${SERIAL})
set_property(TARGET phononcalc_lib PROPERTY SOVERSION ${SOSERIAL})
set_property(TARGET phononcalc_lib PROPERTY OUTPUT_NAME phononcalc_lib)
install(TARGETS phononcalc_lib
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()
# Header file
install(FILES ${PROJECT_SOURCE_DIR}/c/phononcalc.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
endif()
set_property(TARGET phcalc PROPERTY VERSION ${SERIAL})
set_property(TARGET phcalc PROPERTY SOVERSION ${SOSERIAL})
install(TARGETS phcalc LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()
# Static link library
add_library(phcalc_static STATIC ${SOURCES_PHONONCALC})
target_link_libraries(phcalc_static m ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES}
${OpenMP_C_LIBRARIES})
target_include_directories(phcalc_static PRIVATE ${MY_INCLUDES})
target_compile_options(phcalc_static PRIVATE ${OpenMP_C_FLAGS})
if(BLAS_LIBRARIES MATCHES "libmkl")
target_compile_definitions(phcalc_static PRIVATE MKL_LAPACKE
MULTITHREADED_BLAS)
endif()
if(BLAS_LIBRARIES MATCHES "libopenblas")
target_compile_definitions(phcalc_static PRIVATE MULTITHREADED_BLAS)
endif()
set_property(TARGET phcalc_static PROPERTY VERSION ${SERIAL})
set_property(TARGET phcalc_static PROPERTY SOVERSION ${SOSERIAL})
set_property(TARGET phcalc_static PROPERTY OUTPUT_NAME phcalc)
install(TARGETS phcalc_static ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
# Header file
install(FILES ${PROJECT_SOURCE_DIR}/c/phononcalc.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
endif()
# ##############################################################################
# ###################################################################################
# grid #
# ##############################################################################
# ###################################################################################
if(GRIDSYS)
# Source code
set(SOURCES_GRIDSYS
${PROJECT_SOURCE_DIR}/c/bzgrid.c
${PROJECT_SOURCE_DIR}/c/grgrid.c
${PROJECT_SOURCE_DIR}/c/gridsys.c
${PROJECT_SOURCE_DIR}/c/lagrid.c
${PROJECT_SOURCE_DIR}/c/niggli.c
${PROJECT_SOURCE_DIR}/c/phonoc_utils.c
${PROJECT_SOURCE_DIR}/c/snf3x3.c
${PROJECT_SOURCE_DIR}/c/tetrahedron_method.c
${PROJECT_SOURCE_DIR}/c/triplet.c
${PROJECT_SOURCE_DIR}/c/triplet_grid.c
${PROJECT_SOURCE_DIR}/c/triplet_iw.c)
# Source code
set(SOURCES_GRIDSYS
${PROJECT_SOURCE_DIR}/c/bzgrid.c
${PROJECT_SOURCE_DIR}/c/grgrid.c
${PROJECT_SOURCE_DIR}/c/gridsys.c
${PROJECT_SOURCE_DIR}/c/lagrid.c
${PROJECT_SOURCE_DIR}/c/niggli.c
${PROJECT_SOURCE_DIR}/c/phonoc_utils.c
${PROJECT_SOURCE_DIR}/c/snf3x3.c
${PROJECT_SOURCE_DIR}/c/tetrahedron_method.c
${PROJECT_SOURCE_DIR}/c/triplet.c
${PROJECT_SOURCE_DIR}/c/triplet_grid.c
${PROJECT_SOURCE_DIR}/c/triplet_iw.c)
if(BUILD_SHARED_LIBRARIES)
# Shared library
add_library(gridsys SHARED ${SOURCES_GRIDSYS})
target_link_libraries(gridsys m ${OpenMP_C_LIBRARIES})
target_include_directories(gridsys PRIVATE ${MY_INCLUDES})
target_compile_options(gridsys PRIVATE ${OpenMP_C_FLAGS})
target_compile_definitions(gridsys PRIVATE THM_EPSILON=1e-10)
set_property(TARGET gridsys PROPERTY VERSION ${SERIAL})
set_property(TARGET gridsys PROPERTY SOVERSION ${SOSERIAL})
install(TARGETS gridsys LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()
if(BUILD_SHARED_LIBS)
# Shared library
add_library(gridsys SHARED ${SOURCES_GRIDSYS})
target_link_libraries(gridsys m ${OpenMP_C_LIBRARIES})
target_include_directories(gridsys PRIVATE ${MY_INCLUDES})
target_compile_options(gridsys PRIVATE ${OpenMP_C_FLAGS})
target_compile_definitions(gridsys PRIVATE THM_EPSILON=1e-10)
set_property(TARGET gridsys PROPERTY VERSION ${SERIAL})
set_property(TARGET gridsys PROPERTY SOVERSION ${SOSERIAL})
install(TARGETS gridsys LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
else()
# Static link library
add_library(gridsys_static STATIC ${SOURCES_GRIDSYS})
target_link_libraries(gridsys_static m ${OpenMP_C_LIBRARIES})
target_include_directories(gridsys_static PRIVATE ${MY_INCLUDES})
target_compile_options(gridsys_static PRIVATE ${OpenMP_C_FLAGS})
target_compile_definitions(gridsys_static PRIVATE THM_EPSILON=1e-10)
set_property(TARGET gridsys_static PROPERTY VERSION ${SERIAL})
set_property(TARGET gridsys_static PROPERTY SOVERSION ${SOSERIAL})
set_property(TARGET gridsys_static PROPERTY OUTPUT_NAME gridsys)
install(TARGETS gridsys_static ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()
# Static link library
add_library(gridsys_static STATIC ${SOURCES_GRIDSYS})
target_link_libraries(gridsys_static m ${OpenMP_C_LIBRARIES})
target_include_directories(gridsys_static PRIVATE ${MY_INCLUDES})
target_compile_options(gridsys_static PRIVATE ${OpenMP_C_FLAGS})
target_compile_definitions(gridsys_static PRIVATE THM_EPSILON=1e-10)
set_property(TARGET gridsys_static PROPERTY VERSION ${SERIAL})
set_property(TARGET gridsys_static PROPERTY SOVERSION ${SOSERIAL})
set_property(TARGET gridsys_static PROPERTY OUTPUT_NAME gridsys)
install(TARGETS gridsys_static ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
# Header file
install(FILES ${PROJECT_SOURCE_DIR}/c/gridsys.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
# Header file
install(FILES ${PROJECT_SOURCE_DIR}/c/gridsys.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
endif()
if(WITH_Fortran)
add_subdirectory(fortran)
add_subdirectory(fortran)
endif()
if(WITH_TESTS)
if(WITH_Fortran)
set(LIB_MOD_DIR ${CMAKE_CURRENT_BINARY_DIR}/fortran)
endif()
add_subdirectory(ctest)
if(WITH_Fortran)
set(LIB_MOD_DIR ${CMAKE_CURRENT_BINARY_DIR}/fortran)
endif()
add_subdirectory(ctest)
endif()
if(BUILD_NANOBIND_MODULE)
set_target_properties(phphcalc_lib PROPERTIES POSITION_INDEPENDENT_CODE ON)
set_target_properties(phononcalc_lib PROPERTIES POSITION_INDEPENDENT_CODE ON)
execute_process(
COMMAND "${Python_EXECUTABLE}" -m nanobind --cmake_dir
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE NB_DIR)
list(APPEND CMAKE_PREFIX_PATH "${NB_DIR}")
find_package(nanobind CONFIG REQUIRED)
nanobind_add_module(
_phono3py STABLE_ABI ${PROJECT_SOURCE_DIR}/c/phono3py.h
${PROJECT_SOURCE_DIR}/c/phononcalc.h ${PROJECT_SOURCE_DIR}/c/_phono3py.cpp)
if(OpenMP_FOUND)
target_link_libraries(_phono3py PRIVATE phphcalc_lib phononcalc_lib
OpenMP::OpenMP_C)
else()
target_link_libraries(_phono3py PRIVATE phphcalc_lib phononcalc_lib)
endif()
target_compile_definitions(_phono3py PRIVATE THM_EPSILON=1e-10)
install(TARGETS _phono3py LIBRARY DESTINATION ${SKBUILD_PROJECT_NAME})
endif()

4
cmake-format.py Normal file
View File

@ -0,0 +1,4 @@
with section("format"):
disable = False
line_width = 85
tab_size = 4

View File

@ -6,37 +6,37 @@ set(CMAKE_CXX_STANDARD_REQUIRED True)
find_package(GTest)
if(NOT GTest_FOUND)
# pthread (required for GoogleTest)
# https://stackoverflow.com/questions/1620918/cmake-and-libpthread
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
# pthread (required for GoogleTest)
# https://stackoverflow.com/questions/1620918/cmake-and-libpthread
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
# Fetch GoogleTest
include(FetchContent)
# Fetch GoogleTest
include(FetchContent)
# cmake-lint inline directives must be specified at body scope. See
# https://cmake-format.readthedocs.io/en/latest/lint-inline.html
# cmake-lint inline directives must be specified at body scope. See
# https://cmake-format.readthedocs.io/en/latest/lint-inline.html
# cmake-lint: disable=C0301
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG 4fb7039fda3f6588c7ca9664176f8c9e0a023b4a)
FetchContent_MakeAvailable(googletest)
# cmake-lint: disable=C0301
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG 4fb7039fda3f6588c7ca9664176f8c9e0a023b4a)
FetchContent_MakeAvailable(googletest)
endif()
foreach(testcase IN ITEMS test_gridsys test_niggli)
add_executable(${testcase} ${CMAKE_CURRENT_SOURCE_DIR}/${testcase}.cpp
${CMAKE_CURRENT_SOURCE_DIR}/utils.c)
target_link_libraries(
${testcase}
PUBLIC gridsys
PRIVATE GTest::gtest GTest::gtest_main)
target_include_directories(${testcase} PUBLIC ${PROJECT_SOURCE_DIR}/c
${CMAKE_CURRENT_SOURCE_DIR})
gtest_discover_tests(${testcase})
add_executable(${testcase} ${CMAKE_CURRENT_SOURCE_DIR}/${testcase}.cpp
${CMAKE_CURRENT_SOURCE_DIR}/utils.c)
target_link_libraries(
${testcase}
PUBLIC gridsys
PRIVATE GTest::gtest GTest::gtest_main)
target_include_directories(${testcase} PUBLIC ${PROJECT_SOURCE_DIR}/c
${CMAKE_CURRENT_SOURCE_DIR})
gtest_discover_tests(${testcase})
endforeach()
if(WITH_Fortran)
add_subdirectory(fortran)
add_subdirectory(fortran)
endif()

View File

@ -7,6 +7,6 @@ set_target_properties(test_${NAME} PROPERTIES Fortran_MODULE_DIRECTORY
${LIB_MOD_DIR})
add_test(
NAME ${NAME}
COMMAND $<TARGET_FILE:test_${NAME}> ${CMAKE_CURRENT_BINARY_DIR}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
NAME ${NAME}
COMMAND $<TARGET_FILE:test_${NAME}> ${CMAKE_CURRENT_BINARY_DIR}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})

View File

@ -1,9 +1,9 @@
if(USE_OpenMP)
find_package(
OpenMP
COMPONENTS Fortran
REQUIRED)
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${OpenMP_Fortran_FLAGS}")
find_package(
OpenMP
COMPONENTS Fortran
REQUIRED)
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${OpenMP_Fortran_FLAGS}")
endif()
add_library(gridsysf_static STATIC gridsysf.f90)
@ -13,11 +13,11 @@ target_link_libraries(gridsysf_static PRIVATE gridsys_static)
install(TARGETS gridsysf_static ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
if(BUILD_SHARED_LIBRARIES)
add_library(gridsysf SHARED gridsysf.f90)
set_property(TARGET gridsysf PROPERTY VERSION ${PROJECT_VERSION})
set_property(TARGET gridsysf PROPERTY SOVERSION ${soserial})
target_link_libraries(gridsysf PUBLIC gridsys)
install(TARGETS gridsysf LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
add_library(gridsysf SHARED gridsysf.f90)
set_property(TARGET gridsysf PROPERTY VERSION ${PROJECT_VERSION})
set_property(TARGET gridsysf PROPERTY SOVERSION ${soserial})
target_link_libraries(gridsysf PUBLIC gridsys)
install(TARGETS gridsysf LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/gridsysf.mod

View File

@ -1,5 +1,3 @@
#!/usr/bin/env python
# Copyright (C) 2011 Atsushi Togo
# All rights reserved.
#
@ -36,7 +34,9 @@
from phono3py.cui.phono3py_script import main
if __name__ == "__main__":
def run():
"""Run phono3py script."""
argparse_control = {
"fc_symmetry": False,
"is_nac": False,

View File

@ -1,5 +1,3 @@
#!/usr/bin/env python
# Copyright (C) 2020 Atsushi Togo
# All rights reserved.
#
@ -36,6 +34,8 @@
from phono3py.cui.phono3py_script import main
if __name__ == "__main__":
def run():
"""Run phono3py-load script."""
argparse_control = {"fc_symmetry": True, "is_nac": True, "load_phono3py_yaml": True}
main(**argparse_control)

View File

@ -1,5 +1,49 @@
[build-system]
requires = ["setuptools", "wheel", "numpy"]
requires = ["scikit-build-core", "nanobind", "numpy"]
build-backend = "scikit_build_core.build"
[project]
name = "phono3py"
dynamic = ["version"]
readme = { file = "README.md", content-type = "text/markdown" }
description = "This is the phono3py module."
authors = [{ name = "Atsushi Togo", email = "atztogo@gmail.com" }]
requires-python = ">=3.8"
dependencies = [
"numpy>=1.17.0",
"scipy",
"PyYAML>=5.3",
"matplotlib>=2.2.2",
"h5py>=3.0",
"spglib>=2.3",
"phonopy>=2.25,<2.26",
]
license = { file = "LICENSE" }
[project.urls]
Homepage = "https://phonopy.github.io/phono3py/"
Repository = "https://github.com/phonopy/phono3py"
[project.scripts]
phono3py = "phono3py.scripts.phono3py:run"
phono3py-load = "phonopy.scripts.phono3py_load:run"
[tool.scikit-build]
metadata.version.provider = "scikit_build_core.metadata.setuptools_scm"
sdist.exclude = ["*"]
sdist.include = [
"test",
"LICENSE",
"c",
"example",
"phono3py",
"pyproject.toml",
"CMakeLists.txt",
"README.md",
]
[tool.setuptools_scm]
write_to = "phono3py/_version.py"
[tool.ruff]
line-length = 88
@ -10,10 +54,8 @@ lint.select = [
"E", # pycodestyle-errors
"D", # pydocstyle
]
lint.extend-ignore = [
"D417",
"D100",
]
lint.extend-ignore = ["D417", "D100"]
exclude = ["cmake-format.py"]
[tool.ruff.lint.pydocstyle]
convention = "numpy"