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

✨ switch to mqt-core Python package #355

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ repos:
- importlib_resources
- numpy
- pytest
- mqt-core @ git+https://github.com/cda-tum/mqt-core.git@installation-improvements

# Check for spelling
- repo: https://github.com/codespell-project/codespell
Expand Down
23 changes: 15 additions & 8 deletions cmake/ExternalDependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ include(FetchContent)
set(FETCH_PACKAGES "")

if(BUILD_MQT_QCEC_BINDINGS)
# Manually detect the installed mqt-core package.
execute_process(
COMMAND "${Python_EXECUTABLE}" -m mqt.core --cmake_dir
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE mqt-core_DIR
ERROR_QUIET)

# Add the detected directory to the CMake prefix path.
if(mqt-core_DIR)
list(APPEND CMAKE_PREFIX_PATH "${mqt-core_DIR}")
message(STATUS "Found mqt-core package: ${mqt-core_DIR}")
endif()

if(NOT SKBUILD)
# Manually detect the installed pybind11 package.
execute_process(
Expand All @@ -19,20 +32,14 @@ if(BUILD_MQT_QCEC_BINDINGS)
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}
GIT_TAG installation-improvements
FIND_PACKAGE_ARGS ${MQT_CORE_VERSION})
list(APPEND FETCH_PACKAGES mqt-core)
else()
Expand All @@ -41,7 +48,7 @@ else()
FetchContent_Declare(
mqt-core
GIT_REPOSITORY https://github.com/cda-tum/mqt-core.git
GIT_TAG v${MQT_CORE_VERSION})
GIT_TAG installation-improvements)
list(APPEND FETCH_PACKAGES mqt-core)
endif()
endif()
Expand Down
15 changes: 12 additions & 3 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
PYTHON_ALL_VERSIONS = ["3.8", "3.9", "3.10", "3.11", "3.12"]

BUILD_REQUIREMENTS = [
"mqt.core @ git+https://github.com/cda-tum/mqt-core.git@installation-improvements",
"scikit-build-core[pyproject]>=0.6.1",
"setuptools_scm>=7",
"pybind11>=2.11",
Expand Down Expand Up @@ -54,7 +55,12 @@ def _run_tests(
_extras.append("coverage")
posargs.append("--cov-config=pyproject.toml")

session.install(*BUILD_REQUIREMENTS, *install_args, env=env)
# On Linux, `mqt-core` needs to be installed with `--no-binary` to avoid ABI
# incompatibility issues caused by compiling with different GCC versions.
if sys.platform == "linux":
install_args = ["--no-binary", "mqt.core", *install_args]

session.install("-v", *BUILD_REQUIREMENTS, *install_args, env=env)
install_arg = f"-ve.[{','.join(_extras)}]"
session.install("--no-build-isolation", install_arg, *install_args, env=env)
session.run("pytest", *run_args, *posargs, env=env)
Expand Down Expand Up @@ -89,8 +95,11 @@ def docs(session: nox.Session) -> None:
session.error("Must not specify non-HTML builder with --serve")

extra_installs = ["sphinx-autobuild"] if args.serve else []
session.install(*BUILD_REQUIREMENTS, *extra_installs)
session.install("--no-build-isolation", "-ve.[docs]")
# On Linux, `mqt-core` needs to be installed with `--no-binary` to avoid ABI
# incompatibility issues caused by compiling with different GCC versions.
install_args = ["--no-binary", "mqt.core"] if sys.platform == "linux" else []
session.install(*BUILD_REQUIREMENTS, *extra_installs, *install_args)
session.install("--no-build-isolation", "-ve.[docs]", *install_args)
session.chdir("docs")

if args.builder == "linkcheck":
Expand Down
10 changes: 7 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
[build-system]
requires = ["scikit-build-core>=0.6.1", "setuptools-scm>=7", "pybind11>=2.11"]
requires = [
"scikit-build-core>=0.6.1",
"setuptools-scm>=7",
"pybind11>=2.11",
"mqt.core @ git+https://github.com/cda-tum/mqt-core.git@installation-improvements",
]
build-backend = "scikit_build_core.build"

[project]
Expand Down Expand Up @@ -35,9 +40,9 @@ classifiers = [
]
requires-python = ">=3.8"
dependencies = [
"mqt.core[qiskit] @ git+https://github.com/cda-tum/mqt-core.git@installation-improvements",
"importlib_resources>=5.0; python_version < '3.10'",
"typing_extensions>=4.2",
"qiskit[qasm3-import]>=0.45.0",
]
dynamic = ["version"]

Expand Down Expand Up @@ -100,7 +105,6 @@ sdist.exclude = [
[tool.scikit-build.cmake.define]
BUILD_MQT_QCEC_TESTS = "OFF"
BUILD_MQT_QCEC_BINDINGS = "ON"
ENABLE_IPO = "ON"


[tool.check-sdist]
Expand Down
11 changes: 11 additions & 0 deletions src/mqt/qcec/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@

from __future__ import annotations

import sys

# under Windows, make sure to add the appropriate DLL directory to the PATH
if sys.platform == "win32": # pragma: no cover
import os
import sysconfig
from pathlib import Path

bin_dir = Path(sysconfig.get_paths()["purelib"]) / "mqt" / "core" / "bin"
os.add_dll_directory(str(bin_dir))

from ._version import version as __version__
from .compilation_flow_profiles import AncillaMode, generate_profile
from .pyqcec import (
Expand Down
Loading
Loading