C++ libraries and API reference

The native C++ API reference documents the installed public headers, including decision diagrams, benchmarks, and QDMI. It is generated from the same source revision as this guide.

Use the DD library

Create a two-qubit GHZ state, which is a Bell state, and print its amplitudes. Save this as main.cpp:

#include "dd/Package.hpp"
#include "dd/StateGeneration.hpp"

#include <iostream>

int main() {
  dd::Package package(2);
  const auto state = dd::makeGHZState(2, package);
  for (const auto amplitude : state.getVector()) {
    std::cout << amplitude << '\n';
  }
  package.decRef(state);
}

The DD package owns its nodes. The state returned by makeGHZState holds a reference until decRef releases it. Keep the package alive while using the state. Converting a DD to a dense vector takes space exponential in the number of qubits; this example has only four amplitudes.

Save the following as CMakeLists.txt:

cmake_minimum_required(VERSION 3.28)
project(dd-example LANGUAGES CXX)
find_package(mqt-core CONFIG REQUIRED)
add_executable(dd-example main.cpp)
target_link_libraries(dd-example PRIVATE MQT::CoreDD)

With the Python wheel installed in the active environment, CMake and Ninja available, run:

cmake -S . -B build -G Ninja -DCMAKE_PREFIX_PATH="$(mqt-core-cli --cmake_dir)"
cmake --build build
./build/dd-example

The last command is for a Unix shell; on Windows, run build\dd-example.exe. The output has amplitude \(1/\sqrt{2}\) at 00 and 11, and zero at 01 and 10. For a separate C++ installation, point CMAKE_PREFIX_PATH at its install prefix instead. See Installation for source builds and other CMake integration options.

Extend the compiler or QIR runtime

The MLIR compiler and QIR runtime use source-tree C++ interfaces. They are not part of the installed public-header reference above. See device compilation from C++, the QIR runtime guide, and the MLIR dialect and pass references.