Skip to content

Commit

Permalink
Merge branch 'main' into ch-handle.vector.bool.input
Browse files Browse the repository at this point in the history
  • Loading branch information
schweitzpgi committed Mar 15, 2024
2 parents e77639a + f49ab5a commit cec6ccc
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 25 deletions.
33 changes: 17 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,19 +113,6 @@ if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
if(NOT GIT_SUBMOD_RESULT EQUAL "0")
message(FATAL_ERROR "Cloning git submodules failed with ${GIT_SUBMOD_RESULT}, please checkout submodules manually")
endif()
# Apply patches; check if patch is already applied first, and apply it if not
execute_process(COMMAND ${GIT_EXECUTABLE} -C tpls/pybind11/ apply ../customizations/pybind11/pybind.h.diff --ignore-whitespace --reverse --check
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE GIT_PATCH_RESULT
ERROR_QUIET)
if(NOT GIT_PATCH_RESULT EQUAL "0")
execute_process(COMMAND ${GIT_EXECUTABLE} -C tpls/pybind11/ apply ../customizations/pybind11/pybind.h.diff --ignore-whitespace
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE GIT_PATCH_RESULT)
endif()
if(NOT GIT_PATCH_RESULT EQUAL "0")
message(FATAL_ERROR "Applying patch to submodule failed with ${GIT_PATCH_RESULT}, please update patch")
endif()
endif()
endif()

Expand Down Expand Up @@ -543,9 +530,23 @@ add_subdirectory(tools)
add_subdirectory(utils)

if (CUDAQ_ENABLE_PYTHON)
set(PYBIND11_FINDPYTHON ON)
# Manually call find_package due to https://github.com/pybind/pybind11/pull/4805.
find_package(Python 3 COMPONENTS Interpreter Development.Module REQUIRED)
find_package(Python 3 COMPONENTS Interpreter Development)

# Apply specific patch to pybind11 for our documentation.
# Only apply the patch if not already applied.
execute_process(COMMAND ${GIT_EXECUTABLE} -C tpls/pybind11/ apply ../customizations/pybind11/pybind.h.diff --ignore-whitespace --reverse --check
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE GIT_PATCH_RESULT
ERROR_QUIET)
if (NOT GIT_PATCH_RESULT EQUAL "0")
execute_process(COMMAND ${GIT_EXECUTABLE} -C tpls/pybind11/ apply ../customizations/pybind11/pybind.h.diff --ignore-whitespace
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE GIT_PATCH_RESULT)
endif()
if (NOT GIT_PATCH_RESULT EQUAL "0")
message(FATAL_ERROR "Applying patch to submodule failed with ${GIT_PATCH_RESULT}, please update patch")
endif()

add_subdirectory(tpls/pybind11)
add_subdirectory(python)
endif()
Expand Down
4 changes: 3 additions & 1 deletion python/runtime/cudaq/distributed/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ if (SKBUILD)
target_link_libraries(${LIBRARY_NAME} PRIVATE pybind11::pybind11 Python::Module)
target_link_options(${LIBRARY_NAME} PRIVATE -Wl,--unresolved-symbols=ignore-in-object-files)
else()
find_package(Python 3 COMPONENTS Development.Embed REQUIRED)
if (NOT Python_FOUND)
message(FATAL_ERROR "find_package(Python) not run?")
endif()
target_link_libraries(${LIBRARY_NAME} PRIVATE pybind11::pybind11 Python::Python)
endif()
target_include_directories(${LIBRARY_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/runtime/cudaq/distributed)
Expand Down
8 changes: 5 additions & 3 deletions python/runtime/cudaq/domains/plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ add_library(cudaq-pyscf SHARED PySCFDriver.cpp)
if (SKBUILD)
target_link_libraries(cudaq-pyscf PRIVATE pybind11::pybind11 Python::Module cudaq-chemistry cudaq-spin cudaq cudaq-py-utils)
target_link_options(cudaq-pyscf PRIVATE -Wl,--unresolved-symbols=ignore-in-object-files)
else()
find_package(Python 3 COMPONENTS Development.Embed REQUIRED)
else()
if (NOT Python_FOUND)
message(FATAL_ERROR "find_package(Python) not run?")
endif()
target_link_libraries(cudaq-pyscf PRIVATE Python::Python pybind11::pybind11 cudaq-chemistry cudaq-spin cudaq cudaq-py-utils)
endif()
install(TARGETS cudaq-pyscf DESTINATION lib/plugins)
install(TARGETS cudaq-pyscf DESTINATION lib/plugins)
7 changes: 4 additions & 3 deletions tpls/customizations/pybind11/pybind.h.diff
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h
index 6205effd..5307227e 100644
index b87fe66b..b5700db2 100644
--- a/include/pybind11/pybind11.h
+++ b/include/pybind11/pybind11.h
@@ -23,6 +23,7 @@
@@ -25,6 +25,7 @@
#include <string>
#include <utility>
#include <vector>
+#include <regex>

#if defined(__cpp_lib_launder) && !(defined(_MSC_VER) && (_MSC_VER < 1914))
# define PYBIND11_STD_LAUNDER std::launder
@@ -578,9 +579,27 @@ protected:
@@ -628,9 +629,28 @@ protected:
if (chain) {
signatures += std::to_string(++index) + ". ";
}
Expand All @@ -27,6 +27,7 @@ index 6205effd..5307227e 100644
+ formatted_string = std::regex_replace(formatted_string, std::regex("numpy.complex128"), "");
+ formatted_string = std::regex_replace(formatted_string, std::regex(".ndarray[]"), ".ndarray");
+ formatted_string = std::regex_replace(formatted_string, std::regex("buffer"), "numpy.ndarray");
+ formatted_string = std::regex_replace(formatted_string, std::regex("Buffer"), "numpy.ndarray");
+ formatted_string = std::regex_replace(formatted_string, std::regex("::sample_result"), ".SampleResult");
+ formatted_string = std::regex_replace(formatted_string, std::regex("::observe_result"), ".ObserveResult");
+ formatted_string = std::regex_replace(formatted_string, std::regex("::async_result<cudaq.SampleResult>"), ".AsyncSampleResult");
Expand Down
2 changes: 1 addition & 1 deletion tpls/pybind11
Submodule pybind11 updated 132 files
4 changes: 3 additions & 1 deletion unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,9 @@ add_subdirectory(backends)
add_subdirectory(Optimizer)

if (CUDAQ_ENABLE_PYTHON)
find_package(Python COMPONENTS Interpreter)
if (NOT Python_FOUND)
message(FATAL_ERROR "find_package(Python) not run?")
endif()
execute_process(COMMAND ${Python_EXECUTABLE} -c "import openfermionpyscf"
OUTPUT_VARIABLE PYSCF_output
ERROR_VARIABLE PYSCF_error
Expand Down

0 comments on commit cec6ccc

Please sign in to comment.