/tket

Source code for the TKET quantum compiler, Python bindings and utilities

Primary LanguageC++Apache License 2.0Apache-2.0

tket

Introduction

This repository contains the full source code for tket, a quantum SDK.

If you just want to use tket via Python, the easiest way is to install it with pip:

pip install pytket

For full API documentation, as well as a comprehensive user manual and a selection of example notebooks, please follow the links from the pytket main page.

Note that the various pytket extensions (which allow pytket to interface with other software packages and with quantum devices) live in the separate pytket-extensions repository.

If you would like to build tket yourself and help to improve it, read on!

The codebase is split into two main projects:

  • tket: the core functionality of tket, optimised for execution speed and implemented in C++.
  • pytket: the Python interface of tket. This consists of binder modules to tket (written in C++ and making use of pybind11 to link to the tket shared library) and pure Python code that defines abstract interfaces used by the extension modules such as the Backend and BackendResult classes, as well as various other utilities.

How to build tket and pytket

Prerequisites

Build tools

The following compiler toolchains are used to build tket on the CI and are therefore known to work:

  • Linux: gcc-10
  • MacOS: apple-clang 12
  • Windows: MSVC 19

It is recommended that you use these versions to build locally, as code may depend on the features they support. The compiler version can be controlled by setting CC and CXX in your environment (e.g. CC=gcc-10 and CXX=g++-10), or on Debian-based Linux systems using update-alternatives.

You should also have Python (3.7, 3.8 or 3.9) and pip installed. We use cmake and the package manager conan to build tket. Both can be installed with pip:

pip install cmake conan

It is recommended that you also install ninja and ccache to speed up the build process. For example on Debian/Ubuntu:

sudo apt install ninja-build ccache

Set up conan profile

Generate a profile that matches your current machine. This profile does not have to be called tket, but if you give it another name you will have to set CONAN_TKET_PROFILE to its name in your environment when you build the Python module.

conan profile new tket --detect

If this prints a warning about gcc ABI compatibility (as it probably will on Linux), adjust the profile compiler settings with the following command, as recommended in the warning message:

conan profile update settings.compiler.libcxx=libstdc++11 tket

If you wish you can set your profile to Debug mode:

conan profile update settings.build_type=Debug tket

Enable revisions

In order to pick up the proper revision of the pybind11 package, it is currently necessary to do the following (or equivalent):

conan config set general.revisions_enabled=1

Test dependencies

A few of the tket tests require a working LaTeX installation, including latexmk and the quantikz package. By default these are only run on Linux. Passing ~[latex] to the test executable will disable them. To install the Latex dependencies on (Debian flavours of) Linux you can do:

sudo apt-get install texlive texlive-latex-extra latexmk
mkdir -p ~/texmf/tex/latex
wget http://mirrors.ctan.org/graphics/pgf/contrib/quantikz/tikzlibraryquantikz.code.tex -P ~/texmf/tex/latex

The Python tests require a few more packages. These can be installed with:

pip install -r pytket/tests/requirements.txt

Building tket

Method 1

At this point you can run:

conan create --profile=tket recipes/tket

to build the tket library.

To build and run the tket tests:

conan create --profile=tket recipes/tket-tests

If you want to build them without running them, pass --test-folder None to the conan command. (You can still run them manually afterwards.)

There is also a small set of property-based tests which you can build and run with:

conan create --profile=tket recipes/tket-proptests

Now to build pytket:

cd pytket
pip install -e .

And then to run the Python tests:

cd tests
pytest

Method 2

In a development cycle, it may save time to break down the conan create command from above into separate build and export commands.

First create a build folder in the project root. Then proceed as follows.

  1. To install dependencies:

    conan install recipes/tket --install-folder=build --profile=tket --build=missing
  2. To configure the build:

    conan build recipes/tket --configure --build-folder=build --source-folder=tket/src
  3. To build:

    conan build recipes/tket --build --build-folder=build
  4. To export to conan cache (necessary to build pytket):

    conan export-pkg recipes/tket -f --build-folder=build --source-folder=tket/src

Test coverage

The code coverage of the tket tests is reported here. This report is generated weekly from the develop branch.

API documentation

The tket (C++) API documentation (generated with doxygen, and still rather patchy) is available here.

The pytket (Python) API documentation is available here.