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

⬆️ update mqt-core #337

Merged
merged 12 commits into from
Jan 29, 2024
10 changes: 0 additions & 10 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,3 @@
path = extern/mqt-core
url = https://github.com/cda-tum/mqt-core.git
branch = main
[submodule "extern/taskflow"]
path = extern/taskflow
url = https://github.com/taskflow/taskflow.git
branch = master
shallow = true
[submodule "extern/cxxopts"]
path = extern/cxxopts
url = https://github.com/jarro2783/cxxopts.git
branch = master
shallow = true
2 changes: 2 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ repos:
hooks:
- id: cmake-format
additional_dependencies: [pyyaml]
types: [file]
files: (\.cmake|CMakeLists.txt)(.in)?$

# Clang-format the C++ part of the code base automatically
- repo: https://github.com/pre-commit/mirrors-clang-format
Expand Down
38 changes: 16 additions & 22 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,42 +1,34 @@
# set required cmake version
cmake_minimum_required(VERSION 3.19...3.27)
cmake_minimum_required(VERSION 3.19...3.28)

project(
ddsim
mqt-ddsim
LANGUAGES CXX
DESCRIPTION "MQT DDSIM - A quantum simulator based on decision diagrams")

# check whether `modulename` is correctly cloned in the `extern` directory.
macro(CHECK_SUBMODULE_PRESENT modulename)
if(NOT EXISTS "${PROJECT_SOURCE_DIR}/extern/${modulename}/CMakeLists.txt")
message(
FATAL_ERROR
"${modulename} submodule not cloned properly. \
Please run `git submodule update --init --recursive` \
from the main project directory")
endif()
endmacro()

check_submodule_present(mqt-core)
check_submodule_present(taskflow)
DESCRIPTION
"MQT DDSIM - A quantum circuit simulator based on decision diagrams")

option(BUILD_MQT_DDSIM_TESTS "Also build tests for the MQT DDSIM project" ON)
option(BUILD_MQT_DDSIM_BINDINGS "Build the MQT DDSIM Python bindings" OFF)
option(BUILD_MQT_DDSIM_CLI "Build the MQT DDSIM command line interface" ON)

if(BUILD_MQT_DDSIM_BINDINGS)
# ensure that the BINDINGS option is set
set(BINDINGS
ON
CACHE BOOL "Enable settings related to Python bindings" FORCE)
# cmake-lint: disable=C0103
CACHE INTERNAL "Enable settings related to Python bindings")
# Some common settings for finding Python
set(Python_FIND_VIRTUALENV
FIRST
CACHE STRING "Give precedence to virtualenvs when searching for Python")
# cmake-lint: disable=C0103
set(Python_FIND_FRAMEWORK
LAST
CACHE STRING "Prefer Brew/Conda to Apple framework Python")
set(Python_ARTIFACTS_INTERACTIVE
ON
CACHE
BOOL
"Prevent multiple searches for Python and instead cache the results.")

# top-level call to find Python
find_package(
Python 3.8 REQUIRED
Expand All @@ -46,6 +38,9 @@ endif()

include(cmake/ExternalDependencies.cmake)

# set the include directory for the build tree
set(MQT_DDSIM_INCLUDE_BUILD_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include")

add_subdirectory(src)

if(BUILD_MQT_DDSIM_TESTS)
Expand All @@ -54,7 +49,6 @@ if(BUILD_MQT_DDSIM_TESTS)
add_subdirectory(test)
endif()

if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
check_submodule_present(cxxopts)
if(BUILD_MQT_DDSIM_CLI)
add_subdirectory(apps)
endif()
22 changes: 4 additions & 18 deletions apps/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,30 +1,16 @@
add_subdirectory("${PROJECT_SOURCE_DIR}/extern/cxxopts" "extern/cxxopts"
EXCLUDE_FROM_ALL)
# the following sets the SYSTEM flag for the include dirs of the cxxopts libs to
# cmake-lint: disable=C0307
set_target_properties(
cxxopts PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES
$<TARGET_PROPERTY:cxxopts,INTERFACE_INCLUDE_DIRECTORIES>)

# macro to add a executable with the given libraries
macro(ADD_SIM_EXECUTABLE appname)
add_executable(${PROJECT_NAME}_${appname}
${CMAKE_CURRENT_SOURCE_DIR}/${appname}.cpp)
target_link_libraries(${PROJECT_NAME}_${appname} PRIVATE ${PROJECT_NAME}
${ARGN})
add_executable(mqt-ddsim-${appname} ${appname}.cpp)
target_link_libraries(mqt-ddsim-${appname} PRIVATE MQT::DDSim ${ARGN})
endmacro()

set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads)
link_libraries(Threads::Threads)

add_sim_executable(simple cxxopts::cxxopts)
add_sim_executable(primebases cxxopts::cxxopts)
if(Threads_FOUND)
add_sim_executable(noise_aware cxxopts::cxxopts)
target_link_libraries(${PROJECT_NAME}_noise_aware PUBLIC Threads::Threads)
target_link_libraries(mqt-ddsim-noise_aware PRIVATE Threads::Threads)
endif()
find_package(OpenCV QUIET)

if(OpenCV_FOUND)
add_sim_executable(frqi cxxopts::cxxopts ${OpenCV_LIBRARIES})
endif()
Expand Down
113 changes: 113 additions & 0 deletions cmake/ExternalDependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,49 @@
include(FetchContent)
set(FETCH_PACKAGES "")

if(BUILD_MQT_DDSIM_BINDINGS)
if(NOT SKBUILD)
# Manually detect the installed pybind11 package.
execute_process(
COMMAND "${Python_EXECUTABLE}" -m pybind11 --cmakedir
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE pybind11_DIR)

# Add the detected directory to the CMake prefix path.
list(APPEND CMAKE_PREFIX_PATH "${pybind11_DIR}")
endif()

# add pybind11 library
find_package(pybind11 CONFIG REQUIRED)
endif()

set(FETCHCONTENT_SOURCE_DIR_MQT-CORE
${PROJECT_SOURCE_DIR}/extern/mqt-core
CACHE
PATH
"Path to the source directory of the mqt-core library. This variable is used by FetchContent to download the library if it is not already available."
)
set(MQT_CORE_VERSION
2.2.2
CACHE STRING "MQT Core version")
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.24)
FetchContent_Declare(
mqt-core
GIT_REPOSITORY https://github.com/cda-tum/mqt-core.git
GIT_TAG v${MQT_CORE_VERSION}
FIND_PACKAGE_ARGS ${MQT_CORE_VERSION})
list(APPEND FETCH_PACKAGES mqt-core)
else()
find_package(mqt-core ${MQT_CORE_VERSION} QUIET)
if(NOT mqt-core_FOUND)
FetchContent_Declare(
mqt-core
GIT_REPOSITORY https://github.com/cda-tum/mqt-core.git
GIT_TAG v${MQT_CORE_VERSION})
list(APPEND FETCH_PACKAGES mqt-core)
endif()
endif()

if(BUILD_MQT_DDSIM_TESTS)
set(gtest_force_shared_crt
ON
Expand All @@ -26,5 +69,75 @@ if(BUILD_MQT_DDSIM_TESTS)
endif()
endif()

set(TF_BUILD_TESTS
OFF
CACHE INTERNAL "")
set(TF_BUILD_EXAMPLES
OFF
CACHE INTERNAL "")
set(TF_BUILD_PROFILER
OFF
CACHE INTERNAL "")
set(TF_VERSION
3.6.0
CACHE STRING "Taskflow version")
set(TF_URL
https://github.com/taskflow/taskflow/archive/refs/tags/v${TF_VERSION}.tar.gz
)
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.24)
FetchContent_Declare(taskflow URL ${TF_URL} FIND_PACKAGE_ARGS)
list(APPEND FETCH_PACKAGES taskflow)
else()
find_package(taskflow ${TF_VERSION} QUIET)
if(NOT taskflow_FOUND)
FetchContent_Declare(taskflow URL ${TF_URL})
list(APPEND FETCH_PACKAGES taskflow)
endif()
endif()

if(BUILD_MQT_DDSIM_CLI)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads)
link_libraries(Threads::Threads)

find_package(OpenCV QUIET)

set(CXXOPTS_VERSION
3.1.1
CACHE STRING "cxxopts version")
set(CXXOPTS_URL
https://github.com/jarro2783/cxxopts/archive/refs/tags/v${CXXOPTS_VERSION}.tar.gz
)
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.24)
FetchContent_Declare(cxxopts URL ${CXXOPTS_URL} FIND_PACKAGE_ARGS
${CXXOPTS_VERSION})
list(APPEND FETCH_PACKAGES cxxopts)
else()
find_package(cxxopts ${CXXOPTS_VERSION} QUIET)
if(NOT cxxopts_FOUND)
FetchContent_Declare(cxxopts URL ${CXXOPTS_URL})
list(APPEND FETCH_PACKAGES cxxopts)
endif()
endif()
endif()

if(BUILD_MQT_DDSIM_BINDINGS)
# add pybind11_json library
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.24)
FetchContent_Declare(
pybind11_json
GIT_REPOSITORY https://github.com/pybind/pybind11_json
FIND_PACKAGE_ARGS)
list(APPEND FETCH_PACKAGES pybind11_json)
else()
find_package(pybind11_json QUIET)
if(NOT pybind11_json_FOUND)
FetchContent_Declare(
pybind11_json GIT_REPOSITORY https://github.com/pybind/pybind11_json)
list(APPEND FETCH_PACKAGES pybind11_json)
endif()
endif()
endif()

# Make all declared dependencies available.
FetchContent_MakeAvailable(${FETCH_PACKAGES})
1 change: 0 additions & 1 deletion extern/cxxopts
Submodule cxxopts deleted from 554396
2 changes: 1 addition & 1 deletion extern/mqt-core
Submodule mqt-core updated 107 files
1 change: 0 additions & 1 deletion extern/taskflow
Submodule taskflow deleted from b91df2
2 changes: 1 addition & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
if TYPE_CHECKING:
from collections.abc import Sequence

nox.options.sessions = ["lint", "pylint", "tests"]
nox.options.sessions = ["lint", "tests"]

PYTHON_ALL_VERSIONS = ["3.8", "3.9", "3.10", "3.11", "3.12"]

Expand Down
16 changes: 7 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ classifiers = [
]
requires-python = ">=3.8"
dependencies = [
"qiskit-terra>=0.22.1"
"qiskit[qasm3-import]>=0.45.0"
]
dynamic = ["version"]

[project.optional-dependencies]
tnflow = [
"cotengra",
"sparse",
"opt-einsum",
"quimb",
Expand All @@ -63,7 +64,7 @@ docs = [
"breathe",
"sphinxext-opengraph",
"sphinx-autodoc-typehints",
"qiskit-terra[visualization]",
"qiskit[visualization]",
"graphviz",
]
dev = ["mqt.ddsim[tnflow, coverage, docs]"]
Expand All @@ -79,8 +80,8 @@ Discussions = "https://github.com/cda-tum/mqt-ddsim/discussions"
# Protect the configuration against future changes in scikit-build-core
minimum-version = "0.6.1"

# Set the target to build
cmake.targets = ["pyddsim"]
# Set the wheel install directory
wheel.install-dir = "mqt/ddsim"

# Set required CMake and Ninja versions
cmake.minimum-version = "3.19"
Expand All @@ -89,9 +90,6 @@ ninja.minimum-version = "1.10"
# Setuptools-style build caching in a local directory
build-dir = "build/{wheel_tag}"

# Build stable ABI wheels for CPython 3.12+
wheel.py-api = "cp312"

# Explicitly set the package directory
wheel.packages = ["src/mqt"]

Expand All @@ -118,7 +116,7 @@ sdist.exclude = [
[tool.scikit-build.cmake.define]
BUILD_MQT_DDSIM_TESTS = "OFF"
BUILD_MQT_DDSIM_BINDINGS = "ON"
ENABLE_IPO = "ON"
BUILD_MQT_DDSIM_CLI = "OFF"


[tool.check-sdist]
Expand Down Expand Up @@ -147,6 +145,7 @@ filterwarnings = [
"ignore:.*qiskit.utils.algorithm_globals.QiskitAlgorithmGlobals*:DeprecationWarning:qiskit",
"ignore:.*Building a flow controller with keyword arguments is going to be deprecated*:PendingDeprecationWarning:qiskit",
"ignore:.*qiskit.extensions module is pending deprecation*:PendingDeprecationWarning:qiskit",
'ignore:.*datetime\.datetime\.utcfromtimestamp.*:DeprecationWarning:',
]

[tool.coverage]
Expand Down Expand Up @@ -257,7 +256,6 @@ build = "cp3*"
skip = "*-musllinux_*"
archs = "auto64"
test-command = "python -c \"from mqt import ddsim\""
test-skip = "cp312-*" # Qiskit Terra does not support Python 3.12 yet
build-frontend = "build"

[tool.cibuildwheel.linux]
Expand Down
Loading
Loading