Skip to content

Commit

Permalink
♻️ Library update (#161)
Browse files Browse the repository at this point in the history
## Description

This updates the project to the latest best practices within the MQT.

## 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 Jul 2, 2024
1 parent 670040c commit bdc503b
Show file tree
Hide file tree
Showing 13 changed files with 174 additions and 106 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@ on:
release:
types: [published]
workflow_dispatch:
pull_request:
paths:
- .github/workflows/cd.yml

jobs:
python-packaging:
name: 🐍 Packaging
uses: cda-tum/mqt-core/.github/workflows/reusable-python-packaging.yml@v2.2.2
uses: cda-tum/mqt-workflows/.github/workflows/reusable-python-packaging.yml@v1.1.4
with:
setup-z3: true
z3-version: 4.12.6 # 4.13.0 has incorrectly tagged manylinux wheels

deploy:
if: github.event_name == 'release' && github.event.action == 'published'
Expand Down
10 changes: 4 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,29 @@ concurrency:
jobs:
change-detection:
name: 🔍 Change
uses: cda-tum/mqt-core/.github/workflows/reusable-change-detection.yml@v2.2.2
uses: cda-tum/mqt-workflows/.github/workflows/reusable-change-detection.yml@v1.1.4

cpp-tests:
name: 🇨‌ Test
needs: change-detection
if: fromJSON(needs.change-detection.outputs.run-cpp-tests)
uses: cda-tum/mqt-core/.github/workflows/[email protected]
secrets:
token: ${{ secrets.CODECOV_TOKEN }}
uses: cda-tum/mqt-workflows/.github/workflows/[email protected]
with:
setup-z3: true

cpp-linter:
name: 🇨‌ Lint
needs: change-detection
if: fromJSON(needs.change-detection.outputs.run-cpp-linter)
uses: cda-tum/mqt-core/.github/workflows/reusable-cpp-linter.yml@v2.2.2
uses: cda-tum/mqt-workflows/.github/workflows/reusable-cpp-linter.yml@v1.1.4
with:
setup-z3: true

code-ql:
name: 📝 CodeQL
needs: change-detection
if: fromJSON(needs.change-detection.outputs.run-code-ql)
uses: cda-tum/mqt-core/.github/workflows/reusable-code-ql.yml@main
uses: cda-tum/mqt-workflows/.github/workflows/reusable-code-ql.yml@v1.1.4
with:
setup-z3: true

Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/update-mqt-core.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Update MQT Core
on:
schedule:
# run once a month on the first day of the month at 00:00 UTC
- cron: "0 0 1 * *"
workflow_dispatch:
inputs:
update-to-head:
description: "Update to the latest commit on the default branch"
type: boolean
required: false
default: false
pull_request:
paths:
- .github/workflows/update-mqt-core.yml

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
update-mqt-core:
name: ⬆️ Update MQT Core
uses: cda-tum/mqt-workflows/.github/workflows/[email protected]
with:
update-to-head: ${{ fromJSON(github.event.inputs.update-to-head) || false }}
4 changes: 0 additions & 4 deletions .gitmodules

This file was deleted.

14 changes: 6 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ ci:
repos:
# Standard hooks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v4.6.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
Expand Down Expand Up @@ -46,7 +46,7 @@ repos:

# Python linting using ruff
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.4
rev: v0.5.0
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]
Expand All @@ -56,14 +56,14 @@ repos:

# Also run Black on examples in the documentation
- repo: https://github.com/adamchainz/blacken-docs
rev: 1.16.0
rev: 1.18.0
hooks:
- id: blacken-docs
additional_dependencies: [black==23.*]

# Check static types with mypy
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.9.0
rev: v1.10.1
hooks:
- id: mypy
files: ^(src/mqt)
Expand All @@ -73,14 +73,14 @@ repos:

# Check for spelling
- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
rev: v2.3.0
hooks:
- id: codespell
args: ["-L", "wille,linz,applys,lits", "--skip", "*.ipynb"]

# Clang-format the C++ part of the code base automatically
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v18.1.2
rev: v18.1.8
hooks:
- id: clang-format
types_or: [c++, c, cuda]
Expand All @@ -91,8 +91,6 @@ repos:
hooks:
- id: cmake-format
additional_dependencies: [pyyaml]
- id: cmake-lint
additional_dependencies: [pyyaml]

# Format configuration files with prettier
- repo: https://github.com/pre-commit/mirrors-prettier
Expand Down
19 changes: 3 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,9 @@ project(
LANGUAGES CXX
DESCRIPTION "A Tool for Utilizing SAT in Quantum Computing")

# 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)

option(BUILD_MQT_QUSAT_BINDINGS "Build the MQT QUSAT Python bindings" OFF)
option(BUILD_MQT_QUSAT_TESTS "Also build tests for the MQT QUSAT project" ON)

if(BUILD_MQT_QUSAT_BINDINGS)
# ensure that the BINDINGS option is set
set(BINDINGS
Expand All @@ -43,14 +32,12 @@ endif()
# Add path for custom modules
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

# search for Z3
find_package(Z3 REQUIRED)
include(cmake/ExternalDependencies.cmake)

# add main library code
add_subdirectory(src)

# add test code
option(BUILD_MQT_QUSAT_TESTS "Also build tests for the MQT QUSAT project" ON)
if(BUILD_MQT_QUSAT_TESTS)
enable_testing()
include(GoogleTest)
Expand Down
89 changes: 89 additions & 0 deletions cmake/ExternalDependencies.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Declare all external dependencies and make sure that they are available.

include(FetchContent)
set(FETCH_PACKAGES "")

# search for Z3
find_package(Z3 REQUIRED)

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

# cmake-format: off
set(MQT_CORE_VERSION 2.5.1
CACHE STRING "MQT Core version")
set(MQT_CORE_REV "35e06ca3067ca3cf36bda1f0c38edf5bd7456fb6"
CACHE STRING "MQT Core identifier (tag, branch or commit hash)")
set(MQT_CORE_REPO_OWNER "cda-tum"
CACHE STRING "MQT Core repository owner (change when using a fork)")
# cmake-format: on
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.24)
FetchContent_Declare(
mqt-core
GIT_REPOSITORY https://github.com/${MQT_CORE_REPO_OWNER}/mqt-core.git
GIT_TAG ${MQT_CORE_REV}
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/${MQT_CORE_REPO_OWNER}/mqt-core.git
GIT_TAG ${MQT_CORE_REV})
list(APPEND FETCH_PACKAGES mqt-core)
endif()
endif()

if(BUILD_MQT_QUSAT_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_QUSAT_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/mqt-core
Submodule mqt-core deleted from 87f97a
30 changes: 15 additions & 15 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["scikit-build-core>=0.6.1", "setuptools-scm>=7", "pybind11>=2.11"]
requires = ["scikit-build-core>=0.8.1", "setuptools-scm>=7", "pybind11>=2.12"]
build-backend = "scikit_build_core.build"

[project]
Expand Down Expand Up @@ -46,24 +46,23 @@ Research = "https://www.cda.cit.tum.de/research/quantum"

[tool.scikit-build]
# Protect the configuration against future changes in scikit-build-core
minimum-version = "0.6.1"
minimum-version = "0.8.1"

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

# Set required CMake and Ninja versions
cmake.minimum-version = "3.19"
ninja.minimum-version = "1.10"
cmake.version = ">=3.19"
ninja.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"]

install.components = ["mqt-qusat_Python"]

metadata.version.provider = "scikit_build_core.metadata.setuptools_scm"
sdist.include = ["src/mqt/qusat/_version.py"]
sdist.exclude = [
Expand Down Expand Up @@ -221,20 +220,21 @@ build = "cp3*"
skip = "*-musllinux*"
archs = "auto64"
test-command = "python -c \"from mqt import qusat\""
test-skip = "cp312-*" # Qiskit Terra does not support Python 3.12 yet
build-frontend = "build"
test-skip = "cp38-macosx_arm64"
build-frontend = "build[uv]"

[tool.cibuildwheel.linux]
environment = { Z3_ROOT="/opt/python/cp311-cp311/lib/python3.11/site-packages/z3", DEPLOY="ON" }
before-all = "/opt/python/cp311-cp311/bin/pip install z3-solver==4.11.2"
before-all = "/opt/python/cp311-cp311/bin/pip install z3-solver==4.12.6"
repair-wheel-command = [
"export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/python/cp311-cp311/lib/python3.11/site-packages/z3/lib",
"auditwheel repair -w {dest_dir} {wheel}",
]

[tool.cibuildwheel.macos]
environment = { MACOSX_DEPLOYMENT_TARGET = "10.15" }
environment = { MACOSX_DEPLOYMENT_TARGET = "11.0" }

[tool.cibuildwheel.windows]
before-build = "pip install delvewheel"
repair-wheel-command = "delvewheel repair -v -w {dest_dir} {wheel}"
before-build = "pip install delvewheel>=1.4.0"
repair-wheel-command = "delvewheel repair -v -w {dest_dir} {wheel} --namespace-pkg mqt"
environment = { CMAKE_GENERATOR = "Ninja" }
10 changes: 4 additions & 6 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
# add MQT::Core target
set(BUILD_MQT_CORE_TESTS
OFF
CACHE BOOL "Build MQT Core tests")
add_subdirectory("${PROJECT_SOURCE_DIR}/extern/mqt-core" "extern/mqt-core" EXCLUDE_FROM_ALL)
# main project library
add_library(${PROJECT_NAME} ${PROJECT_SOURCE_DIR}/include/SatEncoder.hpp
${PROJECT_SOURCE_DIR}/include/Statistics.hpp SatEncoder.cpp)
Expand All @@ -12,7 +7,10 @@ target_include_directories(${PROJECT_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/include
${PROJECT_BINARY_DIR}/include)

# link to the MQT::Core libraries
target_link_libraries(${PROJECT_NAME} PUBLIC MQT::Core)
target_link_libraries(
${PROJECT_NAME}
PUBLIC MQT::Core nlohmann_json::nlohmann_json
PRIVATE MQT::ProjectOptions MQT::ProjectWarnings)

# add z3 SMT solver
target_link_libraries(${PROJECT_NAME} PUBLIC z3::z3lib)
Expand Down
Loading

0 comments on commit bdc503b

Please sign in to comment.