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 marcelwa/aigverse 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/aigverse.git
    $ git submodule update --init --recursive
    

    If you do have write access to the marcelwa/aigverse repository, clone the repository locally.

    $ git clone git@github.com/marcelwa/aigverse.git
    $ git submodule update --init --recursive
    
  2. Change into the project directory

    $ cd aigverse
    
  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 installing and setting up prek to automatically run a set of checks before each commit.

    The easiest way to install prek is via uv.

    $ uv tool install prek
    

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

    $ pipx install prek
    

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

    $ pip install prek
    

    Afterward, you can install the Git hooks with

    $ prek install
    

Working on the bindings (C++)

Building the project requires a C++ compiler supporting C++17 and CMake with a minimum version of 3.23. Our CI pipeline on GitHub continuously tests the library under Windows, macOS, and Linux.

Configure and Build

Tip

We recommend using an IDE like CLion or Visual Studio Code for development. Both IDEs have excellent support for CMake projects and provide a convenient way to run CMake and build the project. If you prefer to work on the command line, the following instructions will guide you through the process.

The project uses CMake as the main build configuration tool. Building a project using CMake is a two-stage process. First, CMake needs to be configured by calling

$ cmake -S . -B build -DCMAKE_BUILD_TYPE=Release

This tells CMake to

  • search the current directory . (passed via -S) for a CMakeLists.txt file.

  • process it into a directory build (passed via -B).

  • the flag -DCMAKE_BUILD_TYPE=Release tells CMake to configure a Release build (as opposed to, e.g., a Debug build).

After configuring with CMake, the project can be built by calling

$ cmake --build build --config Release

This tries to build the project in the build directory (passed via --build). Some operating systems and development environments explicitly require a configuration to be set, which is why the --config flag is also passed to the build command. The flag --parallel <NUMBER_OF_THREADS> may be added to trigger a parallel build.

C++ Code Formatting and Linting

To ensure the quality of the code and certain formatting guidelines, we use

  • clang-tidy – a static analysis tool that checks for common mistakes in C++ code, and

  • clang-format – a tool that automatically formats C++ code according to a given style guide.

Common IDEs like CLion or Visual Studio Code have plugins that can automatically run clang-tidy on the code and automatically format it with clang-format.

  • If you are using CLion, you can configure the project to use the .clang-tidy and .clang-format files in the project root directory.

  • If you are using Visual Studio Code, you can install the clangd extension.

They will automatically execute clang-tidy on your code and highlight any issues. In many cases, they also provide quick-fixes for these issues. Furthermore, they provide a command to automatically format your code according to the given style.

Note

After configuring CMake, you can also run clang-tidy explicitly on a file by calling

$ clang-tidy <FILE> -- -I <PATH_TO_INCLUDE_DIRECTORY>

where <FILE> is the file you want to analyze and <PATH_TO_INCLUDE_DIRECTORY> is the path to the include directory of the project.

Our hook configuration also includes clang-format. If you have installed prek, it will automatically run clang-format on your code before each commit. If you do not have the hooks set up locally, the pre-commit.ci bot will run clang-format on your code and automatically format it according to the style guide.

Tip

Remember to pull the changes back into your local repository after the bot has formatted your code to avoid merge conflicts.

Our CI pipeline will also run clang-tidy over the changes in your pull request and report any issues it finds. Due to technical limitations, the workflow can only post pull request comments if the changes are not coming from a fork. If you are working on a fork, you can still see the clang-tidy results either in the GitHub Actions logs, on the workflow summary page, or in the “Files changed” tab of the pull request.

Working on the Python project

We use nanobind to expose large parts of the C++ library mockturtle to Python. This allows to keep the performance-critical parts of the code in C++ while providing a convenient interface for Python users. All source files related to C++-Python bindings are contained in the src/aigverse directory.

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 -e .

Tip

While the above commands install the project in editable mode, so that changes to the Python code are immediately reflected in the installed package, any changes to the C++ code will require a rebuild of the Python package.

Note

When attempting to build the documentation, you must make sure to have graphviz installed on your system. Installing the documentation or development dependencies will fail if graphviz cannot be detected.

$ sudo apt-get install graphviz
$ brew install graphviz
$ winget install graphviz

or

$ choco install graphviz

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. Due to the build isolation, the corresponding C++ build directory cannot be reused for subsequent builds. This can make rapid iteration on the Python package cumbersome. However, one can work around this by pre-installing the build dependencies in the virtual environment and then building the package without isolation.

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 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 Python Tests

The Python part of the code base is tested via unit tests using the pytest framework. The corresponding test files can be found in the test/ 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/

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

Test Fixtures and Markers

The test suite uses layered pytest fixtures to keep test setup reusable and localized:

  • test/conftest.py for cross-suite fixtures and global test behavior.

  • Domain-level fixture files like test/networks/conftest.py, test/algorithms/conftest.py, test/adapters/conftest.py, and test/generators/conftest.py.

When adding tests, prefer reusing an existing fixture over recreating the same network setup inline. If a setup pattern is reused in multiple files, move it into the closest shared conftest.py.

Pytest markers are also configured to support targeted runs. Useful marker filters include:

  • networks

  • algorithms

  • io

  • generators

  • adapters

  • tts

Run a marker subset on a specific Python version with:

$ nox -s tests-3.12 -- -m algorithms

or run a file-level subset with:

$ nox -s tests -- test/algorithms/test_simulation.py

Python Code Formatting and Linting

The Python code is formatted and linted using a collection of hooks executed via prek. This collection includes:

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

  • ty – a fast Python type checker.

There are two ways of using these hooks:

  • You can install the hooks manually by running

    $ prek 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 prek.

    $ prek run --all-files
    

Python Documentation

The Python part of 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. For the compiled parts of the code base, we provide type hints in the form of .pyi stub files in the python/aigverse directory. These stubs are generated from the nanobind-based extension modules.

You can regenerate the stubs using the dedicated nox session:

$ nox -s stubs

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.

Note

When attempting to build the documentation, you must make sure to have graphviz installed on your system. Installing the documentation or development dependencies will fail if graphviz cannot be detected.

$ sudo apt-get install graphviz
$ brew install graphviz
$ winget install graphviz

or

$ choco install graphviz

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.