Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: migrate to scikit-build-core #7

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions .github/workflows/build_wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ on:
release:
types: [ published ]
workflow_dispatch:
pull_request:
pull_request: # Temporarily trigger on PRs for debugging, remove later
types: [opened, synchronize, reopened]
cringeyburger marked this conversation as resolved.
Show resolved Hide resolved
branches:
- "main"

Expand All @@ -20,8 +21,6 @@ jobs:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
with:
submodules: 'true'
- uses: actions/setup-python@v5
with:
python-version: 3.11
Expand Down Expand Up @@ -56,7 +55,7 @@ jobs:
CMAKE_GENERATOR_PLATFORM=x64
CMAKE_BUILD_PARALLEL_LEVEL=${{ steps.get_num_cores.outputs.count }}
CIBW_ARCHS: AMD64
CIBW_BEFORE_BUILD: python -m pip install setuptools wheel delvewheel # skip CasADi and CMake
CIBW_BEFORE_BUILD: python -m pip install scikit-build-core delvewheel # skip CasADi and CMake
CIBW_REPAIR_WHEEL_COMMAND: delvewheel repair --add-path C:/Windows/System32 -w {dest_dir} {wheel}
CIBW_TEST_EXTRAS: "dev"
CIBW_TEST_COMMAND: |
Expand All @@ -73,9 +72,6 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: 'true'

- uses: actions/setup-python@v5
with:
python-version: 3.11
Expand All @@ -86,8 +82,8 @@ jobs:
CIBW_ARCHS_LINUX: x86_64
CIBW_BEFORE_ALL_LINUX: >
yum -y install openblas-devel lapack-devel &&
bash install_sundials.sh
CIBW_BEFORE_BUILD_LINUX: python -m pip install cmake casadi setuptools wheel
python install_KLU_Sundials.py
CIBW_BEFORE_BUILD_LINUX: python -m pip install casadi scikit-build-core cmake pybind11
CIBW_REPAIR_WHEEL_COMMAND_LINUX: auditwheel repair -w {dest_dir} {wheel}
CIBW_TEST_EXTRAS: "dev"
CIBW_TEST_COMMAND: |
Expand All @@ -110,8 +106,6 @@ jobs:
fail-fast: false
steps:
- uses: actions/checkout@v4
with:
submodules: 'true'
- uses: actions/setup-python@v5
with:
python-version: '3.11'
Expand Down Expand Up @@ -211,7 +205,7 @@ jobs:
# 10.13 for Intel (macos-13), 11.0 for Apple Silicon (macos-14 and macos-latest)
MACOSX_DEPLOYMENT_TARGET: ${{ matrix.os == 'macos-14' && '11.0' || '10.13' }}
CIBW_ARCHS_MACOS: auto
CIBW_BEFORE_BUILD: python -m pip install cmake casadi setuptools wheel delocate
CIBW_BEFORE_BUILD: python -m pip install casadi scikit-build-core delocate cmake pybind11
CIBW_REPAIR_WHEEL_COMMAND: |
if [[ $(uname -m) == "x86_64" ]]; then
delocate-listdeps {wheel} && delocate-wheel -v -w {dest_dir} {wheel}
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,5 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: 'true'
- uses: actions/setup-python@v4
- uses: pre-commit/[email protected]
3 changes: 0 additions & 3 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ jobs:

steps:
- uses: actions/checkout@v4
with:
submodules: 'true'

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ setup.log
install_KLU_Sundials
.idaklu
build
dist
*.so

# Extra directories for local work
workspace
Expand Down
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

85 changes: 61 additions & 24 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,17 @@ endif()
# casadi seems to compile without the newer versions of std::string
add_compile_definitions(_GLIBCXX_USE_CXX11_ABI=0)

if(NOT PYBIND11_DIR)
set(PYBIND11_DIR pybind11)
endif()
add_subdirectory(${PYBIND11_DIR})
find_package(pybind11 CONFIG REQUIRED)

find_package(Python COMPONENTS Interpreter Development.Module REQUIRED)

# Check Casadi build flag
if(NOT DEFINED PYBAMM_IDAKLU_EXPR_CASADI)
set(PYBAMM_IDAKLU_EXPR_CASADI ON)
if(DEFINED ENV{PYBAMM_IDAKLU_EXPR_CASADI})
set(PYBAMM_IDAKLU_EXPR_CASADI "$ENV{PYBAMM_IDAKLU_EXPR_CASADI}")
else()
set(PYBAMM_IDAKLU_EXPR_CASADI ON)
endif()
endif()
message("PYBAMM_IDAKLU_EXPR_CASADI: ${PYBAMM_IDAKLU_EXPR_CASADI}")

Expand All @@ -59,7 +62,11 @@ endif()

# Check IREE build flag
if(NOT DEFINED PYBAMM_IDAKLU_EXPR_IREE)
set(PYBAMM_IDAKLU_EXPR_IREE OFF)
if(DEFINED ENV{PYBAMM_IDAKLU_EXPR_IREE})
set(PYBAMM_IDAKLU_EXPR_IREE "$ENV{PYBAMM_IDAKLU_EXPR_IREE}")
else()
set(PYBAMM_IDAKLU_EXPR_IREE OFF)
endif()
endif()
message("PYBAMM_IDAKLU_EXPR_IREE: ${PYBAMM_IDAKLU_EXPR_IREE}")

Expand Down Expand Up @@ -116,39 +123,40 @@ pybind11_add_module(idaklu
${IDAKLU_EXPR_IREE_SOURCE_FILES}
)

if (NOT DEFINED USE_PYTHON_CASADI)
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
set(USE_PYTHON_CASADI FALSE)
else()
set(USE_PYTHON_CASADI TRUE)
endif()

# Check if CASADI_PATH is set in the environment
if(NOT DEFINED ENV{CASADI_PATH})
execute_process(
COMMAND "${PYTHON_EXECUTABLE}" -c
"import os; import sysconfig; print(os.path.join(sysconfig.get_path('purelib'), 'casadi', 'cmake'))"
OUTPUT_VARIABLE CASADI_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE)
else()
set(CASADI_DIR $ENV{CASADI_PATH})
message("it is alr set: ${CASADI_DIR}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a good message for printing, please clean this up

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I forgot to change this. Thanks

endif()

execute_process(
COMMAND "${PYTHON_EXECUTABLE}" -c
"import os; import sysconfig; print(os.path.join(sysconfig.get_path('purelib'), 'casadi', 'cmake'))"
OUTPUT_VARIABLE CASADI_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE)

if (CASADI_DIR)
if(CASADI_DIR)
file(TO_CMAKE_PATH ${CASADI_DIR} CASADI_DIR)
message("Found Python casadi path: ${CASADI_DIR}")
message("Found CasADi path: ${CASADI_DIR}")
else()
message(FATAL_ERROR "Did not find casadi path}")
message(FATAL_ERROR "Did not find CasADi path")
endif()

if(${USE_PYTHON_CASADI})
message("Trying to link against Python casadi package in ${CASADI_DIR}")
message("Trying to link against Python CasADi package in ${CASADI_DIR}")
find_package(casadi CONFIG PATHS ${CASADI_DIR} REQUIRED NO_DEFAULT_PATH)
else()
message("Trying to link against any casadi package apart from the Python one")
message("Trying to link against any CasADi package apart from the Python one")
set(CMAKE_IGNORE_PATH "${CASADI_DIR}/cmake")
find_package(casadi CONFIG REQUIRED)
endif()

set_target_properties(
idaklu PROPERTIES
INSTALL_RPATH "${CASADI_DIR}"
INSTALL_RPATH_USE_LINK_PATH TRUE
)

# openmp
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
execute_process(
Expand All @@ -167,6 +175,14 @@ if(OpenMP_CXX_FOUND)
endif()

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR})

if(NOT DEFINED ENV{INSTALL_DIR})
set(INSTALL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/.idaklu")
else()
set(INSTALL_DIR $ENV{INSTALL_DIR})
endif()
message(STATUS "Library path is set: ${INSTALL_DIR}")

# Sundials
find_package(SUNDIALS REQUIRED)
message("SUNDIALS found in ${SUNDIALS_INCLUDE_DIR}: ${SUNDIALS_LIBRARIES}")
Expand All @@ -185,6 +201,21 @@ endif()
include_directories(${SuiteSparse_INCLUDE_DIRS})
target_link_libraries(idaklu PRIVATE ${SuiteSparse_LIBRARIES})

if(DEFINED ENV{CIBUILDWHEEL} AND CMAKE_SYSTEM_NAME STREQUAL "Linux")
set(SUNDIALS_LIBRARY_DIR "${INSTALL_DIR}/lib64")
set(SUITESPARSE_LIBRARY_DIR "${INSTALL_DIR}/lib64")
else()
set(SUNDIALS_LIBRARY_DIR "${INSTALL_DIR}/lib")
set(SUITESPARSE_LIBRARY_DIR "${INSTALL_DIR}/lib")
endif()

set_target_properties(idaklu PROPERTIES
INSTALL_RPATH "${CASADI_DIR};${SUNDIALS_LIBRARY_DIR};${SUITESPARSE_LIBRARY_DIR}"
INSTALL_RPATH_USE_LINK_PATH TRUE
BUILD_RPATH "${CASADI_DIR};${SUNDIALS_LIBRARY_DIR};${SUITESPARSE_LIBRARY_DIR}"
)
message("NOTE: RPATHS linking SUNDIALS, SuiteSparse and casADi are set")

# IREE (MLIR compiler and runtime library) build settings
if(${PYBAMM_IDAKLU_EXPR_IREE} STREQUAL "ON" )
set(IREE_BUILD_COMPILER ON)
Expand All @@ -197,3 +228,9 @@ if(${PYBAMM_IDAKLU_EXPR_IREE} STREQUAL "ON" )
target_link_libraries(idaklu PRIVATE iree_compiler_bindings_c_loader)
target_link_libraries(idaklu PRIVATE iree_runtime_runtime)
endif()

if(DEFINED ENV{CIBUILDWHEEL})
install(TARGETS idaklu DESTINATION "pybammsolvers")
else()
install(TARGETS idaklu DESTINATION "${CMAKE_CURRENT_SOURCE_DIR}/src/pybammsolvers")
endif()
Comment on lines +232 to +236
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be consistent about where files are placed whenever possible

2 changes: 2 additions & 0 deletions FindSUNDIALS.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ find_path(SUNDIALS_INCLUDE_DIR
include
PATHS
${SUNDIALS_ROOT}
${INSTALL_DIR}
)

set(SUNDIALS_WANT_COMPONENTS
Expand Down Expand Up @@ -74,6 +75,7 @@ foreach(LIB ${SUNDIALS_WANT_COMPONENTS})
Lib
PATHS
${SUNDIALS_ROOT}
${INSTALL_DIR}
cringeyburger marked this conversation as resolved.
Show resolved Hide resolved
)

set(SUNDIALS_${LIB}_FOUND FALSE)
Expand Down
34 changes: 29 additions & 5 deletions FindSuiteSparse.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@
# system paths.
#

if(NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin")
enable_language(Fortran)
set(IDAKLU_BLAS_VENDOR
"OpenBLAS"
CACHE
STRING
"Sets the BLAS/LAPACK vendor. See https://cmake.org/cmake/help/latest/module/FindBLAS.html#blas-lapack-vendors."
)
set(BLA_VENDOR ${IDAKLU_BLAS_VENDOR})

# openBLAS: include a "lib" prefix in its names
set(CMAKE_FIND_LIBRARY_PREFIXES "" lib)
endif()

find_package(BLAS QUIET)

# look for desired componenents
Expand All @@ -60,7 +74,9 @@ endif()
# look for library at positions given by the user
find_library(SUITESPARSE_CONFIG_LIB
NAMES "suitesparseconfig"
PATHS ${SuiteSparse_ROOT}
PATHS
${SuiteSparse_ROOT}
${INSTALL_DIR}
PATH_SUFFIXES "lib" "lib32" "lib64" "Lib"
NO_DEFAULT_PATH
)
Expand All @@ -73,7 +89,9 @@ find_library(SUITESPARSE_CONFIG_LIB
#look for header files at positions given by the user
find_path(SUITESPARSE_INCLUDE_DIR
NAMES "SuiteSparse_config.h"
PATHS ${SuiteSparse_ROOT}
PATHS
${SuiteSparse_ROOT}
${INSTALL_DIR}
PATH_SUFFIXES "SuiteSparse_config" "SuiteSparse_config/include" "suitesparse" "include" "src" "SuiteSparse_config/Include"
NO_DEFAULT_PATH
)
Expand All @@ -89,7 +107,9 @@ foreach(_component ${SUITESPARSE_COMPONENTS})
#look for library at positions given by the user
find_library(${_component}_LIBRARY
NAMES "${_componentLower}"
PATHS ${SuiteSparse_ROOT}
PATHS
${SuiteSparse_ROOT}
${INSTALL_DIR}
PATH_SUFFIXES "lib" "lib32" "lib64" "${_component}" "${_component}/Lib"
NO_DEFAULT_PATH
)
Expand All @@ -102,7 +122,9 @@ foreach(_component ${SUITESPARSE_COMPONENTS})
#look for header files at positions given by the user
find_path(${_component}_INCLUDE_DIR
NAMES "${_componentLower}.h"
PATHS ${SuiteSparse_ROOT}
PATHS
${SuiteSparse_ROOT}
${INSTALL_DIR}
PATH_SUFFIXES "${_componentLower}" "include/${_componentLower}" "suitesparse" "include" "src" "${_component}" "${_component}/Include"
NO_DEFAULT_PATH
)
Expand All @@ -117,7 +139,9 @@ endforeach()
#look for header files at positions given by the user
find_path(SPQR_INCLUDE_DIR
NAMES "SuiteSparseQR.hpp"
PATHS ${SuiteSparse_ROOT}
PATHS
${SuiteSparse_ROOT}
${INSTALL_DIR}
PATH_SUFFIXES "spqr" "include/spqr" "suitesparse" "include" "src" "SPQR" "SPQR/Include"
NO_DEFAULT_PATH
)
Expand Down
Loading
Loading