Skip to content

Commit

Permalink
⬆️ update mqt-core (#419)
Browse files Browse the repository at this point in the history
## Description

This PR updates the mqt-core submodule and brings in some further
advancements from #418.
Specifically, it switches to using `FetchContent` for obtaining
`mqt-core` (and `LogicBlocks`).
Per default, it is pointed to the vendored submodule via an overridable
CMake variable.

## Checklist:

<!---
This checklist serves as a reminder of a couple of things that ensure
your pull request will be merged swiftly.
-->

- [x] The pull request only contains commits that are related to it.
- [x] I have added appropriate tests and documentation.
- [x] I have made sure that all CI jobs on GitHub pass.
- [x] The pull request introduces no new warnings and follows the
project's style guidelines.
  • Loading branch information
burgholzer authored Jan 29, 2024
2 parents 63eaf08 + 6b39462 commit 533574f
Show file tree
Hide file tree
Showing 27 changed files with 300 additions and 227 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ repos:
hooks:
- id: cmake-format
additional_dependencies: [pyyaml]
- id: cmake-lint
additional_dependencies: [pyyaml]
types: [file]
files: (\.cmake|CMakeLists.txt)(.in)?$

# Format configuration files with prettier
- repo: https://github.com/pre-commit/mirrors-prettier
Expand Down
44 changes: 19 additions & 25 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,39 +1,30 @@
# set required cmake version
cmake_minimum_required(VERSION 3.19...3.27)
cmake_minimum_required(VERSION 3.19...3.28)

project(
qmap
mqt-qmap
LANGUAGES CXX
DESCRIPTION "MQT QMAP - A library for mapping of quantum circuits to quantum architectures")

# check whether the submodule ``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(LogicBlocks)

option(BUILD_MQT_QMAP_TESTS "Also build tests for the MQT QMAP project" ON)
option(BUILD_MQT_QMAP_BINDINGS "Build the MQT QMAP Python bindings" OFF)

if(BUILD_MQT_QMAP_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 @@ -44,19 +35,22 @@ endif()
# Add path for custom modules
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

# search for Z3
find_package(Z3 4.8.15)
if(NOT Z3_FOUND)
message(WARNING "Did not find Z3. Exact library and other depending target will not be available")
endif()
include(cmake/ExternalDependencies.cmake)

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

# add main library code
add_subdirectory(src)

# add test code
option(BUILD_MQT_QMAP_TESTS "Also build tests for the MQT QMAP project" ON)
if(BUILD_MQT_QMAP_TESTS)
enable_testing()
include(GoogleTest)
add_subdirectory(test)
endif()

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake IMMEDIATE @ONLY)
add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P
${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
108 changes: 108 additions & 0 deletions cmake/ExternalDependencies.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# Declare all external dependencies and make sure that they are available.

include(FetchContent)
set(FETCH_PACKAGES "")

# search for Z3
find_package(Z3 4.8.15)
if(NOT Z3_FOUND)
message(WARNING "Did not find Z3. Exact library and other depending target will not be available")
endif()

if(BUILD_MQT_QMAP_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()

set(BUILD_LB_TESTS
OFF
CACHE BOOL "Build LogicBlocks tests")
set(FETCHCONTENT_SOURCE_DIR_LOGICBLOCKS
${PROJECT_SOURCE_DIR}/extern/LogicBlocks
CACHE
PATH
"Path to the source directory of the LogicBlocks library. This variable is used by FetchContent to download the library if it is not already available."
)
FetchContent_Declare(
LogicBlocks
GIT_REPOSITORY https://github.com/cda-tum/LogicBlocks.git
GIT_TAG main)
list(APPEND FETCH_PACKAGES LogicBlocks)

if(BUILD_MQT_QMAP_TESTS)
set(gtest_force_shared_crt
ON
CACHE BOOL "" FORCE)
set(GTEST_VERSION
1.14.0
CACHE STRING "Google Test version")
set(GTEST_URL https://github.com/google/googletest/archive/refs/tags/v${GTEST_VERSION}.tar.gz)
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.24)
FetchContent_Declare(googletest URL ${GTEST_URL} FIND_PACKAGE_ARGS ${GTEST_VERSION} NAMES GTest)
list(APPEND FETCH_PACKAGES googletest)
else()
find_package(googletest ${GTEST_VERSION} QUIET NAMES GTest)
if(NOT googletest_FOUND)
FetchContent_Declare(googletest URL ${GTEST_URL})
list(APPEND FETCH_PACKAGES googletest)
endif()
endif()
endif()

if(BUILD_MQT_QMAP_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})
23 changes: 23 additions & 0 deletions cmake/cmake_uninstall.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Source: https://gitlab.kitware.com/cmake/community/-/wikis/FAQ#can-i-do-make-uninstall-with-cmake

if(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt")
message(FATAL_ERROR "Cannot find install manifest: @CMAKE_BINARY_DIR@/install_manifest.txt")
endif()

file(READ "@CMAKE_BINARY_DIR@/install_manifest.txt" files)
string(REGEX REPLACE "\n" ";" files "${files}")
foreach(file ${files})
message(STATUS "Uninstalling $ENV{DESTDIR}${file}")
if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
exec_program(
"@CMAKE_COMMAND@" ARGS
"-E remove \"$ENV{DESTDIR}${file}\""
OUTPUT_VARIABLE rm_out
RETURN_VALUE rm_retval)
if(NOT "${rm_retval}" STREQUAL 0)
message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}")
endif()
else(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}")
message(STATUS "File $ENV{DESTDIR}${file} does not exist.")
endif()
endforeach()
2 changes: 1 addition & 1 deletion extern/mqt-core
Submodule mqt-core updated 220 files
4 changes: 2 additions & 2 deletions include/DataLogger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ class DataLogger {
if (deactivated) {
return;
}
qc.dump(dataLoggingPath + "/input.qasm", qc::Format::OpenQASM);
qc.dump(dataLoggingPath + "/input.qasm", qc::Format::OpenQASM3);
};
void logOutputCircuit(qc::QuantumComputation& qc) {
if (deactivated) {
return;
}
qc.dump(dataLoggingPath + "/output.qasm", qc::Format::OpenQASM);
qc.dump(dataLoggingPath + "/output.qasm", qc::Format::OpenQASM3);
}
void close();

Expand Down
2 changes: 1 addition & 1 deletion include/Mapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ class Mapper {
if (extension == "real") {
dumpResult(outputFilename, qc::Format::Real);
} else if (extension == "qasm") {
dumpResult(outputFilename, qc::Format::OpenQASM);
dumpResult(outputFilename, qc::Format::OpenQASM3);
} else {
throw QMAPException("[dump] Extension " + extension +
" not recognized/supported for dumping.");
Expand Down
2 changes: 1 addition & 1 deletion include/cliffordsynthesis/CliffordSynthesizer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class CliffordSynthesizer {
std::stringstream ss;
ss << results.getResultCircuit();
resultCircuit = std::make_unique<qc::QuantumComputation>();
resultCircuit->import(ss, qc::Format::OpenQASM);
resultCircuit->import(ss, qc::Format::OpenQASM3);
}

[[nodiscard]] qc::QuantumComputation& getResultCircuit() {
Expand Down
2 changes: 1 addition & 1 deletion include/cliffordsynthesis/Results.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Results {

void setResultCircuit(qc::QuantumComputation& qc) {
std::stringstream ss;
qc.dumpOpenQASM(ss);
qc.dumpOpenQASM3(ss);
resultCircuit = ss.str();
}
void setResultTableau(const Tableau& tableau) {
Expand Down
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
24 changes: 11 additions & 13 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ classifiers = [
]
requires-python = ">=3.8"
dependencies = [
"qiskit-terra>=0.20.2",
"qiskit[qasm3-import]>=0.45.0",
"rustworkx[all]>=0.13.0",
"importlib_resources>=5.0; python_version < '3.10'",
"typing_extensions>=4.0"
Expand All @@ -59,7 +59,7 @@ docs = [
"nbsphinx",
"sphinxext-opengraph",
"sphinx-autodoc-typehints",
"qiskit-terra[visualization]",
"qiskit[visualization]",
"mqt.qmap[visualization]"
]
visualization = [
Expand All @@ -81,8 +81,8 @@ Discussions = "https://github.com/cda-tum/mqt-qmap/discussions"
# Protect the configuration against future changes in scikit-build-core
minimum-version = "0.6.1"

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

# Set required CMake and Ninja versions
cmake.minimum-version = "3.19"
Expand All @@ -91,9 +91,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 @@ -120,7 +117,6 @@ sdist.exclude = [
[tool.scikit-build.cmake.define]
BUILD_MQT_QMAP_TESTS = "OFF"
BUILD_MQT_QMAP_BINDINGS = "ON"
ENABLE_IPO = "ON"


[tool.check-sdist]
Expand Down Expand Up @@ -149,6 +145,7 @@ filterwarnings = [
"ignore:.*qiskit.__qiskit_version__.*:DeprecationWarning:qiskit:",
"ignore:.*qiskit.utils.algorithm_globals.QiskitAlgorithmGlobals*:DeprecationWarning:qiskit",
"ignore:.*qiskit.extensions module is pending deprecation*:PendingDeprecationWarning:qiskit",
'ignore:.*datetime\.datetime\.utcfromtimestamp.*:DeprecationWarning:',
]

[tool.coverage]
Expand All @@ -157,18 +154,20 @@ run.omit = ["*/visualization/*"]
report.exclude_also = [
'\.\.\.',
'if TYPE_CHECKING:',
'raise AssertionError',
'raise NotImplementedError',
]

[tool.mypy]
files = ["src/mqt", "test/python"]
mypy_path = ["$MYPY_CONFIG_FILE_DIR/src"]
python_version = "3.8"
strict = true
show_error_codes = true
warn_unused_configs = true
enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"]
warn_unreachable = true
strict = true
disallow_untyped_defs = false
explicit_package_bases = true
pretty = true
warn_unreachable = true

[[tool.mypy.overrides]]
module = ["qiskit.*", "matplotlib.*", "networkx.*", "plotly.*", "_plotly_utils.*", "distinctipy.*", "ipywidgets.*", "walkerlayout.*"]
Expand Down Expand Up @@ -256,7 +255,6 @@ build = "cp3*"
skip = "*-musllinux*"
archs = "auto64"
test-command = "python -c \"from mqt import qmap\""
test-skip = "cp312-*" # Qiskit Terra does not support Python 3.12 yet
build-frontend = "build"

[tool.cibuildwheel.linux]
Expand Down
Loading

0 comments on commit 533574f

Please sign in to comment.