Development Guide

Ready to contribute to the project? This guide will get you started.

Initial Setup

  1. Get the code

    If you do not have write access to the munich-quantum-toolkit/bench 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/bench.git mqt-bench
    

    If you do have write access to the munich-quantum-toolkit/bench repository, clone the repository locally.

    $ git clone git@github.com/munich-quantum-toolkit/bench.git mqt-bench
    
  2. Change into the project directory

    $ cd mqt-bench
    
  3. Create a branch for local development

    $ git checkout -b name-of-your-bugfix-or-feature
    

    Now you can make your changes locally.

  4. We highly recommend using uv. It is an extremely fast Python package and project manager, written in Rust and developed by Astral (the same team behind ruff). It can act as a drop-in replacement for pip and virtualenv, and provides a more modern and faster alternative to the traditional Python package management tools. It automatically handles the creation of virtual environments and the installation of packages, and is much faster than pip. Additionally, it can even set up Python for you if it is not installed yet.

    If you do not have uv installed yet, you can install it via:

    $ curl -LsSf https://astral.sh/uv/install.sh | sh
    
    $ powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
    

    Check out their excellent documentation for more information.

  5. We also highly recommend to install and set up pre-commit to automatically run a set of checks before each commit.

    The easiest way to install pre-commit is via uv.

    $ uv tool install pre-commit
    

    If you use macOS, then pre-commit is in Homebrew, and you can use

    $ brew install pre-commit
    

    If you prefer to use pipx, you can install pre-commit with

    $ pipx install pre-commit
    

    If you prefer to use regular pip (preferably in a virtual environment), you can install pre-commit with

    $ pip install pre-commit
    

    Afterwards, you can install the pre-commit hooks with

    $ pre-commit install
    

Working on the Python package

Getting the project up and running locally using uv is as simple as running:

$ uv sync

This will

  • download a suitable version of Python for you (if you don’t have it installed yet),

  • create a virtual environment,

  • install all the project’s dependencies into the virtual environment with known-good versions, and

  • build and install the project itself into the virtual environment.

The whole process is a lot more tedious and manual if you use pip directly. Once you have Python installed, you can first create a virtual environment with:

$ python3 -m venv .venv
$ source .venv/bin/activate
$ python3 -m venv .venv
$ .venv\Scripts\activate.bat

Then, you can install the project via:

(.venv) $ pip install -ve.

Tip

The above commands install the project in editable mode, so that changes to the Python code are immediately reflected in the installed package.

The way the Python package build process in the above commands works is that a wheel for the project is built in an isolated environment and then installed into the virtual environment.

Since the overall process can be quite involved, we recommend using nox to automate the build process. Nox is a Python automation tool that allows you to define tasks in a noxfile.py and then run them with a single command.

The easiest way to install nox is via uv.

$ uv tool install nox

If you use macOS, then nox is in Homebrew, and you can use

$ brew install nox

If you prefer to use pipx, you can install nox with

$ pipx install nox

If you prefer to use regular pip (preferably in a virtual environment), you can install nox with

$ pip install nox

We define four convenient nox sessions in the noxfile.py:

  • tests to run the Python tests

  • minimums to run the Python tests with the minimum dependencies

  • lint to run the Python code formatting and linting

  • docs to build the documentation

These are explained in more detail in the following sections.

Running Tests

The code base is tested by unit tests using the pytest framework. The corresponding test files can be found in the tests directory. A nox session is provided to conveniently run the Python tests.

$ nox -s tests

The above command will automatically build the project and run the tests on all supported Python versions. For each Python version, it will create a virtual environment (in the .nox directory) and install the project into it. We take extra care to install the project without build isolation so that rebuilds are typically very fast.

If you only want to run the tests on a specific Python version, you can pass the desired Python version to the nox command.

$ nox -s tests-3.12

Note

If you don’t want to use nox, you can also run the tests directly using pytest.

(.venv) $ pytest test/python

This requires that you have the project installed in the virtual environment and the test dependency group installed.

We provide an additional nox session minimums that makes use of uv’s --resolution=lowest-direct flag to install the lowest possible versions of the direct dependencies. This ensures that the project can still be built and the tests pass with the minimum required versions of the dependencies.

$ nox -s minimums

Code Formatting and Linting

The code is formatted and linted using a collection of pre-commit hooks. This collection includes:

  • ruff – an extremely fast Python linter and formatter, written in Rust.

  • mypy – a static type checker for Python code

There are two ways of using these hooks:

  • You can install the hooks manually by running

    $ pre-commit install
    

    in the project root directory. This will install the hooks in the .git/hooks directory of the repository. The hooks will then be executed automatically when committing changes.

  • You can use the nox session lint to run the hooks manually.

    $ nox -s lint
    

    Note

    If you don’t want to use nox, you can also run the hooks directly using pre-commit.

    $ pre-commit run --all-files
    

Documentation

The code base is documented using Google-style docstrings. Every public function, class, and module should have a docstring that explains what it does and how to use it. Ruff will check for missing docstrings and will explicitly warn you if you forget to add one.

We heavily rely on type hints to document the expected types of function arguments and return values.

The Python API documentation is integrated into the overall documentation that we host on ReadTheDocs using the sphinx-autoapi extension for Sphinx.

Working on the Documentation

The documentation is written in MyST (a flavour of Markdown) and built using Sphinx. The documentation source files can be found in the docs/ directory.

On top of the API documentation, we provide a set of tutorials and examples that demonstrate how to use the library. These are written in Markdown using myst-nb, which allows to execute Python code blocks in the documentation. The code blocks are executed during the documentation build process, and the output is included in the documentation. This allows us to provide up-to-date examples and tutorials that are guaranteed to work with the latest version of the library.

You can build the documentation using the nox session docs.

$ nox -s docs

This will install all dependencies for building the documentation in an isolated environment, build the Python package, and then build the documentation. Finally, it will host the documentation on a local web server for you to view.

Note

If you don’t want to use nox, you can also build the documentation directly using sphinx-build.

(.venv) $ sphinx-build -b html docs/ docs/_build

The docs can then be found in the docs/_build directory.

Naming Conventions for Benchmarks, Gatesets, and Devices

To ensure the automatic discovery/registration logic finds your contribution, follow these rules whenever you add benchmarks, gatesets, or devices.

Artifact

File location

File name & module

Registration decorator

Naming pattern

Benchmark

mqt/bench/benchmarks/

my_benchmark.py

@register_benchmark("my_benchmark", description="Benchmark Description")

File name ≡ registered name. Only lower-case letters, digits, and underscores. The description argument should hold a concise, human-readable name for the circuit, for example: @register_benchmark("ae", description="Amplitude Estimation")

Gateset

mqt/bench/targets/gatesets/

ibm.py, ionq.py, …

@register_gateset("ibm_falcon") (inside ibm.py)

<vendor>_<family>. Everything before the first _ is the module name. Special cases: clifford+t, clifford+t+rotations → module clifford_t (handled via _SPECIAL_NAME_TO_MODULE).

Device

mqt/bench/targets/devices/

ibm.py, ionq.py, …

@register_device("ibm_falcon_27")

Same rule as gatesets: module is the part before the first underscore.

Guidelines & Gotchas

  1. Register the correct factory

    • Benchmarks → create_circuit(circuit_size: int, …) -> QuantumCircuit

    • Gatesets → get_<vendor>_<family>_gateset() -> list[str]

    • Devices → get_<vendor>_<family>() -> Target

  2. One module = one vendor/family Keep all variants sharing the same prefix in a single file, e.g. ibm.py registers ibm_falcon_27, ibm_falcon_65, and ibm_eagle_127.

  3. Use Python-identifier-friendly names Dashes (-) break import semantics—use underscores (_) instead.

  4. Special names If you need an unusual name for a gateset (e.g. containing +), map it in _SPECIAL_NAME_TO_MODULE inside mqt/bench/targets/gatesets/__init__.py.