Installation

MQT DDSIM is mainly developed as a C++ library that builds upon MQT Core, which forms the backbone of the MQT. In order to make the tool as accessible as possible, it comes with an easy-to-use Python interface.

We encourage installing DDSIM via pip (preferably in a virtual environment):

(venv) $ pip install mqt.ddsim

In most practical cases (under 64-bit Linux, MacOS, and Windows), this requires no compilation and merely downloads and installs a platform-specific pre-built wheel.

Note

In order to set up a virtual environment on Linux or MacOS, you can use the following commands:

$ python3 -m venv venv
$ source venv/bin/activate

If you are using Windows, you can use the following commands instead:

$ python3 -m venv venv
$ venv\Scripts\activate.bat

It is recommended to make sure that you are using the latest version of pip, setuptools, and wheel before trying to install the project:

(venv) $ pip install --upgrade pip setuptools wheel

Warning

As of version 2.0.0, support for Python 3.8 has been officially dropped. We strongly recommend that users upgrade to a more recent version of Python to ensure compatibility and continue receiving updates and support. Thank you for your understanding.

A Detailed Walk Through

First, save the following lines as ghz_3.py in a folder where you want to install the simulator and run the example. Then proceed as described in the section on your operating system.

from qiskit import *
from mqt import ddsim

circ = QuantumCircuit(3)
circ.h(0)
circ.cx(0, 1)
circ.cx(0, 2)

print(circ.draw(fold=-1))

backend = ddsim.DDSIMProvider().get_backend("qasm_simulator")

job = backend.run(circ, shots=10000)
counts = job.result().get_counts(circ)
print(counts)

The following snippet shows the installation process on Linux (more specifically Ubuntu 20.04 LTS) from setting up the virtual environment to running a small example program.

$ python3 -m venv venv
$ . venv/bin/activate
(venv) $ pip install -U pip setuptools wheel
(venv) $ pip install mqt.ddsim
(venv) $ python3 ghz_3.py
        ┌───┐           ░ ┌─┐
   q_0: ┤ H ├──■────■───░─┤M├──────
        └───┘┌─┴─┐  │   ░ └╥┘┌─┐
   q_1: ─────┤ X ├──┼───░──╫─┤M├───
             └───┘┌─┴─┐ ░  ║ └╥┘┌─┐
   q_2: ──────────┤ X ├─░──╫──╫─┤M├
                  └───┘ ░  ║  ║ └╥┘
meas: 3/═══════════════════╩══╩══╩═
                           0  1  2
{'000': 50149, '111': 49851}

Building Wheel from Scratch for Performance

In order to get the best performance out of DDSIM and enable platform-specific compiler optimizations that cannot be enabled on portable wheels, it is recommended to build the package from source via:

(venv) $ pip install mqt.ddsim --no-binary mqt.ddsim

This requires a C++ compiler supporting C++17 and a minimum CMake version of 3.19.

The library is continuously tested under Linux, MacOS, and Windows using the latest available system versions for GitHub Actions. In order to access the latest build logs, visit mqt-ddsim/actions/workflows/ci.yml.

Note

We noticed some issues when compiling with Microsoft’s MSCV compiler toolchain. If you want to start development on this project under Windows, consider using the clang compiler toolchain. A detailed description of how to set this up can be found here.

Building from Cloned Repository

If you want to have the latest features that may not be released to PyPI yet, you can also clone the repository and build from source.

The following snippet clones the repository including the submodules and builds all targets (library, standalone apps, and python bindings) in Release mode for DDSIM.

$ git clone --recurse-submodules https://github.com/cda-tum/mqt-ddsim
[...]
$ cd mqt-ddsim
$ cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DBUILD_MQT_DDSIM_BINDINGS=ON
[...]
$ cmake --build build --config Release
[...]

Afterwards the standalone executables can be found in build/apps/. For the python bindings it’s recommended to install via pip in a virtual environment. To do so, run pip install . instead of the cmake calls above.