Installation¶
MQT Core is primarily developed as a C++20 library with Python bindings. The Python package is available on PyPI and can be installed on all major operating systems with all officially supported Python versions.
Tip
We recommend using uv.
It is a fast Python package and project manager by Astral
(creators of ruff).
It can replace pip and virtualenv,
automatically manages virtual environments, installs packages,
and can install Python itself.
It is significantly faster than pip.
If you do not have uv installed, install it with:
curl -LsSf https://astral.sh/uv/install.sh | sh
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
See the uv documentation for more information.
uv pip install mqt.core
python -m pip install mqt.core
In most cases, no compilation is required; a platform-specific prebuilt wheel is downloaded and installed.
Verify the installation:
python -c "import mqt.core; print(mqt.core.__version__)"
This prints the installed package version.
Building from Source for Performance¶
To get the best performance and enable platform-specific optimizations not available in portable wheels, we recommend building the library from source:
uv pip install mqt.core --no-binary mqt.core
pip install mqt.core --no-binary mqt.core
This requires a C++20-capable C++ compiler and CMake 3.24 or newer.
Integrating MQT Core into Your Project¶
To use the MQT Core Python package in your project,
add it as a dependency in your pyproject.toml or setup.py.
This ensures the package is installed when your project is installed.
uv add mqt.core
[project]
# ...
dependencies = ["mqt.core>=<version>"]
# ...
from setuptools import setup
setup(
# ...
install_requires=["mqt.core>=<version>"],
# ...
)
If you want to integrate the C++ library directly into your project, you can either
add it as a
gitsubmodule and build it as part of your project, orinstall MQT Core on your system and use CMake’s
find_package()command to locate it, oruse CMake’s
FetchContentmodule to combine both approaches.
This is the recommended approach
because it lets you detect installed versions of MQT Core
and only downloads the library if it is not available on the system.
Furthermore, CMake’s FetchContent module provides
flexibility in how the library is integrated into the project.
include(FetchContent)
set(FETCH_PACKAGES "")
# cmake-format: off
set(MQT_CORE_MINIMUM_VERSION "<minimum_version>"
CACHE STRING "MQT Core minimum version")
set(MQT_CORE_VERSION "<version>"
CACHE STRING "MQT Core version")
set(MQT_CORE_REV "<revision>"
CACHE STRING "MQT Core identifier (tag, branch or commit hash)")
set(MQT_CORE_REPO_OWNER "munich-quantum-toolkit"
CACHE STRING "MQT Core repository owner (change when using a fork)")
# cmake-format: on
FetchContent_Declare(
mqt-core
GIT_REPOSITORY https://github.com/${MQT_CORE_REPO_OWNER}/core.git
GIT_TAG ${MQT_CORE_REV}
FIND_PACKAGE_ARGS ${MQT_CORE_MINIMUM_VERSION})
list(APPEND FETCH_PACKAGES mqt-core)
# Make all declared dependencies available.
FetchContent_MakeAvailable(${FETCH_PACKAGES})
Adding the library as a git submodule is a simple
approach.
However, git submodules can be cumbersome,
especially when working with multiple branches or versions of the library.
First, add the submodule to your project
(e.g., in the external directory):
git submodule add https://github.com/munich-quantum-toolkit/core.git external/mqt-core
Then add the following line to your CMakeLists.txt to make the library’s
targets available in your project:
add_subdirectory(external/mqt-core)
You can install MQT Core on your system after building it from source:
git clone https://github.com/munich-quantum-toolkit/core.git mqt-core
cd mqt-core
cmake -S . -B build
cmake --build build
cmake --install build
Then, in your project’s CMakeLists.txt,
use find_package() to locate the installed library:
find_package(mqt-core <version> REQUIRED)
Development Setup¶
Set up a reproducible development environment for MQT Core. This is the recommended starting point for both bug fixes and new features. For detailed guidelines and workflows, see Contributing.
Get the code:
If you do not have write access to the munich-quantum-toolkit/core repository, fork the repository on GitHub (see https://docs.github.com/en/get-started/quickstart/fork-a-repo) and clone your fork locally.
git clone git@github.com:your_name_here/core.git mqt-coreIf you have write access to the munich-quantum-toolkit/core repository, clone the repository locally.
git clone git@github.com/munich-quantum-toolkit/core.git mqt-coreChange into the project directory:
cd mqt-coreCreate a branch for local development:
git checkout -b name-of-your-bugfix-or-featureNow you can make your changes locally.
Install the project and its development dependencies:
We highly recommend using modern, fast tooling for the development workflow. We recommend using
uv. If you don’t haveuv, follow the installation instructions in the recommendation above (see tip above). See the uv documentation for more information.Install the project (including development dependencies) with
uv:uv syncIf you really don’t want to use
uv, you can install the project and the development dependencies into a virtual environment usingpip.python -m venv .venv source ./.venv/bin/activate python -m pip install -U pip python -m pip install -e . --group dev
Install pre-commit hooks to ensure code quality:
The project uses pre-commit hooks for running linters and formatting tools on each commit. These checks can be run manually via
nox, by running:nox -s lintThey can also be run automatically on every commit via
prek(recommended). To set this up, installprek, e.g., via:curl --proto '=https' --tlsv1.2 -LsSf https://github.com/j178/prek/releases/latest/download/prek-installer.sh | shpowershell -ExecutionPolicy ByPass -c "irm https://github.com/j178/prek/releases/latest/download/prek-installer.ps1 | iex"uv tool install prekThen run:
prek installIf you plan to contribute to MQT Core, you will also need to install MLIR. The section below describes how to do this.
Setting Up MLIR¶
MQT Core requires MLIR, which is part of the LLVM project, to be available when building from source. To successfully build MQT Core, you must make an installation of MLIR available to the C++ builds on your platform.
We highly recommend using the prebuilt MLIR distribution provided by the
portable-mlir-toolchain project.
These can be conveniently installed with the setup-mlir scripts
as described below.
Downloading the MLIR Distribution¶
The setup-mlir repository provides installation scripts
for all supported operating systems.
You must pass the LLVM version
(e.g., 22.1.0)
and the installation prefix (directory) where MLIR should be extracted.
The scripts download a platform-specific archive.
The only requirement is that the tar command is available on the system.
Note
tar is included by default on Windows 10 and Windows 11.
On older Windows versions, you can install it, for example,
via Chocolatey: choco install tar.
Run the Bash script with the desired LLVM version and installation path:
curl -LsSf https://github.com/munich-quantum-software/setup-mlir/releases/latest/download/setup-mlir.sh | bash -s -- -v 22.1.0 -p /path/to/installation
Replace /path/to/installation with the directory
where the LLVM distribution should be installed (e.g., /opt/llvm-22.1.0).
Run the PowerShell script with the desired LLVM version and installation path:
powershell -ExecutionPolicy ByPass -c "& ([scriptblock]::Create((irm https://github.com/munich-quantum-software/setup-mlir/releases/latest/download/setup-mlir.ps1))) -llvm_version 22.1.0 -install_prefix \path\to\installation"
Replace \path\to\installation with the directory
where the LLVM distribution should be installed (e.g., C:\llvm-22.1.0).
For debug builds on Windows, add the -use_debug flag to the script invocation.
For supported LLVM versions, commit hashes, and other options,
see the setup-mlir repository and its
version-manifest.json.
Note
If you want to build MLIR from source,
you can follow the instructions in the portable-mlir-toolchain repository.
This is not recommended unless you need a specific configuration
that is not available in the prebuilt distributions,
as building MLIR from source can be complex and time-consuming.
Making MLIR Available to the Build¶
After installing MLIR, point the build system to it by setting the CMake
variable MLIR_DIR to the CMake configuration directory of the
installation:
cmake -S . -B build -DMLIR_DIR=/path/to/installation/lib/cmake/mlir
Replace /path/to/installation with the actual path to the MLIR installation
from the previous step.
Alternatively, you can set the MLIR_DIR environment variable to the same
path before running CMake:
export MLIR_DIR=/path/to/installation/lib/cmake/mlir
$env:MLIR_DIR = "C:\path\to\installation\lib\cmake\mlir"
Disabling MLIR¶
If you do not need MLIR-based functionality,
you can disable it by setting the BUILD_MQT_CORE_MLIR option to
OFF.
This disables all MLIR-related features in MQT Core
and removes the dependency on MLIR.
cmake -S . -B build -DBUILD_MQT_CORE_MLIR=OFF