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 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
pybind11to link to the tket shared library) and pure Python code that defines abstract interfaces used by the extension modules such as the
BackendResultclasses, as well as various other utilities.
How to build tket and pytket
The following compiler toolchains are used to build tket on the CI and are therefore known to work:
- Linux: gcc-10
- MacOS: apple-clang 13
- 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
CXX in your environment (e.g.
CXX=g++-10), or on Debian-based Linux systems using
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 install cmake conan
It is recommended that you also install
ccache to speed up the build process. For example on Debian/Ubuntu:
sudo apt install ninja-build ccache
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
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
There is a known issue with using
pybind11 from the
conan-center that can lead to a Python crash when importing
pytket. To remedy this,
pybind11 must be installed from the local recipe:
conan remove -f pybind11/* conan create --profile=tket recipes/pybind11
where the first line serves to remove any version already installed.
symengine dependency is built from a local conan recipe. Run:
conan create --profile=tket recipes/symengine
to build it.
At this point you can run:
conan create --profile=tket recipes/tket
to build the tket library.
Note: by default,
tket uses the header-only version of
spdlog. This avoids an issue with an undefined symbol when run in some Linux virtual environments, but makes builds slower. For faster local builds you can supply the option
-o tket:spdlog_ho=False to the above
conan create command.
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, first install the
conan create --profile=tket recipes/pybind11
Then build the pytket module:
cd pytket pip install -e .
And then to run the Python tests:
cd tests pytest
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.
To install dependencies:
conan install recipes/tket --install-folder=build --profile=tket --build=missing
To configure the build:
conan build recipes/tket --configure --build-folder=build --source-folder=tket/src
conan build recipes/tket --build --build-folder=build
To export to
conancache (necessary to build pytket):
conan export-pkg recipes/tket -f --build-folder=build --source-folder=tket/src
The code coverage of the
tket tests is reported here. This report is generated weekly from the
tket (C++) API documentation (generated with
doxygen, and still rather patchy) is available here.
pytket (Python) API documentation is available here.