From c1a3c244a0a87d35e93767e7092582958f4799e0 Mon Sep 17 00:00:00 2001 From: purepani Date: Tue, 4 Mar 2025 18:28:40 -0600 Subject: [PATCH 01/14] Add scikit-build system --- pyproject.toml | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 24adcdac4a..c96353722d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,16 @@ [build-system] -requires = ["setuptools>=64", "setuptools_scm>=8"] -build-backend = "setuptools.build_meta" +requires = ["setuptools>=64", "setuptools_scm>=8", + "ipp-static>=2022.0,<2022.1", + "ipp-devel>=2022.0,<2022.1", + "nanobind", + "scikit-build-core>=0.11.0", + "intel-openmp==2025.0.5", +] +build-backend = "scikit_build_core.build" + +[tool.scikit-build.wheel.packages] +cil = "Wrappers/Python/cil" +"cil/cilacc" = "src/cilacc" [tool.setuptools_scm] version_file = "Wrappers/Python/cil/version.py" From b7e5b0f8d4ef5af34d1afd03f05944fbc0def406 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Wed, 23 Apr 2025 10:39:30 +0100 Subject: [PATCH 02/14] fixup build system --- pyproject.toml | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index c96353722d..2e7dff67b7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,16 +1,15 @@ [build-system] -requires = ["setuptools>=64", "setuptools_scm>=8", - "ipp-static>=2022.0,<2022.1", - "ipp-devel>=2022.0,<2022.1", - "nanobind", - "scikit-build-core>=0.11.0", - "intel-openmp==2025.0.5", +requires = [ + "setuptools>=64", + "setuptools_scm>=8", + "scikit-build-core", + #"ipp-devel==2021.12.*", # PyPI conflicts with conda package ] build-backend = "scikit_build_core.build" [tool.scikit-build.wheel.packages] cil = "Wrappers/Python/cil" -"cil/cilacc" = "src/cilacc" +"cil/cilacc" = "src/Core" [tool.setuptools_scm] version_file = "Wrappers/Python/cil/version.py" From f687b9d8301d8a4e5294faecbc341b7974c181da Mon Sep 17 00:00:00 2001 From: purepani Date: Tue, 4 Mar 2025 18:28:40 -0600 Subject: [PATCH 03/14] Add CMake Build Files --- CMakeLists.txt | 19 ++++---- Wrappers/Python/CMakeLists.txt | 30 ------------ src/Core/CMakeLists.txt | 86 +++++++++++++++------------------- 3 files changed, 50 insertions(+), 85 deletions(-) delete mode 100644 Wrappers/Python/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 261c61cb66..d8441f607a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,20 +21,23 @@ else() cmake_minimum_required(VERSION 3.5) endif() -project(cil LANGUAGES CXX) +project(${SKBUILD_PROJECT_NAME} LANGUAGES CXX) cmake_policy(PUSH) cmake_policy(SET CMP0074 NEW) -if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.27) +if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.27) cmake_policy(SET CMP0148 OLD) endif() # If APPLE don't use @rpath -if (APPLE) - option(SHARED_LIBS_ABS_PATH "Force shared libraries to be installed with absolute paths (as opposed to rpaths)" ON) - mark_as_advanced( SHARED_LIBS_ABS_PATH ) - if (SHARED_LIBS_ABS_PATH) +if(APPLE) + option( + SHARED_LIBS_ABS_PATH + "Force shared libraries to be installed with absolute paths (as opposed to rpaths)" + ON) + mark_as_advanced(SHARED_LIBS_ABS_PATH) + if(SHARED_LIBS_ABS_PATH) # Set install_name_dir as the absolute path to install_prefix/lib GET_FILENAME_COMPONENT(CMAKE_INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/lib REALPATH) set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) @@ -45,7 +48,7 @@ if(NOT DEFINED CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE "RelWithDebInfo") endif() -add_subdirectory(src/Core) -add_subdirectory(Wrappers/Python) + +add_subdirectory(src/cilacc) cmake_policy(POP) diff --git a/Wrappers/Python/CMakeLists.txt b/Wrappers/Python/CMakeLists.txt deleted file mode 100644 index 9cb60e0f60..0000000000 --- a/Wrappers/Python/CMakeLists.txt +++ /dev/null @@ -1,30 +0,0 @@ -find_package(Python COMPONENTS Interpreter REQUIRED) - -if(PYTHON_DEST_DIR) - file(TO_CMAKE_PATH "${PYTHON_DEST_DIR}" PYTHON_DEST) -endif() - -message("CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}") -if(NOT DEFINED) - set(CMAKE_BUILD_TYPE "RelWithDebInfo") -endif() - -# TODO: add to add_custom_command DEPENDS the list of python files of the project. -# file(GLOB_RECURSE DEPS ${CMAKE_CURRENT_SOURCE_DIR}/cil/*.py ) -message("SETUPTOOLS_SCM_PRETEND_VERSION_FOR_CIL: $ENV{SETUPTOOLS_SCM_PRETEND_VERSION_FOR_CIL}") -message("CMAKE_SOURCE_DIR: ${CMAKE_SOURCE_DIR}") -if(PYTHON_DEST_DIR) - message(STATUS "CIL install using ${Python_EXECUTABLE} -m pip install -t ${PYTHON_DEST}") - add_custom_target(pythonsetup ALL - COMMAND ${Python_EXECUTABLE} -m pip install ${CMAKE_SOURCE_DIR} -t ${PYTHON_DEST} --upgrade - DEPENDS cilacc) -else() - message(STATUS "CIL install using ${Python_EXECUTABLE} -m pip install") - add_custom_target(pythonsetup ALL - COMMAND ${Python_EXECUTABLE} -m pip install ${CMAKE_SOURCE_DIR} --upgrade - DEPENDS cilacc) -endif() -# install the data if not a conda build. With conda the data is in the dependency package cil-data -if (NOT CONDA_BUILD) - install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data/ DESTINATION ${CMAKE_INSTALL_PREFIX}/share/cil) -endif() diff --git a/src/Core/CMakeLists.txt b/src/Core/CMakeLists.txt index 82f0c8e0b0..1a17f94d61 100644 --- a/src/Core/CMakeLists.txt +++ b/src/Core/CMakeLists.txt @@ -25,20 +25,33 @@ message ("OpenMP_CXX_FLAGS ${OpenMP_CXX_FLAGS}") find_package(OpenMP REQUIRED) add_definitions(${OpenMP_CXX_FLAGS}) -if (WIN32) - set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Ddll_EXPORTS") +cmake_minimum_required(VERSION 3.15) + +find_package(Python REQUIRED COMPONENTS Interpreter Development.Module OPTIONAL_COMPONENTS Development.SABIModule) + +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() +find_package(nanobind CONFIG REQUIRED) + + +####Needed to find IPP libraries +execute_process( + COMMAND "${Python_EXECUTABLE}" -c "import sysconfig; print(sysconfig.get_paths()[\"data\"])" + OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE DATA_DIR) +list(APPEND CMAKE_PREFIX_PATH ${DATA_DIR}/cmake) +find_package(IPP REQUIRED CONFIG) + + + if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNUCC") # appends some flags add_compile_options(-ftree-vectorize -fopt-info-vec-optimized -fopt-info-vec) # add_compile_options(-march=native -mavx ) endif() -message("CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}") -message("CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS}") -message("CMAKE_SHARED_LINKER_FLAGS ${CMAKE_SHARED_LINKER_FLAGS}") -message("CMAKE_STATIC_LINKER_FLAGS ${CMAKE_STATIC_LINKER_FLAGS}") if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.9.0") set (OpenMP_EXE_LINKER_FLAGS OpenMP::OpenMP_CXX) @@ -49,48 +62,27 @@ else() set (OpenMP_EXE_LINKER_FLAGS ${OpenMP_C_FLAGS}) endif() -list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") -find_package(IPP) -list(APPEND cilacc_SOURCES utilities.cpp axpby.cpp FiniteDifferenceLibrary.cpp) -list(APPEND cilacc_INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}/include) -list(APPEND cilacc_LIBRARIES ${OpenMP_EXE_LINKER_FLAGS}) -if(IPP_FOUND) - list(APPEND cilacc_SOURCES FBP_filtering.cpp Binning.cpp) - list(APPEND cilacc_INCLUDES ${IPP_INCLUDE_DIRS}) - list(APPEND cilacc_LIBRARIES ${IPP_LIBRARIES}) -else() - message(WARNING "IPP libraries not found, FBP_filtering not in build") -endif() -add_library(cilacc SHARED ${cilacc_SOURCES}) -target_link_libraries(cilacc ${cilacc_LIBRARIES}) -include_directories(cilacc PUBLIC ${cilacc_INCLUDES}) - -## Install -#include(GNUInstallDirs) -#install(TARGETS cilacc -# RUNTIME DESTINATION bin -# LIBRARY DESTINATION lib -# ARCHIVE DESTINATION lib -# CONFIGURATIONS ${CMAKE_BUILD_TYPE} -# ) - -if (UNIX) -message ("I'd install into ${CMAKE_INSTALL_PREFIX}/lib") -install(TARGETS cilacc - LIBRARY DESTINATION lib - CONFIGURATIONS ${CMAKE_BUILD_TYPE} - ) -elseif(WIN32) -message ("I'd install into ${CMAKE_INSTALL_PREFIX} lib bin") - install(TARGETS cilacc - RUNTIME DESTINATION Library/bin - ARCHIVE DESTINATION lib - CONFIGURATIONS ${CMAKE_BUILD_TYPE} - ) -endif() +nanobind_add_module( + cilacc + NB_STATIC + ${CMAKE_CURRENT_SOURCE_DIR}/nanobind.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/include/axpby.h + ${CMAKE_CURRENT_SOURCE_DIR}/include/Binning.h + ${CMAKE_CURRENT_SOURCE_DIR}/include/FBP_filtering.h + ${CMAKE_CURRENT_SOURCE_DIR}/include/FiniteDifferenceLibrary.h + ${CMAKE_CURRENT_SOURCE_DIR}/include/utilities.h + ${CMAKE_CURRENT_SOURCE_DIR}/axpby.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/Binning.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/FBP_filtering.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/FiniteDifferenceLibrary.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/utilities.cpp +) +target_link_libraries(cilacc PUBLIC ${OpenMP_EXE_LINKER_FLAGS} ${IPP_LIBRARIES}) +include_directories(cilacc PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/include/ +) -install(DIRECTORY ${PROJECT_SOURCE_DIR}/src/Core/include/ - DESTINATION ${CMAKE_INSTALL_PREFIX}/include/cil) +install(TARGETS cilacc LIBRARY DESTINATION cil) From 4fc54724b4aa321845a4f8188d4f767da843c366 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Wed, 23 Apr 2025 11:22:36 +0100 Subject: [PATCH 04/14] fixup & reverts --- CMakeLists.txt | 19 ++++++------- pyproject.toml | 4 --- src/Core/CMakeLists.txt | 63 ++++++++++++++++------------------------- 3 files changed, 33 insertions(+), 53 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d8441f607a..1054e3d78c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,23 +21,23 @@ else() cmake_minimum_required(VERSION 3.5) endif() +if(NOT SKBUILD_PROJECT_NAME) + set(SKBUILD_PROJECT_NAME cil) +endif() project(${SKBUILD_PROJECT_NAME} LANGUAGES CXX) cmake_policy(PUSH) cmake_policy(SET CMP0074 NEW) -if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.27) +if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.27) cmake_policy(SET CMP0148 OLD) endif() # If APPLE don't use @rpath -if(APPLE) - option( - SHARED_LIBS_ABS_PATH - "Force shared libraries to be installed with absolute paths (as opposed to rpaths)" - ON) - mark_as_advanced(SHARED_LIBS_ABS_PATH) - if(SHARED_LIBS_ABS_PATH) +if (APPLE) + option(SHARED_LIBS_ABS_PATH "Force shared libraries to be installed with absolute paths (as opposed to rpaths)" ON) + mark_as_advanced( SHARED_LIBS_ABS_PATH ) + if (SHARED_LIBS_ABS_PATH) # Set install_name_dir as the absolute path to install_prefix/lib GET_FILENAME_COMPONENT(CMAKE_INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/lib REALPATH) set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) @@ -48,7 +48,6 @@ if(NOT DEFINED CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE "RelWithDebInfo") endif() - -add_subdirectory(src/cilacc) +add_subdirectory(src/Core) cmake_policy(POP) diff --git a/pyproject.toml b/pyproject.toml index 2e7dff67b7..a781f9a938 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,10 +7,6 @@ requires = [ ] build-backend = "scikit_build_core.build" -[tool.scikit-build.wheel.packages] -cil = "Wrappers/Python/cil" -"cil/cilacc" = "src/Core" - [tool.setuptools_scm] version_file = "Wrappers/Python/cil/version.py" version_file_template = """ diff --git a/src/Core/CMakeLists.txt b/src/Core/CMakeLists.txt index 1a17f94d61..fadcafcdb7 100644 --- a/src/Core/CMakeLists.txt +++ b/src/Core/CMakeLists.txt @@ -25,33 +25,20 @@ message ("OpenMP_CXX_FLAGS ${OpenMP_CXX_FLAGS}") find_package(OpenMP REQUIRED) add_definitions(${OpenMP_CXX_FLAGS}) -cmake_minimum_required(VERSION 3.15) - -find_package(Python REQUIRED COMPONENTS Interpreter Development.Module OPTIONAL_COMPONENTS Development.SABIModule) - -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") +if (WIN32) + add_definitions("/Ddll_EXPORTS") endif() -find_package(nanobind CONFIG REQUIRED) - - -####Needed to find IPP libraries -execute_process( - COMMAND "${Python_EXECUTABLE}" -c "import sysconfig; print(sysconfig.get_paths()[\"data\"])" - OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_VARIABLE DATA_DIR) -list(APPEND CMAKE_PREFIX_PATH ${DATA_DIR}/cmake) -find_package(IPP REQUIRED CONFIG) - - - if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNUCC") # appends some flags add_compile_options(-ftree-vectorize -fopt-info-vec-optimized -fopt-info-vec) # add_compile_options(-march=native -mavx ) endif() +message("CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}") +message("CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS}") +message("CMAKE_SHARED_LINKER_FLAGS ${CMAKE_SHARED_LINKER_FLAGS}") +message("CMAKE_STATIC_LINKER_FLAGS ${CMAKE_STATIC_LINKER_FLAGS}") if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.9.0") set (OpenMP_EXE_LINKER_FLAGS OpenMP::OpenMP_CXX) @@ -62,27 +49,25 @@ else() set (OpenMP_EXE_LINKER_FLAGS ${OpenMP_C_FLAGS}) endif() +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") +find_package(IPP) +list(APPEND cilacc_SOURCES utilities.cpp axpby.cpp FiniteDifferenceLibrary.cpp) +list(APPEND cilacc_INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}/include) +list(APPEND cilacc_LIBRARIES ${OpenMP_EXE_LINKER_FLAGS}) +if(IPP_FOUND) + list(APPEND cilacc_SOURCES FBP_filtering.cpp Binning.cpp) + list(APPEND cilacc_INCLUDES ${IPP_INCLUDE_DIRS}) + list(APPEND cilacc_LIBRARIES ${IPP_LIBRARIES}) +else() + message(WARNING "IPP libraries not found, FBP_filtering not in build") +endif() -nanobind_add_module( - cilacc - NB_STATIC - ${CMAKE_CURRENT_SOURCE_DIR}/nanobind.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/include/axpby.h - ${CMAKE_CURRENT_SOURCE_DIR}/include/Binning.h - ${CMAKE_CURRENT_SOURCE_DIR}/include/FBP_filtering.h - ${CMAKE_CURRENT_SOURCE_DIR}/include/FiniteDifferenceLibrary.h - ${CMAKE_CURRENT_SOURCE_DIR}/include/utilities.h - ${CMAKE_CURRENT_SOURCE_DIR}/axpby.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/Binning.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/FBP_filtering.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/FiniteDifferenceLibrary.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/utilities.cpp -) -target_link_libraries(cilacc PUBLIC ${OpenMP_EXE_LINKER_FLAGS} ${IPP_LIBRARIES}) -include_directories(cilacc PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/include/ -) +add_library(cilacc SHARED ${cilacc_SOURCES}) +target_link_libraries(cilacc ${cilacc_LIBRARIES}) +include_directories(cilacc PUBLIC ${cilacc_INCLUDES}) -install(TARGETS cilacc LIBRARY DESTINATION cil) +install(TARGETS cilacc LIBRARY DESTINATION ${SKBUILD_PROJECT_NAME}) +install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ + DESTINATION ${SKBUILD_PROJECT_NAME}/include/${SKBUILD_PROJECT_NAME}) From 47ec6eabe8045f8d189e8fe32cb12c022e6b7c29 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Wed, 23 Apr 2025 11:47:21 +0100 Subject: [PATCH 05/14] sdist --- pyproject.toml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index a781f9a938..846644715e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,11 +2,20 @@ requires = [ "setuptools>=64", "setuptools_scm>=8", - "scikit-build-core", + "scikit-build-core>=0.10", #"ipp-devel==2021.12.*", # PyPI conflicts with conda package ] build-backend = "scikit_build_core.build" +[tool.scikit-build] +minimum-version = "build-system.requires" +cmake.version = ">=3.16" +metadata.version.provider = "scikit_build_core.metadata.setuptools_scm" +sdist.include = ["Wrappers/Python/cil/version.py"] +sdist.exclude = ["scripts", "docs", "Wrappers/Python/data", "Wrappers/Python/test", ".*"] +[tool.scikit-build.wheel.packages] +cil = "Wrappers/Python/cil" + [tool.setuptools_scm] version_file = "Wrappers/Python/cil/version.py" version_file_template = """ From 4b56133fc10b5814cf8de4c53ea6d2dac02818c1 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Wed, 23 Apr 2025 13:14:34 +0100 Subject: [PATCH 06/14] fix cilacc lib path --- Wrappers/Python/cil/framework/cilacc.py | 20 +++++------------ .../operators/GradientOperator.py | 22 ++++--------------- src/Core/CMakeLists.txt | 2 +- 3 files changed, 11 insertions(+), 33 deletions(-) diff --git a/Wrappers/Python/cil/framework/cilacc.py b/Wrappers/Python/cil/framework/cilacc.py index fa96ba4c51..88e7046dc0 100644 --- a/Wrappers/Python/cil/framework/cilacc.py +++ b/Wrappers/Python/cil/framework/cilacc.py @@ -16,18 +16,10 @@ # Authors: # CIL Developers, listed at: https://github.com/TomographicImaging/CIL/blob/master/NOTICE.txt import ctypes -import platform -from ctypes import util -# check for the extension +from pathlib import Path -if platform.system() == 'Linux': - dll = 'libcilacc.so' -elif platform.system() == 'Windows': - dll_file = 'cilacc.dll' - dll = util.find_library(dll_file) -elif platform.system() == 'Darwin': - dll = 'libcilacc.dylib' -else: - raise ValueError('Not supported platform, ', platform.system()) - -cilacc = ctypes.cdll.LoadLibrary(dll) +try: + cilacc_path = next((Path(__file__).parent.parent / 'lib').resolve().glob("*cilacc.*")) +except StopIteration: + raise FileNotFoundError("cilacc library not found") +cilacc = ctypes.cdll.LoadLibrary(str(cilacc_path)) diff --git a/Wrappers/Python/cil/optimisation/operators/GradientOperator.py b/Wrappers/Python/cil/optimisation/operators/GradientOperator.py index ae6bbc6922..56dd9b1b1b 100644 --- a/Wrappers/Python/cil/optimisation/operators/GradientOperator.py +++ b/Wrappers/Python/cil/optimisation/operators/GradientOperator.py @@ -18,7 +18,7 @@ from cil.optimisation.operators import LinearOperator from cil.optimisation.operators import FiniteDifferenceOperator -from cil.framework import BlockGeometry, ImageGeometry +from cil.framework import BlockGeometry, ImageGeometry, cilacc import logging from cil.utilities.multiprocessing import NUM_THREADS import numpy as np @@ -258,7 +258,7 @@ def adjoint(self, x, out=None): out.fill(tmp) else: out += tmp - return out + return out else: tmp = self.domain_geometry().allocate() for i, axis_index in enumerate(self.ind): @@ -267,20 +267,7 @@ def adjoint(self, x, out=None): tmp += self.FD.adjoint(x.get_item(i)) return tmp -import ctypes, platform -from ctypes import util -# check for the extension -if platform.system() == 'Linux': - dll = 'libcilacc.so' -elif platform.system() == 'Windows': - dll_file = 'cilacc.dll' - dll = util.find_library(dll_file) -elif platform.system() == 'Darwin': - dll = 'libcilacc.dylib' -else: - raise ValueError('Not supported platform, ', platform.system()) - -cilacc = ctypes.cdll.LoadLibrary(dll) +import ctypes c_float_p = ctypes.POINTER(ctypes.c_float) @@ -457,7 +444,7 @@ def adjoint(self, x, out=None): status = self.fd(out_p, *args) if status != 0: raise RuntimeError('Call to C gradient operator failed') - + out.fill(ndout) #reset input data @@ -466,4 +453,3 @@ def adjoint(self, x, out=None): ndx[i]*= el return out - diff --git a/src/Core/CMakeLists.txt b/src/Core/CMakeLists.txt index fadcafcdb7..8c7d89e928 100644 --- a/src/Core/CMakeLists.txt +++ b/src/Core/CMakeLists.txt @@ -68,6 +68,6 @@ add_library(cilacc SHARED ${cilacc_SOURCES}) target_link_libraries(cilacc ${cilacc_LIBRARIES}) include_directories(cilacc PUBLIC ${cilacc_INCLUDES}) -install(TARGETS cilacc LIBRARY DESTINATION ${SKBUILD_PROJECT_NAME}) +install(TARGETS cilacc LIBRARY DESTINATION ${SKBUILD_PROJECT_NAME}/lib) install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ DESTINATION ${SKBUILD_PROJECT_NAME}/include/${SKBUILD_PROJECT_NAME}) From 0d65f229a6a7e1c2a99112ddff761743ac39dcac Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Wed, 23 Apr 2025 14:07:42 +0100 Subject: [PATCH 07/14] conda: update build --- recipe/bld.bat | 8 +------- recipe/build.sh | 13 +++---------- recipe/meta.yaml | 10 ++++++---- 3 files changed, 10 insertions(+), 21 deletions(-) diff --git a/recipe/bld.bat b/recipe/bld.bat index 696c6a1870..e9931541d5 100644 --- a/recipe/bld.bat +++ b/recipe/bld.bat @@ -4,13 +4,7 @@ set SETUPTOOLS_SCM_PRETEND_VERSION_FOR_CIL=%PKG_VERSION% if not "%GIT_DESCRIBE_NUMBER%"=="0" ( set SETUPTOOLS_SCM_PRETEND_VERSION_FOR_CIL=%PKG_VERSION%.dev%GIT_DESCRIBE_NUMBER%+%GIT_DESCRIBE_HASH% ) - :: -G "Visual Studio 16 2019" specifies the the generator :: -T v142 specifies the toolset - -cmake -S "%RECIPE_DIR%\.." -B "%SRC_DIR%\build_framework" -G "Visual Studio 16 2019" -T "v142" -DCONDA_BUILD=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLIBRARY_LIB=%CONDA_PREFIX%\lib -DLIBRARY_INC=%CONDA_PREFIX% -DCMAKE_INSTALL_PREFIX=%PREFIX% -DPython_EXECUTABLE=%CONDA_PREFIX%\python - -if errorlevel 1 exit 1 - -cmake --build "%SRC_DIR%\build_framework" --target install --config RelWithDebInfo +pip install . --no-deps -Ccmake.args="-G Visual Studio 16 2019 -T v142" if errorlevel 1 exit 1 diff --git a/recipe/build.sh b/recipe/build.sh index 0a1c1c629f..872bff219b 100755 --- a/recipe/build.sh +++ b/recipe/build.sh @@ -1,23 +1,16 @@ #!/usr/bin/env bash set -euxo pipefail +extra_args="-G Ninja" if test $(python -c "from __future__ import print_function; import platform; print(platform.system())") = Darwin ; then echo "Darwin" - extra_args="-DOPENMP_LIBRARIES=${CONDA_PREFIX}/lib -DOPENMP_INCLUDES=${CONDA_PREFIX}/include" + extra_args="$extra_args -DOPENMP_LIBRARIES=${CONDA_PREFIX}/lib -DOPENMP_INCLUDES=${CONDA_PREFIX}/include" else echo "something else" - extra_args="" fi export SETUPTOOLS_SCM_PRETEND_VERSION_FOR_CIL="${PKG_VERSION}" if test "${GIT_DESCRIBE_NUMBER}" != "0"; then export SETUPTOOLS_SCM_PRETEND_VERSION_FOR_CIL="${PKG_VERSION}.dev${GIT_DESCRIBE_NUMBER}+${GIT_DESCRIBE_HASH}" fi -cmake ${RECIPE_DIR}/../ ${extra_args} \ - -DCONDA_BUILD=ON \ - -DCMAKE_BUILD_TYPE=RelWithDebInfo \ - -DLIBRARY_LIB=${CONDA_PREFIX}/lib \ - -DLIBRARY_INC=${CONDA_PREFIX}/include \ - -DCMAKE_INSTALL_PREFIX=${PREFIX} \ - -DPython_EXECUTABLE=${CONDA_PREFIX}/bin/python -cmake --build . --target install +pip install . --no-deps -Ccmake.args="${extra_args}" diff --git a/recipe/meta.yaml b/recipe/meta.yaml index a84600143d..7f2bb87005 100644 --- a/recipe/meta.yaml +++ b/recipe/meta.yaml @@ -34,7 +34,7 @@ test: - pip install unittest-parametrize - python -m unittest discover -v -s Wrappers/Python/test # [win] - python -m unittest discover -s Wrappers/Python/test -v # [not win] - + requirements: build: @@ -50,9 +50,11 @@ requirements: - _openmp_mutex # [linux] - openmp # [osx] - vc 14 # [win] - - ipp-include {{ ipp_version }} - - ipp-devel {{ ipp_version }} - - ipp {{ ipp_version }} + - ninja # [not win] + - ipp-include {{ ipp_version }} + - ipp-devel {{ ipp_version }} + - ipp {{ ipp_version }} + - scikit-build-core >=0.10 run: - python From 77c0c2598b7b5576b03a5b3d710d1318bccec921 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Wed, 23 Apr 2025 14:16:01 +0100 Subject: [PATCH 08/14] CI: update build --- .github/workflows/build.yml | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 98f1428808..7c7f327e2e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -48,8 +48,7 @@ jobs: name: build run: | conda activate "${{ steps.reqs.outputs.envname }}" - cmake -S . -B ./build -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCONDA_BUILD=ON -DCMAKE_INSTALL_PREFIX="$CONDA_PREFIX" - cmake --build ./build --target install + pip install . - name: test run: | conda activate "${{ steps.reqs.outputs.envname }}" @@ -81,10 +80,7 @@ jobs: python-version: ${{ matrix.python-version }} environment-file: scripts/requirements-test.yml activate-environment: cil_dev - - name: build - run: | - cmake -S . -B ./build -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCONDA_BUILD=ON -DCMAKE_INSTALL_PREFIX="$CONDA_PREFIX" - cmake --build ./build --target install + - run: pip install . - name: test run: python -m unittest discover -v ./Wrappers/Python/test conda-matrix: @@ -179,11 +175,7 @@ jobs: conda-merge ../scripts/requirements-test.yml docs_environment.yml > environment.yml conda env update -n test conda list - - name: build cil - working-directory: . - run: | - cmake -S . -B ./build -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCONDA_BUILD=ON -DCMAKE_INSTALL_PREFIX="$CONDA_PREFIX" - cmake --build ./build --target install + - run: pip install .. - name: checkout docs uses: actions/checkout@v4 with: From 3a3bc6dde56769d19a95f328692569fd047b8e75 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Wed, 23 Apr 2025 14:28:49 +0100 Subject: [PATCH 09/14] docker: update build --- Dockerfile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 5dc5f25bca..5c508e0d71 100644 --- a/Dockerfile +++ b/Dockerfile @@ -29,7 +29,5 @@ ENV TENSORBOARD_PROXY_URL=/user-redirect/proxy/6006/ # build & install CIL COPY --chown="${NB_USER}" . src -RUN cmake -S ./src -B ./build -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCONDA_BUILD=ON -DCMAKE_INSTALL_PREFIX="${CONDA_DIR}" \ - && cmake --build ./build --target install \ - && rm -rf src build \ +RUN pip install ./src && rm -rf src \ && fix-permissions "${CONDA_DIR}" /home/${NB_USER} From f703f069bb2186a2126cde3a3a953432c2f4185b Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Mon, 5 May 2025 07:24:19 +0100 Subject: [PATCH 10/14] cilacc: fix windows paths --- src/Core/CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Core/CMakeLists.txt b/src/Core/CMakeLists.txt index 8c7d89e928..51aaa92851 100644 --- a/src/Core/CMakeLists.txt +++ b/src/Core/CMakeLists.txt @@ -68,6 +68,8 @@ add_library(cilacc SHARED ${cilacc_SOURCES}) target_link_libraries(cilacc ${cilacc_LIBRARIES}) include_directories(cilacc PUBLIC ${cilacc_INCLUDES}) -install(TARGETS cilacc LIBRARY DESTINATION ${SKBUILD_PROJECT_NAME}/lib) +install(TARGETS cilacc + LIBRARY DESTINATION ${SKBUILD_PROJECT_NAME}/lib + RUNTIME DESTINATION ${SKBUILD_PROJECT_NAME}/lib) install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ DESTINATION ${SKBUILD_PROJECT_NAME}/include/${SKBUILD_PROJECT_NAME}) From c9bd7391dbf10a8e71fb226917ad1043605e094b Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Thu, 8 May 2025 15:44:27 +0100 Subject: [PATCH 11/14] docs: pip install --- README.md | 47 +++++++++++---------------------- docs/source/developer_guide.rst | 3 +-- 2 files changed, 16 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 5cdd6b3dea..75e80d2e23 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ conda create --name cil -c conda-forge -c https://software.repos.intel.com/pytho ``` where: + - `astra-toolbox=*=py*` enables CIL support for [ASTRA toolbox](http://www.astra-toolbox.com) CPU projector (2D Parallel beam only) (GPLv3 license) - `astra-toolbox=*=cuda*` (requires an NVIDIA GPU) enables CIL support for [ASTRA toolbox](http://www.astra-toolbox.com) GPU projectors (GPLv3 license) - `tigre` (requires an NVIDIA GPU) enables support for [TIGRE](https://github.com/CERN/TIGRE) toolbox projectors (BSD license) @@ -86,7 +87,8 @@ docker run --rm --gpus all -p 8888:8888 -it ghcr.io/tomographicimaging/cil:lates ## Getting Started with CIL ### CIL Training -We typically run training courses at least twice a year - check https://ccpi.ac.uk/training/ for our upcoming events! + +We typically run training courses at least twice a year - check for our upcoming events! ### CIL on binder @@ -116,60 +118,45 @@ The use of `--recurse-submodule` is necessary if the user wants the examples dat git submodule update --init --recursive ``` -### Build dependencies +### Building with `pip` + +#### Install Dependencies To create a conda environment with all the dependencies for building CIL run the following shell script: ```sh -bash scripts/create_local_env_for_cil_development.sh +bash ./scripts/create_local_env_for_cil_development.sh ``` Or with the CIL build and test dependencies: ```sh -bash scripts/create_local_env_for_cil_development.sh -t +bash ./scripts/create_local_env_for_cil_development.sh -t ``` -And then install CIL in to this environment using CMake. +And then install CIL in to this environment using `pip`. Alternatively, one can use the `scripts/requirements-test.yml` to create a conda environment with all the appropriate dependencies on any OS, using the following command: ```sh -conda env create -f scripts/requirements-test.yml +conda env create -f ./scripts/requirements-test.yml ``` -### Build with CMake - -CMake and a C++ compiler are required to build the source code. Let's suppose that the user is in the source directory, then the following commands should work: +#### Build CIL -```sh -cmake -S . -B ./build -DCMAKE_INSTALL_PREFIX= -DPython_EXECUTABLE= -cmake --build ./build --target install -``` +A C++ compiler is required to build the source code. Let's suppose that the user is in the source directory, then the following commands should work: -If targeting an active conda environment then the `` can be set to the `CONDA_PREFIX` environment variable (e.g. `${CONDA_PREFIX}` in Bash, or `%CONDA_PREFIX%` in the Anaconda Prompt on Windows). Similarly, `` can be set to the active conda environment by passing `${CONDA_PREFIX}/bin/python` on linux or `%CONDA_PREFIX%\python` in windows. - -#### Linux -```sh -cmake -S . -B ./build -DCMAKE_INSTALL_PREFIX=${CONDA_PREFIX} -DPython_EXECUTABLE=${CONDA_PREFIX}/bin/python -``` -#### Windows ```sh -cmake -S . -B .\build -DCMAKE_INSTALL_PREFIX=%CONDA_PREFIX% -DPython_EXECUTABLE=%CONDA_PREFIX%\python +pip install --no-deps . ``` -If not installing to a conda environment then the user will also need to set the locations of the IPP library and includes, and the path to CIL. - -By default the location of the IPP library and includes is `${CMAKE_INSTALL_PREFIX}/lib` and `${CMAKE_INSTALL_PREFIX}/include` respectively. To pass the location of the IPP library and headers please pass the following parameters: +If not installing inside a conda environment, then the user might need to set the locations of optional libraries: ```sh -cmake -S . -B ./build -DCMAKE_INSTALL_PREFIX= -DPython_EXECUTABLE= -DIPP_ROOT= +pip install . -Ccmake.define.IPP_ROOT="" -Ccmake.define.OpenMP_ROOT="" ``` -The user will then need to add the path `/lib` to the environment variable `PATH` or `LD_LIBRARY_PATH`, depending on system OS. - - ### Building with Docker In the repository root, simply update submodules and run `docker build`: @@ -179,7 +166,6 @@ git submodule update --init --recursive docker build . -t ghcr.io/tomographicimaging/cil ``` - ### Testing One installed, CIL functionality can be tested using the following command: @@ -189,10 +175,8 @@ export TESTS_FORCE_GPU=1 # optional, makes GPU test failures noisy python -m unittest discover -v ./Wrappers/Python/test ``` - ## Citing CIL - If you use CIL in your research, please include citations to **both** the software on Zenodo, and a CIL paper: E. Pasca, J. S. Jørgensen, E. Papoutsellis, E. Ametova, G. Fardell, K. Thielemans, L. Murgatroyd, M. Duff and H. Robarts (2023)
@@ -200,7 +184,6 @@ Core Imaging Library (CIL)
Zenodo [software archive]
**DOI:** https://doi.org/10.5281/zenodo.4746198
- In most cases, the first CIL paper will be the appropriate choice: J. S. Jørgensen, E. Ametova, G. Burca, G. Fardell, E. Papoutsellis, E. Pasca, K. Thielemans, M. Turner, R. Warr, W. R. B. Lionheart and P. J. Withers (2021)
diff --git a/docs/source/developer_guide.rst b/docs/source/developer_guide.rst index ea78b8bb7e..f1472925f9 100644 --- a/docs/source/developer_guide.rst +++ b/docs/source/developer_guide.rst @@ -137,8 +137,7 @@ Example: cd CIL sh scripts/create_local_env_for_cil_development_tests.sh -n NUMPY_VERSION -p PYTHON_VERSION -e ENVIRONMENT_NAME conda activate ENVIRONMENT_NAME - cmake -S . -B ./build -DCMAKE_INSTALL_PREFIX=${CONDA_PREFIX} - cmake --build ./build --target install + pip install . cd docs conda update -n base -c defaults conda conda env update -f docs_environment.yml # with the name field set to ENVIRONMENT_NAME From 2c226288bcbc5ccc64bc2bff930ba356770c52d9 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Thu, 15 May 2025 14:31:51 +0100 Subject: [PATCH 12/14] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ffad4c4127..93488ba57d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ - Added tests for Normaliser processor - Update minimum cmake version to 3.5 - Dependencies: + - Move from CMake to `pip install` (#2145) - matplotlib-base is an optional dependency, instead of required (#2093) - `unittest-parametrize has been added as a dependency for tests (#1990) - olefile and dxchange are an optional dependency, instead of required (#2149) From b57a779088f3c04e62ba2e79db6f11ff2accb498 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Fri, 16 May 2025 11:37:34 +0100 Subject: [PATCH 13/14] update .gitignore for in-place install --- .gitignore | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index db3970f85a..81b4942ab4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,8 @@ -/build/ +/build* __pycache__/ -/Wrappers/Python/build/ /Wrappers/Python/cil/version.py -/build* +/Wrappers/Python/cil-*.dist-info/ +/Wrappers/Python/cil/include/ +/Wrappers/Python/cil/lib/ *.vscode* *.egg* From 417329313ae3fe564baee50f744e6c8b6f456af8 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Tue, 10 Jun 2025 10:25:23 +0100 Subject: [PATCH 14/14] windows: auto-generator --- recipe/bld.bat | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/recipe/bld.bat b/recipe/bld.bat index e9931541d5..97fb90517d 100644 --- a/recipe/bld.bat +++ b/recipe/bld.bat @@ -4,7 +4,5 @@ set SETUPTOOLS_SCM_PRETEND_VERSION_FOR_CIL=%PKG_VERSION% if not "%GIT_DESCRIBE_NUMBER%"=="0" ( set SETUPTOOLS_SCM_PRETEND_VERSION_FOR_CIL=%PKG_VERSION%.dev%GIT_DESCRIBE_NUMBER%+%GIT_DESCRIBE_HASH% ) -:: -G "Visual Studio 16 2019" specifies the the generator -:: -T v142 specifies the toolset -pip install . --no-deps -Ccmake.args="-G Visual Studio 16 2019 -T v142" +pip install . --no-deps if errorlevel 1 exit 1