Skip to content

CQCL/tket

Repository files navigation

tket

Slack Stack Exchange PyPI version

Introduction

TKET (pronounced "ticket" ) is a high-performance quantum compiler that can optimise circuits for a wide range of quantum computing architectures.

This repository contains the full source code for TKET and its python bindings.

The standard way of using TKET is via its pytket python API.

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

pip install pytket

As well as being an interface to the TKET compiler, pytket also provides an extensive API for other quantum computing tasks. These include constructing quantum circuits and handling the execution of experiments on devices and simulators.

Documentation

Thetket(C++) API documentation (generated withdoxygen,and still rather patchy) is available here.

Thepytket(Python) API documentation is available here.

For getting started using pytket, check out theuser manual and notebook examples.

The source content for the manual and notebook examples can be found in thepytket-docs repository.

Extensions

In addition to the core pytket package there are pytket extension modules which allow pytket to interface with quantum devices and simulators. Some extensions also provide interoperability with other software libraries such as qiskit, cirq and pennylane.

For a list of available pytket extensions see theextensions index page.

These extensions are installed as separate python packages and the source code for each extension lives in its own github repository.

How to build TKET and pytket

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 ofpybind11to link to the tket shared library) and pure Python code that defines abstract interfaces used by the extension modules such as theBackendandBackendResultclasses, as well as various other utilities.

Prerequisites

Build tools

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

  • Linux: gcc-13
  • MacOS: apple-clang 15
  • 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 settingCCandCXXin your environment (e.g.CC=gcc-11andCXX=g++-11), or on Debian-based Linux systems usingupdate-alternatives.

You should also have Python (3.10, 3.11, 3.12 or 3.13) andpipinstalled. We usecmakeand the package managerconanto build tket and pytket. The latter can be installed withpip:

pip install conan

You will need at least cmake version 3.26, and conan version 2.

Set upconanprofile

Generate a profile that matches your current machine, and add the required remote where some dependencies are stored:

conan profile detect
conan remote add tket-libs https://quantinuumsw.jfrog.io/artifactory/api/conan/tket1-libs --index 0

Optional: useninjaandccache

It is recommended that you also installninjaandccacheto speed up the build process. For example withapton Debian/Ubuntu:

apt install ninja-build ccache

Homebrew on MacOS/Linux:

brew install ninja ccache

Chocolatey on Windows:

choco install ninja ccache

On MacOS/Linux:

  • If installed,ccacheis used automatically
  • ninjamust either be set as the default Cmake generator using the following command:
    echo"tools.cmake.cmaketoolchain:generator = Ninja">>$(conan config home)/global.conf
    or be specified on a command-by-command basis by providing the argument -c tools.cmake.cmaketoolchain:generator=Ninjato conan

On Windows:

  • Setninjaas generator as described above (less reliable than the defaultVisual Studiogenerator)
  • ccachewill be used automaticallyonlywhen usingNinjaorMakefileas the Cmake generator. It can also be used withVisual Studiogenerators by setting the environment variableTKET_VSGEN_CCACHE_EXEto the path of theccacheexecutable.Note: this must be the path to the actual binary, not a symlink or shim (as used by Chocolatey).If using Chocolatey to installccache,you can find the path to the binary usingccache --shimgen-help

Building and testing the utility libraries

See theREADMEin thelibsdirectory for instructions on building and testing the utility libraries used by tket (for logging, random-number generation and so on). This is not necessary if you just want to build tket or pytket since the recipes or binaries will be automatically downloaded from the above conan remote.

Building and testing the tket library

See theREADMEin thetketdirectory for instructions on building and testing tket as a standalone C++ library.

Building and testing pytket

See theREADMEin thepytketdirectory for instructions on building and testing pytket.

Nix Support

Tket and pytket are available as a Nix flake, with support for Linux and Apple Silicon systems. See theREADMEin thenix-supportdirectory for instructions on building and testing tket and pytket through Nix, and on how to use it within a Nix project.

To launch into a tket environment, you can use

nix develop github:CQCL/tket

We use Cachix to cache pre-built artifacts, which provides a faster install time for nix users. To make use of this cache, enable our cachix substituter withcachix use tket,or enter a tket nix environment from a trusted user and confirm the use of the tket.cachix.org substituter.