From 02ec585260f53f753af0e5c7aa740900066dc39e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Di=20Remigio=20Eik=C3=A5s?= Date: Fri, 24 Jul 2026 17:11:19 +0200 Subject: [PATCH 01/51] build: only allow to build as python extension --- .vscode/settings.json | 13 +- .vscode/tasks.json | 4 +- CMakeLists.txt | 51 +++-- CMakeLists.txt.orig | 226 +++++++++++++++++++ CMakePresets.json | 228 ++++--------------- CMakePresets.json.orig | 397 ++++++++++++++++++++++++++++++++++ pyproject.toml | 4 +- src/CMakeLists.txt | 2 +- src/monoprop/CMakeLists.txt | 4 +- tests/cpp/CMakeLists.txt | 5 +- tests/cpp/boostAddTests.cmake | 1 + 11 files changed, 718 insertions(+), 217 deletions(-) create mode 100644 CMakeLists.txt.orig create mode 100644 CMakePresets.json.orig diff --git a/.vscode/settings.json b/.vscode/settings.json index 8a8b2aae..ac4719ba 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -181,9 +181,16 @@ ], "cmake.cmakePath": "cmake", "cmake.allowCommentsInPresetsFile": true, - "cmake.configurePreset": "release-gcc-mpi", - "cmake.buildPreset": "release-gcc-mpi", - "cmake.testPreset": "release-gcc-mpi", + // This project only configures correctly through scikit-build-core (invoked + // by `uv sync`), which injects the SKBUILD / Python / nanobind cache + // variables from an ephemeral build-isolation environment. Never let CMake + // Tools reconfigure the adopted build tree: the cached Python interpreter + // path is deleted after the build and a reconfigure would fail. + "cmake.configureOnEdit": false, + "cmake.configureOnOpen": false, + "cmake.automaticReconfigure": false, + "cmake.ctest.testExplorerIntegrationEnabled": true, + "cmake.buildBeforeRun": false, "cmake.options.statusBarVisibility": "hidden", "cmake.options.advanced": { "build": { diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 08707ba9..ca7a2371 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -6,7 +6,7 @@ { "label": "Install in Release mode", "type": "shell", - "command": "uv sync --group dev --group test --group interactive --all-extras -v", + "command": "uv sync --all-extras -v", "problemMatcher": [], "group": { "kind": "build", @@ -16,7 +16,7 @@ { "label": "Install in Debug mode", "type": "shell", - "command": "uv sync --group dev --group test --group interactive --all-extras -v --config-settings=cmake.build-type='Debug'", + "command": "uv sync --all-extras -v --config-settings=cmake.build-type='Debug'", "problemMatcher": [], "group": { "kind": "build", diff --git a/CMakeLists.txt b/CMakeLists.txt index 6caeeb48..3baa6e3b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,18 +1,34 @@ cmake_minimum_required(VERSION 3.28...4.0) -include(cmake/CPM.cmake) - -if(SKBUILD) - # this value doesn't really matter, as it will be set by scikit-build-core - set(PROJECT_VERSION "0.1.0") -else() - cpmaddpackage("gh:LecrisUT/CMakeExtraUtils@0.4.1") - include(${CMakeExtraUtils_BINARY_DIR}/DynamicVersion.cmake) - dynamic_version(PROJECT_PREFIX monoprop_) +project(monoprop LANGUAGES CXX) + +# warn if the user invokes CMake directly +if(NOT SKBUILD) + message( + WARNING + "\ + This CMake file is meant to be executed using 'scikit-build-core'. + Running it directly will almost certainly not produce the desired + result. If you are a user trying to install this package, use the + command below, which will install all necessary build dependencies, + compile the package in an isolated environment, and then install it. + ===================================================================== + $ pip install . + ===================================================================== + If you are a software developer, and this is your own package, then + it is usually much more efficient to install the build dependencies + in your environment once and use the following command that avoids + a costly creation of a new virtual environment at every compilation: + ===================================================================== + $ pip install nanobind scikit-build-core + $ pip install --no-build-isolation -ve . + ===================================================================== + You may optionally add -Ceditable.rebuild=true to auto-rebuild when + the package is imported. Otherwise, you need to rerun the above + after editing C++ files." + ) endif() -project(monoprop LANGUAGES CXX VERSION ${PROJECT_VERSION}) - if(APPLE) set(THREADS_FOUND TRUE CACHE BOOL "") set(CMAKE_THREAD_LIBS_INIT "-lpthread" CACHE STRING "") @@ -50,11 +66,6 @@ endif() include(${PROJECT_SOURCE_DIR}/cmake/compiler_flags/CXXFlags.cmake) -# PROJECT_VERSION_FULL comes from dynamic_version(), which is skipped under scikit-build-core. -if(NOT DEFINED SKBUILD) - message(STATUS "${PROJECT_NAME} version: ${PROJECT_VERSION_FULL}") -endif() - # report on compiler flags in use message(STATUS "Configuring a ${CMAKE_BUILD_TYPE} build") string(TOUPPER ${CMAKE_BUILD_TYPE} _cmake_build_type_upper) @@ -75,9 +86,15 @@ message( " Project defaults : ${CMAKE_CXX${CMAKE_CXX_STANDARD}_STANDARD_COMPILE_OPTION} ${monoprop_CXX_FLAGS}" ) message(STATUS " User-appended : ${EXTRA_CXXFLAGS}") +message( + STATUS + "Maximum simulable Fermionic modes with Python bindings: ${monoprop_MAX_NUM_MODES}" +) + message(STATUS " MPI parallelization : ${monoprop_ENABLE_MPI}") message(STATUS " Wide term index : ${monoprop_WIDE_TERM_INDEX}") message(STATUS " Max simulable modes : ${monoprop_MAX_NUM_MODES}") +message(STATUS " C++ unit tests : ${monoprop_ENABLE_CXX_UNIT_TESTS}") include(GNUInstallDirs) @@ -91,7 +108,7 @@ configure_file( add_subdirectory(src) -if(NOT DEFINED SKBUILD) +if(monoprop_ENABLE_CXX_UNIT_TESTS) enable_testing() include(CTest) diff --git a/CMakeLists.txt.orig b/CMakeLists.txt.orig new file mode 100644 index 00000000..9b5933ee --- /dev/null +++ b/CMakeLists.txt.orig @@ -0,0 +1,226 @@ +cmake_minimum_required(VERSION 3.28...4.0) + +project(monoprop LANGUAGES CXX) + +# warn if the user invokes CMake directly +if(NOT SKBUILD) + message( + WARNING + "\ + This CMake file is meant to be executed using 'scikit-build-core'. + Running it directly will almost certainly not produce the desired + result. If you are a user trying to install this package, use the + command below, which will install all necessary build dependencies, + compile the package in an isolated environment, and then install it. + ===================================================================== + $ pip install . + ===================================================================== + If you are a software developer, and this is your own package, then + it is usually much more efficient to install the build dependencies + in your environment once and use the following command that avoids + a costly creation of a new virtual environment at every compilation: + ===================================================================== + $ pip install nanobind scikit-build-core + $ pip install --no-build-isolation -ve . + ===================================================================== + You may optionally add -Ceditable.rebuild=true to auto-rebuild when + the package is imported. Otherwise, you need to rerun the above + after editing C++ files." + ) +endif() + +if(APPLE) + set(THREADS_FOUND TRUE CACHE BOOL "") + set(CMAKE_THREAD_LIBS_INIT "-lpthread" CACHE STRING "") + set(CMAKE_HAVE_THREADS_LIBRARY TRUE CACHE BOOL "") + set(CMAKE_USE_PTHREADS_INIT TRUE CACHE BOOL "") + set(THREADS_PREFER_PTHREAD_FLAG ON CACHE BOOL "") +endif() + +# if CMAKE_BUILD_TYPE undefined, we set it to Release +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE "Release") +endif() + +<<<<<<< New base: build: only allow to build as python extension +set( + monoprop_MAX_NUM_MODES + "250" + CACHE STRING + "Maximum number of simulable Fermionic modes with Python bindings" +) +option(monoprop_ENABLE_MPI "Enable MPI parallelization" OFF) +option( + monoprop_WIDE_TERM_INDEX + "Use 64-bit term indices (support > 2^32 terms per partition)" + OFF +) +if(monoprop_WIDE_TERM_INDEX) + add_compile_definitions(monoprop_WIDE_TERM_INDEX) +||||||| Common ancestor +# Options handling utilities Macro for printing an option in a consistent manner +# Written by Lori A. Burns (@loriab) and Ryan M. Richard (@ryanmrichard) Syntax: +# print_option(